Interrogating the CAN bus

can
java

#1

In year’s past, we were able to interrogate the CAN bus for the presence or absence of devices, and skip creating WPILIB objects for them if they were not present. We did this to minimize the amount of spam on the console if someone was debugging a project, but the CAN devices were not present in the test chassis.

This thread has the details; much thanks for Omar at CTRE for that.

Unfortunately, it appears that the edu.wpi.first.wpilibj.can.CANJNI.FRCNetCommCANSessionMuxReceiveMessage method used to sniff the bus has disappeared. Is it there and I just missed it, or will I need to come up with a new way to do the interrogation (I see a lot of useful looking methods in edu.wpi.first.hal.CANAPIJNI, especially readCANPacketLatest).

If the latter, has anyone done anything like this so far this season?


#2

It moved packages to


#3

Thanks! I missed that when searching that package. Code builds now, need to test when I get to school.


#4

When we implemented Phoenix Tuner/Diagnostics, I was thinking of your discovery use case.
@fovea1959

An possibly-simpler alternative is to send a “getdevices” command to Phoenix Diag Server from the RIO. Basically open a tcp socket to http://localhost:1250/?action=getversion, and look at the response.

https://phoenix-documentation.readthedocs.io/en/latest/ch06_PrepRobot.html#verify-the-robot-controller-http-api

You can also do this off the rio with http://172.22.11.2:1250/?action=getversion, or whatever hostname you want to use.

That will give you a formatted json list of all discovered devices. You can also do things like use the name of the Talon/Vic/Pigeon/CANifier to make decisions inside the RIO.


#5

This is a good solution, provided we have Phoenix installed. It would be nice if it was integrated into WPILIBJ for those teams that just need it to check for the PDP or PCM…


#6

Note that Phoenix has to be installed in the roborio, not the PC, for this strategy.
Which you are likely to do if you are using talons/victors/pigeons/canifiers anyway or setting-ids at all.

… I agree, it was not my call. I’d be happy if Phoenix was pre-installed for you.


#7

Understood. Upon reflection, installing Phoenix is not an issue; we’ll want it installed on all our roboRIOs so we can assign IDs to Talons, etc.