-
Notifications
You must be signed in to change notification settings - Fork 772
Enable mdof trajectory execution #2740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
EzraBrooks
merged 14 commits into
moveit:main
from
henningkayser:enable_mdof_trajectory_execution
Apr 30, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3cad609
Add RobotTrajectory conversion from MDOF to joints
henningkayser 885ee27
Convert MDOF trajectories to joint trajectories in planning interfaces
henningkayser 35737f9
Treat mdof joint variables as common joints in
henningkayser 42c1bb6
Convert multi-DOF trajectories to joints in TEM
henningkayser 2fd3ede
Revert "Convert MDOF trajectories to joint trajectories in planning i…
henningkayser e0c3a63
Handle multi-DOF variables in TEM's bound checking
henningkayser cf404ed
Add parameter to optionally enable multi-dof conversion
henningkayser ed29aba
Improve error message about unknown controllers
henningkayser 10b349a
Fix name ordering in JointTrajectory conversion
henningkayser 5aa3d13
Improve DEBUG output in TEM
henningkayser d61f642
Comment RobotTrajectory test
henningkayser 8189e65
add acceleration to avoid out of bounds read
pac48 0a8206c
Merge branch 'main' into enable_mdof_trajectory_execution
Abishalini ee0f7ba
Merge branch 'main' into enable_mdof_trajectory_execution
EzraBrooks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -373,29 +373,36 @@ void RobotTrajectory::getRobotTrajectoryMsg(moveit_msgs::msg::RobotTrajectory& t | |
| { | ||
| const std::vector<std::string> names = mdof[j]->getVariableNames(); | ||
| const double* velocities = waypoints_[i]->getJointVelocities(mdof[j]); | ||
| const double* accelerations = waypoints_[i]->getJointAccelerations(mdof[j]); | ||
|
|
||
| geometry_msgs::msg::Twist point_velocity; | ||
| geometry_msgs::msg::Twist point_acceleration; | ||
|
|
||
| for (std::size_t k = 0; k < names.size(); ++k) | ||
| { | ||
| if (names[k].find("/x") != std::string::npos) | ||
| { | ||
| point_velocity.linear.x = velocities[k]; | ||
| point_acceleration.linear.x = accelerations[k]; | ||
| } | ||
| else if (names[k].find("/y") != std::string::npos) | ||
| { | ||
| point_velocity.linear.y = velocities[k]; | ||
| point_acceleration.linear.y = accelerations[k]; | ||
| } | ||
| else if (names[k].find("/z") != std::string::npos) | ||
| { | ||
| point_velocity.linear.z = velocities[k]; | ||
| point_acceleration.linear.z = accelerations[k]; | ||
| } | ||
| else if (names[k].find("/theta") != std::string::npos) | ||
| { | ||
| point_velocity.angular.z = velocities[k]; | ||
| point_acceleration.angular.z = accelerations[k]; | ||
| } | ||
| } | ||
| trajectory.multi_dof_joint_trajectory.points[i].velocities.push_back(point_velocity); | ||
| trajectory.multi_dof_joint_trajectory.points[i].accelerations.push_back(point_acceleration); | ||
| } | ||
| } | ||
| if (duration_from_previous_.size() > i) | ||
|
|
@@ -707,4 +714,129 @@ std::optional<double> waypointDensity(const RobotTrajectory& trajectory) | |
| return std::nullopt; | ||
| } | ||
|
|
||
| std::optional<trajectory_msgs::msg::JointTrajectory> toJointTrajectory(const RobotTrajectory& trajectory, | ||
|
sjahr marked this conversation as resolved.
|
||
| bool include_mdof_joints, | ||
| const std::vector<std::string>& joint_filter) | ||
| { | ||
| const auto group = trajectory.getGroup(); | ||
| const auto robot_model = trajectory.getRobotModel(); | ||
|
sjahr marked this conversation as resolved.
|
||
| const std::vector<const moveit::core::JointModel*>& jnts = | ||
| group ? group->getActiveJointModels() : robot_model->getActiveJointModels(); | ||
|
|
||
| if (trajectory.empty() || jnts.empty()) | ||
| return std::nullopt; | ||
|
|
||
| trajectory_msgs::msg::JointTrajectory joint_trajectory; | ||
| std::vector<const moveit::core::JointModel*> onedof; | ||
| std::vector<const moveit::core::JointModel*> mdof; | ||
|
|
||
| for (const moveit::core::JointModel* active_joint : jnts) | ||
| { | ||
| // only consider joints listed in joint_filter | ||
| if (!joint_filter.empty() && | ||
| std::find(joint_filter.begin(), joint_filter.end(), active_joint->getName()) == joint_filter.end()) | ||
|
sjahr marked this conversation as resolved.
|
||
| continue; | ||
|
|
||
| if (active_joint->getVariableCount() == 1) | ||
| { | ||
| onedof.push_back(active_joint); | ||
| } | ||
| else if (include_mdof_joints) | ||
|
sjahr marked this conversation as resolved.
|
||
| { | ||
| mdof.push_back(active_joint); | ||
| } | ||
| } | ||
|
|
||
| for (const auto& joint : onedof) | ||
| { | ||
| joint_trajectory.joint_names.push_back(joint->getName()); | ||
| } | ||
| for (const auto& joint : mdof) | ||
| { | ||
| for (const auto& name : joint->getVariableNames()) | ||
| { | ||
| joint_trajectory.joint_names.push_back(name); | ||
| } | ||
| } | ||
|
|
||
| if (!onedof.empty() || !mdof.empty()) | ||
| { | ||
| joint_trajectory.header.frame_id = robot_model->getModelFrame(); | ||
| joint_trajectory.header.stamp = rclcpp::Time(0, 0, RCL_ROS_TIME); | ||
| joint_trajectory.points.resize(trajectory.getWayPointCount()); | ||
| } | ||
|
|
||
| static const auto ZERO_DURATION = rclcpp::Duration::from_seconds(0); | ||
| double total_time = 0.0; | ||
| for (std::size_t i = 0; i < trajectory.getWayPointCount(); ++i) | ||
| { | ||
| total_time += trajectory.getWayPointDurationFromPrevious(i); | ||
| joint_trajectory.points[i].time_from_start = rclcpp::Duration::from_seconds(total_time); | ||
| const auto& waypoint = trajectory.getWayPoint(i); | ||
|
|
||
| if (!onedof.empty()) | ||
| { | ||
| joint_trajectory.points[i].positions.resize(onedof.size()); | ||
| joint_trajectory.points[i].velocities.reserve(onedof.size()); | ||
|
|
||
| for (std::size_t j = 0; j < onedof.size(); ++j) | ||
| { | ||
| joint_trajectory.points[i].positions[j] = waypoint.getVariablePosition(onedof[j]->getFirstVariableIndex()); | ||
| // if we have velocities/accelerations/effort, copy those too | ||
| if (waypoint.hasVelocities()) | ||
| { | ||
| joint_trajectory.points[i].velocities.push_back( | ||
| waypoint.getVariableVelocity(onedof[j]->getFirstVariableIndex())); | ||
| } | ||
| if (waypoint.hasAccelerations()) | ||
| { | ||
| joint_trajectory.points[i].accelerations.push_back( | ||
| waypoint.getVariableAcceleration(onedof[j]->getFirstVariableIndex())); | ||
| } | ||
| if (waypoint.hasEffort()) | ||
| { | ||
| joint_trajectory.points[i].effort.push_back(waypoint.getVariableEffort(onedof[j]->getFirstVariableIndex())); | ||
| } | ||
| } | ||
| // clear velocities if we have an incomplete specification | ||
| if (joint_trajectory.points[i].velocities.size() != onedof.size()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe print and error message here, since this probably indicates a bug somewhere |
||
| joint_trajectory.points[i].velocities.clear(); | ||
| // clear accelerations if we have an incomplete specification | ||
| if (joint_trajectory.points[i].accelerations.size() != onedof.size()) | ||
| joint_trajectory.points[i].accelerations.clear(); | ||
| // clear effort if we have an incomplete specification | ||
| if (joint_trajectory.points[i].effort.size() != onedof.size()) | ||
| joint_trajectory.points[i].effort.clear(); | ||
| } | ||
|
|
||
| if (!mdof.empty()) | ||
| { | ||
| for (const auto joint : mdof) | ||
| { | ||
| // Add variable placeholders | ||
| const std::vector<std::string> names = joint->getVariableNames(); | ||
| joint_trajectory.points[i].positions.reserve(joint_trajectory.points[i].positions.size() + names.size()); | ||
|
henningkayser marked this conversation as resolved.
|
||
|
|
||
| joint_trajectory.points[i].velocities.reserve(joint_trajectory.points[i].velocities.size() + names.size()); | ||
|
|
||
| for (const auto& name : names) | ||
| { | ||
| joint_trajectory.points[i].positions.push_back(waypoint.getVariablePosition(name)); | ||
|
|
||
| if (waypoint.hasVelocities()) | ||
| { | ||
| joint_trajectory.points[i].velocities.push_back(waypoint.getVariableVelocity(name)); | ||
| } | ||
| if (waypoint.hasAccelerations()) | ||
| { | ||
| joint_trajectory.points[i].accelerations.push_back(waypoint.getVariableAcceleration(name)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return joint_trajectory; | ||
| } | ||
|
|
||
| } // end of namespace robot_trajectory | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.