Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
英飞凌Infineon
ROS
Serial
英飞凌PSOC62+CYW43012--rosserial实验
发布于 2024-02-02 16:49:47 浏览:288
订阅该版
[tocm] 使用CYW43012模块的WIFI功能,可使用rosserial软件包接入ros系统。本次实验实现了发布按键状态的话题,和订阅LED状态话题来控制LED灯的亮灭 串口输出可参考上篇文章:https://club.rt-thread.org/ask/article/b4a8ddc2844d79f3.html ## 一、RT-studio创建项目 选择wifi_demo  ## 二、rosserial配置 软件包路径:RT-Thread online packages → peripheral libraries and drivers  ## 三、上位机准备 linux上ROS的安装网上有很多教程这里就不多赘述了 运行ros主机 ```shell roscore ``` 后另开一个终端开启rosserial,等待设备连接 ```shell rosrun rosserial_python serial_node.py tcp ``` ## 四、开发板WIFI连接+连接rosserial  ## 五、实验结果  ```shell #输出/btn_status话题信息 rostopic echo /btn_status #发布/led_status话题控制LED rostopic pub -1 /led_status std_msgs/Bool "data: true" rostopic pub -1 /led_status std_msgs/Bool "data: false" ```  hello_world_tcp.cpp 实验代码 ```cpp #include
#include
#include
#include
extern "C" { #include
#include "drv_gpio.h" } #define LED_PIN GET_PIN(0, 1) #define BTN_PIN GET_PIN(6, 2) static ros::NodeHandle nh; static std_msgs::Bool btn_status; static ros::Publisher btn("btn_status", &btn_status); static bool led_status; static struct rt_completion completion; static void messageCb( const std_msgs::Bool &led_msg) { rt_pin_write(LED_PIN,!led_msg.data); //低电平亮灯 } ros::Subscriber
sub("led_status", messageCb ); void btn_exti_cb(void *args) //中断回调 { if(rt_pin_read(BTN_PIN)) { btn_status.data = false; //按键加了上拉电阻,按下为低电平 rt_completion_done(&completion); //释放完成量 } else { btn_status.data = true; rt_completion_done(&completion); } } static void rosserial_thread_entry(void *parameter) { int last_status = 1; rt_completion_init(&completion); //完成量初始化 rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT); rt_pin_mode(BTN_PIN, PIN_MODE_INPUT); rt_pin_attach_irq(BTN_PIN, PIN_IRQ_MODE_RISING_FALLING , btn_exti_cb, RT_NULL); rt_pin_irq_enable(BTN_PIN, PIN_IRQ_ENABLE); nh.getHardware()->setConnection("192.168.0.197", 11411); nh.initNode(); nh.advertise(btn); nh.subscribe(sub); rt_thread_mdelay(5000); nh.spinOnce(); while (1) { if ( nh.connected() ) { if(rt_completion_wait(&completion, 10) == RT_EOK) //等待完成量信号10ms btn.publish( &btn_status ); } else { rt_kprintf("[rosserial] Not Connected \n"); } } } static void spinonce_thread_entry(void *parameter) { while(1) { if ( nh.connected() ) nh.spinOnce(); rt_thread_mdelay(100); } } static void rosserial_hello_world_tcp_example(int argc,char *argv[]) { rt_thread_t thread = rt_thread_create("rosserial", rosserial_thread_entry, RT_NULL, 2048, 25, 10); if(thread != RT_NULL) { rt_thread_startup(thread); rt_kprintf("[rosserial] New thread rosserial\n"); } else { rt_kprintf("[rosserial] Failed to create thread rosserial\n"); } rt_thread_t tid = rt_thread_create("spinonce", spinonce_thread_entry, RT_NULL, 2048, 30, 10); //spinonce运行时间长,另外开线程运行 if(tid != RT_NULL) { rt_thread_startup(tid); rt_kprintf("[spinonce] New thread spinonce\n"); } else { rt_kprintf("[spinonce] Failed to create thread spinonce\n"); } } MSH_CMD_EXPORT(rosserial_hello_world_tcp_example, roserial hello world example with TCP); // If you are using Keil, you can ignore everything below // This is required // If you'd like to compile with scons which uses arm-none-eabi-gcc // extern "C" void __cxa_pure_virtual() // { // while (1); // } // Moreover, you need to add: // CXXFLAGS = CFLAGS + ' -fno-rtti' // in rtconfig.py for arm-none-eabi-gcc ```
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
jfity
这家伙很懒,什么也没写!
文章
2
回答
2
被采纳
0
关注TA
发私信
相关文章
1
有人将RT-Thread移植到Nvidia TX2上面过吗?
2
rt-thread 通过micropython 是否可以创建ros节点
3
RT-Thread Smart上面可以跑ROS吗?
4
请问如何把ros移植到rt-thread上?有这方面的经验和建议吗?谢谢!
5
请问如何在keil下生成libmicroros.a?谢谢!
6
机器人操作系统 (ROS) 协议 rosserial 的移植
7
rosserial publish发布消息时的id问题
8
micro-ros 包下载失败
9
Link error from micro-ros
10
API-PI(RT Thread)与树莓派ROS怎么做通信
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
UART
ESP8266
cubemx
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
编译报错
socket
中断
Debug
rt_mq_消息队列_msg_queue
keil_MDK
ulog
SFUD
msh
C++_cpp
MicroPython
本月问答贡献
RTT_逍遥
10
个答案
3
次被采纳
xiaorui
3
个答案
3
次被采纳
踩姑娘的小蘑菇
6
个答案
2
次被采纳
winfeng
2
个答案
2
次被采纳
三世执戟
8
个答案
1
次被采纳
本月文章贡献
catcatbing
3
篇文章
5
次点赞
lizimu
2
篇文章
9
次点赞
jinchanchan
2
篇文章
2
次点赞
alight
1
篇文章
5
次点赞
swet123
1
篇文章
4
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部