Auto Code Help (JAVA)

I need help coding our robot for Autonomous. All we need it to do is move forward 237cm towards the baseline.

This is the code I currently have:

public void autonomousInit()
{
autoCount = 0;
}

public void autonomousPeriodic()
{
while(isAutonomous() && is Enabled())
{
if(autoCount <= 4.75)
{
driveThingFront.drive(-0.5, 0.012);
driveThingRear.drive(-0.5, 0.012);
autoCount++;
}
else
{
driveThingFront.drive(0, 0);
driveThingRear.drive(0, 0);
}
}
}

Do you use command based or iterative? Do you have any sensors (Specifically encoders)?
An additional note: The code you have right now will not work because you’re not waiting after you drive every time, autoCount will increment by one every time it runs which is about 0.05 secs so after 0.20/0.25 something like that the robot will stop, if you choose to use this code remember to add some kind of delay like Timer.delay(1) which will wait 1 second before continuing…
Plus, it’s a bad habit to use a while loop in a periodic method. remove the while loop because the periodic method will be called… well… periodically (again, once every 0.05 secs).

Command Based and no sensors. I don’t know how to set this up the right way.

Autonomus periodic is called every 200 ms (I believe), or 50 times a second.

Your auto count will exceed 4.75 in less than 1/10 of a second, and then shutoff the motor.

Thank you to everyone that answered. I got it to work!