RP6 ROBOT SYSTEM - 4. Programming the RP6
gram's loop – otherwise the automatic control will not work! Frequently calling from
the main program simply implies to call this function at each and every main loop
cycle. Calling the function at intervals of 10 up to 50 milliseconds will be sufficient, but
its better to call the function at considerably shorter intervals. Calling the function
more frequently will not cause any problems, as a hardware timer is controlling the
timing. For the same reason, we may call the function at changing interval periods,
e.g. ranging from 1ms up to 10ms. Calling the function very frequently will not cost to
much processing time, as the function will only be executed completely in predefined
minimum intervals.
If the function is used correctly, it will automatically regulate the motor's rotational
velocity to the desired value.
Speed control is achieved by determining deviations in every measurement cycle and
summing them up (so-called integrating regulator). This error value is used to adjust
the motor voltages via the Microcontroller's PWM-Modules. If the speed is too low,
the error values will be positive and motor voltage has to be increased at an appropri-
ate rate. If the speed is too high, the voltage must be reduced. This method will
quickly adjust the RP6's speed to a relatively constant PWM value (in which minor de-
viations are quite normal). Speed control allows stabilizing speed independently of
battery voltage, load (weight, surface conditions, slope, etc.) and manufacturing toler-
ances. If we would try to drive a robot at a fixed PWM value, the robot's speed would
be extremely dependent on effective motor load and battery voltage. Additionally,
manufacturing tolerances would result in different speeds for the left and right motor.
The speed control routine is also responsible for reversing the motor turning direction,
as any reversing operation at 15cm/s might considerably accelerate wear out of the
motors and gears. If a motor direction change has to be performed, the robot's speed
will automatically be reduced to zero, followed by the direction change and sub-
sequent acceleration up to the former setpoint speed.
In addition to speed and direction control the system also monitors the current con-
sumption of the motors. It will automatically stop the motors in over current condi-
tions. These safety precaution prevents motor overload and overheating, which may
damage the motors over time.
If three overcurrent events occur within 20 seconds, the protection system will per-
form an emergency shutdown and start flashing the four Status LEDs. Then the Robot
has to be resetted in order to continue operation.
Additionally the system monitors failing encoders or motors (which may happen if
you've tinkered too much with it...). Whenever this happens, the motionControl func-
tion would ramp the PWM value up to maximum and the robot could get out of control
due to this... which of course must be considered as a quite undesirable experience!
Anyway, the robot will be halted completely in this case.
Just to keep this concise, we also included the functions for driving specific distances
and rotating specific angles in the motionControl function.
As you can see, the function is very important for the automatic motor control. As a
matter of fact, the motionControl function itself does not have any parameters like
e.g. the desired speed. Operating parameters need to be set through other functions,
which will be described in detail now.
- 98 -