Shortening Driving Program Code

Many in the community cannot post answers to the Official Tech Support forum so we try to post answers here.

What you are looking for are functions. Here is a link to some RobotC function examples. The first two functions I teach new programmers is Drive() and DriveFor(). The first is a basic function that you can call anywhere in your code to move your chassis. DriveFor() allows you to specify the speed and the duration.

void Drive(int left, int right)
    startMotor(LeftRear, left);
    startMotor(RightRear, right);

void DriveFor(int left, int right, float seconds)
    Drive(left, right);

task main()

The benefit here is that if you were to change your chassis to a different drive system (ie: you added gears, reverse some of the drive motors) then you only need to change your code in one place. The other benefit is that down the road you may want to add an integrated motor encoder or have your robot ramp up to speed and then down when it reaches the destination and, again, you only need to have that code in your Drive() function.

Make sense?

Thank you very much. This helped alot