moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
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 [[nodiscard]] std::string getDescription() const override
60 {
61 return std::string("AddRuckigTrajectorySmoothing");
62 }
63
64 void adapt(const planning_scene::PlanningSceneConstPtr& /*planning_scene*/,
67 {
68 RCLCPP_DEBUG(logger_, " Running '%s'", getDescription().c_str());
69 if (!res.trajectory)
70 {
71 RCLCPP_ERROR(
72 logger_,
73 "Cannot apply response adapter '%s' because MotionPlanResponse does not contain a trajectory to smooth.",
74 getDescription().c_str());
75 res.error_code = moveit::core::MoveItErrorCode::INVALID_MOTION_PLAN;
76 return;
77 }
78
79 if (smoother_.applySmoothing(*res.trajectory, req.max_velocity_scaling_factor, req.max_acceleration_scaling_factor))
80 {
81 res.error_code = moveit::core::MoveItErrorCode::SUCCESS;
82 }
83 else
84 {
85 RCLCPP_ERROR(logger_, "Response adapter '%s' failed to smooth trajectory.", getDescription().c_str());
86 res.error_code = moveit::core::MoveItErrorCode::FAILURE;
87 }
88 }
89
90private:
91 RuckigSmoothing smoother_;
92 rclcpp::Logger logger_;
93};
94
95} // namespace default_planning_response_adapters
96
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.
Definition exceptions.h:43
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
CLASS_LOADER_REGISTER_CLASS(default_planning_request_adapters::ResolveConstraintFrames, planning_interface::PlanningRequestAdapter)
Response to a planning query.
moveit::core::MoveItErrorCode error_code
robot_trajectory::RobotTrajectoryPtr trajectory