@@ -61,20 +61,16 @@ bool RuckigFilterPlugin::initialize(rclcpp::Node::SharedPtr node, moveit::core::
61
61
auto param_listener = online_signal_smoothing::ParamListener (node_);
62
62
params_ = param_listener.get_params ();
63
63
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.
66
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.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 ))
74
68
{
75
- ruckig_input.max_jerk = *joint_jerk_bounds_;
76
- ruckig_input.current_acceleration = std::vector<double >(num_joints_, 0.0 );
69
+ return false ;
77
70
}
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 );
78
74
79
75
ruckig_input_ = ruckig_input;
80
76
@@ -90,40 +86,14 @@ bool RuckigFilterPlugin::doSmoothing(Eigen::VectorXd& positions, Eigen::VectorXd
90
86
{
91
87
if (have_initial_ruckig_output_)
92
88
{
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_);
102
90
}
103
91
104
92
// Update Ruckig target state
105
93
// This assumes stationary at the target (zero vel, zero accel)
106
94
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
- }
113
95
114
96
// 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
- }
127
97
ruckig::Result ruckig_result = ruckig_->update (*ruckig_input_, *ruckig_output_);
128
98
129
99
// 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
160
130
// Initialize Ruckig
161
131
ruckig_input_->current_position = std::vector<double >(positions.data (), positions.data () + positions.size ());
162
132
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 ());
168
135
169
136
have_initial_ruckig_output_ = false ;
170
137
return true ;
171
138
}
172
139
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)
174
143
{
144
+ joint_velocity_bounds.clear ();
145
+ joint_acceleration_bounds.clear ();
146
+ joint_jerk_bounds.clear ();
147
+
175
148
auto joint_model_group = robot_model_->getJointModelGroup (params_.planning_group_name );
176
- bool have_all_jerk_bounds = true ;
177
- std::vector<double > jerk_bounds;
178
149
for (const auto & joint : joint_model_group->getActiveJointModels ())
179
150
{
180
151
const auto & bound = joint->getVariableBounds (joint->getName ());
181
152
182
153
if (bound.velocity_bounded_ )
183
154
{
184
155
// Assume symmetric limits
185
- joint_velocity_bounds_ .push_back (bound.max_velocity_ );
156
+ joint_velocity_bounds .push_back (bound.max_velocity_ );
186
157
}
187
158
else
188
159
{
@@ -193,37 +164,28 @@ bool RuckigFilterPlugin::getVelAccelJerkBounds()
193
164
if (bound.acceleration_bounded_ )
194
165
{
195
166
// Assume symmetric limits
196
- joint_acceleration_bounds_ .push_back (bound.max_acceleration_ );
167
+ joint_acceleration_bounds .push_back (bound.max_acceleration_ );
197
168
}
198
169
else
199
170
{
200
171
RCLCPP_WARN (getLogger (), " No joint acceleration limit defined. Very large accelerations will be "
201
172
" possible." );
202
- joint_acceleration_bounds_ .push_back (DBL_MAX);
173
+ joint_acceleration_bounds .push_back (DBL_MAX);
203
174
}
204
175
205
176
if (bound.jerk_bounded_ )
206
177
{
207
178
// Assume symmetric limits
208
- jerk_bounds .push_back (bound.max_jerk_ );
179
+ joint_jerk_bounds .push_back (bound.max_jerk_ );
209
180
}
210
- // else, joint_jerk_bounds_ will be a std::nullopt and Ruckig doesn't apply jerk limits
181
+ // else, return false
211
182
else
212
183
{
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 ;
214
186
}
215
187
}
216
188
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
-
227
189
return true ;
228
190
}
229
191
0 commit comments