I learned recently that robotc has a command called startMotor. it has two parameters, a motor and a speed, and it sets the motor to the speed.

But the same thing can be accomplished in one line like this:

motor[desiredMotor] = desiredSpeed;

the above line is perfectly readable, and doesn't push a whole new frame to the call stack. Why would anybody choose to use startMotor in this case?


You have to set something else, cause this instruction is telling the programm to set the motor speed to x and because after that, there is nothing else to do, it is going to end the programm, faster then it is able to turn on the motors. In order for it to do something, you have to make it do something else. e.g. idle


You could also put it into a while loop


while(true){motor[desiredMotor] = desiredSpeed;}

or you can do something like this

while(SensorValue[light]> 50) {motor[desiredMotor] = desiredSpeed;}


motor[desiredMotor] = desiredSpeed;
waituntil(SensorValue[light]> 50)
motor[desiredMotor] = 0;

you are welcome to use this function I found and edited to move a fixed distance

const float WHEEL_DIAMETER = 55; //diameter of the wheel in mm.
const float DISTANCE_BETWEEN_WHEELS = 140;//distance between wheels in mm.
const float ENCODER_RESOLUTION = 360; //the encoder's resolution.
// for using just red motor speeds do (red motor value * MOVEMENT_FACTOR )

void drive2distance(int FLEngineSpeed, int FREngineSpeed,int FLEmm, int FREmm)
// set distance
nMotorEncoderTarget[FLEngine] = FLEmm / MOVEMENT_FACTOR;
nMotorEncoderTarget[FREngine] = FREmm / MOVEMENT_FACTOR;


motor[FLEngine] = FLEngineSpeed;
motor[FREngine] = FREngineSpeed;

while (nMotorRunState[FLEngine] != runStateIdle || nMotorRunState[FREngine] != runStateIdle) {}


motor[FLEngine] = 0;
motor[FREngine] = 0;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.