Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "descartes_utilities/ros_conversions.h"
00026 #include <algorithm>
00027 #include <console_bridge/console.h>
00028
00035 static double minTime(const std::vector<double>& pose_a, const std::vector<double>& pose_b, double max_vel)
00036 {
00037 std::vector<double> diff;
00038 diff.reserve(pose_a.size());
00039
00040
00041
00042 std::transform(pose_a.begin(), pose_a.end(), pose_b.begin(), std::back_inserter(diff), [max_vel](double a, double b)
00043 {
00044 return std::abs(a - b) / max_vel;
00045 });
00046
00047 return *std::max_element(diff.begin(), diff.end());
00048 }
00049
00050 bool descartes_utilities::toRosJointPoints(const descartes_core::RobotModel& model,
00051 const std::vector<descartes_core::TrajectoryPtPtr>& joint_traj,
00052 double default_joint_vel,
00053 std::vector<trajectory_msgs::JointTrajectoryPoint>& out)
00054 {
00055 if (default_joint_vel <= 0.0)
00056 {
00057 logError("%s: Invalid value for default joint velocity. Must be > 0 (radians/second)", __FUNCTION__);
00058 return false;
00059 }
00060
00061 const static double max_default_joint_velocity = 100.0;
00062 if (default_joint_vel > max_default_joint_velocity)
00063 {
00064 logError("%s: Default joint velocity of %f exceeds assumed limit of %f.", __FUNCTION__, default_joint_vel,
00065 max_default_joint_velocity);
00066 return false;
00067 }
00068
00069 ros::Duration from_start(0.0);
00070 std::vector<trajectory_msgs::JointTrajectoryPoint> ros_trajectory;
00071 ros_trajectory.reserve(joint_traj.size());
00072
00073 std::vector<double> joint_point;
00074 std::vector<double> dummy;
00075
00076 for (std::size_t i = 0; i < joint_traj.size(); ++i)
00077 {
00078 if (!joint_traj[i])
00079 {
00080 logError("%s: Input trajectory contained null pointer at index %lu", __FUNCTION__, static_cast<unsigned long>(i));
00081 return false;
00082 }
00083
00084 descartes_core::TrajectoryPt& pt = *joint_traj[i];
00085
00086 if (!pt.getNominalJointPose(dummy, model, joint_point))
00087 {
00088 logError("%s: Failed to extract joint positions from input trajectory at index %lu", __FUNCTION__,
00089 static_cast<unsigned long>(i));
00090 return false;
00091 }
00092
00093 trajectory_msgs::JointTrajectoryPoint ros_pt;
00094 ros_pt.positions = joint_point;
00095
00096 ros_pt.velocities.resize(joint_point.size(), 0.0);
00097 ros_pt.accelerations.resize(joint_point.size(), 0.0);
00098 ros_pt.effort.resize(joint_point.size(), 0.0);
00099
00100 if (pt.getTiming().isSpecified())
00101 {
00102 from_start += ros::Duration(pt.getTiming().upper);
00103 }
00104 else
00105 {
00106
00107
00108 double dt;
00109 if (i == 0)
00110 dt = 0.0;
00111 else
00112 dt = minTime(joint_point, ros_trajectory.back().positions, default_joint_vel);
00113
00114 from_start += ros::Duration(dt);
00115 }
00116
00117 ros_pt.time_from_start = from_start;
00118 ros_trajectory.push_back(ros_pt);
00119 }
00120
00121 out = ros_trajectory;
00122 return true;
00123 }