Velocity control on linux robot controller

We are currently using a raspberry pi connected to a talon srx using CAN. We need to be able to control the motors to shoot a ball at a given speed to shoot a ball. We are building a basketball shooting machine and a spinning flywheel mechanism is used to shoot the basketballs.

We are using the Phoenix tuner to get the PID values to write our own PID loop. However, with our limited experience and the lack of examples using a linux robot controller, we are unsure on how to write a program that meets our needs. We found this example,, which helps but we do not have a joy stick. We are not able to use any FRC/WPILib functionality on the Pi. We have read extensivelly the documentation on, but are still lost.

Our idea is that we want to be able to call the function to control the motors from the gui. the input to the program would be the initial velocity at which the ball needs to be shot at. Then the program would control the motors to run at that speed. We want to use the ctre library on c++ and simply modify the example from the link. Below is a summary of what we want the motor controller program to do. Please help if you know what any of the ctre functions actually do.

  • If signal is received to shoot
    • calculate rpm needed to shoot ball at initial velocity
    • Speed up motors
    • Send signal to GUI that rpm has been reached
  • If signal to stop is receive
    • stop motors
    • send signal when motors reach 0 rpm

It would be much simpler to implement this in an Arduino using PWM.

You wouldn’t nget to use the on-board PID control from the SRX but your application this is likely not needed.

Have you tried seeing if someone from CTRE might be willing to walk you through how to do it? This is totally in their wheelhouse and will probably be able to give you way more support and resources. They are awesome folks and might be able to get your implementation to work even though it is not the standard implementation (roboRIO or HERO board).

If I’m reading your post correctly, your question isn’t really about velocity control at all, but how to get user input and display output on a raspberry pi.

I replied to your latest e-mail on Thursday (including an offer to talk through any of your questions over the phone).
I was going to copy my response below, but I want to take a step back.

This project has a couple pieces, so I want to list my current understanding of your project and follow up with a question.

  1. A GUI to pass information to the Pi and get information back.
  2. A program on the Pi to set the output of your Talon + Victor.
  3. Modifying the program to control the set output of the Talon + Victor to a specific velocity.

From our emails I’ve gathered that this is for an academic project, so my question for 3 is: Do you need to implement the code for velocity control yourself, or is using the Talon’s built-in closed-loop OK (what you use via Tuner and with Velocity Control mode)?

That determines whether you should look at our Velocity Control examples or whether you just need the functions to get current sensor velocity and set the percent output of the Talon.

In either case, each of these three pieces are actually independent pieces of your project and should be developed and tested one at a time.

1 is outside the scope of Phoenix. There may be some folks on this forum that can help you with user input and output from the Pi. In any case, I recommend writing and testing this separately - make a simple program on the Pi that just sends and receives your user input/output however you need it to. Once this is working, then you can can integrate it with controlling motors.

2 and 3 are what I’ve been trying to walk you through via e-mail, and they should be done in order (2 first, then 3). Doing 2 first is important because it lets you check that Phoenix and your hardware is working before you do 3 and add in Velocity control mode. If you try to do these at the same time it will be much more difficult to troubleshoot.
This is why our documentation goes through a general bring-up first, then closed-loop control later.

If you try to do all of these things at once rather than one at a time, it will be extremely difficult to troubleshoot and debug where your issues are.

My offer for phone support on the Phoenix items still stands (respond to my last e-mail to set up a time), or you can continue just our e-mail conversation for support. In particular, our documentation is written so that you do each section step-by-step, so I need to know which step you’re stuck at to help get you un-stuck.


If you have extra money and a little time, the VMX-Pi could help. It would allow you to use the WPILib (2019, 2020 is not yet ready). I do not work for them, but just ordered one, and it is amazing. I am not using CAN, but it was easy to get pwm working and CAN is built in. I do not know if it solves your problem, but could be another good option.

I just emailed you back. We are currently using the Tuner to control the motors and get the kF value.

We already have the program that gets the user input and display output on a raspberry pi. We are currently trying to work on a program that allows us to control the motors at a given velocity, using the ctre library.

Thanks for your suggestion.

1 Like

Yes! They are awesome! But though I could get more ideas from this forum! Thanks

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