Skip to content

Commit ba5a493

Browse files
committed
Strictly require joint jerk bounds
1 parent 906bb06 commit ba5a493

File tree

2 files changed

+26
-67
lines changed

2 files changed

+26
-67
lines changed

moveit_core/online_signal_smoothing/include/moveit/online_signal_smoothing/ruckig_filter.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class RuckigFilterPlugin : public SmoothingBaseClass
9191
* A utility to get velocity/acceleration/jerk bounds from the robot model
9292
* @return true if all bounds are defined
9393
*/
94-
bool getVelAccelJerkBounds();
94+
bool getVelAccelJerkBounds(std::vector<double>& joint_velocity_bounds, std::vector<double>& joint_acceleration_bounds,
95+
std::vector<double>& joint_jerk_bounds);
9596

9697
rclcpp::Node::SharedPtr node_;
9798
/** \brief Parameters loaded from yaml file at runtime */
@@ -103,9 +104,5 @@ class RuckigFilterPlugin : public SmoothingBaseClass
103104
std::optional<ruckig::Ruckig<ruckig::DynamicDOFs>> ruckig_;
104105
std::optional<ruckig::InputParameter<ruckig::DynamicDOFs>> ruckig_input_;
105106
std::optional<ruckig::OutputParameter<ruckig::DynamicDOFs>> ruckig_output_;
106-
107-
std::vector<double> joint_velocity_bounds_;
108-
std::vector<double> joint_acceleration_bounds_;
109-
std::optional<std::vector<double>> joint_jerk_bounds_;
110107
};
111108
} // namespace online_signal_smoothing

moveit_core/online_signal_smoothing/src/ruckig_filter.cpp

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,16 @@ bool RuckigFilterPlugin::initialize(rclcpp::Node::SharedPtr node, moveit::core::
6161
auto param_listener = online_signal_smoothing::ParamListener(node_);
6262
params_ = param_listener.get_params();
6363

64-
// Ruckig needs the joint vel/accel bounds, jerk bounds are optional
65-
getVelAccelJerkBounds();
64+
// Ruckig needs the joint vel/accel bounds
65+
// TODO: Ruckig says the jerk bounds can be optional. We require them, for now.
6666
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.current_position = std::vector<double>(num_joints_, 0.0);
70-
ruckig_input.current_velocity = std::vector<double>(num_joints_, 0.0);
71-
72-
// These quantities can be omitted if jerk limits are not applied
73-
if (joint_jerk_bounds_)
67+
if (!getVelAccelJerkBounds(ruckig_input.max_velocity, ruckig_input.max_acceleration, ruckig_input.max_jerk))
7468
{
75-
ruckig_input.max_jerk = *joint_jerk_bounds_;
76-
ruckig_input.current_acceleration = std::vector<double>(num_joints_, 0.0);
69+
return false;
7770
}
71+
ruckig_input.current_position = std::vector<double>(num_joints_, 0.0);
72+
ruckig_input.current_velocity = std::vector<double>(num_joints_, 0.0);
73+
ruckig_input.current_acceleration = std::vector<double>(num_joints_, 0.0);
7874

7975
ruckig_input_ = ruckig_input;
8076

@@ -90,40 +86,14 @@ bool RuckigFilterPlugin::doSmoothing(Eigen::VectorXd& positions, Eigen::VectorXd
9086
{
9187
if (have_initial_ruckig_output_)
9288
{
93-
if (joint_jerk_bounds_)
94-
{
95-
ruckig_output_->pass_to_input(*ruckig_input_);
96-
}
97-
else
98-
{
99-
ruckig_input_->current_position = ruckig_output_->new_position;
100-
ruckig_input_->current_velocity = ruckig_output_->new_velocity;
101-
}
89+
ruckig_output_->pass_to_input(*ruckig_input_);
10290
}
10391

10492
// Update Ruckig target state
10593
// This assumes stationary at the target (zero vel, zero accel)
10694
ruckig_input_->target_position = std::vector<double>(positions.data(), positions.data() + positions.size());
107-
ruckig_input_->target_velocity = std::vector<double>(num_joints_, 0);
108-
if (!joint_jerk_bounds_)
109-
{
110-
ruckig_input_->target_acceleration = std::vector<double>(num_joints_, 0);
111-
ruckig_input_->current_acceleration = std::vector<double>(num_joints_, 0.0);
112-
}
11395

11496
// Call the Ruckig algorithm
115-
try
116-
{
117-
ruckig_->validate_input(*ruckig_input_, true, true);
118-
}
119-
catch (const std::runtime_error& error)
120-
{
121-
RCLCPP_ERROR_STREAM(getLogger(), "Invalid Ruckig input. " << error.what() << std::endl);
122-
}
123-
if (!ruckig_->validate_input(*ruckig_input_, true, true))
124-
{
125-
std::cerr << "Invalid input!" << std::endl;
126-
}
12797
ruckig::Result ruckig_result = ruckig_->update(*ruckig_input_, *ruckig_output_);
12898

12999
// Finished means the target state can be reached in this timestep.
@@ -160,29 +130,30 @@ bool RuckigFilterPlugin::reset(const Eigen::VectorXd& positions, const Eigen::Ve
160130
// Initialize Ruckig
161131
ruckig_input_->current_position = std::vector<double>(positions.data(), positions.data() + positions.size());
162132
ruckig_input_->current_velocity = std::vector<double>(velocities.data(), velocities.data() + velocities.size());
163-
if (joint_jerk_bounds_)
164-
{
165-
ruckig_input_->current_acceleration =
166-
std::vector<double>(accelerations.data(), accelerations.data() + accelerations.size());
167-
}
133+
ruckig_input_->current_acceleration =
134+
std::vector<double>(accelerations.data(), accelerations.data() + accelerations.size());
168135

169136
have_initial_ruckig_output_ = false;
170137
return true;
171138
}
172139

173-
bool RuckigFilterPlugin::getVelAccelJerkBounds()
140+
bool RuckigFilterPlugin::getVelAccelJerkBounds(std::vector<double>& joint_velocity_bounds,
141+
std::vector<double>& joint_acceleration_bounds,
142+
std::vector<double>& joint_jerk_bounds)
174143
{
144+
joint_velocity_bounds.clear();
145+
joint_acceleration_bounds.clear();
146+
joint_jerk_bounds.clear();
147+
175148
auto joint_model_group = robot_model_->getJointModelGroup(params_.planning_group_name);
176-
bool have_all_jerk_bounds = true;
177-
std::vector<double> jerk_bounds;
178149
for (const auto& joint : joint_model_group->getActiveJointModels())
179150
{
180151
const auto& bound = joint->getVariableBounds(joint->getName());
181152

182153
if (bound.velocity_bounded_)
183154
{
184155
// Assume symmetric limits
185-
joint_velocity_bounds_.push_back(bound.max_velocity_);
156+
joint_velocity_bounds.push_back(bound.max_velocity_);
186157
}
187158
else
188159
{
@@ -193,37 +164,28 @@ bool RuckigFilterPlugin::getVelAccelJerkBounds()
193164
if (bound.acceleration_bounded_)
194165
{
195166
// Assume symmetric limits
196-
joint_acceleration_bounds_.push_back(bound.max_acceleration_);
167+
joint_acceleration_bounds.push_back(bound.max_acceleration_);
197168
}
198169
else
199170
{
200171
RCLCPP_WARN(getLogger(), "No joint acceleration limit defined. Very large accelerations will be "
201172
"possible.");
202-
joint_acceleration_bounds_.push_back(DBL_MAX);
173+
joint_acceleration_bounds.push_back(DBL_MAX);
203174
}
204175

205176
if (bound.jerk_bounded_)
206177
{
207178
// Assume symmetric limits
208-
jerk_bounds.push_back(bound.max_jerk_);
179+
joint_jerk_bounds.push_back(bound.max_jerk_);
209180
}
210-
// else, joint_jerk_bounds_ will be a std::nullopt and Ruckig doesn't apply jerk limits
181+
// else, return false
211182
else
212183
{
213-
have_all_jerk_bounds = false;
184+
RCLCPP_WARN(getLogger(), "No joint jerk limit was defined. The output from Ruckig will not be jerk-limited.");
185+
return false;
214186
}
215187
}
216188

217-
if (!have_all_jerk_bounds)
218-
{
219-
joint_jerk_bounds_ = std::nullopt;
220-
RCLCPP_WARN(getLogger(), "No joint jerk limit was defined. The output from Ruckig will not be jerk-limited.");
221-
}
222-
else
223-
{
224-
joint_jerk_bounds_ = jerk_bounds;
225-
}
226-
227189
return true;
228190
}
229191

0 commit comments

Comments
 (0)