-
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
Changes from 8 commits
3cad609
885ee27
35737f9
42c1bb6
2fd3ede
e0c3a63
cf404ed
ed29aba
10b349a
5aa3d13
d61f642
8189e65
0a8206c
ee0f7ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -707,4 +707,120 @@ 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); | ||||||||||||||||||||||||||||
| joint_trajectory.joint_names.push_back(active_joint->getName()); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| else if (include_mdof_joints) | ||||||||||||||||||||||||||||
|
sjahr marked this conversation as resolved.
|
||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| mdof.push_back(active_joint); | ||||||||||||||||||||||||||||
| for (const auto& variable_name : active_joint->getVariableNames()) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| joint_trajectory.joint_names.push_back(variable_name); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (!joint_trajectory.joint_names.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()); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
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.
Suggested change
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. Shouldn't we just exit the function here if joint_names is empty?
Member
Author
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. with the updated logic, I would just keep it the way it is probably |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| 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.
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| for (const auto& name : names) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| joint_trajectory.points[i].positions.push_back(waypoint.getVariablePosition(name)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (waypoint.hasVelocities()) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| joint_trajectory.points[i].velocities.reserve(joint_trajectory.points[i].velocities.size() + names.size()); | ||||||||||||||||||||||||||||
| for (const auto& name : names) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| joint_trajectory.points[i].velocities.push_back(waypoint.getVariableVelocity(name)); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return joint_trajectory; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| } // end of namespace robot_trajectory | ||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.