User manual

RP6 ROBOT SYSTEM - 4. Programming the RP6
In analogy to the bumper sensors, we may automatically perform ADC measurements
and simplify the main program by using a comfortable function:
void task_ADC(void)
which will shorten the time required to evaluate all ADC channels in a program. Call-
ing this function will subsequentially read all ADC channels in “background mode”
(whenever there is some spare time, the measurements are started / read out...) and
store the results in predefined variables.
The ADC requires some time for each measurement and the readADC function would
block the program flow during that time. The measurement itself does not require any
program action, so we can do something else during this time (the ADC is a hardware
module)
Individual channel measurements are stored in the following 16Bit Variables, which
can be used any time and anywhere in your programs:
ADC_BAT: adcBat
ADC_MCURRENT_L: adcMotorCurrentLeft
ADC_MCURRENT_R: adcMotorCurrentRight
ADC_LS_L: adcLSL
ADC_LS_R: adcLSR
ADC_ADC0: adc0
ADC_ADC1: adc1
As soon as you have started using the task_ADC() function, you must use these vari-
ables instead of the readADC-function!
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "RP6RobotBaseLib.h"
int main(void)
{
initRobotBase();
startStopwatch1();
writeString_P("\n\nJust a sample ADC evaluation program...\n\n");
while(true)
{
if(getStopwatch1() > 300) // Every 300ms...
{
writeString_P("\nADC Left-sided light-sensor: ");
writeInteger(adcLSL, DEC);
writeString_P("\nADC Right-sided light-sensor: ");
writeInteger(adcLSL, DEC);
writeString_P("\nADC Battery: ");
writeInteger(adcBat, DEC);
writeChar('\n');
if(adcBat < 600)
writeString_P("Warning! Low battery level!\n");
setStopwatch1(0); // Reset Stopwatch1 to zero
}
task_ADC(); // ADC evaluation – this has to be called
} // permanently from the main loop!
return 0; // But then you can NOT use readADC anymore!
}
This program will output measurement values of both light sensors and the battery
- 92 -