Robot name in the Java code

Is it possible to know the radio name from within the code. The reason I am asking is we would like to run mostly the same code for the practice bot and competition bot but the competition bot has different drive motors and controllers. This would allow mechanisms to be swapped between bots and mechanical to work while programming works.

What my team has historically done is use robot preferences (which are stored on the RoboRIO) to differentiate between robots. You can just have a boolean that is true for the practice bot and false for the comp bot

https://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1Preferences.html

2 Likes

Wow I did not know that this existed.
Javadoc here: https://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/Preferences.html
I will look into using this for my team, as right now we have to right a new branch for every single test robot we have as they have different numbers of speed controllers etc.

How do you modify this preferences file? There are put methods for in the code, but is there a way to do it directly without programming?

2 Likes

You can put the preferences to smartdashboard/shuffleboard and edit the values there.

1 Like

I haven’t done this in a while (not since my Freshman year), but there are several ways to do it:

The best option is to load in an INI file using OutlineViewer. You can write your INI like so (this is from a demo a team mentor did and there were three versions, each for a different robot):

[NetworkTables Storage 3.0]
string "/FMSInfo/.type"="FMSInfo"
string "/FMSInfo/EventName"=""
double "/FMSInfo/FMSControlData"=1.10839e+06
string "/FMSInfo/GameSpecificMessage"=""
boolean "/FMSInfo/IsRedAlliance"=true
double "/FMSInfo/MatchNumber"=0
double "/FMSInfo/MatchType"=0
double "/FMSInfo/ReplayNumber"=0
double "/FMSInfo/StationNumber"=1
boolean "/LiveWindow/.status/LW Enabled"=false
string "/LiveWindow/Ungrouped/.type"="LW Subsystem"
string "/LiveWindow/Ungrouped/DifferentialDrive[1]/.name"="DifferentialDrive[1]"
string "/Preferences/.type"="RobotPreferences"
double "/Preferences/ELEVATOR_KD"=0
double "/Preferences/ELEVATOR_KF"=0.105
double "/Preferences/ELEVATOR_KI"=0
double "/Preferences/ELEVATOR_KP"=0.0302
double "/Preferences/LeftID"=0
double "/Preferences/RightID"=15
string "/Preferences/SpeedControllerType"="WPI_TalonSRX"
double "/Preferences/ThrottleRatio"=0.2
double "/Preferences/Velocity"=1.5
boolean "/Preferences/arcadeDrive"=false
boolean "/Preferences/rightStick"=false
double "/SmartDashboard/LeftMotorVoltage"=0
string "/SmartDashboard/MotorType"="WPI_TalonSRX"
double "/SmartDashboard/RightMotorVoltage"=-0
double "/SmartDashboard/ThrottleRatio"=0.2

You can do the same but rather than using Outline Viewer, you can FTP into the RoboRIO.

SmartDashboard is another good option, but I personally feel more comfortable not having it easily accessible to users.

What we did in 2018 was we had the INI file on the Rio and on a USB stick so if anything bad happened, we could easily load the INI back onto the RoboRIO

1 Like

The demo was very similar code running across a Talon SRX drivetrain, a Spark MAX drivetrain, and a sample electronics board, so there were three options. She says that it worked very well at the demo

Another possible way of differentiating between robots is to put a jumper on a specific DIO port on the practice robot only (for redundancy against metal shavings we’re actually planning to have two). If the robot sees that the jumper is connected (by reading the value of the digital input) it goes into practice robot mode.

1 Like

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