Controlling CTRE CAN motor controllers directly from a Raspberry Pi, without a RoboRIO

Yes, it would need to be a device with a socketcan driver.

There is a socketcan driver for MCP2515, you’ll have to configure a device tree overlay to use it.

im able to see the devices in phoenix tuner but unable to update the firmware, i get a generalCouldNotConnect error when i try to load it. Im still rocking the MCP2515 but have the one you recommenced showing up monday, but being able to see the device would indicate that the CAN module I have is setup correctly right?

I use this DSD TECH one as well. It’s solid.

There are Chinese clone that have better build quality and more feature (optical coupler, better connector, USB-C, etc) and cost less than $10 but those are hard to source in North American and come with no support.

I successfully used the Raspberry Pi RS485/CAN Hat from Waveshare. There are instructions for setting it up for use with SocketCAN on Waveshare’s website. It seems to use the same MCP2515 controller that you have, though, and I was able to update the firmware with it just fine.

One thing I would suggest is factory resetting the motor controller via PhoenixTuner first to clear the FRC lock. I’m not sure if that would help, but I didn’t try to update the firmware until after I had already done that, and it worked for me.

when using the DSD Tech adapter did you have to flash anyfimware onto it or did it run out of the box?

also if you have anymore details about your setup that would be greatly appriciated

im attempting to use a raspi running raspi os with a victor spx

I remember I updated the FW using the Updater. 0.4 should be used for these clones. If you flashed the wrong one it will be recognized by raspberry pi but there will be no CAN communication. Edit: Maybe try both FW. there will be different version of DSD adapter.

You will need to add CTR_TARGET=Hardware to PATH as per this document.

I had not tried victor spx as the only device I have are Kraken, Cancoder and pigeon.

The DSD tech adapter I linked is based on the Canable 2.0 and uses the 2.0 firmware

I think there might be differences between different adapter. Not all DSD tech adapter are the same.

Yes, DSD sells several different versions. I’m just saying the one that I linked earlier in the thread needs the 2.0 firmware.

I should be using the SLCAN one correct?

I think I used Candlelight. Also CTRE doc said this. SLCAN FW will have the adapter appear as a virtual serial port while Candlelight interact with USB drivers directly. (not related to this but Sometimes libusb driver is used for Candlelight on windows on some application.)

Add: I worked with these DSD adapter on some other devices. Specifically Robomaster Motor which require writing code to send CAN packet directly to the motor by yourself and I used Candlelight for most of the time. It is more reliable.

hmmm have been trying with both, sticking with candlelight if thats what u got to work

When i bring up the CAN interface on the pi i see the can status light change from off to green but still not getting the can frames from the victor.

did you use this repo as well to start?

have also been trying to see the devices on phoenix tuner thats running on my windows machine and pointed at the diagnotic server running on the pi

add: there is a red status light in the row of 3, trying to find some documentation on what those indicate.

add2: dont know what changed but i restarted the interface and now i can see the victor in the tunner and am getting the frames, trying to update the firmware but still getting the same issue i was having with the MCP where when i try to flash it says generalCouldNotConnect

I did not use the example you qouted. I use Python aka robotpy with simulation.

Can you check the termination resistor (switch) on your adapter and the end of the line (last device, you would need to add this resistor by yourself)

It’s been a long time since I done this. I can not remember many of the detail but I could pull out my robot and try it later this week.

have a resistor at the end of the line and have tried with the resistor switch on the adapter in both directions (assuming on is with it pushed down or opposite of the boot switch)

If you could get diag server running and discover device, I would think is something within the code is trying to do something causing conflict and your adapter and connection is good. What I would suggest to do is create an empty code where you import phoenix, init all motor and run into a infinit loop doing nothing, while this is running, try tuner.

Edit: Something like this. Note that I used canivore here as this is windows.

Edit 2:

still same issue,

Can you show me your console printout? It should say what is bus connected when diag server started.

[phoenix] CANbus Connected: can0

[phoenix] CANbus Network Up: can0

[phoenix] CANbus Failed Bring-up: can0

[phoenix] Library initialization is complete.

[phoenix-diagnostics] Server 2024.1.0 (Apr 30 2024, 17:31:04) running on port: 1250

i see the bring up failed but im assuming thats because the can netowrk is initialized by another script

which is this one

#!/bin/bash

interface=can0
if [ $# -gt 0 ]; then
interface=$1
fi

sudo ip link set $interface type can bitrate 1000000
sudo ip link set $interface up
sudo ip link set $interface txqueuelen 1000

I am running out of ideas now. would need to dig out my robot to test to know.

all good thanks for all the help so far! let me know if you get any other ideas. You mentioned robotpy, thats part of WPI lib stuff correct? are there any docs for use on a raspi? might be worth to give that a shot