SocketCAN is a set of open source CAN device drivers and networking stack that extend the Berkeley socket API in Linux. Installing SocketCAN is rather easy. It introduces a new protocol family called PF_CAN. SocketCAN coexists with other protocol families like PF_INET for the Internet Protocol. The communication with the CAN bus is therefore done analogously to the use of the Internet Protocol, via sockets.
Installing SocketCAN is rather easy. In fact, it just needs to install Debian/Ubuntu packages. To proceed, uses the following command:
sudo apt-get install can-utils
You can find the detailed installation and configuration commands in the following web site. However, I copied some parts below to avoid the reader jumping from a site to another ans ease its life.
By default, the SocketCAN device drivers are not automatically loaded by Linux at boot time on all systems: you may need to enable the relevant linux kernel modules. You can manually load these modules with the following command:
sudo modprobe can sudo modprobe vcan sudo modprobe slcan
Loading kernel modules at boot time
Instead of manually loading the modules after the system has booted, you can configure the system to do it automatically for you. For that, just edit the file /etc/modules and configure it as below:
# /etc/modules: kernel modules to load at boot time. # # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. can can_raw can_dev intrepid
Using SocketCAN with CanUSB
To use CanUSB with SocketCAN, you have to establish a “link” between the drivers and the hardware. This is done with the following command:
sudo slcand -o -c -s8 /dev/ttyACM0 can0
The -s parameter allow to configure different interface speed as indicated below.
|ASCII Command||CAN Bitrate|
If everything worked fine, you should now see the can0 network device. To very it, just type the following command:
Now that socketcan works, it is possible to prepare ROS to use CAN.