CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/CAN/can_sitl.sh
Views: 1799
1
#!/usr/bin/env bash
2
# this script sets up SITL to be able to attach to real CAN devices
3
# once run, you can configure SITL for CAN just like a real board, with the CAN parameters
4
#
5
# CAN_P1_DRIVER=1
6
# CAN_D1_PROTOCOL=1
7
8
# once running you can also attach uavcan_gui_tool to vcan0 to monitor the CAN bus
9
10
[ $# -eq 1 ] || {
11
echo "Usage: can_sitl.sh DEVICE"
12
echo "for example can_sitl.sh /dev/serial/by-id/usb-Zubax_Robotics_Zubax_Babel_3700330018514D563935392000000000-if00"
13
exit 1
14
}
15
16
DEVPATH="$1"
17
18
if readlink $DEVPATH > /dev/null; then
19
DEVNAME=$(basename $(readlink $DEVPATH))
20
else
21
DEVNAME=$(basename $DEVPATH)
22
fi
23
24
set -e
25
26
# cleanup from a previous run
27
sudo killall -9 slcand 2> /dev/null || true
28
for m in slcan can-gw vcan can_raw can; do
29
sudo rmmod $m 2> /dev/null || true
30
done
31
32
sudo modprobe vcan
33
sudo ip link add dev vcan0 type vcan
34
sudo ip link set up vcan0
35
sudo ip link set vcan0 mtu 72
36
sudo modprobe slcan
37
sudo modprobe can-gw
38
sudo slcan_attach -f -s8 -o "$DEVPATH"
39
sudo slcand "$DEVNAME" slcan0
40
sudo ifconfig slcan0 up
41
sudo cangw -A -s vcan0 -d slcan0 -e
42
sudo cangw -A -s slcan0 -d vcan0 -e
43
44
echo "slcan0 setup"
45
ifconfig slcan0
46
47