@@ -140,7 +140,7 @@ InterfaceConfiguration DiffDriveController::state_interface_configuration() cons
140
140
}
141
141
142
142
controller_interface::return_type DiffDriveController::update (
143
- const rclcpp::Time & time, const rclcpp::Duration & /* period*/ )
143
+ const rclcpp::Time & time, const rclcpp::Duration & period)
144
144
{
145
145
auto logger = get_node ()->get_logger ();
146
146
if (get_state ().id () == State::PRIMARY_STATE_INACTIVE)
@@ -153,8 +153,6 @@ controller_interface::return_type DiffDriveController::update(
153
153
return controller_interface::return_type::OK;
154
154
}
155
155
156
- const auto current_time = time;
157
-
158
156
std::shared_ptr<Twist> last_command_msg;
159
157
received_velocity_msg_ptr_.get (last_command_msg);
160
158
@@ -164,7 +162,7 @@ controller_interface::return_type DiffDriveController::update(
164
162
return controller_interface::return_type::ERROR;
165
163
}
166
164
167
- const auto age_of_last_command = current_time - last_command_msg->header .stamp ;
165
+ const auto age_of_last_command = time - last_command_msg->header .stamp ;
168
166
// Brake if cmd_vel has timeout, override the stored command
169
167
if (age_of_last_command > cmd_vel_timeout_)
170
168
{
@@ -178,6 +176,8 @@ controller_interface::return_type DiffDriveController::update(
178
176
double & linear_command = command.twist .linear .x ;
179
177
double & angular_command = command.twist .angular .z ;
180
178
179
+ previous_update_timestamp_ = time;
180
+
181
181
// Apply (possibly new) multipliers:
182
182
const auto wheels = wheel_params_;
183
183
const double wheel_separation = wheels.separation_multiplier * wheels.separation ;
@@ -186,7 +186,7 @@ controller_interface::return_type DiffDriveController::update(
186
186
187
187
if (odom_params_.open_loop )
188
188
{
189
- odometry_.updateOpenLoop (linear_command, angular_command, current_time );
189
+ odometry_.updateOpenLoop (linear_command, angular_command, time );
190
190
}
191
191
else
192
192
{
@@ -214,25 +214,27 @@ controller_interface::return_type DiffDriveController::update(
214
214
215
215
if (odom_params_.position_feedback )
216
216
{
217
- odometry_.update (left_feedback_mean, right_feedback_mean, current_time );
217
+ odometry_.update (left_feedback_mean, right_feedback_mean, time );
218
218
}
219
219
else
220
220
{
221
- odometry_.updateFromVelocity (left_feedback_mean, right_feedback_mean, current_time);
221
+ odometry_.updateFromVelocity (
222
+ left_feedback_mean*period.seconds (), right_feedback_mean*period.seconds (),
223
+ time);
222
224
}
223
225
}
224
226
225
227
tf2::Quaternion orientation;
226
228
orientation.setRPY (0.0 , 0.0 , odometry_.getHeading ());
227
229
228
- if (previous_publish_timestamp_ + publish_period_ < current_time )
230
+ if (previous_publish_timestamp_ + publish_period_ < time )
229
231
{
230
232
previous_publish_timestamp_ += publish_period_;
231
233
232
234
if (realtime_odometry_publisher_->trylock ())
233
235
{
234
236
auto & odometry_message = realtime_odometry_publisher_->msg_ ;
235
- odometry_message.header .stamp = current_time ;
237
+ odometry_message.header .stamp = time ;
236
238
odometry_message.pose .pose .position .x = odometry_.getX ();
237
239
odometry_message.pose .pose .position .y = odometry_.getY ();
238
240
odometry_message.pose .pose .orientation .x = orientation.x ();
@@ -247,7 +249,7 @@ controller_interface::return_type DiffDriveController::update(
247
249
if (odom_params_.enable_odom_tf && realtime_odometry_transform_publisher_->trylock ())
248
250
{
249
251
auto & transform = realtime_odometry_transform_publisher_->msg_ .transforms .front ();
250
- transform.header .stamp = current_time ;
252
+ transform.header .stamp = time ;
251
253
transform.transform .translation .x = odometry_.getX ();
252
254
transform.transform .translation .y = odometry_.getY ();
253
255
transform.transform .rotation .x = orientation.x ();
@@ -258,15 +260,12 @@ controller_interface::return_type DiffDriveController::update(
258
260
}
259
261
}
260
262
261
- const auto update_dt = current_time - previous_update_timestamp_;
262
- previous_update_timestamp_ = current_time;
263
-
264
263
auto & last_command = previous_commands_.back ().twist ;
265
264
auto & second_to_last_command = previous_commands_.front ().twist ;
266
265
limiter_linear_.limit (
267
- linear_command, last_command.linear .x , second_to_last_command.linear .x , update_dt .seconds ());
266
+ linear_command, last_command.linear .x , second_to_last_command.linear .x , period .seconds ());
268
267
limiter_angular_.limit (
269
- angular_command, last_command.angular .z , second_to_last_command.angular .z , update_dt .seconds ());
268
+ angular_command, last_command.angular .z , second_to_last_command.angular .z , period .seconds ());
270
269
271
270
previous_commands_.pop ();
272
271
previous_commands_.emplace (command);
@@ -275,7 +274,7 @@ controller_interface::return_type DiffDriveController::update(
275
274
if (publish_limited_velocity_ && realtime_limited_velocity_publisher_->trylock ())
276
275
{
277
276
auto & limited_velocity_command = realtime_limited_velocity_publisher_->msg_ ;
278
- limited_velocity_command.header .stamp = current_time ;
277
+ limited_velocity_command.header .stamp = time ;
279
278
limited_velocity_command.twist = command.twist ;
280
279
realtime_limited_velocity_publisher_->unlockAndPublish ();
281
280
}
0 commit comments