@@ -484,8 +484,67 @@ RobotTrajectory& RobotTrajectory::setRobotTrajectoryMsg(const moveit::core::Robo
484484 {
485485 for (std::size_t j = 0 ; j < trajectory.multi_dof_joint_trajectory .joint_names .size (); ++j)
486486 {
487+ const auto & joint_name = trajectory.multi_dof_joint_trajectory .joint_names [j];
487488 Eigen::Isometry3d t = tf2::transformToEigen (trajectory.multi_dof_joint_trajectory .points [i].transforms [j]);
488- st->setJointPositions (trajectory.multi_dof_joint_trajectory .joint_names [j], t);
489+ st->setJointPositions (joint_name, t);
490+
491+ if (!trajectory.multi_dof_joint_trajectory .points [i].velocities .empty ())
492+ {
493+ // Note: angular x and y are not currently supported
494+ const auto names = st->getVariableNames ();
495+
496+ for (const auto & name : names)
497+ {
498+ if (name.find (" /x" ) != std::string::npos)
499+ {
500+ st->setVariableVelocity (joint_name + " /x" ,
501+ trajectory.multi_dof_joint_trajectory .points [i].velocities [j].linear .x );
502+ }
503+ else if (name.find (" /y" ) != std::string::npos)
504+ {
505+ st->setVariableVelocity (joint_name + " /y" ,
506+ trajectory.multi_dof_joint_trajectory .points [i].velocities [j].linear .y );
507+ }
508+ else if (name.find (" /z" ) != std::string::npos)
509+ {
510+ st->setVariableVelocity (joint_name + " /z" ,
511+ trajectory.multi_dof_joint_trajectory .points [i].velocities [j].linear .z );
512+ }
513+ else if (name.find (" /theta" ) != std::string::npos)
514+ {
515+ st->setVariableVelocity (joint_name + " /theta" ,
516+ trajectory.multi_dof_joint_trajectory .points [i].velocities [j].angular .z );
517+ }
518+ }
519+ }
520+ if (!trajectory.multi_dof_joint_trajectory .points [i].accelerations .empty ())
521+ {
522+ // Note: angular x and y are not currently supported
523+ const auto names = st->getVariableNames ();
524+ for (const auto & name : names)
525+ {
526+ if (name.find (" /x" ) != std::string::npos)
527+ {
528+ st->setVariableAcceleration (joint_name + " /x" ,
529+ trajectory.multi_dof_joint_trajectory .points [i].accelerations [j].linear .x );
530+ }
531+ else if (name.find (" /y" ) != std::string::npos)
532+ {
533+ st->setVariableAcceleration (joint_name + " /y" ,
534+ trajectory.multi_dof_joint_trajectory .points [i].accelerations [j].linear .y );
535+ }
536+ else if (name.find (" /z" ) != std::string::npos)
537+ {
538+ st->setVariableAcceleration (joint_name + " /z" ,
539+ trajectory.multi_dof_joint_trajectory .points [i].accelerations [j].linear .z );
540+ }
541+ else if (name.find (" /theta" ) != std::string::npos)
542+ {
543+ st->setVariableAcceleration (joint_name + " /theta" ,
544+ trajectory.multi_dof_joint_trajectory .points [i].accelerations [j].angular .z );
545+ }
546+ }
547+ }
489548 }
490549 this_time_stamp = rclcpp::Time (trajectory.multi_dof_joint_trajectory .header .stamp ) +
491550 trajectory.multi_dof_joint_trajectory .points [i].time_from_start ;
@@ -509,7 +568,7 @@ RobotTrajectory& RobotTrajectory::setRobotTrajectoryMsg(const moveit::core::Robo
509568void RobotTrajectory::findWayPointIndicesForDurationAfterStart (double duration, int & before, int & after,
510569 double & blend) const
511570{
512- if (duration < 0.0 )
571+ if (duration < 0.0 || waypoints_. empty () )
513572 {
514573 before = 0 ;
515574 after = 0 ;
@@ -522,22 +581,22 @@ void RobotTrajectory::findWayPointIndicesForDurationAfterStart(double duration,
522581 double running_duration = 0.0 ;
523582 for (; index < num_points; ++index)
524583 {
525- running_duration += duration_from_previous_[ index] ;
584+ running_duration += duration_from_previous_. at ( index) ;
526585 if (running_duration >= duration)
527586 break ;
528587 }
529588 before = std::max<int >(index - 1 , 0 );
530589 after = std::min<int >(index, num_points - 1 );
531590
532591 // Compute duration blend
533- double before_time = running_duration - duration_from_previous_[index];
534592 if (after == before)
535593 {
536594 blend = 1.0 ;
537595 }
538596 else
539597 {
540- blend = (duration - before_time) / duration_from_previous_[index];
598+ double before_time = running_duration - duration_from_previous_.at (index);
599+ blend = (duration - before_time) / duration_from_previous_.at (index);
541600 }
542601}
543602
0 commit comments