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