Control Kraken X60 With Raspberry Pi

Hello FRC!
I’m working on a personal project where I’d control a Kraken X60 motor using a raspberry pi. My hope is to have an external application talk to a server on the pi which then will communicate through CAN to the motor controller. However, from what I’ve read elsewhere this isn’t so easy.

What would be the best way to do this? I’ve been looking into USB to CAN adapters, and I just haven’t had enough time with these systems to understand what I’m looking at, so I’m deferring to people who know more than I.

Thank you!

4 Likes

I believe this article from CTRE should have most of the information you are looking for. You will also want to read this article on requirements to make sure you are using a supported setup, if you have not yet read these documents. Good luck with your project!

Edit: disclaimer I have never used phoenix outside of FRC

1 Like

Depending on what prices you find you could either use a canivore or other Linux socket-can compatible usb adapter, I’ve had success with a canable for non frc robotics

1 Like

Same! They are usually out of stock when I look. This works for CAN 2.0 but I don’t know about Kraken with CAN FD. The CANivore however should work for CAN FD. I have not used the CANivore outside of FRC yet so can’t speak to that myself.

It looks like that would arrive a little late. Do you think this would work?Amazon.com: USB to CAN Module Type C Power Supply Converter Adapter for CAN 2.0A CAN 2.0B CAN FD Protocol Bus Analyzer V2.0 LED Indicator High Performance : Electronics

Yeah that looks fine, make sure to flash the newest firmware if you do get it though

If you don’t mind explaining, how do you control motors with the canable. I’ve only gotten to see the data and can’t find anything about controlling online

Of note, PWM control is an option… depending on the need could be a lot simpler.

3 Likes

I’ve been reading the same thing elsewhere. This is the first programming I’ve done with these systems, so I don’t actually know the pros and cons between the two. From what I understand, CAN is useful to get the feedback from the encoders and stuff, right?

Gotcha.

Short answer is that PWM communicates one thing, one direction. CAN communicates many things, both directions. It’s up to the motor and controller what all those things will be.

In the case of a Kraken, PWM control gives you the ability to control… I believe… what percentage of battery voltage is forwarded to the windings.

With that context, this seems to be a bit of an X/Y problem.

You chose “Raspberry Pi” and “Kraken X60” - talk me through that. Why those, and not something else?

Secondly, talk us a bit through the overall goal. Regardless of the hardware chosen, what’s the outcome you’re looking for?

These are important questions to ensure you haven’t over-complicated things for yourself. There’s a lot that wpilib and the RIO provide under the hood to make motor integration easy for FRC, and picking a Pi throws a lot of that out the window. Meaning you have to re-create it, maybe.

2 Likes

CTRE has a lot of info about using phoenix on a pi and all the apt stuff, I’ve only used the canable for socket can with a custom brushless controller with the Linux side in python just communicating with the socket can device

1 Like

Depending on what you are doing, most cases you are making use of the Phoenix motor control library and calling functions just like you do in your regular FRC code but solely in c++ (afaik).

My first use case was on a Jetson Nano driving two TalonSRX motor controllers with joystick inputs. You create a regular c++ program that includes those libraries.

I’ll see if I can find my sample code for a super basic program tonight

Edit: My old repo is gone, I might have an offline copy, but looking at the example here is not too far off from what I had for mine. I started from this and changed as needed for my project. You will see examples of setting can IDs, inverted or not, control modes, speed, reading SDL joystick (I went Bluetooth and app control eventually)

1 Like

I’m starting to feel the effects of the XY problem, which is why I came here lol.

I’m choosing the Pi because the RoboRio is out of the price range and has more functionality that I need personally. My goal is to make a svelte application that will control this motor over a network (OSC or TCP, I don’t know yet). To do this, I need to set up a webserver that can control the motor.

I chose the Kraken due to its power and speed. While it will take a little bit to integrate mechanically, it is the best on the market for the purpose I’m trying to use it for.

My hope is to make a Python program that will accept inputs from the GPIO and a webserver and it will handle all the logic and then finally communicate with the motor. I’m planning on using limit switches and potentially a laser distance sensor in the GPIO, so it’s probable that I won’t need to use the CAN bus for feedback at all and only use PWM, which the Pi should be able to provide. However, I just don’t know enough about these systems to make firm decisions on how to communicate from the Pi to the Talon FX

1 Like

What do you want the svelte application to do and what will the motor be controlling? PWM will be significantly easier in almost every way on the pi.

I can’t get into many specifics, but it’ll be adjusting the height of something using a belt/pulley or a chain/sprocket system. I want to have buttons connected to the GPIO for up/down, and the svelte app to utilize preset locations that I can create, update, and go to.

Do you need to get the “thing” to a specific height every time or just moved up or down?

Specific height. Hence the laser distance sensor. I’m guessing I could use that for position and not have to worry about the encoders on the Kraken at all

Would it be something that you could just use an ultrasonic distance sensor line of sight with? If so pwm would be as good as can

1 Like

Yep. So it seems PWM is the correct path to take. I’ll do some reading to see how it all works and try to run it!

2 Likes