Straight line in moveit
I have been working for several months with a 6gdl arm in Moveit2 in ROS" Foxy. I have not been able to accomplish a seemingly simple task. I need to make a straight line between two known points (both with the same orientation). I have tried OMPL Constrained Planning( boxes and orientation) and generate cartesain paths. All to no avail. I am desperate, has anyone worked with moveit before and would know how to tackle this, seemingly, simple problem?
I have a simple function that interpolates points between two given points:
std::vector<geometry_msgs::msg::Pose> RobotArmNode::interpolatePoses(const geometry_msgs::msg::PoseStamped& pose1,
const geometry_msgs::msg::PoseStamped& pose2,
double separation_distance)
{
std::vector<geometry_msgs::msg::Pose> interpolated_poses;
// Calculate the linear interpolation between pose1 and pose2
// based on the separation_distance
// Calculate the direction vector from pose1 to pose2
double dx = pose2.pose.position.x - pose1.pose.position.x;
double dy = pose2.pose.position.y - pose1.pose.position.y;
double dz = pose2.pose.position.z - pose1.pose.position.z;
// Calculate the distance between pose1 and pose2
double distance = std::sqrt(dx*dx + dy*dy + dz*dz);
// Calculate the number of interpolation points
int num_points = static_cast<int>(std::ceil(distance / separation_distance));
// Calculate the step size for each interpolation point
double step_size = distance / num_points;
// Interpolate the points and add them to the vector
for (int i = 0; i <= num_points; ++i)
{
double t = static_cast<double>(i) / num_points;
geometry_msgs::msg::Pose interpolated_pose;
interpolated_pose.position.x = pose1.pose.position.x + t * dx;
interpolated_pose.position.y = pose1.pose.position.y + t * dy;
interpolated_pose.position.z = pose1.pose.position.z + t * dz;
// Add the interpolated pose to the vector
interpolated_poses.push_back(interpolated_pose);
}
return interpolated_poses;
}
I use these points in the computecartesianpath method:
waypoints = interpolatePoses(pose_40_, pose_20_, 0.05);
fraction_ = move_group_.computeCartesianPath(waypoints, 10.0, 0.01, trajectory);
RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "Visualizing plan 4 (Cartesian path) (%.2f%% achieved)", fraction_ * 100.0);
Finally, I scale the speed of the trajectory and execute it: r_trajec = std::make_shared<robot_trajectory::robottrajectory>(move_group_.getRobotModel(), "handlerbot_arm");
r_trajec->setRobotTrajectoryMsg(*move_group_.getCurrentState(), trajectory);
iptp.computeTimeStamps(*r_trajec, 1, 1);
r_trajec->getRobotTrajectoryMsg(trajectory);
iptp.computeTimeStamps(*r_trajec, 0.03, 0.03);
r_trajec->getRobotTrajectoryMsg(trajectory_slow);
RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "VOY A SLOW");
move_group_.execute(trajectory_slow);
RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "SALDO DE SLOW");
La función de interpolación ha sido un añadido para probar a ver si se solucionaba el problema, inicialmente utilicé 2 waypoints directamente en ComputeCartesianPath y no funcionaba. I have also tested various Jump Threshold values.
The problem is that ComputeCartesianPath returns a fraction of 0. When I enter the interpolated points (plus points) it returns values of 20%. The path is perfectly achievable.