首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在C++ (和MoveIt API)上作为参数传递成员函数的std::bind时遇到的问题

在C++ (和MoveIt API)上作为参数传递成员函数的std::bind时遇到的问题
EN

Stack Overflow用户
提问于 2019-02-08 14:30:32
回答 1查看 269关注 0票数 0

日安,

注意:虽然这是一个与ROS相关的问题,但我在这里发布它,因为我确信我的问题是C++而不是ROS。

我正在尝试使用在setFromIK上定义的函数moveit::核心::RobotState

该函数接受一个名为GroupStateValidityCallbackFn的可调用参数,其类型为(函数签名):

typedef boost::function

问题的出现是因为我试图将一个成员类函数传递给这个参数(因为我需要处理中的来类实例成员字段),然后绑定过程就会变成地狱。

我们班的样子是这样的:

代码语言:javascript
复制
class CSDA10F{
    public:
       bool validateIKSolution( robot_state::RobotState* robot_state, 
                                        const robot_state::JointModelGroup* joint_group, 
                                        const double* joint_group_variable_value){
              [...]
              // some code here
              [...]
          }

       bool planCartesianMotionTask(MoveGroupInterface* move_group, 
                                                    geometry_msgs::Pose initial_pose, 
                                                    geometry_msgs::Pose final_pose,
                                                    std::vector<MoveGroupInterface::Plan> motion_plans,
                                                    uint max_configurations = 10) {
         [...] // Here I make the call!!!.
            auto ik_check_callback = std::bind(&CSDA10F::validateIKSolution, this, _1, _2, _3);
            ik_solution_found = start_state.setFromIK( joint_model_group, initial_pose, 10, 0.01, ik_check_callback);
         [...]
         }

对于函数中的3个参数,我使用了3个占位符,但是编译器出现了一个我根本不理解的错误。

代码语言:javascript
复制
In file included from /usr/include/boost/function/detail/maybe_include.hpp:28:0,
                 from /usr/include/boost/function/detail/function_iterate.hpp:14,
                 from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:62,
                 from /usr/include/boost/function.hpp:64,
                 from /opt/ros/kinetic/include/ros/forwards.h:40,
                 from /opt/ros/kinetic/include/ros/common.h:37,
                 from /opt/ros/kinetic/include/ros/ros.h:43,
                 from /home/invite/catkin_ws/src/invite-robotics/drum_automation/src/bag_handling.cpp:1:
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static R boost::detail::function::function_obj_invoker3<FunctionObj, R, T0, T1, T2>::invoke(boost::detail::function::function_buffer&, T0, T1, T2) [with FunctionObj = std::_Bind<std::_Mem_fn<bool (invite_utils::CSDA10F::*)(moveit::core::RobotState*, const moveit::core::JointModelGroup*, const double*)>(invite_utils::CSDA10F, boost::arg<1>, boost::arg<2>, boost::arg<3>)>; R = bool; T0 = moveit::core::RobotState*; T1 = const moveit::core::JointModelGroup*; T2 = const double*]’:
/usr/include/boost/function/function_template.hpp:940:38:   required from ‘void boost::function3<R, T1, T2, T3>::assign_to(Functor) [with Functor = std::_Bind<std::_Mem_fn<bool (invite_utils::CSDA10F::*)(moveit::core::RobotState*, const moveit::core::JointModelGroup*, const double*)>(invite_utils::CSDA10F, boost::arg<1>, boost::arg<2>, boost::arg<3>)>; R = bool; T0 = moveit::core::RobotState*; T1 = const moveit::core::JointModelGroup*; T2 = const double*]’
/usr/include/boost/function/function_template.hpp:728:7:   required from ‘boost::function3<R, T1, T2, T3>::function3(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = std::_Bind<std::_Mem_fn<bool (invite_utils::CSDA10F::*)(moveit::core::RobotState*, const moveit::core::JointModelGroup*, const double*)>(invite_utils::CSDA10F, boost::arg<1>, boost::arg<2>, boost::arg<3>)>; R = bool; T0 = moveit::core::RobotState*; T1 = const moveit::core::JointModelGroup*; T2 = const double*; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/usr/include/boost/function/function_template.hpp:1077:16:   required from ‘boost::function<R(T0, T1, T2)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = std::_Bind<std::_Mem_fn<bool (invite_utils::CSDA10F::*)(moveit::core::RobotState*, const moveit::core::JointModelGroup*, const double*)>(invite_utils::CSDA10F, boost::arg<1>, boost::arg<2>, boost::arg<3>)>; R = bool; T0 = moveit::core::RobotState*; T1 = const moveit::core::JointModelGroup*; T2 = const double*; typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
/home/invite/catkin_ws/src/invite-robotics/invite_utils/include/invite_utils/csda10f_interface.h:202:116:   required from here
/usr/include/boost/function/function_template.hpp:138:22: error: no match for call to ‘(std::_Bind<std::_Mem_fn<bool (invite_utils::CSDA10F::*)(moveit::core::RobotState*, const moveit::core::JointModelGroup*, const double*)>(invite_utils::CSDA10F, boost::arg<1>, boost::arg<2>, boost::arg<3>)>) (moveit::core::RobotState*, const moveit::core::JointModelGroup*, const double*)’
           return (*f)(BOOST_FUNCTION_ARGS);

RobotState上的声明不允许成员函数吗?我认为我在std::bind上犯了一个错误,但我似乎找不到它是什么东西的提供者。

我知道些什么:

  • 我在要绑定的函数中使用正确的参数类型。
  • 我有正确的参数数(3)

有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-08 15:02:15

看起来您正在将Boost _1_2_3占位符与std::bind混合使用。尝试以下方法之一:

  • 切换到boost::bind
  • 在呼叫前添加using std::placeholders;
  • 使用捕获this的lambda表达式。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54594555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档