RobotC Commands

We see in the help files that you can make a motor move by doing this:

motor[port1] = 127; 

We also find other instructions that tell you to do this:

setMotorSpeeds(port1, 127);

They both worked for us. Is one way better than the other?

TL;DR both are equivalent (except it should be setMotorSpeed, no s on the end, that’s a different function).

RobotC includes a feature called natural language, this was introduced a few years ago to try and make programs a little easier to read.

motor[port1] = 127;


setMotorSpeed( port1, 127 );

If you look in the files that define the natural language functions, setMotorSpeed looks like this.

#define setMotorSpeed(motorPort, speedValue) motor[motorPort] = speedValue

That’s called a macro, ‘setMotorSpeed’ is replaced when the program is compiled and becomes ‘motor’.

There is different function called setMotorSpeeds (with the s on the end). This is a natural language function for setting both left and right drive motor speeds together, the motors attached to left and right side of your drivetrain are defined in the motors and sensors dialog, you can have up to 4 motors on each side.