Beginner Java Help - Question 1

Hello! I’m new to Java (we’re planning to switch to it next year after passing the last three years using Labview) and I have one important question. In the “Getting Started with Java for FRC” pdf, it shows the following code for an autonomous that drives in a square pattern by driving half speed for 2 seconds, then turns 90 degrees. This is repeated 4 times :

public void autonomous() { 

     for (int i = 0; i < 4; i++) { 
, 0.0); // drive 50% fwd 0% turn 
          Timer.delay(2.0); // wait 2 seconds 
, 0.75); // drive 0% fwd, 75% turn 
       }, 0.0); // drive 0% forward, 0% turn 

What I don’t understand is why it’s a 75% turn for a 90 deg turn? Is there some way this was calculated?


P.S. I called this “Question 1” because I know that I will have other questions about Java in the future!

I doubt it was calculated. It is just a code example so try not to read too much into it.

It was probably reduced to control speed of the turn. But paramters on your test chasis will be different.

The take away from the example is to show how to set individual motor speeds, and performing time based waits.

Hope this helps,

So, for one robot, it could be o.6, but for another, it could be 0.8?

It also depends how far you’re driving. The smallest amount of rotate will cause the robot to go into a circle. If you want to truly move in a 90 degree line, you have to rotate 90 degrees than move forward.

E/ nvm misread it.

0.75 has nothing to do with the degree of the turn. When the move value is 0, the robot will stay in place.

However, a rotate will cause the motors to run in opposite of each other, essentially turning the robot. 0.75 for 0 seconds (thats what the code says… rotate for 0 seconds) might be + or - depending on the weight of the robot and the condition of the battery.

Yes that is correct, you will need to play with the paramerts to achieve the turn you want based on your particular robot. The % will be based on the weight or the robot, # of motors on each side of your drive train, type of motors, and a couple of other paramters which describe the dynamics of your particular bot.

The example is open-loop, which means it turns without sensors, once you get the example working, dont worry too much if it the turn is not accurate or repeatable.

The main thing here is to make sure you understand the logic of what the code is doing.

After which, try adding sensors to make the turn more repeatable like encoders on the drivetrain, or gryo or digial compass if you would like to stick with this example and enhance upon it.

Hope this helps,

I get it know … thanks!