Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Access the Auto List on Driver Station in Java (http://www.chiefdelphi.com/forums/showthread.php?t=145538)

RSNovi 10-03-2016 20:06

Access the Auto List on Driver Station in Java
 
Hello All,

Last weekend we had our first competition. We were using the Smart Dashboard with radio buttons to select our various autonomous modes. It didn't work very well and many others told us they had difficulty using the Smart Dashboard for this purpose. Even though the Smart Dashboard selected the desired autonomous mode I think it had to be selected after the laptop was connected to the robot through the competition system. It was quite error prone for the kids. I would like to use LV Driver Station to choose the autonomous mode.

Under the Drive tab in the driver station there is a blank drop down. Does anyone know how to access this drop dow?. Essentially setup strings and then read from it. I read a little bit, but it all seems to be describing LV to access it via "Auto List" and "Auto Selector"

Thanks.

Chris

RufflesRidge 10-03-2016 20:19

Re: Access the Auto List on Driver Station in Java
 
Here's some sample code that should get you started.

Class members:
final String defaultAuto = "Default";
final String customAuto = "My Auto";
String[] autoList = {defaultAuto, customAuto};
String autoSelected;

in robotInit():
NetworkTable table = NetworkTable.getTable("SmartDashboard");
table.putStringArray("Auto List", autoList);

in autonomousInit():
autoSelected = (String) chooser.getSelected();
System.out.println("Auto selected: " + autoSelected);

in autonomousPeriodic():
switch(autoSelected) {
case customAuto:
//Put custom auto code here
break;
case defaultAuto:
default:
//Put default auto code here
break;
}

BenBernard 10-03-2016 22:25

Re: Access the Auto List on Driver Station in Java
 
Regarding the SmartDashboard, we've had the same issues. We've told our drive team to make each selection twice, and that seems to do the trick. We will be moving (running?) away from the SmartDashboard in future events.

RSNovi 11-03-2016 16:03

Re: Access the Auto List on Driver Station in Java
 
Thank you Ruffles for the advice and I appreciate the validation of our troubles Ben. I will try this code the next time the team meets.

Chris

RufflesRidge 11-03-2016 19:41

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by RufflesRidge (Post 1555258)

in autonomousInit():
autoSelected = (String) chooser.getSelected();
System.out.println("Auto selected: " + autoSelected);

Sorry!!! This part of the code is wrong (that's the code for sendable chooser).

should be something like this instead:
autoSelected = SmartDashboard.getString("Auto Selector", defaultAuto);

GreyingJay 14-03-2016 00:58

Re: Access the Auto List on Driver Station in Java
 
My team decided to use a hardware solution instead. We put a 12-position rotary switch on the robot. It has a little led to indicate which position is selected and it's easy to read using an analog input on the Roborio.

http://www.robotshop.com/en/rotary-e...module-v1.html

rdmarsh 15-03-2016 12:40

Re: Access the Auto List on Driver Station in Java
 
We had a similar problem but with only two auto modes (cross low bar or don't move). We wound up using the throttle on a joystick for it - there is no rule against reading joystick inputs from the driver station during autonomous, just against drivers touching any of them during that period. If you have more than two modes, you might try building a multi-position selector you can hook up over USB using a TI Launchpad.

lethc 15-03-2016 13:13

We had the same issue last year using LabVIEW but after switching to Java this year we've had no problems with SmartDashboard or Sendable Choosers.

mikets 16-03-2016 05:05

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by RSNovi (Post 1555255)
Hello All,

Last weekend we had our first competition. We were using the Smart Dashboard with radio buttons to select our various autonomous modes. It didn't work very well and many others told us they had difficulty using the Smart Dashboard for this purpose. Even though the Smart Dashboard selected the desired autonomous mode I think it had to be selected after the laptop was connected to the robot through the competition system. It was quite error prone for the kids. I would like to use LV Driver Station to choose the autonomous mode.

Under the Drive tab in the driver station there is a blank drop down. Does anyone know how to access this drop dow?. Essentially setup strings and then read from it. I read a little bit, but it all seems to be describing LV to access it via "Auto List" and "Auto Selector"

Thanks.

Chris

We are using the SendableChooser and it works great with the SmartDashboard. We have 8 choices in our autonomous. The list is displayed on the SmartDashboard and we can click and select any one of them. Here is our code using it.
https://github.com/trc492/Frc2016Fir...utonomous.java

RSNovi 17-03-2016 15:39

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by mikets (Post 1558108)
We are using the SendableChooser and it works great with the SmartDashboard. We have 8 choices in our autonomous. The list is displayed on the SmartDashboard and we can click and select any one of them. Here is our code using it.
https://github.com/trc492/Frc2016Fir...utonomous.java

Thank you. Does it matter when you make the selection? For instance does it matter for you whether you make the selection prior to the robot being connected at the competition?

mikets 18-03-2016 02:24

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by RSNovi (Post 1559006)
Thank you. Does it matter when you make the selection? For instance does it matter for you whether you make the selection prior to the robot being connected at the competition?

It doesn't matter. The selection actually sticks meaning even for the next match if you don't select anything else, the previous selection is still in effect until you select something different.

RSNovi 18-03-2016 13:50

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by mikets (Post 1559267)
It doesn't matter. The selection actually sticks meaning even for the next match if you don't select anything else, the previous selection is still in effect until you select something different.

Thank you for sharing your code with me. It is pretty similar to what we have, although yours is more elegant and we put all the code in Robot.java. For some reason we are getting sporadic results. I was thinking that we needed to make sure we toggled the buttons after the robot was connected to the competition system. It was working fine during our normal testing, but something is different when we connect to the competition system. We ended just hard coding the auto choice at our last competition which made it always work, but there were times we needed to change it.

If you get a chance please let me know if you see anything
public void robotInit() {
RobotMap.init();
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
driveTrain = new DriveTrain();
ballArm = new BallArm();
pneumaticArm = new PneumaticArm();

// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS

autoChooser = new SendableChooser();
autoChooser.addDefault("Do Nothing 15 sec", new DoNothing(15));
autoChooser.addObject("Front of low bar", new AutoFrontOfLowBarGroup());
autoChooser.addObject("BW Front of low bar", new AutoFrontOfLowBarBackwardGroup());
autoChooser.addObject("Drive straight forward", new AutoDriveStraightForwardGroup());
autoChooser.addObject("Turn right in front of low bar", new AutoTurnRightLowBar());
autoChooser.addObject("Custom mode", new AutoCustomGroup());
SmartDashboard.putData("Autonomous mode chooser", autoChooser);


SmartDashboard.putData(Scheduler.getInstance());
RobotMap.pneumaticArmCompressor.setClosedLoopContr ol(true);

//autonomousCommand = new DoNothing();

// OI must be constructed after subsystems. If the OI creates Commands
//(which it very likely will), subsystems are not guaranteed to be
// constructed yet. Thus, their requires() statements may grab null
// pointers. Bad news. Don't move it.
oi = new OI();

// instantiate the command used for the autonomous period

// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS


// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
// autonomousCommand = new LookBothWays();

new DisplayDashboard();

}

/**
* This function is called when the disabled button is hit.
* You can use it to reset subsystems before shutting down.
*/
public void disabledInit(){

}

public void disabledPeriodic() {
Scheduler.getInstance().run();
}

public void autonomousInit() {
// schedule the autonomous command (example)
autonomousCommand = (Command) autoChooser.getSelected();
if (autonomousCommand !=null) autonomousCommand.start();
SmartDashboard.putData(Scheduler.getInstance());
}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic()
{
SmartDashboard.putData(Scheduler.getInstance());
Scheduler.getInstance().run();

}

mikets 18-03-2016 14:55

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by RSNovi (Post 1559412)
Thank you for sharing your code with me. It is pretty similar to what we have, although yours is more elegant and we put all the code in Robot.java. For some reason we are getting sporadic results. I was thinking that we needed to make sure we toggled the buttons after the robot was connected to the competition system. It was working fine during our normal testing, but something is different when we connect to the competition system. We ended just hard coding the auto choice at our last competition which made it always work, but there were times we needed to change it.

If you get a chance please let me know if you see anything
public void robotInit() {
RobotMap.init();
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
driveTrain = new DriveTrain();
ballArm = new BallArm();
pneumaticArm = new PneumaticArm();

// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS

autoChooser = new SendableChooser();
autoChooser.addDefault("Do Nothing 15 sec", new DoNothing(15));
autoChooser.addObject("Front of low bar", new AutoFrontOfLowBarGroup());
autoChooser.addObject("BW Front of low bar", new AutoFrontOfLowBarBackwardGroup());
autoChooser.addObject("Drive straight forward", new AutoDriveStraightForwardGroup());
autoChooser.addObject("Turn right in front of low bar", new AutoTurnRightLowBar());
autoChooser.addObject("Custom mode", new AutoCustomGroup());
SmartDashboard.putData("Autonomous mode chooser", autoChooser);


SmartDashboard.putData(Scheduler.getInstance());
RobotMap.pneumaticArmCompressor.setClosedLoopContr ol(true);

//autonomousCommand = new DoNothing();

// OI must be constructed after subsystems. If the OI creates Commands
//(which it very likely will), subsystems are not guaranteed to be
// constructed yet. Thus, their requires() statements may grab null
// pointers. Bad news. Don't move it.
oi = new OI();

// instantiate the command used for the autonomous period

// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS


// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
// autonomousCommand = new LookBothWays();

new DisplayDashboard();

}

/**
* This function is called when the disabled button is hit.
* You can use it to reset subsystems before shutting down.
*/
public void disabledInit(){

}

public void disabledPeriodic() {
Scheduler.getInstance().run();
}

public void autonomousInit() {
// schedule the autonomous command (example)
autonomousCommand = (Command) autoChooser.getSelected();
if (autonomousCommand !=null) autonomousCommand.start();
SmartDashboard.putData(Scheduler.getInstance());
}

/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic()
{
SmartDashboard.putData(Scheduler.getInstance());
Scheduler.getInstance().run();

}

Nothing jumps out at me but then again I am not familiar with Command based code. When you said it doesn't work very well, what were the issues/symptoms? Did you get a null back when calling getSelected()? Did you get an exception? What is the exact failure? From the SmartDashboard and SendableChooser's point of view, that should work. However, one major difference between your code and ours is that we only "newing" an auto strategy when it is selected whereas you are newing all your strategies (commands) and added them to the chooser. There shouldn't be anything wrong with it but I am just trying to figure out if the problem lies in the command based code. Again, I am not familiar with command-based code, but depends on what failure you were seeing, you may want to look at it from a different angle.

RSNovi 18-03-2016 19:50

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by mikets (Post 1559441)
Nothing jumps out at me but then again I am not familiar with Command based code. When you said it doesn't work very well, what were the issues/symptoms? Did you get a null back when calling getSelected()? Did you get an exception? What is the exact failure? From the SmartDashboard and SendableChooser's point of view, that should work. However, one major difference between your code and ours is that we only "newing" an auto strategy when it is selected whereas you are newing all your strategies (commands) and added them to the chooser. There shouldn't be anything wrong with it but I am just trying to figure out if the problem lies in the command based code. Again, I am not familiar with command-based code, but depends on what failure you were seeing, you may want to look at it from a different angle.

I appreciate the help thinking through this.

When the game was activated I think it just ran the default of Do Nothing even one of the Low Bar options was selected. No errors that I know of. The one time we did get it to work I was at the driver station and i toggled the buttons back and forth after the robot was connected to the system. After a few failures we just hard coded the one choice.

During practicing at our school the buttons seemed to work fine.

I will look into newing all of the commands.

RufflesRidge 19-03-2016 08:37

Re: Access the Auto List on Driver Station in Java
 
Quote:

Originally Posted by RSNovi (Post 1559538)
I appreciate the help thinking through this.

When the game was activated I think it just ran the default of Do Nothing even one of the Low Bar options was selected. No errors that I know of. The one time we did get it to work I was at the driver station and i toggled the buttons back and forth after the robot was connected to the system. After a few failures we just hard coded the one choice.

During practicing at our school the buttons seemed to work fine.

I will look into newing all of the commands.

I wonder if the different behavior you are seeing vs. the other poster is related to you using command based vs. them not. Because your data in each option is an object, it may be considered to be different each time where if there's is a string or something, the dashboard side may see it as the same. That may trigger the behavior difference, if the list is "different" it's possible you need to make the selection after the robot links to give you the new value for the object.


All times are GMT -5. The time now is 01:30.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi