ROS moveit约束

时间:2015-04-21 16:14:35

标签: c++ ros moveit

我正试图用它来移动它只能垂直移动手臂。我们的想法是保持末端执行器的尖端始终保持x轴和y轴的位置,并在每次迭代中改变z轴位置,同时保持其方向。我还想在每次迭代中约束从开始位置到结束位置的移动以遵循这些约束(x和y固定,z仅改变)。只要抓手(我的末端执行器)只向上移动,我不关心关节变化多少。

我尝试按照下面的说明进行操作,但我没有看到任何限制被遵循?我做错了什么?

int main(int argc, char **argv){

    ros::init(argc, argv, "move_group_interface_tutorial");
    ros::NodeHandle node_handle;
    ros::AsyncSpinner spinner(1);
    spinner.start();


    /* This sleep is ONLY to allow Rviz to come up */
    sleep(20.0);

    moveit::planning_interface::MoveGroup group_r("right_arm");

    robot_state::RobotState start_state(*group_r.getCurrentState());
    geometry_msgs::Pose start_pose;
    start_pose.orientation.x = group_r.getCurrentPose().pose.orientation.x;
    start_pose.orientation.y = group_r.getCurrentPose().pose.orientation.y;
    start_pose.orientation.z = group_r.getCurrentPose().pose.orientation.z;
    start_pose.orientation.w = group_r.getCurrentPose().pose.orientation.w;
    start_pose.position.x = group_r.getCurrentPose().pose.position.x;
    start_pose.position.y = group_r.getCurrentPose().pose.position.y;
    start_pose.position.z = group_r.getCurrentPose().pose.position.z;

    //const robot_state::JointModelGroup *joint_model_group = start_state.getJointModelGroup(group_r.getName());
    //start_state.setFromIK(joint_model_group, start_pose);
    group_r.setStartState(start_state);

    moveit_msgs::OrientationConstraint ocm;

    ocm.link_name = "r_wrist_roll_link";
    ocm.header.frame_id = "base_link";
    ocm.orientation.w = 0.0;
    ocm.absolute_x_axis_tolerance = 0.0;
    ocm.absolute_y_axis_tolerance = 0.0;
    ocm.absolute_z_axis_tolerance = 0.1;
    ocm.weight = 1.0;
    moveit_msgs::Constraints test_constraints;
    test_constraints.orientation_constraints.push_back(ocm);
    group_r.setPathConstraints(test_constraints);



    geometry_msgs::Pose next_pose = start_pose;
    while(1){
        std::vector<geometry_msgs::Pose> waypoints;
        next_pose.position.z -= 0.03;
        waypoints.push_back(next_pose);  // up and out

        moveit_msgs::RobotTrajectory trajectory;
        double fraction = group_r.computeCartesianPath(waypoints, 0.005, 0.0, trajectory);

        /* Sleep to give Rviz time to visualize the plan. */
        sleep(5.0);
    }


}

1 个答案:

答案 0 :(得分:1)

我认为问题出在这个问题上:

i = "1,'Test',NULL,'items (one, two, etc.)',1,'long, list'"



print([ele for ele in map(lambda x:  x.strip(", "), i.split("'")) if ele])

['1', 'Test', 'NULL', 'items (one, two, etc.)', '1', 'long, list']

如果您查看moveit_msgs::OrientationConstraint引用,就会找到该ocm.orientation.w = 0.0; 字段的解释。

orientation

但是,您要将四元数的所有字段设置为0(如果未指定,则假想x,y和z初始化为0),这可能会导致意外行为。

如果您已经跟踪this tutorial,您可能已经看到作者设置# The desired orientation of the robot link specified as a quaternion geometry_msgs/Quaternion orientation 这意味着方向没有变化(即滚动俯仰和偏航角等于0)。因此,请尝试为约束指定逼真的方向。

最后但同样重要的是,为了清楚起见,最简单地写一下ocm.orientation.w = 1.0;初始化:

start_pose