Move Group C++ Interface 遇到的问题

问题一:

问题描述:

Rviz终端显示信息:

[ERROR] [1680517834.059111587]: 
Invalid Trajectory: start point deviates from current robot state more than 0.01
joint 'panda_joint1': expected: -1.63258, current: 0

Moveit终端显示信息:

[ INFO] [1680517834.059803588]: ABORTED: CONTROL_FAILED

出现问题的原因:

move_group_interface_tutorial.cpp第324行:

 // You can execute a trajectory like this.
// move_group_interface.execute(trajectory);

原代码中,在轨迹规划完成后,对规划轨迹进行执行,导致机器人位置发生变化,导致机器人当前位置和开始点出现偏差。

因此可以将move_group_interface.execute(trajectory)注释掉,即可避免该问题出现。

问题二:

问题描述:

Rviz终端显示信息:[ WARN] [1680518036.897648660]: Unable to find a valid state nearby the start state (using jiggle fraction of 0.050000 and 100 sampling attempts).

Moveit终端显示信息:

[ WARN] [1680518036.897928719]: Fail: ABORTED: START_STATE_IN_COLLISION
[ INFO] [1680518036.897957642]: Visualizing plan 7 (move around cuboid with cylinder) FAILED

出现问题的原因:move_group_interface.attachObject()函数需要三个变量,被夹持物体,机械臂,接触物体的机械臂,原代码中:move_group_interface.attachObject(object_to_attach.id, "panda_hand");只有两个参数(重构函数中有仅需前两个参数,在函数中生成第三个变量的形式,但是运行报错),因此对此段代码进行修改(参考moveit2该):

 //新增内容
  
  std::vector<std::string> touch_links;
  touch_links = { "panda_leftfinger", "panda_rightfinger" };

  //修改内容
  move_group_interface.attachObject(object_to_attach.id, "panda_hand",touch_links);

上述两个地方修改完成后返回ws_catkin根目录,运行catkin_make。
  

小tip:如果执行该程序时,机械臂重复执行,将Planed_Path  - Loop Animation取消勾选即可。此选项是重复执行。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,将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
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值