micro-ROS之esp32与ros2资料(freertos)
【摘要】
重中之重:micro.ros.org/docs/tutorials/core/overview/
所有案例都是流畅稳定运行的。
比arduino+esp32+ros2稳定性好很多哦。
eps32复位重联,会有节点重名现象。
不过,rqt图正常
源码都是开放的,稍微改一下也是非常方便的。
#inclu...
重中之重:micro.ros.org/docs/tutorials/core/overview/
所有案例都是流畅稳定运行的。
比arduino+esp32+ros2稳定性好很多哦。
eps32复位重联,会有节点重名现象。
不过,rqt图正常
源码都是开放的,稍微改一下也是非常方便的。
-
#include <string.h>
-
#include <stdio.h>
-
#include <unistd.h>
-
-
#include "freertos/FreeRTOS.h"
-
#include "freertos/task.h"
-
#include "esp_log.h"
-
#include "esp_system.h"
-
-
#include <uros_network_interfaces.h>
-
#include <rcl/rcl.h>
-
#include <rcl/error_handling.h>
-
#include <std_msgs/msg/int32.h>
-
#include <rclc/rclc.h>
-
#include <rclc/executor.h>
-
#include <rmw_microros/rmw_microros.h>
-
#include "uxr/client/config.h"
-
-
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Aborting.\n",__LINE__,(int)temp_rc);vTaskDelete(NULL);}}
-
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf("Failed status on line %d: %d. Continuing.\n",__LINE__,(int)temp_rc);}}
-
-
rcl_publisher_t publisher;
-
std_msgs__msg__Int32 msg;
-
-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
-
{
-
RCLC_UNUSED(last_call_time);
-
if (timer != NULL) {
-
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
-
msg.data++;
-
}
-
}
-
-
void micro_ros_task(void * arg)
-
{
-
rcl_allocator_t allocator = rcl_get_default_allocator();
-
rclc_support_t support;
-
-
rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
-
RCCHECK(rcl_init_options_init(&init_options, allocator));
-
rmw_init_options_t* rmw_options = rcl_init_options_get_rmw_init_options(&init_options);
-
-
// Static Agent IP and port can be used instead of autodisvery.
-
RCCHECK(rmw_uros_options_set_udp_address(CONFIG_MICRO_ROS_AGENT_IP, CONFIG_MICRO_ROS_AGENT_PORT, rmw_options));
-
//RCCHECK(rmw_uros_discover_agent(rmw_options));
-
-
// create init_options
-
RCCHECK(rclc_support_init_with_options(&support, 0, NULL, &init_options, &allocator));
-
-
// create node
-
rcl_node_t node;
-
RCCHECK(rclc_node_init_default(&node, "esp32_int32_publisher", "", &support));
-
-
// create publisher
-
RCCHECK(rclc_publisher_init_default(
-
&publisher,
-
&node,
-
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
-
"freertos_int32_publisher"));
-
-
// create timer,
-
rcl_timer_t timer;
-
const unsigned int timer_timeout = 1000;
-
RCCHECK(rclc_timer_init_default(
-
&timer,
-
&support,
-
RCL_MS_TO_NS(timer_timeout),
-
timer_callback));
-
-
// create executor
-
rclc_executor_t executor;
-
RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator));
-
RCCHECK(rclc_executor_add_timer(&executor, &timer));
-
-
msg.data = 0;
-
-
while(1){
-
rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100));
-
usleep(10000);
-
}
-
-
// free resources
-
RCCHECK(rcl_publisher_fini(&publisher, &node));
-
RCCHECK(rcl_node_fini(&node));
-
-
vTaskDelete(NULL);
-
}
-
-
void app_main(void)
-
{
-
#ifdef UCLIENT_PROFILE_UDP
-
// Start the networking if required
-
ESP_ERROR_CHECK(uros_network_interface_initialize());
-
#endif // UCLIENT_PROFILE_UDP
-
-
//pin micro-ros task in APP_CPU to make PRO_CPU to deal with wifi:
-
xTaskCreate(micro_ros_task,
-
"uros_task",
-
CONFIG_MICRO_ROS_APP_STACK,
-
NULL,
-
CONFIG_MICRO_ROS_APP_TASK_PRIO,
-
NULL);
-
}
数值每次是加1:
msg.data++;
修改为+10;
节点名称:
RCCHECK(rclc_node_init_default(&node, "esp32_int32_publisher", "", &support));
修改一下:
RCCHECK(rclc_node_init_default(&node, "love_esp32_pub", "", &support));
主题名称:
-
RCCHECK(rclc_publisher_init_default(
-
&publisher,
-
&node,
-
ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32),
-
"freertos_int32_publisher"));
修改一下:
love_esp32_pub
(随意修改看看效果?)
超级稳定,测试半天,无任何丢包。
文章来源: zhangrelay.blog.csdn.net,作者:zhangrelay,版权归原作者所有,如需转载,请联系作者。
原文链接:zhangrelay.blog.csdn.net/article/details/120341863
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)