|
@@ -159,14 +159,24 @@ void microros_task(void *param)
|
|
|
// 等待 2 秒,以便网络连接得到建立。
|
|
|
delay(2000);
|
|
|
|
|
|
-+ rclc_publisher_init_best_effort(
|
|
|
-+ &odom_publisher,
|
|
|
-+ &node,
|
|
|
-+ ROSIDL_GET_MSG_TYPE_SUPPORT(nav_msgs, msg, Odometry),
|
|
|
-+ "odom");
|
|
|
- // 设置 micro-ROS 执行器,并将订阅添加到其中。
|
|
|
- rclc_executor_init(&executor, &support.context, 1, &allocator);
|
|
|
- rclc_executor_add_subscription(&executor, &subscriber, &sub_msg, &twist_callback, ON_NEW_DATA);
|
|
|
+ // 设置 micro-ROS 支持结构、节点和订阅。
|
|
|
+ allocator = rcl_get_default_allocator();
|
|
|
+ rclc_support_init(&support, 0, NULL, &allocator);
|
|
|
+ rclc_node_init_default(&node, "esp32_car", "", &support);
|
|
|
+ rclc_subscription_init_default(
|
|
|
+ &subscriber,
|
|
|
+ &node,
|
|
|
+ ROSIDL_GET_MSG_TYPE_SUPPORT(geometry_msgs, msg, Twist),
|
|
|
+ "/cmd_vel");
|
|
|
+
|
|
|
++ rclc_publisher_init_best_effort(
|
|
|
++ &odom_publisher,
|
|
|
++ &node,
|
|
|
++ ROSIDL_GET_MSG_TYPE_SUPPORT(nav_msgs, msg, Odometry),
|
|
|
++ "odom");
|
|
|
+ // 设置 micro-ROS 执行器,并将订阅添加到其中。
|
|
|
+ rclc_executor_init(&executor, &support.context, 1, &allocator);
|
|
|
+ rclc_executor_add_subscription(&executor, &subscriber, &sub_msg, &twist_callback, ON_NEW_DATA);
|
|
|
|
|
|
// 循环运行 micro-ROS 执行器以处理传入的消息。
|
|
|
while (true)
|