废话不多说,直接整起
##平台说明
ubunt18.04 melodic 松灵hunter usb转can模块
#1.安装ros_canopen
cd ~/catkin_ws/src
git clone https://github.com/ros-industrial/ros_canopen/tree/melodic
cd ..
catkin_make
注意编译时候出现错误:
muparser library not found
解决方案:
sudo apt install libmuparser-dev
#2.安装can_utils
cd ~/catkin_ws/src
git clone https://github.com/linux-can/can-utils.git
cd can-utils
make
sudo install make
#3.写脚本使能can口
touch can_init.sh
然后复制下面的东西进can_init.sh脚本里进行保存
#!/bin/bash
modprobe can
modprobe can-raw
modprobe can-bcm
modprobe can-gw
modprobe can_dev
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
给它权限:
sudo chmod 777 can_init.sh
运行它:
sudo ./can_init.sh
#4.测试下有没有数据
candump can0
正常的话会有can的数据流出现
ifconfig
查看第一个是不是can0啥的
#5.发布can话题,后面写代码根据需求订阅获取数据就成
cd ~/catkin_ws
source devel/setup.bash
rosrun socketcan_bridge socketcan_to_topic_node
会出现
[ INFO] [1649863167.872074434]: Successfully connected to can0.
#查看话题发布
cd ~/catkin_ws
source devel/setup.bash
rostopic list
发现多出来个received_messages
#查看具体数据信息
```perl
rostopic echo /received_messages
header:
seq: 34782
stamp:
secs: 1649863424
nsecs: 998589707
frame_id: ''
id: 514
is_rtr: False
is_extended: False
is_error: False
dlc: 8
data: [0, 0, 0, 0, 30, 0, 216, 2]
运行时候出现啥问题,评论区滴滴,本篇参照了这位博主的博客:
https://blog.csdn.net/weixin_40358083/article/details/86229776