Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

raceTrack.C

Go to the documentation of this file.
00001 //
00002 // The contents of this file are subject to the Mozilla Public License
00003 // Version 1.0 (the "License"); you may not use this file except in
00004 // compliance with the License. You may obtain a copy of the License
00005 // at http://www.mozilla.org/MPL/
00006 // 
00007 // Software distributed under the License is distributed on an "AS IS"
00008 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00009 // the License for the specific language governing rights and
00010 // limitations under the License.
00011 //
00012 // This software was developed as part of the legOS project.
00013 //
00014 // Contributor: Pat Welch (legOS@mousebrains.com)
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 // This is a naive example of a rover which follows a dark line
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

Generated on Fri Feb 25 08:02:34 2005 for brickos by  doxygen 1.3.9.1