Monday, 11 February 2013

Motors and Motion


Motors and Motion

Up to this point, we have only discussed the sensors and the display. Sensors provide infor-
mation to the robot the environment. The screen provides information to the environment.
So far everything has been quite passive. Now it is time to get proactive! The NXT kit
contains 3 motors. The motors allow the robot to change its environment{to go from a
passive observer to an active participant.
7.1 Motors
The NXT motors are sophisticated devices that not only provide a way to apply force, but
also act as rotational sensors{able to measure rotation to the nearest of 360 . Most of the
motor control is done through the use of a collection of special reserved arrays.
7.1.1 Motor Arrays
Motors are connected to the NXT brick through the A, B, or C ports only (not the numbered
ports). Motors are connected and identi ed to your program in the same way that sensors
are using the \Motors and Sensors Setup" window. It is important that the programmer
know which motor is connected to which lettered port.
When motors are connected to the NXT brick and identi ed to the program, the program
maintains two important arrays associated with the motors summarized in Table 7.1.

The motor[] array is a 3-element integer array with motor[0] corresponding to Port A,
motor[1] to Port B, and motor[2] to Port C. The \Motors and Sensors Setup" window,
among other things, sets up meaningful aliases for the array indices 0, 1, and 2, to make
your program more readable.
At the start of the program, the motor array elements are all 0 (motors o ). Assigning a
non-zero value between -100 and 100 to a motor array element instantly turns on the motor
to that power and in the direction speci ed by the sign. The motor will remain on, at that
power, and in that direction for the duration of the program or until the programmer changes
the value.
The nMotorEncoder[] array elements have the same correspondence to Ports A, B, and
C as the motor[] array. Each integer element indicates the number of degrees of rotation of
the motor since the beginning of the program or since the programmer last set the element
to zero. For example, a value of 360 indicates that the motor has completed one full turn,
720 indicates two turns, 765 indicate two and a quarter turns.
Other motor arrays, as described in the RobotC On-line Support on the left side-bar
under the NXT Functions ! Motors section, allow the programmer to control more subtle
aspects of the motors.

No comments:

Post a Comment