ubuntu18.04发布CAN话题

废话不多说,直接整起
##平台说明
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

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值