General example using CTRE Phoenix class library on Linux/RaspPi platforms. Two use cases are demonstrated...
- Run robot with no roboRIO for nonFRC use cases (wireless gamepad plugged into Raspberry PI).
- Run robot with roboRIO in FRC competition (roboRIO is used for gamepad and enable/disable, Talons controlled from Raspberry PI).
Note: Requires libsdl2-dev (sudo apt-get install libsdl2-dev) for USB Gamepad interface on Raspberry PI.
Note: There is no more FRC versus nonFRC firmware. Latest Talon/Victor firmware works for both use cases.
Simple example here, we use libSDL2 to get gamepad values...
Library binaries here
This is the requisite platform interface for the integrator to provide for other platforms.
If you link in phoenix-can-utils, you don't need to implement CANComm_* , just implement CANbus_*. Conversely you can just implement the mid-level and don't bother with the low-level.
Name | Notes |
---|---|
libCTRE_PhoenixPlatformLinuxSocketCan.a | Platform implementation to support USB-to-CANbus adapters in Linux (see parent folder for arch). |
libCTRE_PhoenixCanutils.a | Implements CANComm_* routines so you don't have to. But if you want to, remove this from the link list. |
libCTRE_PhoenixCCI.a | Phoenix Common C Interface, leave this be. |
libCTRE_Phoenix.a | Class library, this is built from Phoenix-frc-lib. |
For the latest version of binaries, see our maven repository here:
http://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/
SocketCAN USB adapter used below.
- Firmware : https://github.com/HubertD/candleLight_fw
- Hardware : http://canable.io/
Or alternatively deploy the SocketCAN firmware to a HERO
- Firmware : https://github.com/CrossTheRoadElec/HERO-STM32F4
- Hardware : http://www.ctr-electronics.com/control-system/hro.html
Test robot has a RaspPi + CANable.
Robot also has an FRC roboRIO - however this only necessary to enable actuators if CTRE CAN devices are FRC-Locked. See Phoenix Tuner to determine/modify FRC Lock state.
- Raspberry Pi (3B+)
- Micro SD card
- CANable with CandleLight Firmware (https://canable.io/updater/ update here if not already done)
- Laptop
- Raspbian Buster with desktop (https://www.raspberrypi.org/downloads/raspbian/)
- Flash SD card with Raspbian Desktop image. (see https://www.raspberrypi.org/documentation/installation/installing-images/README.md)
- Boot your Pi and connect to a Wi-Fi network (if you'd like to use Tuner on a windows PC make sure your windows PC and Raspberry Pi is connected to the same network.
- Continue with Software Setup.
- Jetson Nano
- Micro SD card
- CANable with CandleLight Firmware (https://canable.io/updater/ update here if not already done)
- Laptop
- Setup Jetson Nano using instructions from Nvidia. https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#intro
- Continue with Software Setup.
- Once you have your Device setup open a terminal and run the following commands to install necessary files.
sudo apt-get upgrade
sudo apt-get update
sudo apt-get upgrade
- Install CAN tools
sudo apt-get install can-utils
. - Install git
sudo apt-get install git
. - Install necessary libs to build example.
sudo apt-get install cmake
sudo apt-get install libsdl2-dev
- Clone repo into user directory
git clone https://github.com/CrossTheRoadElec/Phoenix-Linux-SocketCAN-Example.git
. - Navigate into repo
cd ./Phoenix-Linux-SocketCAN-Example/.
- Chmod shell scripts to allow you to use them:
chmod +x build.sh
chmod +x clean.sh
chmod +x canableStart.sh
- Bring up can 0
./canableStart.sh
(if you see the messageDevice or resource busy
it means the can network is already up and requires no further action).
- Make sure you have talons or another CTRE CAN device connected for validation of can network.
- Use
ifconfig
to display status of the CAN socket. - The first network listed should be can0 and should look like this .
- Type
cansend can0 999#DEADBEEF
to send a CAN frame, your talons should now blink orange since a valid CAN message has been seen. - Use
candump can0
to see all incoming CAN traffic, which should display all periodic information being sent by a Talon. - You should see a constant stream of messages similar to this:
- To end the stream press
Ctrl+z
.
- adding files for hot swapping compatibility
- Open a new terminal
- Type
cd /etc/network/.
- Type
sudo gedit interfaces
- Copy the following lines into the file and click save
allow-hotplug can0
iface can0 can static
bitrate 1000000
up /sbin/ip link set $IFACE down
up /sbin/ip link set $IFACE up type can
Your file should look like this when finished. - When saving you may get a warning in your terminal; this is expected and not an issue.
- Type
cd
.
- Run Build.sh with
./build.sh
. - Run program with
./bin/example
. - You're now running Phoenix on your device. Confirm there are no error messages being sent to console output.
- You can stop your Program with
Ctrl+z
.
Note: SSH must be enabled on the Linux Robot Controller to perform a field upgrade or modify a device's configuration using Phoenix Tuner.
- Make sure your device is connected to the same Wi-Fi network as the windows PC you want to run Tuner on.
- Open a terminal on the device and run
ifconfig
. - Find the ip listed under wlan0 and next to inet. (Note: depending on your connection setup the ip you want to use may be under a different wlan#).
- Enter your ip into Phoenix tuner.
The Phoenix Diagnostics Server is an HTTP server that communicates with the Phoenix Tuner. There are two versions of the server: a standalone version installed through Phoenix Tuner (legacy), and a version built into your user program (latest). Only one version of the diagnostics server may be running at any given time. We recommend you run the diagnostics server through your user program.
You can disable the diagnostics server in your program by adding c_SetPhoenixDiagnosticsStartTime(-1);
to the start
of your main method. The line is commented out in the example program.
Warning: The instructions below are available for legacy support. We recommend you instead run the Phoenix Diagnostics Server in your user program.
Warning: The legacy instructions below currently do not work. See: CrossTheRoadElec#15
To install the standalone diagnostics server:
- Click
Install Phoenix Library/Diagnostics
. - Enter your username and password when prompted. (Note: The user must have sudo permissions to successfully install Tuner ).
(To find your username look at the text before the@
in the terminal for example in this terminal the user isctre
. ).
- Tuner will then install and start the diagnostics server on the device.
- The diagnostics server is now installed and running on your device.
- See https://phoenix-documentation.readthedocs.io/en/latest/ch08_BringUpCAN.html?highlight=field%20upgrade#field-upgrade-devices for information about field upgrading your devices to the latest version.
- Once connected see https://phoenix-documentation.readthedocs.io/en/latest/ch13_MC.html?highlight=frc%20lock#confirm-frc-unlock to confirm the device you are using is not frc locked.