Quote:
Originally Posted by Zer0
We use java for our programming
jaruar1 is our left drive motor
jaguar2 is our right drive motor
|
Unless your team has used them already you should have E4P US Digital Optical Encoders from previous years' Kit of Parts. Mounting this on a drive shaft would allow you to detect the shaft's rotation to calculate the distance or speed the robot is travelling at. You can use this to tell your robot to drive a distance autonomous and then stop once it reaches that distance.
There is a gyro and an accelerometer included in the Kit of Parts. The gyro is an analog sensor that detects change in angle. Mounting this on the robot parallel to the ground allows you to tell the robot to turn until it reaches 90 degrees (right.)
If you do not use an encoder, gyro, or any other sensor to detect the robot position then the only alternative is a timer based autonomous. You can specify through logic (while statement for SimpleRobot & if then statement for IterativeRobot) to turn on the motors at specific times and turn it off when it shouldn't be running.
Example code of how a timer based autonomous could run. In the example the robot drives backwards for 1 second, sits still for 1 second, and then turn right in place for 1 second.
Code:
Timer timer = new Timer();
Jaguar leftDrive = new Jaguar(1);
Jaguar rightDrive = new Jaguar(2);
autonomousInit() {
timer.start();
timer.reset();
}
autonomousPeriodic() {
double currentTime = timer.get() * MathUtils.pow(10, -6);
if (currentTime < 2) { //if time is less than 2 seconds
leftDrive.set(-0.5); //drive left motors backwards
rightDrive.set(-0.5); //drive right motors backwards
} else if (currentTime >= 2 && currentTime < 3) { //time between 2&3 secs.
leftDrive.set(0);
rightDrive.set(0);
} else if (currentTime >= 3 && currentTime < 4) { //time between 3&4 secs.
leftDrive.set(0.5); //set left forward to turn right
rightDrive.set(-0.5); //set right backward to turn right in place
}
}