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

rover.c

Go to the documentation of this file.
00001 
00009 /*
00010  *  The contents of this file are subject to the Mozilla Public License
00011  *  Version 1.0 (the "License"); you may not use this file except in
00012  *  compliance with the License. You may obtain a copy of the License at
00013  *  http://www.mozilla.org/MPL/
00014  *
00015  *  Software distributed under the License is distributed on an "AS IS"
00016  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
00017  *  License for the specific language governing rights and limitations
00018  *  under the License.
00019  *
00020  *  The Original Code is legOS code, released October 17, 1999.
00021  *
00022  *  The Initial Developer of the Original Code is Markus L. Noga.
00023  *  Portions created by Markus L. Noga are Copyright (C) 1999
00024  *  Markus L. Noga. All Rights Reserved.
00025  *
00026  *  Contributor(s): Markus L. Noga <markus@noga.de>
00027  */
00028  
00029 #include <config.h>
00030 #if defined(CONF_DSENSOR) && defined(CONF_DMOTOR)
00031 
00032 #include <conio.h>
00033 #include <unistd.h>
00034 
00035 #include <dsensor.h>
00036 #include <dmotor.h>
00037 
00038 #include <sys/lcd.h>
00039 #include <tm.h>
00040 
00042 //
00043 // Functions
00044 //
00046 
00047 wakeup_t sensor_press_wakeup(wakeup_t data);
00048 
00049 // the rover driver
00050 //
00051 int main(int argc, char *argv[]) {
00052   int dir=0;
00053 
00054   while (!shutdown_requested()) {
00055     motor_a_speed(2*MAX_SPEED/3);               // go!
00056     motor_c_speed(2*MAX_SPEED/3);
00057 
00058     motor_a_dir(fwd);
00059     motor_c_dir(fwd);
00060 
00061     cputs("fwwd ");
00062 
00063     if (wait_event(&sensor_press_wakeup, 0) != 0) {
00064             if(SENSOR_1<0xf000)               // keep in mind.
00065             dir=0;
00066         else
00067         dir=1;
00068 
00069             // back up
00070           //
00071         motor_a_dir(rev);
00072             motor_c_dir(rev);
00073 
00074           cputs("rev  ");
00075 
00076             msleep(500);
00077 
00078           motor_a_speed(MAX_SPEED);             // go!
00079         motor_c_speed(MAX_SPEED);
00080 
00081             if(dir==1) {
00082             motor_c_dir(fwd);
00083           cputs("left ");
00084             } else {
00085             motor_a_dir(fwd);
00086           cputs("right");
00087             }
00088 
00089             msleep(500);
00090           }
00091   }
00092   
00093   return 0;
00094 }
00095 
00096 wakeup_t sensor_press_wakeup(wakeup_t data) {
00097         lcd_refresh();
00098         return (SENSOR_1<0xf000) || (SENSOR_3<0xf000);
00099 }
00100 
00101 #else
00102 #warning rover.c requires CONF_DMOTOR and CONF_DSENSOR
00103 #warning rover demo will do nothing
00104 int main(int argc, char *argv[]) {
00105   return 0;
00106 }
00107 #endif // CONF_DSENSOR, CONF_DMOTOR

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