|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
No Robot Left Behind 2014
I was thinking this week about an old thread I remembered in 2008. For anyone who doesn't know or doesn't remember the 2008 game, robots could gain points by simply driving forward in autonomous. Now, in 2008, there was less space and a longer distance to drive, but it was still very doable for almost any team. That year, there was a thread urging teams to help other, perhaps more inexperienced teams, out there and moving in auto, and I'd like to encourage this for Aerial Assist.
What I would like from this thread are easy ways, in your language/template/architecture of choice, to make a robot drive forward for a certain amount of time, then stop. This will provide teams with extra members or bored programmers with a nice palette of solutions from which to draw from for certain situations to help teams drive forward then stop! Please list assumptions (I think the team being able to drive and having code for that is a safe assumption, but not a ton else). I'll start first, with Command-Based Java. Assumptions:
You'll want a command to do the driving forward and stopping: Code:
package sample;
import edu.wpi.first.wpilibj.Timer;
public class DriveForwardThenStop extends CommandBase {
Timer timer;
double time;
double speed;
public DriveForwardThenStop(double seconds, double speed) {
requires(drive);
timer = new Timer();
time = seconds;
this.speed = speed;
}
// Called just before this Command runs the first time
protected void initialize() {
drive.stop();
timer.start();
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
drive.driveForward(speed);
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return (timer.get() > time);
}
// Called once after isFinished returns true
protected void end() {
drive.stop();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
end();
}
}
Code:
...
class ExampleRobot extends IterativeRobot{
...
Command autonomousCommand;
...
public void robotInit() {
autonomousCommand = new DriveForwardThenStop(2.0, 0.5);
// Initialize all subsystems
CommandBase.init();
}
public void autonomousInit() {
autonomousCommand.start();
}
public void autonomousPeriodic() {
Scheduler.getInstance().run();
}
...
}
P.S. Make sure you remember to stop! Last edited by BigJ : 04-03-2014 at 16:37. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|