Skip to content

JCaporuscio/Phoenix-Linux-SocketCAN-Example-JetsonGPIO

Repository files navigation

Phoenix-Linux-SocketCAN-Example

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.

Binaries

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/

CAN USB Adapter

SocketCAN USB adapter used below.

Or alternatively deploy the SocketCAN firmware to a HERO

Test Platform

Test robot has a RaspPi + CANable. image

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.

Using Raspbian Buster Raspberry Pi image to control your robot

Materials needed:

Procedure:

  1. Flash SD card with Raspbian Desktop image. (see https://www.raspberrypi.org/documentation/installation/installing-images/README.md)
  2. 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.
  3. Continue with Software Setup.

Jetson Nano setup

Materials needed:

  1. Setup Jetson Nano using instructions from Nvidia. https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#intro
  2. Continue with Software Setup.

Software Setup:

  1. 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
  2. Install CAN tools sudo apt-get install can-utils.
  3. Install git sudo apt-get install git.
  4. Install necessary libs to build example.
    • sudo apt-get install cmake
    • sudo apt-get install libsdl2-dev
  5. Clone repo into user directory git clone https://github.com/CrossTheRoadElec/Phoenix-Linux-SocketCAN-Example.git.
  6. Navigate into repo cd ./Phoenix-Linux-SocketCAN-Example/.
  7. Chmod shell scripts to allow you to use them:
    • chmod +x build.sh
    • chmod +x clean.sh
    • chmod +x canableStart.sh
  8. Bring up can 0 ./canableStart.sh (if you see the message Device or resource busy it means the can network is already up and requires no further action).

Validating SocketCan functionality

  1. Make sure you have talons or another CTRE CAN device connected for validation of can network.
  2. Use ifconfig to display status of the CAN socket.
  3. The first network listed should be can0 and should look like this can0.
  4. Type cansend can0 999#DEADBEEF to send a CAN frame, your talons should now blink orange since a valid CAN message has been seen.
  5. Use candump can0 to see all incoming CAN traffic, which should display all periodic information being sent by a Talon.
  6. You should see a constant stream of messages similar to this:candump
  7. To end the stream press Ctrl+z.

Set up hot swapping

  1. adding files for hot swapping compatibility
  2. Open a new terminal
  3. Type cd /etc/network/.
  4. Type sudo gedit interfaces
  5. 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. sudo
  6. When saving you may get a warning in your terminal; this is expected and not an issue.
  7. Type cd.

Connecting to Diagnostics server:

  1. Make sure your device is connected to the same Wi-Fi network as the windows PC you want to run Tuner on.
  2. Open a terminal on the device and run ifconfig.
  3. 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#).
    ip
  4. Enter your ip into Phoenix tuner.
  5. Click Install Phoenix Library/Diagnostics.
  6. 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 is ctre. ).
    image
  7. Tuner will then install and start the diagnostics server on the device.
  8. The diagnostics server is now installed and running on your device.
  9. 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.
  10. 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.

Running Socket Can Example:

  1. Run Build.sh with ./build.sh.
  2. Run program with ./bin/example.
  3. You're now running Phoenix on your device. Confirm there are no error messages being sent to console output.
  4. You can stop your Program with Ctrl+z.

Errata: The wireless Logitech F710 is currently not supported on the Nvidia Jetson Nano due to a driver issue.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages