moveit2
The MoveIt Motion Planning Framework for ROS 2.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
add_ruckig_traj_smoothing.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 * BSD 3-Clause License
3 *
4 * Copyright (c) 2021, PickNik Robotics
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * * Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
33
34/* Author: Jack Center, Wyatt Rees, Andy Zelenak
35 * Desc: An adapter that uses ruckig (https://github.com/pantor/ruckig) to adapt the trajectory to be jerk-constrained and
36 * time-optimal. It is necessary to run another trajectory generation algorithm before this adapter, because the
37 * algorithm requires a fully configured trajectory as initial guess.
38 */
39
43#include <class_loader/class_loader.hpp>
44#include <moveit_msgs/msg/move_it_error_codes.hpp>
45
47{
48using namespace trajectory_processing;
49
53{
54public:
55 AddRuckigTrajectorySmoothing() : logger_(moveit::getLogger("moveit.ros.add_ruckig_trajectory_smoothing"))
56 {
57 }
58
59 ~AddRuckigTrajectorySmoothing() override = default;
60
61 [[nodiscard]] std::string getDescription() const override
62 {
63 return std::string("AddRuckigTrajectorySmoothing");
64 }
65
66 void adapt(const planning_scene::PlanningSceneConstPtr& /*planning_scene*/,
69 {
70 RCLCPP_DEBUG(logger_, " Running '%s'", getDescription().c_str());
71 if (!res.trajectory)
72 {
73 RCLCPP_ERROR(
74 logger_,
75 "Cannot apply response adapter '%s' because MotionPlanResponse does not contain a trajectory to smooth.",
76 getDescription().c_str());
77 res.error_code = moveit::core::MoveItErrorCode::INVALID_MOTION_PLAN;
78 return;
79 }
80
81 if (smoother_.applySmoothing(*res.trajectory, req.max_velocity_scaling_factor, req.max_acceleration_scaling_factor))
82 {
83 res.error_code = moveit::core::MoveItErrorCode::SUCCESS;
84 }
85 else
86 {
87 RCLCPP_ERROR(logger_, "Response adapter '%s' failed to smooth trajectory.", getDescription().c_str());
88 res.error_code = moveit::core::MoveItErrorCode::FAILURE;
89 }
90 }
91
92private:
93 RuckigSmoothing smoother_;
94 rclcpp::Logger logger_;
95};
96
97} // namespace default_planning_response_adapters
98
Use ruckig (https://github.com/pantor/ruckig) to adapt the trajectory to be jerk-constrained and time...
std::string getDescription() const override
Get a description of this adapter.
void adapt(const planning_scene::PlanningSceneConstPtr &, const planning_interface::MotionPlanRequest &req, planning_interface::MotionPlanResponse &res) const override
Adapt the planning response.
Concept in MoveIt which can be used to modify the planning solution (post-processing) in a planning p...
static bool applySmoothing(robot_trajectory::RobotTrajectory &trajectory, const double max_velocity_scaling_factor=1.0, const double max_acceleration_scaling_factor=1.0, const bool mitigate_overshoot=false, const double overshoot_threshold=0.01)
Apply smoothing to a time-parameterized trajectory so that jerk limits are not violated.
Main namespace for MoveIt.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
CLASS_LOADER_REGISTER_CLASS(default_planning_request_adapters::ResolveConstraintFrames, planning_interface::PlanningRequestAdapter)
moveit::core::MoveItErrorCode error_code
robot_trajectory::RobotTrajectoryPtr trajectory