RechteckDemo.c

gehe zur Dokumentation dieser Datei
00001 /*******************************************************************************
00002 *
00003 * File Name:   RechteckDemo.c
00004 * Project  :   Demo
00005 *
00006 * Description: This file contains RechteckDemo
00007 *
00008 * Ver.     Date         Author           Comments
00009 * -------  ----------   --------------   ------------------------------
00010 * 1.00     14.08.2003   Jan Grewe                build
00011 * 2.00     22.10.2003   Jan Grewe        angepasst auf asuro.c Ver.2.10
00012 *
00013 * Copyright (c) 2003 DLR Robotics & Mechatronics
00014 *****************************************************************************/
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   any later version.                                                    *
00021  ***************************************************************************/
00022 #include "asuro.h"
00023 
00024 #define LEFT 0
00025 #define RIGHT 1
00026 #define LINE 0
00027 #define EDGE 1
00028 
00029 SIGNAL (SIG_ADC)
00030 {
00031   static unsigned char tmp[2],flag[2],toggle;
00032   static unsigned char state = LINE, posFlag[2] =
00033                                  {
00034                                    FALSE,FALSE
00035                                  };
00036   static unsigned char pos[2] =
00037     {
00038       0,0
00039     };
00040   static unsigned char rightSpeed = 200, leftSpeed = 200;
00041 
00042   tmp[toggle]= ADCH;
00043 
00044   if (toggle)   ADMUX = (1 <<ADLAR) | (1 <<REFS0) | WHEEL_RIGHT;
00045   else ADMUX = (1 <<ADLAR) | (1 <<REFS0) | WHEEL_LEFT;
00046 
00047   if ( (tmp[toggle] < 128) && (flag[toggle] == TRUE))
00048   {
00049     pos[toggle] ++;
00050     flag[toggle] = FALSE;
00051   }
00052   if ( (tmp[toggle] > 128) && (flag[toggle] == FALSE))
00053   {
00054     pos[toggle] ++;
00055     flag[toggle] = TRUE;
00056   }
00057   toggle ^= 1;
00058 
00059   if (state == LINE)
00060   {
00061     if (pos[LEFT]  > 100)
00062     {
00063       leftSpeed = 0;
00064       pos[LEFT] = 0;
00065       posFlag[LEFT] = TRUE;
00066     }
00067     if (pos[RIGHT] > 100)
00068     {
00069       rightSpeed = 0;
00070       pos[RIGHT] = 0;
00071       posFlag[RIGHT] = TRUE;
00072     }
00073     if (posFlag[RIGHT] == TRUE && posFlag[LEFT] == TRUE)
00074     {
00075       state = EDGE;
00076       leftSpeed = 180;
00077     }
00078   }
00079   if (state == EDGE)
00080   {
00081     if (pos[LEFT]  > 50)
00082     {
00083       leftSpeed = 0;
00084       pos[LEFT] = 0;
00085       posFlag[LEFT] = posFlag[RIGHT] = FALSE;
00086       state = LINE;
00087       leftSpeed = rightSpeed = 200;
00088     }
00089   }
00090   MotorSpeed(leftSpeed,rightSpeed);
00091 }
00092 
00093 
00094 void RechteckDemo(void)
00095 {
00096   Init();
00097   cli();
00098   MotorSpeed(200,200);
00099   DDRC &= ~ ((1<<PC0) | (1<<PC1)); // Input => no break LED
00100   ODOMETRIE_LED_ON;
00101   ADCSRA = (1<<ADEN) | (1<<ADFR) | (1<<ADIE) | (1<<ADSC) | (1<<ADPS0) | (1<<ADPS1) | (1<<ADPS2); // clk/128
00102   ADMUX = (1<<ADLAR) | (1<<REFS0) | WHEEL_LEFT; // AVCC reference with external capacitor
00103   sei();
00104   for (;;);
00105 }

Erzeugt am Wed Feb 14 16:10:02 2007 für ASURO Library von  doxygen 1.5.1-p1