Concept Explanation: motor [ sLabel ]

Printer-friendly version


The NXT brick can't move without the assistance of external motors. The only thing the NXT can do is send electric power to an attached motor. The more power the NXT provides, the faster the motor will rotate. RobotC controls this power by using special variables. It sets up a numerical scale from +100 to -100 where 0 is no power and 100 is full power. This scale is easier for humans to understand and the NXT uses that number to determine how much power to send to the motor. The direction in which the motor rotates is based on if the integer is positive or negative. On the waddle bot, positive number move the robot forward, negative numbers move the robot backwards.

Let's take a look at the motor control commands. Both of them control the same motor.


When you configure the motors, the motor variables are automatically created. These special variables all begin with "motor" followed by the motor name encapsulated in square brackets. Each motor is given two names, one static and one dynamic. The static name is based off of the port that the motor is plugged into. Port A is called "motorA", Port B is "motorB", and Port C is "motorC". While you can technically use these names, it is generally better to use the dynamic name that you put in the "name" field in the motor and sensor setup. In the example, we use the "Left" and "Right" for our motors. By using dynamic names, we can change ports and only need to reconfigure the NXT instead of renaming every motor command.

RobotC Rule 6: When possible, name your attached devices and use the dynamic name.