@@ -611,6 +611,17 @@ rclcpp_action::GoalResponse JointTrajectoryController::goal_callback(
611611 " Joints on incoming goal don't match the controller joints." );
612612 return rclcpp_action::GoalResponse::REJECT;
613613 }
614+
615+ std::vector<unsigned int > mapping_vector = mapping (goal->trajectory .joint_names , joint_names_);
616+ if (mapping_vector.empty ())
617+ {
618+ RCLCPP_ERROR (
619+ lifecycle_node_->get_logger (),
620+ " Joints on incoming goal don't match the controller joints." );
621+ return rclcpp_action::GoalResponse::REJECT;
622+ }
623+
624+ goal->trajectory .joint_names .size () != joint_names_.size ();
614625 }
615626
616627 RCLCPP_ERROR (lifecycle_node_->get_logger (), " Accepted new action goal" );
@@ -653,6 +664,38 @@ void JointTrajectoryController::feedback_setup_callback(
653664 rt_active_goal_.reset ();
654665 auto traj_msg = std::make_shared<trajectory_msgs::msg::JointTrajectory>(
655666 goal_handle->get_goal ()->trajectory );
667+
668+ // rearrange all points in the trajectory message based on mapping
669+ std::vector<unsigned int > mapping_vector = mapping (traj_msg->joint_names , joint_names_);
670+ auto remap = [](const std::vector<double >& to_remap, const std::vector<unsigned int >& mapping)
671+ -> std::vector<double >
672+ {
673+ if (to_remap.size () != mapping.size ())
674+ return to_remap;
675+ std::vector<double > output;
676+ output.resize (mapping.size (), 0.0 );
677+ for (auto index = 0ul ; index<mapping.size (); ++index)
678+ {
679+ unsigned int map_index = mapping[index];
680+ output[map_index] = to_remap[index];
681+ }
682+ return output;
683+ };
684+ for (auto index = 0ul ; index < traj_msg->points .size (); ++index)
685+ {
686+ traj_msg->points [index].positions =
687+ remap (traj_msg->points [index].positions , mapping_vector);
688+
689+ traj_msg->points [index].velocities =
690+ remap (traj_msg->points [index].velocities , mapping_vector);
691+
692+ traj_msg->points [index].accelerations =
693+ remap (traj_msg->points [index].accelerations , mapping_vector);
694+
695+ traj_msg->points [index].effort =
696+ remap (traj_msg->points [index].effort , mapping_vector);
697+ }
698+
656699 traj_external_point_ptr_->update (traj_msg);
657700
658701 RealtimeGoalHandlePtr rt_goal = std::make_shared<RealtimeGoalHandle>(goal_handle);
0 commit comments