Skip to content

Commit c2935dc

Browse files
committed
Tune Servo params so it does not get stuck so easily
1 parent 937834b commit c2935dc

File tree

9 files changed

+294
-22
lines changed

9 files changed

+294
-22
lines changed

moveit_core/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ install(
9292
moveit_robot_model
9393
moveit_robot_state
9494
moveit_robot_trajectory
95+
moveit_ruckig_filter
96+
moveit_ruckig_filter_parameters
9597
moveit_smoothing_base
9698
moveit_test_utils
9799
moveit_trajectory_processing
@@ -142,9 +144,10 @@ pluginlib_export_plugin_description_file(moveit_core
142144
collision_detector_fcl_description.xml)
143145
pluginlib_export_plugin_description_file(
144146
moveit_core collision_detector_bullet_description.xml)
145-
pluginlib_export_plugin_description_file(moveit_core
146-
filter_plugin_butterworth.xml)
147147
pluginlib_export_plugin_description_file(moveit_core
148148
filter_plugin_acceleration.xml)
149+
pluginlib_export_plugin_description_file(moveit_core
150+
filter_plugin_butterworth.xml)
151+
pluginlib_export_plugin_description_file(moveit_core filter_plugin_ruckig.xml)
149152

150153
ament_package(CONFIG_EXTRAS ConfigExtras.cmake)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<library path="moveit_ruckig_filter">
2+
<class type="online_signal_smoothing::RuckigFilterPlugin"
3+
base_class_type="online_signal_smoothing::SmoothingBaseClass">
4+
<description>
5+
Jerk/acceleration/velocity-limited command smoothing.
6+
</description>
7+
</class>
8+
</library>

moveit_core/online_signal_smoothing/CMakeLists.txt

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,32 @@ set_target_properties(moveit_smoothing_base
1313
ament_target_dependencies(moveit_smoothing_base rclcpp tf2_eigen)
1414

1515
# Plugin implementations
16+
add_library(moveit_acceleration_filter SHARED src/acceleration_filter.cpp)
17+
generate_export_header(moveit_acceleration_filter)
18+
target_include_directories(
19+
moveit_acceleration_filter
20+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
21+
set_target_properties(moveit_acceleration_filter
22+
PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}")
23+
generate_parameter_library(moveit_acceleration_filter_parameters
24+
src/acceleration_filter_parameters.yaml)
25+
target_link_libraries(
26+
moveit_acceleration_filter moveit_acceleration_filter_parameters
27+
moveit_robot_state moveit_smoothing_base osqp::osqp)
28+
ament_target_dependencies(
29+
moveit_acceleration_filter srdfdom # include dependency from
30+
# moveit_robot_model
31+
pluginlib)
32+
1633
add_library(moveit_butterworth_filter SHARED src/butterworth_filter.cpp)
1734
generate_export_header(moveit_butterworth_filter)
1835
target_include_directories(
1936
moveit_butterworth_filter
2037
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
2138
set_target_properties(moveit_butterworth_filter
2239
PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}")
23-
2440
generate_parameter_library(moveit_butterworth_filter_parameters
2541
src/butterworth_parameters.yaml)
26-
2742
target_link_libraries(
2843
moveit_butterworth_filter moveit_butterworth_filter_parameters
2944
moveit_robot_model moveit_smoothing_base)
@@ -32,32 +47,30 @@ ament_target_dependencies(
3247
srdfdom # include dependency from moveit_robot_model
3348
pluginlib)
3449

35-
add_library(moveit_acceleration_filter SHARED src/acceleration_filter.cpp)
36-
generate_export_header(moveit_acceleration_filter)
50+
add_library(moveit_ruckig_filter SHARED src/ruckig_filter.cpp)
51+
generate_export_header(moveit_ruckig_filter)
3752
target_include_directories(
38-
moveit_acceleration_filter
39-
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
40-
set_target_properties(moveit_acceleration_filter
53+
moveit_ruckig_filter PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
54+
set_target_properties(moveit_ruckig_filter
4155
PROPERTIES VERSION "${${PROJECT_NAME}_VERSION}")
42-
43-
generate_parameter_library(moveit_acceleration_filter_parameters
44-
src/acceleration_filter_parameters.yaml)
45-
56+
generate_parameter_library(moveit_ruckig_filter_parameters
57+
src/ruckig_filter_parameters.yaml)
4658
target_link_libraries(
47-
moveit_acceleration_filter moveit_acceleration_filter_parameters
48-
moveit_robot_state moveit_smoothing_base osqp::osqp)
59+
moveit_ruckig_filter moveit_robot_state moveit_ruckig_filter_parameters
60+
moveit_smoothing_base ruckig::ruckig)
4961
ament_target_dependencies(
50-
moveit_acceleration_filter srdfdom # include dependency from
51-
# moveit_robot_model
62+
moveit_ruckig_filter srdfdom # include dependency from moveit_robot_model
5263
pluginlib)
5364

5465
# Installation
5566
install(DIRECTORY include/ DESTINATION include/moveit_core)
5667
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/moveit_smoothing_base_export.h
5768
DESTINATION include/moveit_core)
69+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/moveit_acceleration_filter_export.h
70+
DESTINATION include/moveit_core)
5871
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/moveit_butterworth_filter_export.h
5972
DESTINATION include/moveit_core)
60-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/moveit_acceleration_filter_export.h
73+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/moveit_ruckig_filter_export.h
6174
DESTINATION include/moveit_core)
6275

6376
# Testing
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*********************************************************************
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2024, Andrew Zelenak
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
9+
* are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* * Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
* * Neither the name of PickNik Inc. nor the names of its
18+
* contributors may be used to endorse or promote products derived
19+
* from this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*********************************************************************/
34+
35+
/* Author: Andy Zelenak
36+
Description: Applies jerk/acceleration/velocity limits to online motion commands
37+
*/
38+
39+
#pragma once
40+
41+
#include <cstddef>
42+
43+
#include <moveit/robot_model/robot_model.h>
44+
#include <moveit/online_signal_smoothing/smoothing_base_class.h>
45+
#include <moveit_ruckig_filter_parameters.hpp>
46+
47+
#include <ruckig/ruckig.hpp>
48+
49+
namespace online_signal_smoothing
50+
{
51+
52+
class RuckigFilterPlugin : public SmoothingBaseClass
53+
{
54+
public:
55+
/**
56+
* Initialize the smoothing algorithm
57+
* @param node ROS node, used for parameter retrieval
58+
* @param robot_model used to retrieve vel/accel/jerk limits
59+
* @param num_joints number of actuated joints in the JointGroup
60+
* @return True if initialization was successful
61+
*/
62+
bool initialize(rclcpp::Node::SharedPtr node, moveit::core::RobotModelConstPtr robot_model,
63+
size_t num_joints) override;
64+
65+
/**
66+
* Smooth the command signals for all DOF
67+
* @param positions array of joint position commands
68+
* @param velocities array of joint velocity commands
69+
* @param accelerations array of joint acceleration commands
70+
* @return True if initialization was successful
71+
*/
72+
bool doSmoothing(Eigen::VectorXd& positions, Eigen::VectorXd& velocities, Eigen::VectorXd& accelerations) override;
73+
74+
/**
75+
* Reset to a given joint state
76+
* @param positions reset the filters to these joint positions
77+
* @param velocities (unused)
78+
* @param accelerations (unused)
79+
* @return True if reset was successful
80+
*/
81+
bool reset(const Eigen::VectorXd& positions, const Eigen::VectorXd& velocities,
82+
const Eigen::VectorXd& accelerations) override;
83+
84+
private:
85+
rclcpp::Node::SharedPtr node_;
86+
void getDefaultJointVelAccelBounds();
87+
88+
online_signal_smoothing::Params params_;
89+
90+
size_t num_joints_;
91+
moveit::core::RobotModelConstPtr robot_model_;
92+
93+
bool have_initial_ruckig_output_ = false;
94+
std::optional<ruckig::Ruckig<ruckig::DynamicDOFs>> ruckig_;
95+
std::optional<ruckig::InputParameter<ruckig::DynamicDOFs>> ruckig_input_;
96+
std::optional<ruckig::OutputParameter<ruckig::DynamicDOFs>> ruckig_output_;
97+
98+
std::vector<double> joint_velocity_bounds_;
99+
std::vector<double> joint_acceleration_bounds_;
100+
std::vector<double> joint_jerk_bounds_;
101+
};
102+
} // namespace online_signal_smoothing

moveit_core/online_signal_smoothing/include/moveit/online_signal_smoothing/smoothing_base_class.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,5 @@ class SmoothingBaseClass
8989
*/
9090
virtual bool reset(const Eigen::VectorXd& positions, const Eigen::VectorXd& velocities,
9191
const Eigen::VectorXd& accelerations) = 0;
92-
;
9392
};
9493
} // namespace online_signal_smoothing

moveit_core/online_signal_smoothing/src/acceleration_filter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
#include <moveit/online_signal_smoothing/acceleration_filter.h>
3636
#include <rclcpp/logging.hpp>
37-
#include <Eigen/Sparse>
3837

3938
// Disable -Wold-style-cast because all _THROTTLE macros trigger this
4039
#pragma GCC diagnostic ignored "-Wold-style-cast"
@@ -345,5 +344,4 @@ bool AccelerationLimitedPlugin::reset(const Eigen::VectorXd& positions, const Ei
345344
} // namespace online_signal_smoothing
346345

347346
#include <pluginlib/class_list_macros.hpp>
348-
349347
PLUGINLIB_EXPORT_CLASS(online_signal_smoothing::AccelerationLimitedPlugin, online_signal_smoothing::SmoothingBaseClass)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*********************************************************************
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2024, Andrew Zelenak
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
9+
* are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* * Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
* * Neither the name of PickNik Inc. nor the names of its
18+
* contributors may be used to endorse or promote products derived
19+
* from this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*********************************************************************/
34+
35+
#include <moveit/online_signal_smoothing/ruckig_filter.h>
36+
#include <rclcpp/clock.hpp>
37+
#include <rclcpp/logging.hpp>
38+
39+
// Disable -Wold-style-cast because all _THROTTLE macros trigger this
40+
#pragma GCC diagnostic ignored "-Wold-style-cast"
41+
42+
namespace online_signal_smoothing
43+
{
44+
namespace
45+
{
46+
rclcpp::Logger getLogger()
47+
{
48+
return moveit::getLogger("moveit.core.ruckig_filter_plugin");
49+
}
50+
inline constexpr double DEFAULT_JERK_BOUND = 300; // rad/s^3
51+
} // namespace
52+
53+
bool RuckigFilterPlugin::initialize(rclcpp::Node::SharedPtr node, moveit::core::RobotModelConstPtr robot_model,
54+
size_t num_joints)
55+
{
56+
node_ = node;
57+
num_joints_ = num_joints;
58+
robot_model_ = robot_model;
59+
60+
// get node parameters and store in member variables
61+
auto param_listener = online_signal_smoothing::ParamListener(node_);
62+
params_ = param_listener.get_params();
63+
64+
// Ruckig needs the joint vel/accel/jerk bounds.
65+
getDefaultJointVelAccelBounds();
66+
ruckig::InputParameter<ruckig::DynamicDOFs> ruckig_input(num_joints_);
67+
ruckig_input.max_velocity = joint_velocity_bounds_;
68+
ruckig_input.max_acceleration = joint_acceleration_bounds_;
69+
ruckig_input.max_jerk = joint_jerk_bounds_;
70+
// initialize positions. All other quantities are initialized to zero in the constructor.
71+
// This will be overwritten in the first control loop
72+
ruckig_input.current_position = std::vector<double>(num_joints_, 0.0);
73+
ruckig_input_ = ruckig_input;
74+
75+
ruckig_output_.emplace(ruckig::OutputParameter<ruckig::DynamicDOFs>(num_joints_));
76+
77+
ruckig_.emplace(ruckig::Ruckig<ruckig::DynamicDOFs>(num_joints_, params_.update_period));
78+
79+
return true;
80+
}
81+
82+
bool RuckigFilterPlugin::doSmoothing(Eigen::VectorXd& positions, Eigen::VectorXd& velocities,
83+
Eigen::VectorXd& accelerations)
84+
{
85+
return true;
86+
}
87+
88+
bool RuckigFilterPlugin::reset(const Eigen::VectorXd& positions, const Eigen::VectorXd& velocities,
89+
const Eigen::VectorXd& accelerations)
90+
{
91+
return true;
92+
}
93+
94+
void RuckigFilterPlugin::getDefaultJointVelAccelBounds()
95+
{
96+
auto joint_model_group = robot_model_->getJointModelGroup(params_.planning_group_name);
97+
for (const auto& joint : joint_model_group->getActiveJointModels())
98+
{
99+
const auto& bound = joint->getVariableBounds(joint->getName());
100+
101+
if (bound.velocity_bounded_)
102+
{
103+
// Assume symmetric limits
104+
joint_velocity_bounds_.push_back(bound.max_velocity_);
105+
}
106+
else
107+
{
108+
RCLCPP_ERROR(getLogger(), "No joint vel limit defined. Exiting for safety.");
109+
std::exit(EXIT_FAILURE);
110+
}
111+
112+
if (bound.acceleration_bounded_)
113+
{
114+
// Assume symmetric limits
115+
joint_acceleration_bounds_.push_back(bound.max_acceleration_);
116+
}
117+
else
118+
{
119+
RCLCPP_ERROR(getLogger(), "WARNING: No joint accel limit defined. Very large accelerations will be "
120+
"possible.");
121+
joint_acceleration_bounds_.push_back(DBL_MAX);
122+
}
123+
124+
// MoveIt and the URDF don't support jerk limits, so use a safe default always
125+
joint_jerk_bounds_.push_back(DEFAULT_JERK_BOUND);
126+
}
127+
128+
assert(joint_jerk_bounds_.size() == num_joints_);
129+
}
130+
} // namespace online_signal_smoothing
131+
132+
#include <pluginlib/class_list_macros.hpp>
133+
PLUGINLIB_EXPORT_CLASS(online_signal_smoothing::RuckigFilterPlugin, online_signal_smoothing::SmoothingBaseClass)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
online_signal_smoothing:
2+
update_period: {
3+
type: double,
4+
description: "The expected time in seconds between calls to `doSmoothing` method.",
5+
read_only: true,
6+
validation: {
7+
gt<>: 0.0
8+
}
9+
}
10+
planning_group_name: {
11+
type: string,
12+
read_only: true,
13+
description: "The name of the MoveIt planning group of the robot \
14+
This parameter does not have a default value and \
15+
must be passed to the node during launch time."
16+
}

moveit_ros/moveit_servo/config/panda_simulated_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ publish_joint_accelerations: false
2828

2929
## Plugins for smoothing outgoing commands
3030
use_smoothing: true
31-
smoothing_filter_plugin_name: "online_signal_smoothing::AccelerationLimitedPlugin"
31+
smoothing_filter_plugin_name: "online_signal_smoothing::RuckigFilterPlugin"
3232

3333
# If is_primary_planning_scene_monitor is set to true, the Servo server's PlanningScene advertises the /get_planning_scene service,
3434
# which other nodes can use as a source for information about the planning environment.

0 commit comments

Comments
 (0)