Hardware-Attached Simulation¶
CANivore supports hardware-attached simulation when used in an FRC robot program. This allows a CANivore to be used with real devices on supported host operating systems. The below video showcases controlling a real Falcon 500 in a robot program using hardware-attached simulation.
To utilize hardware-attached simulation, ensure the CANivore is connected directly via USB to the machine running the simulation. All devices on the CANivore CAN Bus should be independently powered, as the CANivore does not provide power. In the robot program, the CANivore name or *
must be specified in the device constructor.
Important
Any motors/actuators that have been connected to a roboRIO CAN Bus at any time must be factory defaulted due to them being FRC Locked. Factory defaulting can be done in Tuner X and should be done when the CANivore is not connected to a roboRIO.
TalonFX m_motor = new TalonFX(0, "mycanivore");
hardware::TalonFX m_motor{0, "mycanivore"};
self.motor = hardware.TalonFX(0, "mycanivore")
In VS Code, select the 3 dots in the top-right, then select Hardware Sim Robot Code
A message in the console should appear that the CAN Bus is connected.
********** Robot program startup complete **********
[phoenix] CANbus Connected: uno (WinUSB, 2B189E633353385320202034383803FF)
[phoenix] CANbus Network Up: uno (WinUSB, 2B189E633353385320202034383803FF)
[phoenix] Library initialization is complete.
Simulation can be started using
python -m robotpy sim
Users may notice the robot program is using simulated devices by default. This is the default behavior if the host platform supports simulation (see requirements for a full list of supported platforms).
In order for the robot program to communicate with physical devices (on platforms that support both simulation and hardware), the CTR_TARGET
environment variable must be set. Examples of this are shown below.
export CTR_TARGET=Hardware # Export the environment variable so it's persistent in the shell
Or
CTR_TARGET=Hardware python3 application.py # Set the environment variable only for the python call