RP6 ROBOT SYSTEM - 4. Programming the RP6
In this example program, the RP6 will first drive forwards – which is the default set-
ting for movements after a reset. We are using one of the stopwatches to wait 4
seconds and then the direction is reversed. In line 16 and 18 the current rotational
direction is determined and changed accordingly. This repeats at intervals of 4
seconds, which will cause the robot to drive forwards and backwards the whole time.
Clearly the robot will still ignore any obstacles!
Its not that easy to drive specific distances with the functions discussed until now.
There are two special functions for this purpose:
void move(uint8_t desired_speed, uint8_t dir, uint16_t distance,
uint8_t blocking)
The move-function allows the Robot to drive a specific distance. You need to pass de-
sired speed, direction (FWD or BWD) and distance in encoder counts.
The macro:
DIST_MM(DISTANCE)
is helpful for converting a distance from millimetres to encoder counts. Of course you
will need to calibrate the encoder resolution before (see appendix). The sample pro-
gram further down below shows how to use this.
The robot will try to drive the desired distance as accurately as possible. The motion-
Control function starts by accelerating to the setpoint speed and slows down the robot
shortly before the distance is reached to avoid overshooting. Accuracy is around 5mm,
which usually may be considered to be all right.
The function does not support driving very short distances under 5cm, but this can be
improved, of course!
The trailing parameter, named “blocking” is a special feature, which needs a detailed
description.
Usually the function will only set a few variables and immediately returns to the pro-
gram. The robot is then controlled by the motionControl-function “in background”.
This is useful for performing other jobs such as avoiding obstacles. However, if the ro-
bot just has to follow a predefined geometric figure, you can change this with the
blocking parameter.
Setting the parameter “true” (this means 1), the function will call the motionControl
function in a loop until the predefined distance has been reached. The program does
not leave this function – instead it will “block” the normal program flow for the re-
quired time.
Setting the parameter “false” will cause the function to perform as described previ-
ously. It will immediately return after it set the command “start to drive a predefined
distance”. If you call other functions, which set the speed or give other movement
commands, the program could behave incorrectly. You will have to either wait for the
original movement command to finish, or alternatively you can abort the command.
- 101 -