![]() |
Multiple Autons
I want to run different autonomous modes for different starting positions and i was wondering A) How do you do that in the code and B) can it be set from the Classmate and if not can it be set from a controller
|
Re: Multiple Autons
The simplest way to do this is to have a switch/case taking in a variable that you predetermine before a match and having the separate autonomous modes there. For example...
Code:
int position = 1; |
Re: Multiple Autons
Our robot has 16 different autonomous modes that can be programmed. We simply put 4 switches onto the robot and used the get() method to get true or false. Then we converted true (or false, depending on preference). Into 1's and 0's. Finally, we multiplied the values together into a variable and switch/case/breaked it. Although for readability we made a seperate method for each case, and called the specific method.
edit: the switches work only on the robot, i beleive, because we tried control board switches last year and it did not read them, therefore we had to switch to robot switches. But both are easy to use. Also not it's good to write down what each autonomous position is, oh yeah and make copies of it. |
Re: Multiple Autons
You can definitely do it from the Classmate. Just go to the I/O tab and select one or more of the digital inputs. In the code, use station.getInstance().getDigitalInput(number) to get the value of the input, where station is the name of the DriverStation object. There are 10 digital inputs, so you can have 2^10-1=1023 different autonomous programs.
|
Re: Multiple Autons
where do you assign the switch between the autons in the code do you do it in disabled periodic or robot init
|
Re: Multiple Autons
Quote:
Also, 1024 different autonomous programs, you only subtract 1 to get the highest number you can represent, so you can represent 0-1023, which is 1024 integers total. |
Re: Multiple Autons
Quote:
|
Re: Multiple Autons
Quote:
Quote:
|
Re: Multiple Autons
Ok i really have very little preference to how the switch is made i am just looking for help with the code. if you can tell me anyway to set and switch between autons that would be fantastic
|
Re: Multiple Autons
Here is a sniippet of our code that handles auton switiching. It is sanitized, and not all variables are shown declared.
Switching takes place during disabledPeriodic. Care should be taken in teleopinit to clean up after autonomous before heading into teleop mode so that nothing unexpected happens. Code:
public void autonomousPeriodic() |
Re: Multiple Autons
Quote:
|
Re: Multiple Autons
It is my code i am just relatively new to java
|
Re: Multiple Autons
I wrote a code that can switch between i am wondering were i can put it that it will be accessible in disabled and in autonomous.
if it helps my code looks like this( private boolean AutonMode0() { if (driveStick.getRawButton(1)) return false; if (driveStick.getRawButton(2)) return false; if (driveStick.getRawButton(3)) return true; if (driveStick.getRawButton(4)) return true; else { return false; } } private boolean AutonMode1() { if (driveStick.getRawButton(1)) return false; if (driveStick.getRawButton(2)) return true; if (driveStick.getRawButton(3)) return false; if (driveStick.getRawButton(4)) return true; else { return false; } } ) |
Re: Multiple Autons
That works,and you'd put it inside the brackets enclosing the class, except you have to change the method declarations from private boolean Name to private static boolean Name.
There's a much simpler way to do this. In autonomousInit(), do: if (driveStick.getRawButton(1)) { run whatever; } if (driveStick.getRawButton(2)) { run whatever; } and so on |
Re: Multiple Autons
Will these work if you are standing 5 feet away from your controls? If you are using a joystick as your method for selecting an autonomous mode, you need to do it in disabledPeriodic. And you need to set a VARIABLE to some value in response to the input. Your joystick methods are state calls. They don't remember what was done in the past. You store the input in a GLOBAL variable that can be examined by autonomous.
Do not place your autonomous code in autonomousInit, as this is called only once on the way to autonomousPeriodic. Initialize variables and motors and perhaps decide which auton to run in autonomousPeriodic. HINT: see my code above |
| All times are GMT -5. The time now is 09:27. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi