-
Notifications
You must be signed in to change notification settings - Fork 2
Network

Here we use the Raspberry Pi as a node/interface between the SPI-linked CANBUS via the MCP2515 hat with ROS over ethernet. Other types of connections for converting ROS messages to CANBUS interfaces can also be used instead.
To begin, install ubuntu mate for arm64
WIP
Attach the hat. Alternatives include Waveshare RS485 CAN HAT
edit .bashrc to include:
export ROS_MASTER_URI=http://192.168.1.100:11311/
export ROS_IP=192.168.1.102
source /opt/ros/noetic/setup.bash
source ~/catkin_ws/devel/setup.bash
edit the files /boot/config.txt' syscfg.txtandusercfg.txt` to enable spi for raspberry pi boards
the line: dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
Update oscillator frequency according to your hat, same with the interrupt pin
Connect the Ethernet cables for the RPI and the main computer to the router. The router should automatically allocate the IP for each device accordingly.
Please make sure the router IP is also in the same domain of 192.168.1.xxx, ideally 192.168.1.1 should be the router's IP
Run rostopic list or rostopic echo \TEST_TOPIC_PUBLISHER to check if the ROS network has successfully connected.
Once the can0 connection is setup via SPI, reboot and use the following to check the status of the connection:
ip -det link show can0
ip -details -statistics link show can0
we need to reduce the tx queue length to make sure the most recent data is being broadcasted onto the CAN network from ROS First, we need to shut down can0
sudo ip link set can0 down
Then we can edit the interface's properties
sudo ip link set can0 up type can bitrate 1000000
sudo ip link set can0 txqueuelen 1000
sudo ip link set can0 txqueuelen 1
To make the change effective, restart the systemd-networkd
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd
sudo systemctl restart systemd-networkd
Now running ip -details -statistics link show can0, we should see the txqueuelen reduced to 1
Here are some useful commands to monitor your CANBUS
dmesg | grep -i spi
dmesg | grep -i can
rosrun socketcan_interface socketcan_dump can0
canbusload can0@1000000
python3 -m can.viewer -c "can0" -i "socketcan"
candump can0 -xct z -n 10
WIP