| 329 | } |
| 330 | |
| 331 | void TurtleBot3::cmd_vel_callback() |
| 332 | { |
| 333 | auto qos = rclcpp::QoS(rclcpp::KeepLast(10)); |
| 334 | cmd_vel_sub_ = std::make_unique<TwistSubscriber>( |
| 335 | node_handle_, |
| 336 | "cmd_vel", |
| 337 | qos, |
| 338 | std::function<void(const geometry_msgs::msg::Twist::SharedPtr)>( |
| 339 | [this](const geometry_msgs::msg::Twist::SharedPtr msg) -> void |
| 340 | { |
| 341 | std::string sdk_msg; |
| 342 | |
| 343 | union Data { |
| 344 | int32_t dword[6]; |
| 345 | uint8_t byte[4 * 6]; |
| 346 | } data; |
| 347 | |
| 348 | data.dword[0] = static_cast<int32_t>(msg->linear.x * 100); |
| 349 | data.dword[1] = 0; |
| 350 | data.dword[2] = 0; |
| 351 | data.dword[3] = 0; |
| 352 | data.dword[4] = 0; |
| 353 | data.dword[5] = static_cast<int32_t>(msg->angular.z * 100); |
| 354 | |
| 355 | uint16_t start_addr = extern_control_table.cmd_velocity_linear_x.addr; |
| 356 | uint16_t addr_length = |
| 357 | (extern_control_table.cmd_velocity_angular_z.addr - |
| 358 | extern_control_table.cmd_velocity_linear_x.addr) + |
| 359 | extern_control_table.cmd_velocity_angular_z.length; |
| 360 | |
| 361 | uint8_t * p_data = &data.byte[0]; |
| 362 | |
| 363 | dxl_sdk_wrapper_->set_data_to_device(start_addr, addr_length, p_data, &sdk_msg); |
| 364 | |
| 365 | RCLCPP_DEBUG( |
| 366 | this->get_logger(), |
| 367 | "lin_vel: %f ang_vel: %f msg : %s", msg->linear.x, msg->angular.z, sdk_msg.c_str()); |
| 368 | } |
| 369 | ), |
| 370 | std::function<void(const geometry_msgs::msg::TwistStamped::SharedPtr)>( |
| 371 | [this](const geometry_msgs::msg::TwistStamped::SharedPtr msg) -> void |
| 372 | { |
| 373 | std::string sdk_msg; |
| 374 | |
| 375 | union Data { |
| 376 | int32_t dword[6]; |
| 377 | uint8_t byte[4 * 6]; |
| 378 | } data; |
| 379 | |
| 380 | data.dword[0] = static_cast<int32_t>(msg->twist.linear.x * 100); |
| 381 | data.dword[1] = 0; |
| 382 | data.dword[2] = 0; |
| 383 | data.dword[3] = 0; |
| 384 | data.dword[4] = 0; |
| 385 | data.dword[5] = static_cast<int32_t>(msg->twist.angular.z * 100); |
| 386 | |
| 387 | uint16_t start_addr = extern_control_table.cmd_velocity_linear_x.addr; |
| 388 | uint16_t addr_length = |
nothing calls this directly
no test coverage detected