You're missing a few steps to do this the way the framework intends.
Pull the following out of autonomousPeriodic:
Code:
driveTrain.forwardMove(0.05, 0.05);
It doesn't belong there. You don't want to control the robot from there, just use it to keep the scheduler running, like it does by default, and put code that updates SmartDashboard there, or moves data from sensors into global areas. Stuff like that.
Next change:
Code:
Command autonomousCommand;
to something like
Code:
Command autonomousCommand = new DriveForwardForXAtYCommand(0.80, 6000);
In the above my dummy values represent 80% power for 6 seconds. The DriveForwardForXAtYCommand class would look like:
Code:
/**
* Imports skipped for brevity
*/
public class DriveStraightForXAtY extends Command {
protected double power;
protected double time;
protected long endTime;
public DriveStraightForDistance(double power, double timeInMillis) {
this.power = power;
this.time = timeInMillis;
requires(Robot.driveTrain);
}
// Called just before this Command runs the first time
protected void initialize() {
long startTime = System.currentTimeMillis();
endTime = startTime + this.time;
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
Robot.driveTrain.setPower(power, power);
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return System.currentTimeInMillis() >= endTime;
}
// Called once after isFinished returns true
protected void end() {
Robot.driveTrain.setPower(0, 0);
}
protected void interrupted() {
end();
}
}
That's roughly the right idea to get your design goal working.