Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 1441

Correct implementation of ComputeCartesianPath to move end actuator in a straight line?

$
0
0
Hello everyone. I'm quite new to ROS, doing a practicum project right now and have been pretty stumped with this for a few days. I have a TIAGo Robot, with a 6DOF arm with whom I want to be able to move on a straight line. The "straight" part is important as we'll be having a pressure sensor on the fingertip with which we want to do "feeling" of surfaces, so we need to be able to move it on a straight line (maintaining orientation of it) on the XY plane. So I've been basically doing some frankencode because while I'm familiar with C++, I'm not with ROS and MoveIt!; and been piecing something together from a basic code in the [TIAGo tutorials](http://wiki.ros.org/Robots/TIAGo/Tutorials/MoveIt/Planning_cartesian_space) that moves the actuator to a cartesian point and orientation (but not necessarily in a straight line) and the [moveit tutorial](http://docs.ros.org/indigo/api/moveit_tutorials/html/doc/pr2_tutorials/planning/src/doc/move_group_interface_tutorial.html#cartesian-paths) that deals with Cartesian path. Current code: /* * Software License Agreement (Modified BSD License) * * Copyright (c) 2016, PAL Robotics, S.L. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of PAL Robotics, S.L. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** \author Jordi Pages. */ // ROS headers #include #include "shape_msgs/SolidPrimitive.h" #include "moveit_msgs/BoundingVolume.h" // MoveIt! headers #include //#include // Std C++ headers #include #include #include #include int main(int argc, char** argv) { ros::init(argc, argv, "plan_arm_torso_ik_idril"); if ( argc < 7 ) { ROS_INFO(" "); ROS_INFO("\tUsage:"); ROS_INFO(" "); ROS_INFO("\trosrun tiago_moveit_tutorial plan_arm_torso_ik_idril x y z r p y"); ROS_INFO(" "); ROS_INFO("\twhere the list of arguments specify the target pose of /arm_tool_link expressed in /base_footprint"); ROS_INFO(" "); return EXIT_FAILURE; } geometry_msgs::PoseStamped goal_pose; goal_pose.header.frame_id = "base_footprint"; goal_pose.pose.position.x = atof(argv[1]); goal_pose.pose.position.y = atof(argv[2]); goal_pose.pose.position.z = atof(argv[3]); goal_pose.pose.orientation = tf::createQuaternionMsgFromRollPitchYaw(atof(argv[4]), atof(argv[5]), atof(argv[6])); ros::NodeHandle nh; ros::AsyncSpinner spinner(1); spinner.start(); std::vector torso_arm_joint_names; //select group of joints moveit::planning_interface::MoveGroupInterface group_arm_torso("arm_torso"); const robot_state::JointModelGroup* joint_model_group = group_arm_torso.getCurrentState()->getJointModelGroup("arm_torso"); //choose your preferred planner group_arm_torso.setPlannerId("SBLkConfigDefault"); group_arm_torso.setPoseReferenceFrame("base_footprint"); group_arm_torso.setPoseTarget(goal_pose); ROS_INFO_STREAM("Planning to move" << group_arm_torso.getEndEffectorLink() << " to a target pose expressed in " << group_arm_torso.getPlanningFrame()); group_arm_torso.setStartStateToCurrentState(); group_arm_torso.setMaxVelocityScalingFactor(1.0); // Getting Basic Information // ^^^^^^^^^^^^^^^^^^^^^^^^^ // // We can print the name of the reference frame for this robot. ROS_INFO_NAMED("tutorial", "Reference frame: %s", group_arm_torso.getPlanningFrame().c_str()); // We can also print the name of the end-effector link for this group. ROS_INFO_NAMED("tutorial", "End effector link: %s", group_arm_torso.getEndEffectorLink().c_str()); // Planning with Path Constraints // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // // Path constraints can easily be specified for a link on the robot. straight line // Let's specify a path constraint and a pose goal for our group. // First define the path constraint. ROS_INFO_STREAM("Calculating Restrictions"); geometry_msgs::PoseStamped start_pose; start_pose.header.frame_id = "base_footprint"; start_pose.pose = group_arm_torso.getCurrentPose().pose; geometry_msgs::PoseStamped vector_direccional; vector_direccional.pose.position.x = goal_pose.pose.position.x - start_pose.pose.position.x; vector_direccional.pose.position.y = goal_pose.pose.position.y - start_pose.pose.position.y; vector_direccional.pose.position.z = goal_pose.pose.position.z - start_pose.pose.position.z; double dist = sqrt(pow(vector_direccional.pose.position.x,2) + pow(vector_direccional.pose.position.y, 2) + pow(vector_direccional.pose.position.z,2)); ROS_INFO_STREAM("Calculated directional vector: " << vector_direccional.pose.position << "Start and goal points are at distance: " << dist); moveit_msgs::OrientationConstraint ocm; ocm.link_name = "arm_tool_link"; ocm.header.frame_id = "base_footprint"; ocm.orientation = group_arm_torso.getCurrentPose().pose.orientation; ocm.absolute_x_axis_tolerance = 0.1; ocm.absolute_y_axis_tolerance = 0.1; ocm.absolute_z_axis_tolerance = 0.1; ocm.weight = 1.0; ROS_INFO_STREAM("Calculated Orientation Constraint"); moveit_msgs::Constraints test_constraints; test_constraints.orientation_constraints.push_back(ocm); group_arm_torso.setPathConstraints(test_constraints); ROS_INFO_STREAM("Constraints set"); //Cartesian Path std::vector waypoints; waypoints.push_back(start_pose); waypoints.push_back(goal_pose); } moveit_msgs::RobotTrajectory trajectory; const double jump_threshold = 100; const double eef_step = dist; double fraction = 0; double old_jump_threshold = jump_threshold; double old_eef_step = eef_step; double good_jump_threshold = jump_threshold; double good_eef_step = eef_step; double good_fraction = fraction; //This loop is only to check how eef_step and jump_treshold affect the outcome. for(int i = 1; i <= 300; ++i){ for(int j = 1; j <= 1000; ++j){ fraction = group_arm_torso.computeCartesianPath(waypoints, eef_step/i, jump_threshold/j, trajectory, true); if (fraction < 0.15) break; if (fraction > good_fraction){ ROS_INFO_STREAM("Found better parameters: " << good_fraction* 100.0 << '%' << " ==> " << fraction * 100.0 << '%' << ":"); ROS_INFO_STREAM("eef " << old_eef_step << " ==> " << good_eef_step); ROS_INFO_STREAM("jump " << old_jump_threshold << " ==> " << good_jump_threshold); good_fraction = fraction; old_eef_step = good_eef_step; old_jump_threshold = good_jump_threshold; good_eef_step = eef_step/i; good_jump_threshold = jump_threshold/j; } if (fraction == 1) break; } if (fraction == 1) break; } if (fraction == 1) ROS_INFO_NAMED("tutorial", "Visualizing plan 4 (Cartesian path) (%.2f%% achieved)", fraction * 100.0); else{ fraction = group_arm_torso.computeCartesianPath(waypoints, good_eef_step, good_jump_threshold, trajectory, true); ROS_INFO_NAMED("tutorial", "Best I could do was (%.2f%% achieved)", fraction * 100.0); ROS_INFO_STREAM("With eef = " << good_eef_step << ", jump = " << good_jump_threshold); } moveit::planning_interface::MoveGroupInterface::Plan my_plan; //set maximum time to find a plan ROS_INFO_STREAM("Finding Plan..."); group_arm_torso.setPlanningTime(20.0); bool success = bool(group_arm_torso.plan(my_plan)); if ( !success ) throw std::runtime_error("No plan found"); ROS_INFO_STREAM("Plan found in " << my_plan.planning_time_ << " seconds"); // Execute the plan ros::Time start = ros::Time::now(); moveit::planning_interface::MoveItErrorCode e = group_arm_torso.move(); if (!bool(e)) throw std::runtime_error("Error executing plan"); ROS_INFO_STREAM("Motion duration: " << (ros::Time::now() - start).toSec()); group_arm_torso.clearPathConstraints(); spinner.stop(); return EXIT_SUCCESS; } I realise that it's probably just a newbie error somewhere but I've been scouring the forums about the ComputeCartesianPath() function and I don't really get how it works. Sometimes it returns 100% but the path comes out clearly curved, other times it's 0% but the path is visually straight. To add to this, is there a way to "compare" the outcome of the planned (executed) path to the "perfect" path? To make sure it's actually straight and have a number that gives me the error. Thank you very much for your help

Viewing all articles
Browse latest Browse all 1441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>