Issue Recieving FMS Data [Java]

Hi! I have followed all the steps on the WPI website for gathering the data from the FMS. The only issue is that I can only retrieve the updated values if I reboot the robot code once they have been given, which I can not due during autonomous. I am really wondering how to get the data at the beginning of the match. Any help is extremely appreciated.

In your Robot.java, you are constructing RightAuto from within robotInit (line 84). The game specific data is not available at that point in time. You will need to construct RightAuto from within autonomousInit instead. You can use a different object (e.g. a string) in autonomousModes so you can move the RightAuto construction later.

Thank you so much! You have really helped. I feel like I should repay you somehow. :smiley:

We are having this same problem at competition. This post helped us figure out our crashing issue. We are using the sendable chooser and I believe this constructs each of our command classes in RobotInit before the data is available.

I am having trouble figuring out how to keep using the sendable chooser and still receive the FMS data.

Chris

What we’re doing is reading the game data in the initialize method of the commands, and then only running the command if it’s the game data that we want for that command.

Thanks. I think I understand the problem now, but not sure how to fix it given our use of command groups.

I think using a command group with the sendablechooser in the RobotInit constructs by group of commands before the data is even available. This is my fault for not understanding the timing of the command group construction.

I use if/else statements in the command group based on the data which isn’t there. It will be a big change for us, but necessary.

Chris

The other option is to not use the command itself as the SendableChooser “value”. If you use an Integer or String object instead, you can compare it in autonomousInit and based on its value construct the actual command.

Great idea. Can you share a little bit of code for me. How would it change from this?

        chooser.addDefault("Cross Line", new AutoCrossLine());
        chooser.addObject("RED Scale", new AutoRedScale());
        chooser.addObject("RED Switch", new AutoRedSwitch());
        chooser.addObject("BLUE Scale", new AutoBlueScale());        
        chooser.addObject("BLUE Switch", new AutoBlueSwitch());
        chooser.addObject("Do Nothing", new AutoDoNothing());
        SmartDashboard.putData("Autonomous mode chooser", chooser);

Do something like this:

        chooser.addDefault("Cross Line", "AutoCrossLine");
        chooser.addObject("RED Scale", "AutoRedScale");
        chooser.addObject("RED Switch", "AutoRedSwitch");
        chooser.addObject("BLUE Scale", "AutoBlueScale");        
        chooser.addObject("BLUE Switch", "AutoBlueSwitch);
        chooser.addObject("Do Nothing", "AutoDoNothing");
        SmartDashboard.putData("Autonomous mode chooser", chooser);

And then in your autonomousInit() do something like:


  String value = (String) chooser.getSelected();
  Command cmd;
  if (value == null) {
    ...
  } else if (value.equals("AutoCrossLine")) {
    cmd = new AutoCrossLine();
  } else if (value.equals("AutoRedScale")) {
    cmd = new AutoRedScale();
  } ...

Excellent! Thank you.

chooser.addObject(String, String) gives a compiler error. I will do some research to see if I need another method.

You might need to cast. E.g. chooser.addObject(“Cross Line”, (Object) “AutoCrossLine”);

How does this look to you?

RobitInit() {
chooser.addDefault("Cross Line", (Command)(Object) "AutoCrossLine");
        chooser.addObject("RED Scale", (Command)(Object) "AutoRedScale");
        chooser.addObject("RED Switch", (Command)(Object) "AutoRedSwitch");
        chooser.addObject("BLUE Scale", (Command)(Object) "AutoBlueScale");        
        chooser.addObject("BLUE Switch", (Command)(Object) "AutoBlueSwitch");
        chooser.addObject("Do Nothing", (Command)(Object) "AutoDoNothing");
        SmartDashboard.putData("Autonomous mode chooser", chooser); }
    public void autonomousInit() {
        Command chooserCommand = chooser.getSelected();
        if(chooserCommand == (Command)(Object) "AutoRedScale"){
        	autonomousCommand = new AutoRedScale();
        }
        else if (chooserCommand == (Command)(Object) "AutoRedSwitch"){
        	autonomousCommand = new AutoRedSwitch();
        }
        else if (chooserCommand == (Command)(Object) "AutoBlueScale"){
        	autonomousCommand = new AutoBlueScale();
        }
        else if (chooserCommand == (Command)(Object) "AutoBlueSwitch"){
        	autonomousCommand = new AutoBlueSwitch();
        }
        else {
        	autonomousCommand = new AutoCrossLine();        	
        }
         // schedule the autonomous command (example)
        if (autonomousCommand != null) autonomousCommand.start();
    }

No, this won’t work. String equality in Java requires the use of String.equals(). Make chooserCommand a String and use String.equals(). You do not need to cast to Command when using chooser.addObject(), you should change chooser to be SendableChooser and that will avoid all casts.


SendableChooser<String> chooser;

robotInit() {
chooser.addDefault("Cross Line", "AutoCrossLine");
        chooser.addObject("RED Scale", "AutoRedScale");
        chooser.addObject("RED Switch", "AutoRedSwitch");
        chooser.addObject("BLUE Scale", "AutoBlueScale");        
        chooser.addObject("BLUE Switch", "AutoBlueSwitch");
        chooser.addObject("Do Nothing", "AutoDoNothing");
        SmartDashboard.putData("Autonomous mode chooser", chooser); }
    public void autonomousInit() {
        String chooserCommand = chooser.getSelected();
        if(chooserCommand == null) {
                autonomousCommand = null;
        }
        else if(chooserCommand.equals("AutoRedScale")){
        	autonomousCommand = new AutoRedScale();
        }
        else if (chooserCommand.equals("AutoRedSwitch")){
        	autonomousCommand = new AutoRedSwitch();
        }
        else if (chooserCommand.equals("AutoBlueScale")){
        	autonomousCommand = new AutoBlueScale();
        }
        else if (chooserCommand.equals("AutoBlueSwitch")){
        	autonomousCommand = new AutoBlueSwitch();
        }
        else {
        	autonomousCommand = new AutoCrossLine();        	
        }
         // schedule the autonomous command (example)
        if (autonomousCommand != null) autonomousCommand.start();
    }

Robot is up for the last match of the day and I will give it a shot.

You are correct that all that casting was not welcomed. Thanks for setting this C coder straight!

Chris

Peter, it works! I can’t thank you enough for the real time support your provided.

A hidden command is the conditional command. Use Robotbuilder and add a conditional command to see how it is created. We are using them to decide if the switch is favorable then if the Scale is favorable and finally just cross the base Line.

It’s not an option in eclipse to add this type of command but its there. Our team git is a mess so I just pushed this copy to my repo https://github.com/cpapplefamily/SuperSirAntsAbot/tree/master/SuperSirAntsABot/src/org/usfirst/frc3244/SuberSirAntsABot2/autonomousroutines look at the Autos labeled with “Conditional”

Auto_11_2_Conditional_IsSwitch_L.java

We get the FMS data as described in the ScreenStepsLive example stored to a string then we look at that sting in the conditional command.