Using RobotPy on a Raspberry Pi running Bullseye to control CTRE Talon SRX

We are trying to use python3 on a Raspberry Pi running Bullseye 64bit version to control a CTRE Talon SRX.

We have followed the instructions found on GitHub CrossTheRoadElec/Phoenix-Linux-SocketCAN-Example/tree/master and are able to use Phoenix Tuner X on a Win10 computer to control a motor connected to a Talon SRX that is connected to the CAN bus on the Raspberry Pi. We are using a USB2CAN adapter by inno-maker to accomplish this.

Several posts here on CD, make us believe that we should be able to install RobotPy on our Raspberry Pi and then use Python commands on our Raspberry Pi to control our Talon SRX.

We followed this documentation here: Computer Installation — RobotPy 2023 documentation for the Linux ARM Coprocessor. The command listed below, completed without errors.

pi@phoenix-tuner-pi:~ $ sudo pip3 install --find-links=https://tortall.net/~robotpy/wheels/2023/raspbian/ robotpy

We then followed this documentation here: RobotPy Components — RobotPy 2023 documentation

Which we believe indicated that we needed to install the CTRE package. As you can see from the terminal output included here that did not go so well.

Is anyone able to confirm this is the best path to accomplish our goal of being able to use Python to control our CTRE Talon SRX via CAN bus from our Raspberry PI?

If by some chance the path we went down is the recommended path, can anyone provide assistance in resolving this error? Looks like the package may be out of date or looking for a file that is not where it is expected.

Thank you for any assistance you are able to provide.

pi@phoenix-tuner-pi:~ $ sudo pip3 install --find-links=https://tortall.net/~robotpy/wheels/2023/raspbian/ -U robotpy[ctre]
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Looking in links: https://tortall.net/~robotpy/wheels/2023/raspbian/
Requirement already satisfied: robotpy[ctre] in /usr/local/lib/python3.9/dist-packages (2023.4.3.1)
Collecting robotpy[ctre]
  Using cached robotpy-2023.4.3.1-py3-none-any.whl (3.2 kB)
  Downloading robotpy-2023.4.3.0-py3-none-any.whl (3.2 kB)
Requirement already satisfied: robotpy-hal==2023.4.3.0 in /usr/local/lib/python3.9/dist-packages (from robotpy[ctre]) (2023.4.3.0)
Requirement already satisfied: pyntcore==2023.4.3.0 in /usr/local/lib/python3.9/dist-packages (from robotpy[ctre]) (2023.4.3.0)
Requirement already satisfied: robotpy-wpiutil==2023.4.3.0 in /usr/local/lib/python3.9/dist-packages (from robotpy[ctre]) (2023.4.3.0)
Requirement already satisfied: robotpy-wpilib-utilities<2024,>=2023.0.0 in /usr/local/lib/python3.9/dist-packages (from robotpy[ctre]) (2023.1.0)
Requirement already satisfied: robotpy-wpimath==2023.4.3.0 in /usr/local/lib/python3.9/dist-packages (from robotpy[ctre]) (2023.4.3.0)
Requirement already satisfied: wpilib==2023.4.3.0 in /usr/local/lib/python3.9/dist-packages (from robotpy[ctre]) (2023.4.3.0)
Collecting robotpy-ctre<2024.0.0,>=2023.0.0
  Downloading robotpy-ctre-2023.1.0.tar.gz (35 kB)
  Installing build dependencies ... done
  WARNING: Missing build requirements in pyproject.toml for robotpy-ctre<2024.0.0,>=2023.0.0 from https://files.pythonhosted.org/packages/0e/05/3daadad7a386f5d08e124798d1e3b2a1d7cd803ab8e0a28b572af472dd7d/robotpy-ctre-2023.1.0.tar.gz#sha256=33536a86b44b4fda4cd1fc4e7b3db03ad9a71268b83f7a3f495d22d6875b6274 (from robotpy[ctre]).
  WARNING: The project does not specify a build backend, and pip cannot fall back to setuptools without 'wheel'.
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Requirement already satisfied: robotpy-wpinet~=2023.4.3 in /usr/local/lib/python3.9/dist-packages (from pyntcore==2023.4.3.0->robotpy[ctre]) (2023.4.3.0)
Building wheels for collected packages: robotpy-ctre
  Building wheel for robotpy-ctre (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmpu665yzy3_in_process.py build_wheel /tmp/tmpt3bz4z0d
       cwd: /tmp/pip-install-mpzwm216/robotpy-ctre_b8de8fc636fc4b1fb6f60d6c7e81efd7
  Complete output (7 lines):
  running bdist_wheel
  running build
  running build_py
  running build_gen
  running build_dl
  Downloading https://maven.ctr-electronics.com/release/com/ctre/phoenix/sim/wpiapi-cpp-sim/5.30.4/wpiapi-cpp-sim-5.30.4-linuxarm64.zip
  error: HTTP Error 404: Not Found
  ----------------------------------------
  ERROR: Failed building wheel for robotpy-ctre
Failed to build robotpy-ctre
ERROR: Could not build wheels for robotpy-ctre which use PEP 517 and cannot be installed directly
pi@phoenix-tuner-pi:~ $
1 Like

While this error comes after the main CTRE error, it is of interest I think.

This part of the error stands out to me in particular as either you don’t have Internet or that specific version of the wpi API cannot be found at that address. This may be related to not being able to find the correct version of CTRE or install it correctly.

According to the docs that syntax you used is correct for picking components so it’s pointing to the right place it seems.

Outside of that I haven’t used RobotPy but I have done Linux socketCAN for controlling the TalonSRX on a Jetson nano. In that scenario I wasn’t using the wpi code at all. It was just the Phoenix libraries in CPP for a non frc project.

Are you trying to do something that requires FRC driver station and other wpi code or just simply drive a talonSrx from a non RoboRio Linux board?

If you are okay with CPP and can get ahold of a canable or other device for Can to USB (a Canivore will not work. TalonSRX is 2.0 and Canivore is FD). Prepare Linux Robot Controller — Phoenix documentation is the guide I started from.

CTRE currently recommends the CANable for use as a generic CAN 2.0 SocketCAN device. More information can be found here: https://canable.io/

Other potential issues

Raspberry Pi/Jetson Nano
Image your device with the respective image below. Other Images can also be used, although these images have been tested and are known to be supported.

Raspbian Buster is what they have tested with for PI. On Jetson nano I was using the default jetpack image they link to but eventually found how to get Ubuntu 20.04. as they note other versions may work. Just no promises.

Alternatively you can deploy SocketCAN firmware to a HERO. See our repository on Github.

The canable can end up out of stock quite often. If you can get ahold of a hero board that would work as well. They have custom firmware for the hero that will make it capable of socketCAN.

Edit: also I found this nifty PDF awhile ago. I’m sure the original authors might have some insights about this as well.

*Cough @marshall *

Jetson Nano, TileRunner, Talon SRX, and ROS Tutorial.pdf (83.2 MB)

Btw awesome documentation!

1 Like

Thanks for you help.

The Rasberry Pi did have access to the Internet at the time.

We are doing a nonFRC project so we don’t need FRC driver station and other wpi code.

We want to be able to use the built in PID controller on the TalonSRX with the built in encoder counter. We have the CPP working, but all our other code is in Python so would prefer to use that.

Thanks!

That linked PDF about ROS would allow python or cpp nodes. Meaning you leave the motor control in CPP and it could still communicate with your python code with some modifications

For the bad news: even if you could get it to build, it is likely the thing you’re trying to do will not work with our distributed builds as-is. My understanding is that CTRE has two different versions of their library, one that is for simulation and one that is for hardware control. robotpy’s CTRE package only include the simulation version, and the build configuration is only set up for that.

It is possible that you could adjust the configuration of our build and use the non-simulation version as a custom build by modifying pyproject.toml. We did discuss some of this at Allow this to be used standalone on an RPi · Issue #106 · robotpy/robotpy-ctre · GitHub, but at the end of the day nobody who cares about this has put in the work to make it happen.

Another wrinkle is that I believe CTRE never published the ARM libraries in vendor library form, which probably in part explains the 404 error. I think maybe they published an ARM apt package that likely has the libraries in it? You might be able to get the correct libraries and headers, put them in the right zip file, then modify pyproject.toml (see setup.py and pyproject.toml — robotpy-build 0.0.0 documentation), and build it… it would be challenging but if you have deep C++ experience it could be doable. (Edit: thinking about it some more, we could change robotpy-build to be able to link against system-installed libraries and that might be enough to make it work, but you’d still need C++ experience to pull off your side of this if you wanted to try that).

CTRE is releasing a new python package this year called ‘phoenix6’ which has support for switching between library versions at runtime, but uses the phoenix v6 API which may not support all of their hardware. See their documentation for details.

2 Likes

This is actually exactly what we do today. Our auto balance was written in Python this past year.

2 Likes

Thank you all for your wisdom and suggestions.

Based on your input, we will no longer be trying to utilize RobotPy for this project and will possibly look into ROS.

Thanks again.

1 Like

Automatic Addison had good lessons I started to follow for learning about Ros in general. Again that PDF I shared before is specifically about ROS, TalonSRX and Linux which is what you are after. The link above is about Ros with Arduino but the topics can carry over and apply to controlling FRC components as well on rpi.

Also I liked https://www.theconstructsim.com/ when I was starting out. They have some free basic python for robotics and basics of ROS courses. There is paid stuff for advanced learning but if you did the basics of ROS and python you might be well on your way to just control a TalonSRX

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.