From 87564f145b1fa8892cc81f62e466bd73be465e87 Mon Sep 17 00:00:00 2001 From: Siddharth Purohit Date: Mon, 9 Nov 2020 13:41:20 +0530 Subject: [PATCH] AP_Periph: add docs for CAN SITL --- Tools/AP_Periph/README.md | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/Tools/AP_Periph/README.md b/Tools/AP_Periph/README.md index 9b79f103bb..86b7727215 100644 --- a/Tools/AP_Periph/README.md +++ b/Tools/AP_Periph/README.md @@ -95,6 +95,80 @@ parameter "FLASH_BOOTLOADER" to 1. After setting it to 1 the node will respond with a debug text message which can be seen in the UAVCAN GUI tool to show the result of the flash. +# SITL Testing + +Currently GPS peripheral build is supported under linux environment, +we simulate a UAVCAN GPS Peripheral on SocketCAN. + +Setup can be done as follows, this is on top of usual setup required +to build ardupilot: + +``` +sudo dpkg --add-architecture i386 +sudo apt-get update +sudo apt-get install -y gcc-multilib g++-multilib +sudo apt-get update +sudo apt-get -y install can-utils iproute2 linux-modules-extra-$(uname -r) +sudo modprobe vcan +sudo ip link add dev vcan0 type vcan +sudo ip link set up vcan0 +``` +Build Commands: +``` +./waf configure --board sitl_periph_gps +./waf AP_Periph +``` +Autotest Command: +``` +Tools/autotest/autotest.py -v Copter build.SITLPeriphGPS test.CAN +``` + + +--- +**Note** + +To run valgrind on AP_Periph binary you might need to get 32 bit version of libc6-dbg which can be simply get using following command for Ubuntu machines: `sudo apt-get install libc6-dbg:i386` + +--- + + +https://github.com/linux-can/can-utils contains a nice set of utility to do CAN related testings on Linux system. I used Ubuntu for this development, for Ubuntu systems you can simply download this tool using `sudo apt-get install can-utils` + +Following are the common commands that can be used while testing or developing: +* Create Virtual CAN Interface: +``` +sudo modprobe vcan +sudo ip link add dev vcan0 type vcan +sudo ip link set up vcan0 +sudo ip link add dev vcan1 type vcan +sudo ip link set up vcan1 +``` +* Route one CANSocket to another +``` +sudo modprobe can-gw +sudo cangw -A -s vcan0 -d vcan1 -e +sudo cangw -A -s vcan1 -d vcan0 -e +``` +* Delete routes +``` +sudo cangw -D -s vcan0 -d vcan1 -e +sudo cangw -D -s vcan1 -d vcan0 -e +``` +* Route SLCAN to VCAN, this allows connecting CAN devices to SITL run via CAN Adapter like the one running in Ardupilot itself. +``` +sudo modprobe slcan +sudo modprobe can-gw +sudo slcan_attach -f -s8 -o /dev/ttyACM0 +sudo slcand ttyACM0 slcan0 +sudo ifconfig slcan0 up +sudo cangw -A -s vcan0 -d slcan0 -e +sudo cangw -A -s slcan0 -d vcan0 -e +``` +* Dump can messages: +``` +sudo candump vcan0 +``` + # Discussion and Feedback Please join the discussions at these locations: