ROS 编译 moveit::planning_interface::MoveItErrorCode to bool 错误

ROS 编译 moveit::planning_interface::MoveItErrorCode to bool 错误

flyfish

环境 Ubuntu 16.04 ,ROS Kinetic

错误信息如下

/home/pumpkinking/catkin_ws/src/pick-place-robot/kuka_arm/src/trajectory_sampler.cpp: In constructor ‘TrajectorySampler::TrajectorySampler(ros::NodeHandle)’:
/home/pumpkinking/catkin_ws/src/pick-place-robot/kuka_arm/src/trajectory_sampler.cpp:180:43: error: cannot convert ‘moveit::planning_interface::MoveItErrorCode’ to ‘bool’ in initialization
     bool success = move_group.plan(my_plan);

查看MoveIt代码

namespace moveit_msgs
{
template <class ContainerAllocator>
struct MoveItErrorCodes_
{
  typedef MoveItErrorCodes_<ContainerAllocator> Type;

  MoveItErrorCodes_()
    : val(0)  {
    }
  MoveItErrorCodes_(const ContainerAllocator& _alloc)
    : val(0)  {
  (void)_alloc;
    }



   typedef int32_t _val_type;
  _val_type val;



  enum {
    SUCCESS = 1,
    FAILURE = 99999,
    PLANNING_FAILED = -1,
    INVALID_MOTION_PLAN = -2,
    MOTION_PLAN_INVALIDATED_BY_ENVIRONMENT_CHANGE = -3,
    CONTROL_FAILED = -4,
    UNABLE_TO_AQUIRE_SENSOR_DATA = -5,
    TIMED_OUT = -6,
    PREEMPTED = -7,
    START_STATE_IN_COLLISION = -10,
    START_STATE_VIOLATES_PATH_CONSTRAINTS = -11,
    GOAL_IN_COLLISION = -12,
    GOAL_VIOLATES_PATH_CONSTRAINTS = -13,
    GOAL_CONSTRAINTS_VIOLATED = -14,
    INVALID_GROUP_NAME = -15,
    INVALID_GOAL_CONSTRAINTS = -16,
    INVALID_ROBOT_STATE = -17,
    INVALID_LINK_NAME = -18,
    INVALID_OBJECT_NAME = -19,
    FRAME_TRANSFORM_FAILURE = -21,
    COLLISION_CHECKING_UNAVAILABLE = -22,
    ROBOT_STATE_STALE = -23,
    SENSOR_INFO_STALE = -24,
    NO_IK_SOLUTION = -31,
  };


  typedef boost::shared_ptr< ::moveit_msgs::MoveItErrorCodes_<ContainerAllocator> > Ptr;
  typedef boost::shared_ptr< ::moveit_msgs::MoveItErrorCodes_<ContainerAllocator> const> ConstPtr;

}; // struct MoveItErrorCodes_

typedef ::moveit_msgs::MoveItErrorCodes_<std::allocator<void> > MoveItErrorCodes;

typedef boost::shared_ptr< ::moveit_msgs::MoveItErrorCodes > MoveItErrorCodesPtr;
typedef boost::shared_ptr< ::moveit_msgs::MoveItErrorCodes const> MoveItErrorCodesConstPtr;

所以兼容性代码可以这样写
最简单的写法

 bool success = move_group_->move() == moveit::planning_interface::MoveItErrorCode::SUCCESS;

或者复杂写法 可以输出多种错误类型

moveit::planning_interface::MoveItErrorCode r=move_group_->move() 
r.val判断是否是moveit::planning_interface::MoveItErrorCode::SUCCESS 值是1
好的,将move_group节点封装为一个ROS Service的步骤如下: 1. 首先,在ROS工作空间中创建一个新的ROS包,例如"move_group_service"。 2. 在该ROS包下创建一个名为"src"的文件夹,并在该文件夹下创建一个名为"move_group_service.cpp"的源文件。 3. 在move_group_service.cpp文件中,包含以下头文件: ```cpp #include <ros/ros.h> #include <moveit/move_group_interface/move_group_interface.h> #include <moveit_msgs/MoveGroupAction.h> #include <actionlib/client/simple_action_client.h> #include <moveit_msgs/ExecuteTrajectoryAction.h> #include <moveit_msgs/RobotTrajectory.h> #include <moveit_msgs/RobotState.h> #include <moveit_msgs/PlanningScene.h> #include <moveit/planning_scene_interface/planning_scene_interface.h> #include <moveit/robot_state/conversions.h> #include <moveit/trajectory_processing/iterative_time_parameterization.h> #include <moveit/kinematic_constraints/utils.h> ``` 4. 创建一个ROS Service,它将接收一个请求,其中包含要执行的运动规划的目标姿态和机器人的名称等信息。在move_group_service.cpp文件中,定义如下的ROS Service: ```cpp bool move_group_callback(moveit_msgs::MoveGroup::Request& req, moveit_msgs::MoveGroup::Response& res) { static ros::NodeHandle nh; static const std::string PLANNING_GROUP = "manipulator"; static moveit::planning_interface::MoveGroupInterface move_group(PLANNING_GROUP); static moveit::planning_interface::PlanningSceneInterface planning_scene_interface; moveit::planning_interface::MoveGroupInterface::Plan my_plan; move_group.setPlannerId("RRTConnectkConfigDefault"); move_group.setPoseReferenceFrame("base_link"); move_group.setStartStateToCurrentState(); geometry_msgs::Pose target_pose; target_pose.orientation.w = req.target_pose.orientation.w; target_pose.orientation.x = req.target_pose.orientation.x; target_pose.orientation.y = req.target_pose.orientation.y; target_pose.orientation.z = req.target_pose.orientation.z; target_pose.position.x = req.target_pose.position.x; target_pose.position.y = req.target_pose.position.y; target_pose.position.z = req.target_pose.position.z; move_group.setPoseTarget(target_pose); bool success = move_group.plan(my_plan); if (success) { res.success = true; move_group.move(); } else { ROS_ERROR("Failed to plan"); res.success = false; } return true; } ``` 5. 在main函数中,创建ROS节点和move_group服务,并将ROS Service注册到ROS Master上: ```cpp int main(int argc, char** argv) { ros::init(argc, argv, "move_group_service"); ros::NodeHandle nh; ros::ServiceServer service = nh.advertiseService("/move_group_service", move_group_callback); ROS_INFO("Ready to receive move_group requests"); ros::spin(); } ``` 6. 编译ROS包并运行ROS节点: ```bash $ catkin_make $ roscore $ rosrun move_group_service move_group_service ``` 7. 使用ROS Service测试move_group_service节点: ```bash $ rosservice call /move_group_service "target_pose: position: x: 0.5 y: 0.0 z: 0.5 orientation: w: 1.0 x: 0.0 y: 0.0 z: 0.0" ``` 这个ROS Service将使用move_group节点规划机器人的运动轨迹,使机器人移动到目标姿态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西笑生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值