00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <config.h>
00017 #if defined(CONF_DMOTOR) && defined(CONF_DSENSOR)
00018
00019 #include <c++/MotorPair.H>
00020 #include <c++/LightSensor.H>
00021 #include <conio.h>
00022 #include <unistd.h>
00023 #include <tm.h>
00024
00025
00026
00027
00028
00029 int
00030 main(int argc,
00031 char **argv)
00032 {
00033 MotorPair m(Motor::A, Motor::C);
00034 LightSensor l(LightSensor::S2);
00035
00036 const int speed = (m.max + m.min) / 3;
00037 m.off();
00038
00039 unsigned int lightLevel(l.sample());
00040 unsigned int threshold(lightLevel + 5);
00041
00042 cputw (lightLevel);
00043 sleep(2);
00044
00045 while (!shutdown_requested()) {
00046 m.forward(speed);
00047 while (1) {
00048 const unsigned int value(l.get());
00049 cputw(value);
00050 if (value > threshold)
00051 break;
00052 }
00053 m.brake(100);
00054 m.left(m.max);
00055 while (1) {
00056 const unsigned int value(l.get());
00057 cputw(value);
00058 if (value < threshold)
00059 break;
00060 }
00061 m.brake(100);
00062 }
00063 return 0;
00064 }
00065 #else // CONF_DMOTOR && CONF_DSENSOR
00066 #warning raceTrack.C requires CONF_DMOTOR and CONF_DSENSOR
00067 #warning raceTrack demo will do nothing
00068 int
00069 main(int argc,
00070 char **argv)
00071 {
00072 return 0;
00073 }
00074 #endif // CONF_DMOTOR && CONF_DSENSOR