MCPcopy Create free account
hub / github.com/ROBOTIS-GIT/turtlebot3 / parameter_event_callback

Method parameter_event_callback

turtlebot3_node/src/turtlebot3.cpp:271–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271void TurtleBot3::parameter_event_callback()
272{
273 priv_parameters_client_ = std::make_shared<rclcpp::AsyncParametersClient>(this);
274 while (!priv_parameters_client_->wait_for_service(std::chrono::seconds(1))) {
275 if (!rclcpp::ok()) {
276 RCLCPP_ERROR(this->get_logger(), "Interrupted while waiting for the service. Exiting.");
277 return;
278 }
279
280 RCLCPP_WARN(this->get_logger(), "service not available, waiting again...");
281 }
282
283 auto param_event_callback =
284 [this](const rcl_interfaces::msg::ParameterEvent::SharedPtr event) -> void
285 {
286 for (const auto & changed_parameter : event->changed_parameters) {
287 RCLCPP_DEBUG(
288 this->get_logger(),
289 "changed parameter name : %s",
290 changed_parameter.name.c_str());
291
292 if (changed_parameter.name == "motors.profile_acceleration") {
293 std::string sdk_msg;
294
295 motors_.profile_acceleration =
296 rclcpp::Parameter::from_parameter_msg(changed_parameter).as_double();
297
298 motors_.profile_acceleration =
299 motors_.profile_acceleration / motors_.profile_acceleration_constant;
300
301 union Data {
302 int32_t dword[2];
303 uint8_t byte[4 * 2];
304 } data;
305
306 data.dword[0] = static_cast<int32_t>(motors_.profile_acceleration);
307 data.dword[1] = static_cast<int32_t>(motors_.profile_acceleration);
308
309 uint16_t start_addr = extern_control_table.profile_acceleration_left.addr;
310 uint16_t addr_length =
311 (extern_control_table.profile_acceleration_right.addr -
312 extern_control_table.profile_acceleration_left.addr) +
313 extern_control_table.profile_acceleration_right.length;
314
315 uint8_t * p_data = &data.byte[0];
316
317 dxl_sdk_wrapper_->set_data_to_device(start_addr, addr_length, p_data, &sdk_msg);
318
319 RCLCPP_INFO(
320 this->get_logger(),
321 "changed parameter value : %f [rev/min2] sdk_msg : %s",
322 motors_.profile_acceleration,
323 sdk_msg.c_str());
324 }
325 }
326 };
327
328 parameter_event_sub_ = priv_parameters_client_->on_parameter_event(param_event_callback);

Callers

nothing calls this directly

Calls 1

set_data_to_deviceMethod · 0.80

Tested by

no test coverage detected