You need to initialize all used objects in RobotInit() – You’re calling data from the gyro, but it’s never been initialized, so you’ll get Null Pointers from that; same for your Watchdog.
You don’t need to use the watchdog class.
During teleopPeriodic: Timer.delay(0.002) only slows down the robot, same for Timer.delay(1.0) – it makes that thread sleep and you can’t do anything until it wakes up. You’d be better off using if(KTrigger.getTrigger())drivetrain.drive(0,0);} – Since teleopPeriodic is looped anyway, the “while” loop is redundant.
This may just be one of the things that I do and find useful, but creating constants for port numbers can be extremely useful for someone who has not read your code and is not using your robot.
Things like
private static final int DRIVE_LEFT_FRONT = 1;
Jaguar frontLeftDrive = new Jaguar(DRIVE_LEFT_FRONT);
will be a lot easier for others to understand. (And when you want to make a change you can just find your constants and type in a new number)
Also, to find the x axis/y axis value just type joystick.getX() or joystick.getY(). You also do not need to set the value of the joystick to a double before supplying it to the drive() method.
public static String log(String aMessage){
System.out.println(aMessage);
return aMessage;
}
The above would probably just be better off as a void where you don’t have to bother with the return type. You’ll just be telling yourself something that you already know.
double angle = 0;
do {
drivetrain.drive(0.0, 0.15); //TURN
drivetrainTimer.delay(0.5);
angle += gyro.getAngle(); //
gyro.reset();
log("Gyro reads "+angle);
}while(angle<90); //Keep going in increments of .15 until gyro
I don’t use the standard drive() methods, but IIRC the first value is the forward speed and the second the turning offset speed-wise, not an angle. So unless you know 0.5 second increments is going to end up close to 90, you could be over by a bit.
And only reset your gyro when you need to, and not when its moving. You want to stop and wait a little so that you have a steady zero value.
Like omalleyj said, resetting gyro in the loop isn’t a good way, especially when it’s moving.
I would do something simple like this:
// Reset gyro before the main loop, or with a button.
double angle = gyro.getAngle();
if (angle < 90) {
drivetrain.drive(0.0, 0.15); // I don't know how turn works, I've only done tank drive and mecanum drive in the past.
}