From 3c3c628b617dc53f0b7b59285c7d67888074c33d Mon Sep 17 00:00:00 2001 From: sicarius Date: Sun, 18 Feb 2007 00:14:00 +0000 Subject: +++ Additional Codework --- source/Concept/Framework/RoboCode.aps | 2 +- source/Concept/Framework/atmega128io.c | 585 +++++++++++++++++++++ source/Concept/Framework/atmega128io.cpp | 585 --------------------- source/Concept/Framework/default/Makefile | 46 +- source/Concept/Framework/defines.h | 19 +- source/Concept/Framework/display.cpp | 1 - source/Concept/Framework/distance_sensor.cpp | 26 - source/Concept/Framework/dribbler.cpp | 1 - source/Concept/Framework/engine.cpp | 1 - source/Concept/Framework/io_module.cpp | 1 - source/Concept/Framework/ir_sensor.cpp | 9 - source/Concept/Framework/keyboard.cpp | 1 - source/Concept/Framework/kicker.cpp | 1 - source/Concept/Framework/led.cpp | 1 - source/Concept/Framework/main.c | 189 +++++++ source/Concept/Framework/main.cpp | 158 ------ .../Concept/Framework/modules/executor/navigator.c | 199 +++++++ .../Concept/Framework/modules/executor/navigator.h | 53 ++ .../Framework/modules/input/distance_sensor.c | 32 ++ .../Framework/modules/input/distance_sensor.h | 71 +++ source/Concept/Framework/modules/input/ir_sensor.c | 9 + source/Concept/Framework/modules/input/ir_sensor.h | 62 +++ source/Concept/Framework/modules/input/keyboard.c | 1 + source/Concept/Framework/modules/input/keyboard.h | 87 +++ .../Concept/Framework/modules/input/mouse_sensor.c | 1 + .../Concept/Framework/modules/input/mouse_sensor.h | 199 +++++++ source/Concept/Framework/modules/input/sensor.c | 1 + source/Concept/Framework/modules/input/sensor.h | 27 + .../Framework/modules/interpreter/ball_tracker.c | 125 +++++ .../Framework/modules/interpreter/ball_tracker.h | 35 ++ .../modules/interpreter/position_tracker.c | 7 + .../modules/interpreter/position_tracker.h | 45 ++ source/Concept/Framework/modules/io_module.c | 1 + source/Concept/Framework/modules/io_module.h | 45 ++ source/Concept/Framework/modules/output/display.c | 1 + source/Concept/Framework/modules/output/display.h | 198 +++++++ source/Concept/Framework/modules/output/dribbler.c | 1 + source/Concept/Framework/modules/output/dribbler.h | 118 +++++ source/Concept/Framework/modules/output/engine.c | 1 + source/Concept/Framework/modules/output/engine.h | 124 +++++ source/Concept/Framework/modules/output/kicker.c | 1 + source/Concept/Framework/modules/output/kicker.h | 84 +++ source/Concept/Framework/modules/output/led.c | 1 + source/Concept/Framework/modules/output/led.h | 65 +++ source/Concept/Framework/mouse_sensor.cpp | 1 - source/Concept/Framework/position_tracker.cpp | 7 - source/Concept/Framework/robot.c | 135 +++++ source/Concept/Framework/robot.cpp | 129 ----- source/Concept/Framework/sensor.cpp | 1 - source/Concept/Framework/stdafx.h | 2 + source/Concept/Framework/tools.c | 17 + source/Concept/Framework/tools.cpp | 17 - source/Concept/Framework/tools.h | 10 +- 53 files changed, 2578 insertions(+), 961 deletions(-) create mode 100755 source/Concept/Framework/atmega128io.c delete mode 100644 source/Concept/Framework/atmega128io.cpp delete mode 100644 source/Concept/Framework/display.cpp delete mode 100644 source/Concept/Framework/distance_sensor.cpp delete mode 100644 source/Concept/Framework/dribbler.cpp delete mode 100644 source/Concept/Framework/engine.cpp delete mode 100644 source/Concept/Framework/io_module.cpp delete mode 100644 source/Concept/Framework/ir_sensor.cpp delete mode 100644 source/Concept/Framework/keyboard.cpp delete mode 100644 source/Concept/Framework/kicker.cpp delete mode 100644 source/Concept/Framework/led.cpp create mode 100755 source/Concept/Framework/main.c delete mode 100644 source/Concept/Framework/main.cpp create mode 100755 source/Concept/Framework/modules/executor/navigator.c create mode 100755 source/Concept/Framework/modules/executor/navigator.h create mode 100755 source/Concept/Framework/modules/input/distance_sensor.c create mode 100755 source/Concept/Framework/modules/input/distance_sensor.h create mode 100755 source/Concept/Framework/modules/input/ir_sensor.c create mode 100755 source/Concept/Framework/modules/input/ir_sensor.h create mode 100755 source/Concept/Framework/modules/input/keyboard.c create mode 100755 source/Concept/Framework/modules/input/keyboard.h create mode 100755 source/Concept/Framework/modules/input/mouse_sensor.c create mode 100755 source/Concept/Framework/modules/input/mouse_sensor.h create mode 100755 source/Concept/Framework/modules/input/sensor.c create mode 100755 source/Concept/Framework/modules/input/sensor.h create mode 100755 source/Concept/Framework/modules/interpreter/ball_tracker.c create mode 100755 source/Concept/Framework/modules/interpreter/ball_tracker.h create mode 100755 source/Concept/Framework/modules/interpreter/position_tracker.c create mode 100755 source/Concept/Framework/modules/interpreter/position_tracker.h create mode 100755 source/Concept/Framework/modules/io_module.c create mode 100755 source/Concept/Framework/modules/io_module.h create mode 100755 source/Concept/Framework/modules/output/display.c create mode 100755 source/Concept/Framework/modules/output/display.h create mode 100755 source/Concept/Framework/modules/output/dribbler.c create mode 100755 source/Concept/Framework/modules/output/dribbler.h create mode 100755 source/Concept/Framework/modules/output/engine.c create mode 100755 source/Concept/Framework/modules/output/engine.h create mode 100755 source/Concept/Framework/modules/output/kicker.c create mode 100755 source/Concept/Framework/modules/output/kicker.h create mode 100755 source/Concept/Framework/modules/output/led.c create mode 100755 source/Concept/Framework/modules/output/led.h delete mode 100644 source/Concept/Framework/mouse_sensor.cpp delete mode 100644 source/Concept/Framework/position_tracker.cpp create mode 100755 source/Concept/Framework/robot.c delete mode 100644 source/Concept/Framework/robot.cpp delete mode 100644 source/Concept/Framework/sensor.cpp create mode 100755 source/Concept/Framework/tools.c delete mode 100644 source/Concept/Framework/tools.cpp (limited to 'source/Concept') diff --git a/source/Concept/Framework/RoboCode.aps b/source/Concept/Framework/RoboCode.aps index dc61dc5..4822e36 100644 --- a/source/Concept/Framework/RoboCode.aps +++ b/source/Concept/Framework/RoboCode.aps @@ -1 +1 @@ -RoboCode16-Feb-2007 15:16:4617-Feb-2007 14:21:10241016-Feb-2007 15:16:4644, 12, 0, 462AVR GCCdefault\RoboCode.elfY:\Concept\Framework\falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31000main.cppsensor.cpptools.cppatmega128io.cppdistance_sensor.cppengine.cppio_module.cppir_sensor.cppkicker.cppled.cpprobot.cppdribbler.cppdisplay.cppmouse_sensor.cppkeyboard.cppposition_tracker.cppsensor.hstdafx.htools.hatmega128io.hdefines.hdistance_sensor.hengine.hio_module.hir_sensor.hkicker.hled.hrobot.hdribbler.hdisplay.hmouse_sensor.hkeyboard.hposition_tracker.hdefault\MakefiledefaultYESdefault\Makefileatmega128100RoboCode.elfdefault\1-Wall -gdwarf-2 -O0 -fsigned-chardefault1C:\WinAVR\bin\avr-gcc.exeC:\WinAVR\utils\bin\make.exeY:\Concept\Framework\sensor.hY:\Concept\Framework\stdafx.hY:\Concept\Framework\tools.hY:\Concept\Framework\atmega128io.hY:\Concept\Framework\defines.hY:\Concept\Framework\distance_sensor.hY:\Concept\Framework\engine.hY:\Concept\Framework\io_module.hY:\Concept\Framework\ir_sensor.hY:\Concept\Framework\kicker.hY:\Concept\Framework\led.hY:\Concept\Framework\robot.hY:\Concept\Framework\dribbler.hY:\Concept\Framework\display.hY:\Concept\Framework\mouse_sensor.hY:\Concept\Framework\keyboard.hY:\Concept\Framework\main.cppY:\Concept\Framework\sensor.cppY:\Concept\Framework\tools.cppY:\Concept\Framework\atmega128io.cppY:\Concept\Framework\distance_sensor.cppY:\Concept\Framework\engine.cppY:\Concept\Framework\io_module.cppY:\Concept\Framework\ir_sensor.cppY:\Concept\Framework\kicker.cppY:\Concept\Framework\led.cppY:\Concept\Framework\robot.cppY:\Concept\Framework\dribbler.cppY:\Concept\Framework\display.cppY:\Concept\Framework\mouse_sensor.cppY:\Concept\Framework\keyboard.cpp00000stdafx.h100001engine.h100002defines.h100003io_module.h100004robot.h100005robot.cpp100006atmega128io.h100007main.cpp100008tools.cpp100009tools.h100010distance_sensor.h100011ir_sensor.h100012kicker.h100013led.h100014sensor.h100015dribbler.h100016kicker.cpp100017dribbler.cpp100018ir_sensor.cpp100019io_module.cpp100020engine.cpp100021distance_sensor.cpp100022atmega128io.cpp100023led.cpp100024sensor.cpp100025display.h100026display.cpp100027mouse_sensor.h100028mouse_sensor.cpp100029keyboard.h100030keyboard.cpp100031position_tracker.h100032position_tracker.cpp1299 74 1025 52920 29344 135 944 381111 2366 157 966 403148 6388 179 988 42516 0410 201 1010 44719 0300 91 900 33797 44344 135 944 38118 0296 70 1022 525149 41388 179 988 4252 0410 201 1010 44732 17297 98 927 40319 33319 127 949 43257 7341 156 971 46129 0363 185 993 49058 0385 214 1015 51917 22297 98 927 40358 16341 156 971 4611 0363 185 993 4900 0385 214 1015 5199 0297 98 927 4031 0319 127 949 4321 0341 156 971 4610 0363 185 993 490511 0385 214 1015 5191 0297 98 927 4030 0300 100 930 405170 2344 158 974 4630 0347 160 977 465198 38391 218 1021 5231 0303 102 933 40734 10347 160 977 4651 0299 72 1025 52717 28Maximized303 102 933 4071 0 +RoboCode16-Feb-2007 15:16:4617-Feb-2007 21:48:40241016-Feb-2007 15:16:4644, 12, 0, 462AVR GCCdefault\RoboCode.elfY:\Concept\Framework\falseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31000modules\io_module.catmega128io.cmain.crobot.ctools.cmodules\input\distance_sensor.cmodules\input\ir_sensor.cmodules\input\keyboard.cmodules\input\mouse_sensor.cmodules\input\sensor.cmodules\interpreter\position_tracker.cmodules\output\display.cmodules\output\dribbler.cmodules\output\engine.cmodules\output\kicker.cmodules\output\led.cmodules\interpreter\ball_tracker.cmodules\executor\navigator.cstdafx.htools.hatmega128io.hdefines.hrobot.hmodules\input\distance_sensor.hmodules\input\ir_sensor.hmodules\input\keyboard.hmodules\input\mouse_sensor.hmodules\input\sensor.hmodules\output\display.hmodules\output\dribbler.hmodules\output\engine.hmodules\output\kicker.hmodules\output\led.hmodules\interpreter\position_tracker.hmodules\io_module.hmodules\interpreter\ball_tracker.hmodules\executor\navigator.hdefaultNOatmega128100RoboCode.elfdefault\1modules\modules\executor\modules\input\modules\interpreter\modules\logic\modules\output\-Wall -gdwarf-2 -O3 -fsigned-char default0C:\WinAVR\bin\avr-g++.exeC:\WinAVR\utils\bin\make.exeY:\Concept\Framework\stdafx.hY:\Concept\Framework\tools.hY:\Concept\Framework\atmega128io.hY:\Concept\Framework\defines.hY:\Concept\Framework\robot.hY:\Concept\Framework\modules\input\distance_sensor.hY:\Concept\Framework\modules\input\ir_sensor.hY:\Concept\Framework\modules\input\keyboard.hY:\Concept\Framework\modules\input\mouse_sensor.hY:\Concept\Framework\modules\input\sensor.hY:\Concept\Framework\modules\output\display.hY:\Concept\Framework\modules\output\dribbler.hY:\Concept\Framework\modules\output\engine.hY:\Concept\Framework\modules\output\kicker.hY:\Concept\Framework\modules\output\led.hY:\Concept\Framework\modules\interpreter\position_tracker.hY:\Concept\Framework\modules\io_module.hY:\Concept\Framework\modules\interpreter\ball_tracker.hY:\Concept\Framework\modules\executor\navigator.hY:\Concept\Framework\modules\io_module.cY:\Concept\Framework\atmega128io.cY:\Concept\Framework\main.cY:\Concept\Framework\robot.cY:\Concept\Framework\tools.cY:\Concept\Framework\modules\input\distance_sensor.cY:\Concept\Framework\modules\input\ir_sensor.cY:\Concept\Framework\modules\input\keyboard.cY:\Concept\Framework\modules\input\mouse_sensor.cY:\Concept\Framework\modules\input\sensor.cY:\Concept\Framework\modules\interpreter\position_tracker.cY:\Concept\Framework\modules\output\display.cY:\Concept\Framework\modules\output\dribbler.cY:\Concept\Framework\modules\output\engine.cY:\Concept\Framework\modules\output\kicker.cY:\Concept\Framework\modules\output\led.cY:\Concept\Framework\modules\interpreter\ball_tracker.cY:\Concept\Framework\modules\executor\navigator.c00000stdafx.h100001defines.h100002robot.h100003robot.cpp100004atmega128io.h100005main.cpp100006tools.cpp100007tools.h100008atmega128io.cpp100009modules\interpreter\position_tracker.cpp100010modules\interpreter\position_tracker.h100011modules\io_module.h100012modules\output\display.h100013modules\input\ir_sensor.h100014modules\output\engine.h100015modules\input\sensor.h100016modules\input\keyboard.h100017modules\io_module.c100018robot.c100019modules\input\ir_sensor.c100020modules\output\dribbler.h100021modules\output\kicker.h100022modules\output\led.h100023modules\input\distance_sensor.h100024modules\input\mouse_sensor.h100025modules\input\sensor.c100026main.c100027modules\interpreter\ball_tracker.h100028modules\interpreter\ball_tracker.c100029modules\interpreter\position_tracker.c100030modules\input\distance_sensor.c100031modules\output\engine.c100032modules\output\dribbler.c100033modules\executor\navigator.h100034modules\executor\navigator.c1310 73 1036 52822 2232650 32233 33250 32479155 1932672 32255 33272 3250145 032694 32277 33294 3252316 032716 32299 33316 3254519 032606 32189 33206 3243597 032650 32233 33250 3247917 032602 32168 33328 326234 1732694 32277 33294 325232 0399 216 1025 5174 0311 100 941 40531 2336 131 966 4366 0358 160 988 46542 16380 189 1010 49417 2402 218 1032 52322 12314 102 944 4073 16336 131 966 43618 9358 160 988 4651 0380 189 1010 49491 34402 218 1032 5230 0314 102 944 40724 13336 131 966 4363 16358 160 988 4653 16380 189 1010 49447 30402 218 1032 523187 20314 102 944 4071 0336 131 966 436125 14358 160 988 46519 25380 189 1010 49467 38402 218 1032 5237 0314 102 944 40727 0336 131 966 4360 0358 160 988 4650 0402 218 1021 52335 15310 72 1025 52778 34Maximized diff --git a/source/Concept/Framework/atmega128io.c b/source/Concept/Framework/atmega128io.c new file mode 100755 index 0000000..b1d6f4d --- /dev/null +++ b/source/Concept/Framework/atmega128io.c @@ -0,0 +1,585 @@ +#include "atmega128io.h" + +/************************************************************************* +Title: Interrupt UART library with receive/transmit circular buffers +Author: Peter Fleury http://jump.to/fleury +File: $Id: uart.c,v 1.5.2.10 2005/11/15 19:49:12 peter Exp $ +Software: AVR-GCC 3.3 +Hardware: any AVR with built-in UART, + tested on AT90S8515 at 4 Mhz and ATmega at 1Mhz + +DESCRIPTION: + An interrupt is generated when the UART has finished transmitting or + receiving a byte. The interrupt handling routines use circular buffers + for buffering received and transmitted data. + + The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables define + the buffer size in bytes. Note that these variables must be a + power of 2. + +USAGE: + Refere to the header file uart.h for a description of the routines. + See also example test_uart.c. + +NOTES: + Based on Atmel Application Note AVR306 + +*************************************************************************/ +#include +#include +//#include +#include + +/* + * constants and macros + */ + +/* size of RX/TX buffers */ +#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1) +#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1) + +#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK ) +#error RX buffer size is not a power of 2 +#endif +#if ( UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK ) +#error TX buffer size is not a power of 2 +#endif + +#if defined(__AVR_AT90S2313__) \ + || defined(__AVR_AT90S4414__) || defined(__AVR_AT90S4434__) \ + || defined(__AVR_AT90S8515__) || defined(__AVR_AT90S8535__) \ + || defined(__AVR_ATmega103__) + /* old AVR classic or ATmega103 with one UART */ + #define AT90_UART + #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA + #define UART0_STATUS USR + #define UART0_CONTROL UCR + #define UART0_DATA UDR + #define UART0_UDRIE UDRIE +#elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__) + /* old AVR classic with one UART */ + #define AT90_UART + #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA + #define UART0_STATUS UCSRA + #define UART0_CONTROL UCSRB + #define UART0_DATA UDR + #define UART0_UDRIE UDRIE +#elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \ + || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__) \ + || defined(__AVR_ATmega323__) + /* ATmega with one USART */ + #define ATMEGA_USART + #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA + #define UART0_STATUS UCSRA + #define UART0_CONTROL UCSRB + #define UART0_DATA UDR + #define UART0_UDRIE UDRIE +#elif defined(__AVR_ATmega163__) + /* ATmega163 with one UART */ + #define ATMEGA_UART + #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA + #define UART0_STATUS UCSRA + #define UART0_CONTROL UCSRB + #define UART0_DATA UDR + #define UART0_UDRIE UDRIE +#elif defined(__AVR_ATmega162__) + /* ATmega with two USART */ + #define ATMEGA_USART0 + #define ATMEGA_USART1 + #define UART0_RECEIVE_INTERRUPT SIG_USART0_RECV + #define UART1_RECEIVE_INTERRUPT SIG_USART1_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_USART0_DATA + #define UART1_TRANSMIT_INTERRUPT SIG_USART1_DATA + #define UART0_STATUS UCSR0A + #define UART0_CONTROL UCSR0B + #define UART0_DATA UDR0 + #define UART0_UDRIE UDRIE0 + #define UART1_STATUS UCSR1A + #define UART1_CONTROL UCSR1B + #define UART1_DATA UDR1 + #define UART1_UDRIE UDRIE1 +#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) + /* ATmega with two USART */ + #define ATMEGA_USART0 + #define ATMEGA_USART1 + #define UART0_RECEIVE_INTERRUPT SIG_UART0_RECV + #define UART1_RECEIVE_INTERRUPT SIG_UART1_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_UART0_DATA + #define UART1_TRANSMIT_INTERRUPT SIG_UART1_DATA + #define UART0_STATUS UCSR0A + #define UART0_CONTROL UCSR0B + #define UART0_DATA UDR0 + #define UART0_UDRIE UDRIE0 + #define UART1_STATUS UCSR1A + #define UART1_CONTROL UCSR1B + #define UART1_DATA UDR1 + #define UART1_UDRIE UDRIE1 +#elif defined(__AVR_ATmega161__) + /* ATmega with UART */ + #error "AVR ATmega161 currently not supported by this libaray !" +#elif defined(__AVR_ATmega169__) + /* ATmega with one USART */ + #define ATMEGA_USART + #define UART0_RECEIVE_INTERRUPT SIG_USART_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_USART_DATA + #define UART0_STATUS UCSRA + #define UART0_CONTROL UCSRB + #define UART0_DATA UDR + #define UART0_UDRIE UDRIE +#elif defined(__AVR_ATmega48__) ||defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) + #define ATMEGA_USART0 + #define UART0_RECEIVE_INTERRUPT SIG_USART_RECV + #define UART0_TRANSMIT_INTERRUPT SIG_USART_DATA + #define UART0_STATUS UCSR0A + #define UART0_CONTROL UCSR0B + #define UART0_DATA UDR0 + #define UART0_UDRIE UDRIE0 +#elif defined(__AVR_ATtiny2313__) + #define ATMEGA_USART + #define UART0_RECEIVE_INTERRUPT SIG_USART0_RX + #define UART0_TRANSMIT_INTERRUPT SIG_USART0_UDRE + #define UART0_STATUS UCSRA + #define UART0_CONTROL UCSRB + #define UART0_DATA UDR + #define UART0_UDRIE UDRIE +#else + #error "no UART definition for MCU available" +#endif + + +/* + * module global variables + */ +static volatile unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE]; +static volatile unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE]; +static volatile unsigned char UART_TxHead; +static volatile unsigned char UART_TxTail; +static volatile unsigned char UART_RxHead; +static volatile unsigned char UART_RxTail; +static volatile unsigned char UART_LastRxError; + +#if defined( ATMEGA_USART1 ) +static volatile unsigned char UART1_TxBuf[UART_TX_BUFFER_SIZE]; +static volatile unsigned char UART1_RxBuf[UART_RX_BUFFER_SIZE]; +static volatile unsigned char UART1_TxHead; +static volatile unsigned char UART1_TxTail; +static volatile unsigned char UART1_RxHead; +static volatile unsigned char UART1_RxTail; +static volatile unsigned char UART1_LastRxError; +#endif + + + +SIGNAL(UART0_RECEIVE_INTERRUPT) +/************************************************************************* +Function: UART Receive Complete interrupt +Purpose: called when the UART has received a character +**************************************************************************/ +{ + unsigned char tmphead; + unsigned char data; + unsigned char usr; + unsigned char lastRxError; + + + /* read UART status register and UART data register */ + usr = UART0_STATUS; + data = UART0_DATA; + + /* */ +#if defined( AT90_UART ) + lastRxError = (usr & (_BV(FE)|_BV(DOR)) ); +#elif defined( ATMEGA_USART ) + lastRxError = (usr & (_BV(FE)|_BV(DOR)) ); +#elif defined( ATMEGA_USART0 ) + lastRxError = (usr & (_BV(FE0)|_BV(DOR0)) ); +#elif defined ( ATMEGA_UART ) + lastRxError = (usr & (_BV(FE)|_BV(DOR)) ); +#endif + + /* calculate buffer index */ + tmphead = ( UART_RxHead + 1) & UART_RX_BUFFER_MASK; + + if ( tmphead == UART_RxTail ) { + /* error: receive buffer overflow */ + lastRxError = UART_BUFFER_OVERFLOW >> 8; + }else{ + /* store new index */ + UART_RxHead = tmphead; + /* store received data in buffer */ + UART_RxBuf[tmphead] = data; + } + UART_LastRxError = lastRxError; +} + + +SIGNAL(UART0_TRANSMIT_INTERRUPT) +/************************************************************************* +Function: UART Data Register Empty interrupt +Purpose: called when the UART is ready to transmit the next byte +**************************************************************************/ +{ + unsigned char tmptail; + + + if ( UART_TxHead != UART_TxTail) { + /* calculate and store new buffer index */ + tmptail = (UART_TxTail + 1) & UART_TX_BUFFER_MASK; + UART_TxTail = tmptail; + /* get one byte from buffer and write it to UART */ + UART0_DATA = UART_TxBuf[tmptail]; /* start transmission */ + }else{ + /* tx buffer empty, disable UDRE interrupt */ + UART0_CONTROL &= ~_BV(UART0_UDRIE); + } +} + + +/************************************************************************* +Function: uart_init() +Purpose: initialize UART and set baudrate +Input: baudrate using macro UART_BAUD_SELECT() +Returns: none +**************************************************************************/ +void uart_init(unsigned int baudrate) +{ + UART_TxHead = 0; + UART_TxTail = 0; + UART_RxHead = 0; + UART_RxTail = 0; + +#if defined( AT90_UART ) + /* set baud rate */ + UBRR = (unsigned char)baudrate; + + /* enable UART receiver and transmmitter and receive complete interrupt */ + UART0_CONTROL = _BV(RXCIE)|_BV(RXEN)|_BV(TXEN); + +#elif defined (ATMEGA_USART) + /* Set baud rate */ + if ( baudrate & 0x8000 ) + { + UART0_STATUS = (1<>8); + UBRRL = (unsigned char) baudrate; + + /* Enable USART receiver and transmitter and receive complete interrupt */ + UART0_CONTROL = _BV(RXCIE)|(1<>8); + UBRR0L = (unsigned char) baudrate; + + /* Enable USART receiver and transmitter and receive complete interrupt */ + UART0_CONTROL = _BV(RXCIE0)|(1<>8); + UBRR = (unsigned char) baudrate; + + /* Enable UART receiver and transmitter and receive complete interrupt */ + UART0_CONTROL = _BV(RXCIE)|(1<> 8; + }else{ + /* store new index */ + UART1_RxHead = tmphead; + /* store received data in buffer */ + UART1_RxBuf[tmphead] = data; + } + UART1_LastRxError = lastRxError; +} + + +SIGNAL(UART1_TRANSMIT_INTERRUPT) +/************************************************************************* +Function: UART1 Data Register Empty interrupt +Purpose: called when the UART1 is ready to transmit the next byte +**************************************************************************/ +{ + unsigned char tmptail; + + + if ( UART1_TxHead != UART1_TxTail) { + /* calculate and store new buffer index */ + tmptail = (UART1_TxTail + 1) & UART_TX_BUFFER_MASK; + UART1_TxTail = tmptail; + /* get one byte from buffer and write it to UART */ + UART1_DATA = UART1_TxBuf[tmptail]; /* start transmission */ + }else{ + /* tx buffer empty, disable UDRE interrupt */ + UART1_CONTROL &= ~_BV(UART1_UDRIE); + } +} + + +/************************************************************************* +Function: uart1_init() +Purpose: initialize UART1 and set baudrate +Input: baudrate using macro UART_BAUD_SELECT() +Returns: none +**************************************************************************/ +void uart1_init(unsigned int baudrate) +{ + UART1_TxHead = 0; + UART1_TxTail = 0; + UART1_RxHead = 0; + UART1_RxTail = 0; + + + /* Set baud rate */ + if ( baudrate & 0x8000 ) + { + UART1_STATUS = (1<>8); + UBRR1L = (unsigned char) baudrate; + + /* Enable USART receiver and transmitter and receive complete interrupt */ + UART1_CONTROL = _BV(RXCIE1)|(1< http://jump.to/fleury -File: $Id: uart.c,v 1.5.2.10 2005/11/15 19:49:12 peter Exp $ -Software: AVR-GCC 3.3 -Hardware: any AVR with built-in UART, - tested on AT90S8515 at 4 Mhz and ATmega at 1Mhz - -DESCRIPTION: - An interrupt is generated when the UART has finished transmitting or - receiving a byte. The interrupt handling routines use circular buffers - for buffering received and transmitted data. - - The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables define - the buffer size in bytes. Note that these variables must be a - power of 2. - -USAGE: - Refere to the header file uart.h for a description of the routines. - See also example test_uart.c. - -NOTES: - Based on Atmel Application Note AVR306 - -*************************************************************************/ -#include -#include -//#include -#include - -/* - * constants and macros - */ - -/* size of RX/TX buffers */ -#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1) -#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1) - -#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK ) -#error RX buffer size is not a power of 2 -#endif -#if ( UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK ) -#error TX buffer size is not a power of 2 -#endif - -#if defined(__AVR_AT90S2313__) \ - || defined(__AVR_AT90S4414__) || defined(__AVR_AT90S4434__) \ - || defined(__AVR_AT90S8515__) || defined(__AVR_AT90S8535__) \ - || defined(__AVR_ATmega103__) - /* old AVR classic or ATmega103 with one UART */ - #define AT90_UART - #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA - #define UART0_STATUS USR - #define UART0_CONTROL UCR - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE -#elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__) - /* old AVR classic with one UART */ - #define AT90_UART - #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA - #define UART0_STATUS UCSRA - #define UART0_CONTROL UCSRB - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE -#elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \ - || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__) \ - || defined(__AVR_ATmega323__) - /* ATmega with one USART */ - #define ATMEGA_USART - #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA - #define UART0_STATUS UCSRA - #define UART0_CONTROL UCSRB - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE -#elif defined(__AVR_ATmega163__) - /* ATmega163 with one UART */ - #define ATMEGA_UART - #define UART0_RECEIVE_INTERRUPT SIG_UART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_UART_DATA - #define UART0_STATUS UCSRA - #define UART0_CONTROL UCSRB - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE -#elif defined(__AVR_ATmega162__) - /* ATmega with two USART */ - #define ATMEGA_USART0 - #define ATMEGA_USART1 - #define UART0_RECEIVE_INTERRUPT SIG_USART0_RECV - #define UART1_RECEIVE_INTERRUPT SIG_USART1_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_USART0_DATA - #define UART1_TRANSMIT_INTERRUPT SIG_USART1_DATA - #define UART0_STATUS UCSR0A - #define UART0_CONTROL UCSR0B - #define UART0_DATA UDR0 - #define UART0_UDRIE UDRIE0 - #define UART1_STATUS UCSR1A - #define UART1_CONTROL UCSR1B - #define UART1_DATA UDR1 - #define UART1_UDRIE UDRIE1 -#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) - /* ATmega with two USART */ - #define ATMEGA_USART0 - #define ATMEGA_USART1 - #define UART0_RECEIVE_INTERRUPT SIG_UART0_RECV - #define UART1_RECEIVE_INTERRUPT SIG_UART1_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_UART0_DATA - #define UART1_TRANSMIT_INTERRUPT SIG_UART1_DATA - #define UART0_STATUS UCSR0A - #define UART0_CONTROL UCSR0B - #define UART0_DATA UDR0 - #define UART0_UDRIE UDRIE0 - #define UART1_STATUS UCSR1A - #define UART1_CONTROL UCSR1B - #define UART1_DATA UDR1 - #define UART1_UDRIE UDRIE1 -#elif defined(__AVR_ATmega161__) - /* ATmega with UART */ - #error "AVR ATmega161 currently not supported by this libaray !" -#elif defined(__AVR_ATmega169__) - /* ATmega with one USART */ - #define ATMEGA_USART - #define UART0_RECEIVE_INTERRUPT SIG_USART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_USART_DATA - #define UART0_STATUS UCSRA - #define UART0_CONTROL UCSRB - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE -#elif defined(__AVR_ATmega48__) ||defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) - #define ATMEGA_USART0 - #define UART0_RECEIVE_INTERRUPT SIG_USART_RECV - #define UART0_TRANSMIT_INTERRUPT SIG_USART_DATA - #define UART0_STATUS UCSR0A - #define UART0_CONTROL UCSR0B - #define UART0_DATA UDR0 - #define UART0_UDRIE UDRIE0 -#elif defined(__AVR_ATtiny2313__) - #define ATMEGA_USART - #define UART0_RECEIVE_INTERRUPT SIG_USART0_RX - #define UART0_TRANSMIT_INTERRUPT SIG_USART0_UDRE - #define UART0_STATUS UCSRA - #define UART0_CONTROL UCSRB - #define UART0_DATA UDR - #define UART0_UDRIE UDRIE -#else - #error "no UART definition for MCU available" -#endif - - -/* - * module global variables - */ -static volatile unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE]; -static volatile unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE]; -static volatile unsigned char UART_TxHead; -static volatile unsigned char UART_TxTail; -static volatile unsigned char UART_RxHead; -static volatile unsigned char UART_RxTail; -static volatile unsigned char UART_LastRxError; - -#if defined( ATMEGA_USART1 ) -static volatile unsigned char UART1_TxBuf[UART_TX_BUFFER_SIZE]; -static volatile unsigned char UART1_RxBuf[UART_RX_BUFFER_SIZE]; -static volatile unsigned char UART1_TxHead; -static volatile unsigned char UART1_TxTail; -static volatile unsigned char UART1_RxHead; -static volatile unsigned char UART1_RxTail; -static volatile unsigned char UART1_LastRxError; -#endif - - - -SIGNAL(UART0_RECEIVE_INTERRUPT) -/************************************************************************* -Function: UART Receive Complete interrupt -Purpose: called when the UART has received a character -**************************************************************************/ -{ - unsigned char tmphead; - unsigned char data; - unsigned char usr; - unsigned char lastRxError; - - - /* read UART status register and UART data register */ - usr = UART0_STATUS; - data = UART0_DATA; - - /* */ -#if defined( AT90_UART ) - lastRxError = (usr & (_BV(FE)|_BV(DOR)) ); -#elif defined( ATMEGA_USART ) - lastRxError = (usr & (_BV(FE)|_BV(DOR)) ); -#elif defined( ATMEGA_USART0 ) - lastRxError = (usr & (_BV(FE0)|_BV(DOR0)) ); -#elif defined ( ATMEGA_UART ) - lastRxError = (usr & (_BV(FE)|_BV(DOR)) ); -#endif - - /* calculate buffer index */ - tmphead = ( UART_RxHead + 1) & UART_RX_BUFFER_MASK; - - if ( tmphead == UART_RxTail ) { - /* error: receive buffer overflow */ - lastRxError = UART_BUFFER_OVERFLOW >> 8; - }else{ - /* store new index */ - UART_RxHead = tmphead; - /* store received data in buffer */ - UART_RxBuf[tmphead] = data; - } - UART_LastRxError = lastRxError; -} - - -SIGNAL(UART0_TRANSMIT_INTERRUPT) -/************************************************************************* -Function: UART Data Register Empty interrupt -Purpose: called when the UART is ready to transmit the next byte -**************************************************************************/ -{ - unsigned char tmptail; - - - if ( UART_TxHead != UART_TxTail) { - /* calculate and store new buffer index */ - tmptail = (UART_TxTail + 1) & UART_TX_BUFFER_MASK; - UART_TxTail = tmptail; - /* get one byte from buffer and write it to UART */ - UART0_DATA = UART_TxBuf[tmptail]; /* start transmission */ - }else{ - /* tx buffer empty, disable UDRE interrupt */ - UART0_CONTROL &= ~_BV(UART0_UDRIE); - } -} - - -/************************************************************************* -Function: uart_init() -Purpose: initialize UART and set baudrate -Input: baudrate using macro UART_BAUD_SELECT() -Returns: none -**************************************************************************/ -void uart_init(unsigned int baudrate) -{ - UART_TxHead = 0; - UART_TxTail = 0; - UART_RxHead = 0; - UART_RxTail = 0; - -#if defined( AT90_UART ) - /* set baud rate */ - UBRR = (unsigned char)baudrate; - - /* enable UART receiver and transmmitter and receive complete interrupt */ - UART0_CONTROL = _BV(RXCIE)|_BV(RXEN)|_BV(TXEN); - -#elif defined (ATMEGA_USART) - /* Set baud rate */ - if ( baudrate & 0x8000 ) - { - UART0_STATUS = (1<>8); - UBRRL = (unsigned char) baudrate; - - /* Enable USART receiver and transmitter and receive complete interrupt */ - UART0_CONTROL = _BV(RXCIE)|(1<>8); - UBRR0L = (unsigned char) baudrate; - - /* Enable USART receiver and transmitter and receive complete interrupt */ - UART0_CONTROL = _BV(RXCIE0)|(1<>8); - UBRR = (unsigned char) baudrate; - - /* Enable UART receiver and transmitter and receive complete interrupt */ - UART0_CONTROL = _BV(RXCIE)|(1<> 8; - }else{ - /* store new index */ - UART1_RxHead = tmphead; - /* store received data in buffer */ - UART1_RxBuf[tmphead] = data; - } - UART1_LastRxError = lastRxError; -} - - -SIGNAL(UART1_TRANSMIT_INTERRUPT) -/************************************************************************* -Function: UART1 Data Register Empty interrupt -Purpose: called when the UART1 is ready to transmit the next byte -**************************************************************************/ -{ - unsigned char tmptail; - - - if ( UART1_TxHead != UART1_TxTail) { - /* calculate and store new buffer index */ - tmptail = (UART1_TxTail + 1) & UART_TX_BUFFER_MASK; - UART1_TxTail = tmptail; - /* get one byte from buffer and write it to UART */ - UART1_DATA = UART1_TxBuf[tmptail]; /* start transmission */ - }else{ - /* tx buffer empty, disable UDRE interrupt */ - UART1_CONTROL &= ~_BV(UART1_UDRIE); - } -} - - -/************************************************************************* -Function: uart1_init() -Purpose: initialize UART1 and set baudrate -Input: baudrate using macro UART_BAUD_SELECT() -Returns: none -**************************************************************************/ -void uart1_init(unsigned int baudrate) -{ - UART1_TxHead = 0; - UART1_TxTail = 0; - UART1_RxHead = 0; - UART1_RxTail = 0; - - - /* Set baud rate */ - if ( baudrate & 0x8000 ) - { - UART1_STATUS = (1<>8); - UBRR1L = (unsigned char) baudrate; - - /* Enable USART receiver and transmitter and receive complete interrupt */ - UART1_CONTROL = _BV(RXCIE1)|(1<GetADCValue(channel); -} diff --git a/source/Concept/Framework/keyboard.cpp b/source/Concept/Framework/keyboard.cpp deleted file mode 100644 index 65fc7cf..0000000 --- a/source/Concept/Framework/keyboard.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "keyboard.h" diff --git a/source/Concept/Framework/kicker.cpp b/source/Concept/Framework/kicker.cpp deleted file mode 100644 index 6670efb..0000000 --- a/source/Concept/Framework/kicker.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "kicker.h" diff --git a/source/Concept/Framework/led.cpp b/source/Concept/Framework/led.cpp deleted file mode 100644 index 687b2db..0000000 --- a/source/Concept/Framework/led.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "led.h" diff --git a/source/Concept/Framework/main.c b/source/Concept/Framework/main.c new file mode 100755 index 0000000..fa6d718 --- /dev/null +++ b/source/Concept/Framework/main.c @@ -0,0 +1,189 @@ +#include "stdafx.h" + +int main() +{ + //Init our robot + Robot* localRobot = new Robot(); + + //Init Engines + for(uint8 i = IO_ENGINE_START; i < IO_ENGINE_END; i++) + { + Engine* newEngine = new Engine(i); + localRobot->AddModule(newEngine); + newEngine = NULL; + } + + //Init Dribbler + for(uint8 i = IO_DRIBBLER_START; i < IO_DRIBBLER_END; i++) + { + Dribbler* newDribbler = new Dribbler(i); + localRobot->AddModule(newDribbler); + newDribbler = NULL; + } + + //Init Kicker + for(uint8 i = IO_KICKER_START; i < IO_KICKER_END; i++) + { + Kicker* newKicker = new Kicker(i); + localRobot->AddModule(newKicker); + newKicker = NULL; + } + + //Init Sensors + for(uint8 i = IO_SENSOR_START; i < IO_SENSOR_END; i++) + { + switch(i) + { + //Create correct type of sensor + case IO_SENSOR_IR_0_DEG: + case IO_SENSOR_IR_30_DEG: + case IO_SENSOR_IR_60_DEG: + case IO_SENSOR_IR_100_DEG: + case IO_SENSOR_IR_180_DEG: + case IO_SENSOR_IR_260_DEG: + case IO_SENSOR_IR_300_DEG: + case IO_SENSOR_IR_330_DEG: + { + IR_Sensor* newSensor = new IR_Sensor(i); + localRobot->AddModule(newSensor); + newSensor = NULL; + break; + } + case IO_SENSOR_DISTANCE_0_DEG: + case IO_SENSOR_DISTANCE_90_DEG: + case IO_SENSOR_DISTANCE_180_DEG: + case IO_SENSOR_DISTANCE_270_DEG: + { + Distance_Sensor* newSensor = new Distance_Sensor(i); + localRobot->AddModule(newSensor); + newSensor = NULL; + break; + } + case IO_SENSOR_MOUSE_LEFT: + case IO_SENSOR_MOUSE_RIGHT: + { + Mouse_Sensor* newSensor = new Mouse_Sensor(i); + localRobot->AddModule(newSensor); + newSensor = NULL; + break; + } + //Other cases + default: + { + Sensor* newSensor = new Sensor(i); + localRobot->AddModule(newSensor); + newSensor = NULL; + break; + } + } + } + + //Init Leds + for(uint8 i = IO_LED_START; i < IO_LED_END; i++) + { + Led* newLed = new Led(i); + localRobot->AddModule(newLed); + newLed = NULL; + } + + //Init Displays + for(uint8 i = IO_DISPLAY_START; i < IO_DISPLAY_END; i++) + { + Display* newDisplay = new Display(i); + localRobot->AddModule(newDisplay); + newDisplay = NULL; + } + + //Init Keyboards + for(uint8 i = IO_KEYBOARD_START; i < IO_KEYBOARD_END; i++) + { + Keyboard* newKeyboard = new Keyboard(i); + localRobot->AddModule(newKeyboard); + newKeyboard = NULL; + } + + //Init Position Tracker + for(uint8 i = IO_POSITION_TRACKER_START; i < IO_POSITION_TRACKER_END; i++) + { + Position_Tracker* newPositionTracker = new Position_Tracker(i); + localRobot->AddModule(newPositionTracker); + newPositionTracker = NULL; + } + + //Init Ball Tracker + for(uint8 i = IO_BALL_TRACKER_START; i < IO_BALL_TRACKER_END; i++) + { + Ball_Tracker* newBallTracker = new Ball_Tracker(i); + localRobot->AddModule(newBallTracker); + newBallTracker = NULL; + } + + //Init Navigators + for(uint8 i = IO_NAVIGATOR_START; i < IO_NAVIGATOR_END; i++) + { + Navigator* newNavigator = new Navigator(i); + localRobot->AddModule(newNavigator); + newNavigator = NULL; + } + + + + IR_Sensor* ourSensor = NULL; + uint16 value = 0; + int8 value2 = 0; + Display* ourDisplay = localRobot->GetModule(IO_DISPLAY_MAIN); + uint32 i = 1; + Ball_Tracker* ourBallTracker = localRobot->GetModule(IO_BALL_TRACKER_MAIN); + + //Run + while(true) + { + msleep(500); + ourDisplay->Clear(); + ourDisplay->Print(i++); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_0_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value, 1, 2); + ourDisplay->Print(";"); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_30_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value); + ourDisplay->Print(";"); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_60_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value); + ourDisplay->Print(";"); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_100_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value); + ourDisplay->Print(";"); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_180_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value, 1, 3); + ourDisplay->Print(";"); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_260_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value); + ourDisplay->Print(";"); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_300_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value); + ourDisplay->Print(";"); + ourSensor = localRobot->GetModule(IO_SENSOR_IR_330_DEG); + value = ourSensor->GetIRIntensity(); + ourDisplay->Print(value); + ourDisplay->Print(";"); + value2 = (localRobot->GetModule(IO_SENSOR_MOUSE_LEFT))->GetXMovement(); + ourDisplay->Print(value2, 10, 4); + value2 = (localRobot->GetModule(IO_SENSOR_MOUSE_LEFT))->GetYMovement(); + ourDisplay->Print(value2, 15, 4); + + localRobot->Update(); + + ourDisplay->PrintFloat(ourBallTracker->GetBallDirection(), 1, 4); + } + + //Cleanup + delete localRobot; + localRobot = NULL; +} diff --git a/source/Concept/Framework/main.cpp b/source/Concept/Framework/main.cpp deleted file mode 100644 index f689d88..0000000 --- a/source/Concept/Framework/main.cpp +++ /dev/null @@ -1,158 +0,0 @@ -#include "stdafx.h" - -int main() -{ - //Init our robot - Robot* localRobot = new Robot(); - - //Init Engines - for(uint8 i = IO_ENGINE_START; i < IO_ENGINE_END; i++) - { - Engine* newEngine = new Engine(i); - localRobot->AddModule(newEngine); - newEngine = NULL; - } - - //Init Dribbler - for(uint8 i = IO_DRIBBLER_START; i < IO_DRIBBLER_END; i++) - { - Dribbler* newDribbler = new Dribbler(i); - localRobot->AddModule(newDribbler); - newDribbler = NULL; - } - - //Init Kicker - for(uint8 i = IO_KICKER_START; i < IO_KICKER_END; i++) - { - Kicker* newKicker = new Kicker(i); - localRobot->AddModule(newKicker); - newKicker = NULL; - } - - //Init Sensors - for(uint8 i = IO_SENSOR_START; i < IO_SENSOR_END; i++) - { - switch(i) - { - //Create correct type of sensor - case IO_SENSOR_IR_0_DEG: - case IO_SENSOR_IR_30_DEG: - case IO_SENSOR_IR_60_DEG: - case IO_SENSOR_IR_100_DEG: - case IO_SENSOR_IR_180_DEG: - case IO_SENSOR_IR_260_DEG: - case IO_SENSOR_IR_300_DEG: - case IO_SENSOR_IR_330_DEG: - { - IR_Sensor* newSensor = new IR_Sensor(i); - localRobot->AddModule(newSensor); - newSensor = NULL; - break; - } - case IO_SENSOR_DISTANCE_0_DEG: - case IO_SENSOR_DISTANCE_90_DEG: - case IO_SENSOR_DISTANCE_180_DEG: - case IO_SENSOR_DISTANCE_270_DEG: - { - Distance_Sensor* newSensor = new Distance_Sensor(i); - localRobot->AddModule(newSensor); - newSensor = NULL; - break; - } - case IO_SENSOR_MOUSE_LEFT: - case IO_SENSOR_MOUSE_RIGHT: - { - Mouse_Sensor* newSensor = new Mouse_Sensor(i); - localRobot->AddModule(newSensor); - newSensor = NULL; - break; - } - //Other cases - default: - { - Sensor* newSensor = new Sensor(i); - localRobot->AddModule(newSensor); - newSensor = NULL; - break; - } - } - } - - //Init Leds - for(uint8 i = IO_LED_START; i < IO_LED_END; i++) - { - Led* newLed = new Led(i); - localRobot->AddModule(newLed); - newLed = NULL; - } - - //Init Displays - for(uint8 i = IO_DISPLAY_START; i < IO_DISPLAY_END; i++) - { - Display* newDisplay = new Display(i); - localRobot->AddModule(newDisplay); - newDisplay = NULL; - } - - //Init Keyboards - for(uint8 i = IO_KEYBOARD_START; i < IO_KEYBOARD_END; i++) - { - Keyboard* newKeyboard = new Keyboard(i); - localRobot->AddModule(newKeyboard); - newKeyboard = NULL; - } - - Keyboard* ourKeyboard = localRobot->GetModule(IO_KEYBOARD_MAIN); - IR_Sensor* ourSensor = NULL; - uint16 value = 0; - Display* ourDisplay = localRobot->GetModule(IO_DISPLAY_MAIN); - uint32 i = 1; - - //Run - while(true) - { - msleep(500); - ourDisplay->Clear(); - ourDisplay->Print(i++); - ourDisplay->NewLine(); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_0_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value, 1, 2); - ourDisplay->Print(";"); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_30_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value); - ourDisplay->Print(";"); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_60_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value); - ourDisplay->Print(";"); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_100_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value); - ourDisplay->Print(";"); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_180_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value, 1, 3); - ourDisplay->Print(";"); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_260_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value); - ourDisplay->Print(";"); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_300_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value); - ourDisplay->Print(";"); - ourSensor = localRobot->GetModule(IO_SENSOR_IR_330_DEG); - value = ourSensor->GetIRIntensity(); - ourDisplay->Print(value); - ourDisplay->Print(";"); - ourDisplay->Print(ourKeyboard->GetInput(), 1, 4); - - localRobot->Update(); - } - - //Cleanup - delete localRobot; - localRobot = NULL; -} diff --git a/source/Concept/Framework/modules/executor/navigator.c b/source/Concept/Framework/modules/executor/navigator.c new file mode 100755 index 0000000..459d4c1 --- /dev/null +++ b/source/Concept/Framework/modules/executor/navigator.c @@ -0,0 +1,199 @@ +#include "navigator.h" + +//----------------------------------------------------------------------------- +void Navigator::Stop() +{ + this->direction = -1.0f; + this->targetAngle = -1.0f; + this->targetX = -1.0f; + this->targetY = -1.0f; + this->speed = 0; + this->rotationSpeed = 0; + + for(uint8 i = IO_ENGINE_START; i < IO_ENGINE_END; i++) + { + (parent->GetModule(i))->SetSpeed(0); + (parent->GetModule(i))->SetEnabled(true); + } +} + +//----------------------------------------------------------------------------- +void Navigator::Rotate(float rotationSpeed) +{ + this->rotationSpeed = rotationSpeed; + this->direction = -1.0f; + this->targetAngle = -1.0f; + this->targetX = -1.0f; + this->targetY = -1.0f; + this->speed = 0; + + for(uint8 i = IO_ENGINE_START; i < IO_ENGINE_END; i++) + { + (parent->GetModule(i))->SetSpeed(rotationSpeed); + (parent->GetModule(i))->SetEnabled(true); + } +} + +//----------------------------------------------------------------------------- +void Navigator::Update() +{ + Position_Tracker* locationeer = parent->GetModule(IO_POSITION_TRACKER_MAIN); + + bool hasDistanceToDrive = true; + bool hasOrientationToAdjust = true; + + //Check for distance to drive + if((targetX >= 0) != (targetY >= 0)) + { + targetX = -1.0f; + targetY = -1.0f; + + hasDistanceToDrive = false; + } + else if(targetX >= 0 && targetY >= 0) + { + if(distance2d(targetX, targetY, locationeer->GetPositionX(), locationeer->GetPositionY()) < 1.0f) + { + targetX = -1.0f; + targetY = -1.0f; + + hasDistanceToDrive = false; + } + else + { + hasDistanceToDrive = true; + } + } + else + { + if(direction >= 0) + { + hasDistanceToDrive = true; + } + else + { + hasDistanceToDrive = false; + } + } + + //Check for orientation to adjust + if(targetAngle >= 0) + { + if(fabs(targetAngle - locationeer->GetOrientation()) < 0.1f) + { + hasOrientationToAdjust = false; + } + else + { + hasOrientationToAdjust = true; + } + } + else + { + if(rotationSpeed != 0) + { + hasOrientationToAdjust = true; + } + else + { + hasOrientationToAdjust = false; + } + } + + //Calculate directional/rotational engine speed + if(hasDistanceToDrive) + { + + + float maxRobotSpeed = 255.0f * sqrt(2) / 2.0f; + + if(speed > maxRobotSpeed) + { + speed = maxRobotSpeed; + } + + maxMotorSpeed = speed / (sqrt(2) / 2); + + + + relAngel = direction - orientation + + robotSpeed = sin(45) * maxMotorSpeed + maxMotorSpeed = robotSpeed / sin(45) + + if(relAngel > 45) + { + sin(relAngel) * (speed / sin(45)) * sin(relAngel + 45); + + back = speed / sin(relAngel); + } + else + { + + } + + left = + back = sin(relAngel) * speed + + + direction = 0: + orientation = 0: + left = speed + right = -speed + back = 0 + + direction = 0: + orientation = 90: + left = speed + right = speed + back = (sinVcos)(45) * speed + + direction = 0: + orientation = 45: + left = speed + right = 0 + back = -speed + + direction = 0: + orientation = 180: + left = -speed + right = speed + back = 0 + + } + else if(!hasOrientationToAdjust) + { + Stop(); + } + else + { + } +} + +// Aktualieren ohne Parameter +/*void Navigator::Update() { + // Richtung in x und y-Kompontente zerlegen + double y = cos((double)direction*0.01745); // richtung ist winkel + double x = sin((double)direction*0.01745); + + // Abweichung der Ausrichtung ermitteln(als winkel) + int w = sensor.GetAusrichtung() - ausrichtung; + + // Stärke der einzelnen Motoren berechnen + double v0 = (-x+sqrt(3)*y)/2; + double v1 = x; + double v2 = (-x-sqrt(3)*y)/2; + + // Ausgerechnete Stärke an die Motoren übergeben + board.motor(0,(int)((double)v0*speed +w)); + board.motor(1,(int)((double)v1*speed +w)); + board.motor(2,(int)((double)v2*speed +w)); +} + +// Aktualieren mit allen Parametern +void Navigator::Drive(float newDirection, float newAngle, float newSpeed) { + SetDirection(newDirection); + SetAngle(newAngle); + SetSpeed(newSpeed); + Update(); // Und anwenden +}*/ diff --git a/source/Concept/Framework/modules/executor/navigator.h b/source/Concept/Framework/modules/executor/navigator.h new file mode 100755 index 0000000..ed8b3c8 --- /dev/null +++ b/source/Concept/Framework/modules/executor/navigator.h @@ -0,0 +1,53 @@ +#ifndef _NAVIGATOR_H +#define _NAVIGATOR_H + +#include "../../stdafx.h" + +class Navigator : public IO_Module +{ +public: + Navigator() + { + this->parent = NULL; + this->moduleId = 0; + this->direction = -1.0f; + this->targetAngle = -1.0f; + this->targetX = -1.0f; + this->targetY = -1.0f; + this->speed = 0; + this->rotationSpeed = 0; + } + + Navigator(uint32 navigatorId) + { + this->parent = NULL; + this->moduleId = navigatorId; + this->direction = -1.0f; + this->targetAngle = -1.0f; + this->targetX = -1.0f; + this->targetY = -1.0f; + this->speed = 0; + this->rotationSpeed = 0; + } + +protected: + float direction; + float targetAngle; + float targetX; + float targetY; + float speed; + float rotationSpeed; + +public: + void Update(); + + void Stop(); + + void Drive(float newDirection, float newAngle, float newSpeed, float rotationSpeed); + + void DriveTo(float newX, float newY, float newAngle); + + void Rotate(float rotationSpeed); +}; + +#endif diff --git a/source/Concept/Framework/modules/input/distance_sensor.c b/source/Concept/Framework/modules/input/distance_sensor.c new file mode 100755 index 0000000..977784f --- /dev/null +++ b/source/Concept/Framework/modules/input/distance_sensor.c @@ -0,0 +1,32 @@ +#include "distance_sensor.h" + +//----------------------------------------------------------------------------- +float Distance_Sensor::GetDistance() +{ + uint32 result = 0; + + //Generate pulse + *hardwareDDR |= pin;//Set pin output + *hardwarePort |= pin;//Activate port + usleep(10);//Wait for 10µs + //*hardwarePort &= ~pin;//Deactivate port + *hardwareDDR &= ~pin;//Set pin input + + (parent->GetModule(IO_DISPLAY_MAIN))->Print("pre 1", 4, 1); + + //Wait for response + while(!(PINC & pin)){asm volatile("nop");} + + (parent->GetModule(IO_DISPLAY_MAIN))->Print("pre 2", 4, 1); + + //Calculate duration of response + while(*hardwarePin & pin) + { + result++; + asm volatile("nop"); + } + + (parent->GetModule(IO_DISPLAY_MAIN))->Print("pre 3", 4, 1); + + return (float(result) * DISTANCE_PER_VALUE); +} diff --git a/source/Concept/Framework/modules/input/distance_sensor.h b/source/Concept/Framework/modules/input/distance_sensor.h new file mode 100755 index 0000000..8e6aa21 --- /dev/null +++ b/source/Concept/Framework/modules/input/distance_sensor.h @@ -0,0 +1,71 @@ +#ifndef _DISTANCE_SENSOR_H +#define _DISTANCE_SENSOR_H + +#include "../../stdafx.h" +#include "sensor.h" + +class Distance_Sensor : public Sensor +{ +public: + Distance_Sensor() + { + this->parent = NULL; + this->moduleId = 0; + this->hardwarePort = NULL; + this->hardwareDDR = NULL; + this->hardwarePin = NULL; + this->pin = 0; + } + + Distance_Sensor(uint32 sensorId) + { + this->parent = NULL; + this->moduleId = sensorId; + + switch(sensorId) + { + case IO_SENSOR_DISTANCE_0_DEG: + this->hardwarePort = &PORTC; + this->hardwareDDR = &DDRC; + this->hardwarePin = &PINC; + this->pin = (1 << 0); + break; + case IO_SENSOR_DISTANCE_90_DEG: + this->hardwarePort = &PORTC; + this->hardwareDDR = &DDRC; + this->hardwarePin = &PINC; + this->pin = (1 << 1); + break; + case IO_SENSOR_DISTANCE_180_DEG: + this->hardwarePort = &PORTC; + this->hardwareDDR = &DDRC; + this->hardwarePin = &PINC; + this->pin = (1 << 2); + break; + case IO_SENSOR_DISTANCE_270_DEG: + this->hardwarePort = &PORTC; + this->hardwareDDR = &DDRC; + this->hardwarePin = &PINC; + this->pin = (1 << 3); + break; + default: + this->hardwarePort = NULL; + this->hardwareDDR = NULL; + this->hardwarePin = NULL; + this->pin = 0; + break; + } + } + +protected: + //Hardware + volatile uint8* hardwarePort; + volatile uint8* hardwareDDR; + volatile uint8* hardwarePin; + uint8 pin; + +public: + float GetDistance(); +}; + +#endif diff --git a/source/Concept/Framework/modules/input/ir_sensor.c b/source/Concept/Framework/modules/input/ir_sensor.c new file mode 100755 index 0000000..c34feed --- /dev/null +++ b/source/Concept/Framework/modules/input/ir_sensor.c @@ -0,0 +1,9 @@ +#include "ir_sensor.h" + +//----------------------------------------------------------------------------- +uint16 IR_Sensor::GetIRIntensity() +{ + if(!parent) return 0; + + return parent->GetADCValue(channel); +} diff --git a/source/Concept/Framework/modules/input/ir_sensor.h b/source/Concept/Framework/modules/input/ir_sensor.h new file mode 100755 index 0000000..30e6ea4 --- /dev/null +++ b/source/Concept/Framework/modules/input/ir_sensor.h @@ -0,0 +1,62 @@ +#ifndef _IR_SENSOR_H +#define _IR_SENSOR_H + +#include "../../defines.h" +#include "../../robot.h" +#include "sensor.h" + +class IR_Sensor : public Sensor +{ +public: + IR_Sensor() + { + this->parent = NULL; + this->moduleId = 0; + } + + IR_Sensor(uint32 sensorId) + { + this->parent = NULL; + this->moduleId = sensorId; + + switch(sensorId) + { + case IO_SENSOR_IR_0_DEG: + this->channel = 0; + break; + case IO_SENSOR_IR_30_DEG: + this->channel = 1; + break; + case IO_SENSOR_IR_60_DEG: + this->channel = 2; + break; + case IO_SENSOR_IR_100_DEG: + this->channel = 3; + break; + case IO_SENSOR_IR_180_DEG: + this->channel = 4; + break; + case IO_SENSOR_IR_260_DEG: + this->channel = 5; + break; + case IO_SENSOR_IR_300_DEG: + this->channel = 6; + break; + case IO_SENSOR_IR_330_DEG: + this->channel = 7; + break; + default: + this->channel = 8; + break; + } + } + +protected: + //Hardware + uint8 channel; + +public: + uint16 GetIRIntensity(); +}; + +#endif diff --git a/source/Concept/Framework/modules/input/keyboard.c b/source/Concept/Framework/modules/input/keyboard.c new file mode 100755 index 0000000..65fc7cf --- /dev/null +++ b/source/Concept/Framework/modules/input/keyboard.c @@ -0,0 +1 @@ +#include "keyboard.h" diff --git a/source/Concept/Framework/modules/input/keyboard.h b/source/Concept/Framework/modules/input/keyboard.h new file mode 100755 index 0000000..243bb6c --- /dev/null +++ b/source/Concept/Framework/modules/input/keyboard.h @@ -0,0 +1,87 @@ +#ifndef _KEYBOARD_H +#define _KEYBOARD_H + +#include "../../stdafx.h" + +class Keyboard : public IO_Module +{ +public: + Keyboard() + { + this->parent = NULL; + this->moduleId = 0; + this->commandSetting = 0; + this->settingClearBuffer = 0; + } + + Keyboard(uint32 keyboardId) + { + this->parent = NULL; + this->moduleId = keyboardId; + + switch(keyboardId) + { + case IO_KEYBOARD_MAIN: + this->commandSetting = 27; + this->settingClearBuffer = 123; + break; + default: + this->commandSetting = 0; + this->settingClearBuffer = 0; + break; + } + } + +protected: + //Commands + uint8 commandSetting; + //Settings + uint8 settingClearBuffer; + + void SendCommand(uint8 newCommand) + { + switch(moduleId) + { + case IO_KEYBOARD_MAIN: + uart1_putc(newCommand); + break; + default: + break; + } + } + +public: + uint8 GetInput() + { + uint16 input = uart1_getc(); + + if(input == 0x100)//no data + { + return 0xEE;//empty + } + else if(input >= '0' && input <= '9') + { + return (uint8)(input - '0'); + } + else if(input == '*') + { + return 10; + } + else if(input == '#') + { + return 11; + } + else + { + return 0xFF;//unknown + } + } + + void ClearKeyBuffer() + { + SendCommand(commandSetting); + SendCommand(settingClearBuffer); + } +}; + +#endif diff --git a/source/Concept/Framework/modules/input/mouse_sensor.c b/source/Concept/Framework/modules/input/mouse_sensor.c new file mode 100755 index 0000000..214a13e --- /dev/null +++ b/source/Concept/Framework/modules/input/mouse_sensor.c @@ -0,0 +1 @@ +#include "mouse_sensor.h" diff --git a/source/Concept/Framework/modules/input/mouse_sensor.h b/source/Concept/Framework/modules/input/mouse_sensor.h new file mode 100755 index 0000000..30f9d53 --- /dev/null +++ b/source/Concept/Framework/modules/input/mouse_sensor.h @@ -0,0 +1,199 @@ +#ifndef _MOUSE_SENSOR_H +#define _MOUSE_SENSOR_H + +#include "../../stdafx.h" +#include "sensor.h" + +class Mouse_Sensor : public Sensor +{ +public: + Mouse_Sensor() + { + this->parent = NULL; + this->moduleId = 0; + this->hardwarePort = NULL; + this->hardwareDDR = NULL; + this->hardwarePin = NULL; + this->pinSDA = 0; + this->pinSCK = 0; + this->registerConfig = 0; + this->registerPixelData = 0; + this->registerSqual = 0; + this->registerDeltaX = 0; + this->registerDeltaY = 0; + this->configReset = 0; + this->configAwake = 0; + this->newImage = false; + } + + Mouse_Sensor(uint32 sensorId) + { + this->parent = NULL; + this->moduleId = sensorId; + this->newImage = false; + + switch(sensorId) + { + case IO_SENSOR_MOUSE_LEFT: + this->hardwarePort = &PORTC; + this->hardwareDDR = &DDRC; + this->hardwarePin = &PINC; + this->pinSDA = (1 << 4); + this->pinSCK = (1 << 6); + this->registerConfig = 0x00; + this->registerPixelData = 0x08; + this->registerSqual = 0x4; + this->registerDeltaX = 0x3; + this->registerDeltaY = 0x2; + this->configReset = 0x80; + this->configAwake = 0x01; + break; + case IO_SENSOR_MOUSE_RIGHT: + this->hardwarePort = &PORTC; + this->hardwareDDR = &DDRC; + this->hardwarePin = &PINC; + this->pinSDA = (1 << 5); + this->pinSCK = (1 << 7); + this->registerConfig = 0x00; + this->registerPixelData = 0x08; + this->registerSqual = 0x4; + this->registerDeltaX = 0x3; + this->registerDeltaY = 0x2; + this->configReset = 0x80; + this->configAwake = 0x01; + break; + default: + this->hardwarePort = NULL; + this->hardwareDDR = NULL; + this->hardwarePin = NULL; + this->pinSDA = 0; + this->pinSCK = 0; + this->registerConfig = 0; + this->registerPixelData = 0; + this->registerSqual = 0; + this->registerDeltaX = 0; + this->registerDeltaY = 0; + this->configReset = 0; + this->configAwake = 0; + break; + } + + *hardwareDDR |= pinSCK; + *hardwarePort &= ~pinSCK; + + Write(registerConfig, configReset); + Write(registerConfig, configAwake); + } + +protected: + //Hardware + volatile uint8* hardwarePort; + volatile uint8* hardwareDDR; + volatile uint8* hardwarePin; + uint8 pinSDA; + uint8 pinSCK; + bool newImage; + //Registers and Settings + uint8 registerConfig; + uint8 registerPixelData; + uint8 registerSqual; + uint8 registerDeltaX; + uint8 registerDeltaY; + uint8 configReset; + uint8 configAwake; + +public: + void WriteByte(uint8 newByte) + { + *hardwareDDR |= pinSDA;//Set SDA output + + for(uint8 i = 0; i < 8; i++) + { + *hardwarePort &= ~pinSCK;//prepare SCK + + //write data + *hardwarePort = (*hardwarePort & (~(*hardwarePin))) | + ((newByte >> 7) * pinSDA); + + newByte = newByte << 1;//prepare next byte + asm volatile("nop"); + + *hardwarePort |= pinSCK; + } + } + + void Write(int8 adr, uint8 data) + { + WriteByte(adr | 0x80); + WriteByte(data); + usleep(100); + } + + uint8 ReadByte() + { + uint8 data=0; + + *hardwareDDR &= ~pinSDA;//Set SDA input + + for(uint8 i = 0; i < 8; i++) + { + *hardwarePort &= ~pinSCK;//Prepare data + data = data << 1; + + asm volatile("nop"); + *hardwarePort |= pinSCK;//Prepare for reading + + data |= (*hardwarePin & pinSDA) / pinSDA; + } + + return data; + } + + uint8 Read(uint8 adr) + { + WriteByte(adr); + usleep(100); + + return ReadByte(); + } + + void ImagePrepare() + { + Write(registerConfig, configAwake); + Write(registerPixelData, 0x00); + + newImage = true; + } + + uint8 ImageRead() + { + uint8 pixel = Read(registerPixelData); + if(newImage) + { + while (!(pixel & 0x80))//0x80 indicates first pixel + { + pixel=Read(registerPixelData); + } + newImage = false; + } + + return pixel; + } + + uint8 GetSqual() + { + return Read(registerSqual); + } + + int8 GetXMovement() + { + return (int8)(Read(registerDeltaX)); + } + + int8 GetYMovement() + { + return (int8)(Read(registerDeltaY)); + } +}; + +#endif diff --git a/source/Concept/Framework/modules/input/sensor.c b/source/Concept/Framework/modules/input/sensor.c new file mode 100755 index 0000000..3036159 --- /dev/null +++ b/source/Concept/Framework/modules/input/sensor.c @@ -0,0 +1 @@ +#include "sensor.h" diff --git a/source/Concept/Framework/modules/input/sensor.h b/source/Concept/Framework/modules/input/sensor.h new file mode 100755 index 0000000..e44c739 --- /dev/null +++ b/source/Concept/Framework/modules/input/sensor.h @@ -0,0 +1,27 @@ +#ifndef _SENSOR_H +#define _SENSOR_H + +#include "../../defines.h" +#include "../io_module.h" + +class Sensor : public IO_Module +{ +public: + Sensor() + { + this->parent = NULL; + this->moduleId = 0; + } + + Sensor(uint32 sensorId) + { + this->parent = NULL; + this->moduleId = sensorId; + } + +protected: + +public: +}; + +#endif diff --git a/source/Concept/Framework/modules/interpreter/ball_tracker.c b/source/Concept/Framework/modules/interpreter/ball_tracker.c new file mode 100755 index 0000000..6679d3e --- /dev/null +++ b/source/Concept/Framework/modules/interpreter/ball_tracker.c @@ -0,0 +1,125 @@ +#include "ball_tracker.h" + +//----------------------------------------------------------------------------- +void Ball_Tracker::Update() +{ + uint8 sensorCount = (IO_SENSOR_IR_330_DEG - IO_SENSOR_IR_0_DEG) + 1; + uint16 intensity[sensorCount]; + uint8 greatestIntensity = 0; + for(uint8 i = 0; i < sensorCount; i++) + { + IR_Sensor* currentSensor = parent->GetModule(i + IO_SENSOR_IR_0_DEG); + + intensity[i] = 1023 - currentSensor->GetIRIntensity(); + + if(intensity[i] < 24) + { + intensity[i] = 0; + } + + if(intensity[i] > intensity[greatestIntensity]) + { + greatestIntensity = i; + } + } + + if(intensity[greatestIntensity]) + { + uint8 secondIntensity = 0xFF; + uint8 leftSensor = (greatestIntensity + 1) % sensorCount; + uint8 rightSensor = (greatestIntensity + sensorCount - 1) % sensorCount; + + if(intensity[leftSensor]) + { + secondIntensity = leftSensor; + } + + if(intensity[rightSensor] > intensity[leftSensor]) + { + secondIntensity = rightSensor; + } + + float mainDirection; + + switch(greatestIntensity + IO_SENSOR_IR_0_DEG) + { + case IO_SENSOR_IR_0_DEG: + mainDirection = 0; + break; + case IO_SENSOR_IR_30_DEG: + mainDirection = 1.0f * PI / 6.0f; + break; + case IO_SENSOR_IR_60_DEG: + mainDirection = 1.0f * PI / 3.0f; + break; + case IO_SENSOR_IR_100_DEG: + mainDirection = 5.0f * PI / 9.0f; + break; + case IO_SENSOR_IR_180_DEG: + mainDirection = PI; + break; + case IO_SENSOR_IR_260_DEG: + mainDirection = 13.0f * PI / 9.0f; + break; + case IO_SENSOR_IR_300_DEG: + mainDirection = 15.0f * PI / 9.0f; + break; + case IO_SENSOR_IR_330_DEG: + mainDirection = 33.0f * PI / 18.0f; + break; + default: + mainDirection = -1.0f; + return; + break; + } + + if(secondIntensity != 0xFF) + { + float secondDirection; + + switch(secondIntensity + IO_SENSOR_IR_0_DEG) + { + case IO_SENSOR_IR_0_DEG: + secondDirection = 0; + break; + case IO_SENSOR_IR_30_DEG: + secondDirection = 1.0f * PI / 6.0f; + break; + case IO_SENSOR_IR_60_DEG: + secondDirection = 1.0f * PI / 3.0f; + break; + case IO_SENSOR_IR_100_DEG: + secondDirection = 5.0f * PI / 9.0f; + break; + case IO_SENSOR_IR_180_DEG: + secondDirection = PI; + break; + case IO_SENSOR_IR_260_DEG: + secondDirection = 13.0f * PI / 9.0f; + break; + case IO_SENSOR_IR_300_DEG: + secondDirection = 15.0f * PI / 9.0f; + break; + case IO_SENSOR_IR_330_DEG: + secondDirection = 33.0f * PI / 18.0f; + break; + default: + secondDirection = -1.0f; + return; + break; + } + + direction = (intensity[greatestIntensity] * mainDirection + + intensity[secondIntensity] * secondDirection) / + (intensity[greatestIntensity] + intensity[secondIntensity]); + } + else + { + direction = mainDirection; + } + } + else + { + direction = -1.0f; + } +} diff --git a/source/Concept/Framework/modules/interpreter/ball_tracker.h b/source/Concept/Framework/modules/interpreter/ball_tracker.h new file mode 100755 index 0000000..ed8801f --- /dev/null +++ b/source/Concept/Framework/modules/interpreter/ball_tracker.h @@ -0,0 +1,35 @@ +#ifndef _BALL_TRACKER_H +#define _BALL_TRACKER_H + +#include "../../stdafx.h" + +class Ball_Tracker : public IO_Module +{ +public: + Ball_Tracker() + { + this->parent = NULL; + this->moduleId = 0; + this->direction = -1.0f; + } + + Ball_Tracker(uint32 trackerId) + { + this->parent = NULL; + this->moduleId = trackerId; + this->direction = -1.0f; + } + +protected: + float direction; + +public: + void Update(); + + float GetBallDirection() + { + return direction; + } +}; + +#endif diff --git a/source/Concept/Framework/modules/interpreter/position_tracker.c b/source/Concept/Framework/modules/interpreter/position_tracker.c new file mode 100755 index 0000000..262069a --- /dev/null +++ b/source/Concept/Framework/modules/interpreter/position_tracker.c @@ -0,0 +1,7 @@ +#include "position_tracker.h" + +//----------------------------------------------------------------------------- +void Position_Tracker::Update() +{ + //insert code here +} diff --git a/source/Concept/Framework/modules/interpreter/position_tracker.h b/source/Concept/Framework/modules/interpreter/position_tracker.h new file mode 100755 index 0000000..b31dd8f --- /dev/null +++ b/source/Concept/Framework/modules/interpreter/position_tracker.h @@ -0,0 +1,45 @@ +#ifndef _POSITION_TRACKER_H +#define _POSITION_TRACKER_H + +#include "../../stdafx.h" + +class Position_Tracker : public IO_Module +{ +public: + Position_Tracker() + { + this->parent = NULL; + this->moduleId = 0; + } + + Position_Tracker(uint32 trackerId) + { + this->parent = NULL; + this->moduleId = trackerId; + } + +protected: + float positionX; + float positionY; + float orientation; + +public: + void Update(); + + float GetPositionX() + { + return positionX; + } + + float GetPositionY() + { + return positionY; + } + + float GetOrientation() + { + return orientation; + } +}; + +#endif diff --git a/source/Concept/Framework/modules/io_module.c b/source/Concept/Framework/modules/io_module.c new file mode 100755 index 0000000..3549af5 --- /dev/null +++ b/source/Concept/Framework/modules/io_module.c @@ -0,0 +1 @@ +#include "io_module.h" diff --git a/source/Concept/Framework/modules/io_module.h b/source/Concept/Framework/modules/io_module.h new file mode 100755 index 0000000..383eefb --- /dev/null +++ b/source/Concept/Framework/modules/io_module.h @@ -0,0 +1,45 @@ +#ifndef _MODULE_H +#define _MODULE_H + +#include "../defines.h" +#include "../tools.h" + +class Robot; + +class IO_Module +{ +public: + IO_Module() + { + this->parent = NULL; + this->moduleId = 0; + } + + IO_Module(uint32 moduleId) + { + this->parent = NULL; + this->moduleId = moduleId; + } + +protected: + Robot* parent; + uint32 moduleId; + +public: + Robot* GetParent() + { + return parent; + } + + void SetParent(Robot* newParent) + { + parent = newParent; + } + + uint32 GetId() + { + return moduleId; + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/display.c b/source/Concept/Framework/modules/output/display.c new file mode 100755 index 0000000..82fbb41 --- /dev/null +++ b/source/Concept/Framework/modules/output/display.c @@ -0,0 +1 @@ +#include "display.h" diff --git a/source/Concept/Framework/modules/output/display.h b/source/Concept/Framework/modules/output/display.h new file mode 100755 index 0000000..e221120 --- /dev/null +++ b/source/Concept/Framework/modules/output/display.h @@ -0,0 +1,198 @@ +#ifndef _DISPLAY_H +#define _DISPLAY_H + +#include "../../stdafx.h" + +class Display : public IO_Module +{ +public: + Display() + { + this->parent = NULL; + this->moduleId = 0; + this->cursorVisible = false; + this->illuminationEnabled = true; + this->commandClear = 0; + this->commandReturnCursor = 0; + this->commandNewLine = 0; + this->commandSetting = 0; + this->settingCursorVisible = 0; + this->settingIllumination = 0; + this->settingCursorPosition = 0; + } + + Display(uint32 displayId) + { + this->parent = NULL; + this->moduleId = displayId; + this->cursorVisible = false; + this->illuminationEnabled = true; + + switch(displayId) + { + case IO_DISPLAY_MAIN: + this->commandClear = 12; + this->commandReturnCursor = 13; + this->commandNewLine = 10; + this->commandSetting = 27; + this->settingCursorVisible = 67; + this->settingIllumination = 76; + this->settingCursorPosition = 79; + msleep(100); + uart1_init(103);//9600 BAUD at 16MHz Atmel + msleep(100); + break; + default: + this->commandClear = 0; + this->commandReturnCursor = 0; + this->commandNewLine = 0; + this->commandSetting = 0; + this->settingCursorVisible = 0; + this->settingIllumination = 0; + this->settingCursorPosition = 0; + break; + } + } + +protected: + bool cursorVisible; + bool illuminationEnabled; + //Commands + uint8 commandClear; + uint8 commandReturnCursor; + uint8 commandNewLine; + uint8 commandSetting; + //Settings + uint8 settingCursorVisible; + uint8 settingIllumination; + uint8 settingCursorPosition; + + void SendCommand(uint8 newCommand) + { + switch(moduleId) + { + case IO_DISPLAY_MAIN: + uart1_putc(newCommand); + break; + default: + break; + } + } + +public: + void Print(char* newString) + { + switch(moduleId) + { + case IO_DISPLAY_MAIN: + uart1_puts(newString); + break; + default: + break; + } + } + + void Print(int32 newInteger) + { + char buffer[12]; + ltoa(newInteger, buffer, 10); + Print(buffer); + } + + void PrintFloat(float newFloat) + { + Print((int32)(newFloat)); + Print("."); + Print(abs((uint32)(newFloat - float((int32)(newFloat)) * 100000))); + } + + void Print(char* newString, uint8 xPos, uint8 yPos) + { + SetCursorPosition(xPos, yPos); + Print(newString); + } + + void Print(int32 newInteger, uint8 xPos, uint8 yPos) + { + SetCursorPosition(xPos, yPos); + Print(newInteger); + } + + void PrintFloat(float newFloat, uint8 xPos, uint8 yPos) + { + SetCursorPosition(xPos, yPos); + PrintFloat(newFloat); + } + + void Clear() + { + SendCommand(commandClear); + } + + void ReturnCursor() + { + SendCommand(commandReturnCursor); + } + + void NewLine() + { + SendCommand(commandNewLine); + } + + bool GetCursorVisible() + { + return cursorVisible; + } + + void SetCursorVisible(bool newStatus) + { + cursorVisible = newStatus; + + SendCommand(commandSetting); + SendCommand(settingCursorVisible); + + if(cursorVisible) + { + SendCommand(1); + } + else + { + SendCommand(0); + } + } + + bool GetLightingEnabled() + { + return illuminationEnabled; + } + + void SetLightingEnabled(bool newStatus) + { + illuminationEnabled = newStatus; + + SendCommand(commandSetting); + SendCommand(settingIllumination); + + if(illuminationEnabled) + { + SendCommand(1); + } + else + { + SendCommand(0); + } + } + + void SetCursorPosition(uint8 newX, uint8 newY) + { + if(!newX || newX > 20) return; + if(!newY || newY > 4) return; + + SendCommand(commandSetting); + SendCommand(settingCursorPosition); + SendCommand(newX); + SendCommand(newY); + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/dribbler.c b/source/Concept/Framework/modules/output/dribbler.c new file mode 100755 index 0000000..20557e4 --- /dev/null +++ b/source/Concept/Framework/modules/output/dribbler.c @@ -0,0 +1 @@ +#include "dribbler.h" diff --git a/source/Concept/Framework/modules/output/dribbler.h b/source/Concept/Framework/modules/output/dribbler.h new file mode 100755 index 0000000..b11af69 --- /dev/null +++ b/source/Concept/Framework/modules/output/dribbler.h @@ -0,0 +1,118 @@ +#ifndef _DRIBBLER_H +#define _DRIBBLER_H + +#include "../../stdafx.h" + +class Dribbler : public IO_Module +{ +public: + Dribbler() + { + this->enabled = false; + this->curSpeed = 0; + this->parent = NULL; + this->moduleId = 0; + this->hardwarePort = NULL; + this->portPower = NULL; + this->pinForward = 0; + this->pinReverse = 0; + this->pinPower = 0; + } + + Dribbler(uint32 dribblerId) + { + this->enabled = false; + this->curSpeed = 1.0f; + this->parent = NULL; + this->moduleId = dribblerId; + + switch(dribblerId) + { + case IO_DRIBBLER_MAIN: + this->hardwarePort = &PORTD; + this->portPower = &PORTA; + this->pinForward = (1 << 6); + this->pinReverse = (1 << 7); + this->pinPower = (1 << 5); + break; + default: + this->hardwarePort = NULL; + this->portPower = NULL; + this->pinForward = 0; + this->pinReverse = 0; + this->pinPower = 0; + break; + } + + UpdateDirection(); + } + +protected: + bool enabled; + float curSpeed; + + //Hardware + volatile uint8* hardwarePort; + volatile uint8* portPower; + uint8 pinForward; + uint8 pinReverse; + uint8 pinPower; + + void UpdateDirection() + { + if(enabled) + { + if(curSpeed > 0) + { + *hardwarePort |= pinForward; + *hardwarePort &= ~pinReverse; + } + else if(curSpeed < 0) + { + *hardwarePort |= pinReverse; + *hardwarePort &= ~pinForward; + } + else + { + *hardwarePort |= pinForward; + *hardwarePort |= pinReverse; + } + + *portPower |= pinPower; + } + else + { + *hardwarePort &= ~pinForward; + *hardwarePort &= ~pinReverse; + + *portPower &= ~pinPower; + } + } + +public: + float GetSpeed() + { + return curSpeed; + } + + void SetSpeed(float newSpeed) + { + curSpeed = newSpeed; + + UpdateDirection(); + } + + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newStatus) + { + enabled = newStatus; + + UpdateDirection(); + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/engine.c b/source/Concept/Framework/modules/output/engine.c new file mode 100755 index 0000000..5c14c17 --- /dev/null +++ b/source/Concept/Framework/modules/output/engine.c @@ -0,0 +1 @@ +#include "engine.h" diff --git a/source/Concept/Framework/modules/output/engine.h b/source/Concept/Framework/modules/output/engine.h new file mode 100755 index 0000000..27b9905 --- /dev/null +++ b/source/Concept/Framework/modules/output/engine.h @@ -0,0 +1,124 @@ +#ifndef _ENGINE_H +#define _ENGINE_H + +#include "../../stdafx.h" + +class Engine : public IO_Module +{ +public: + Engine() + { + this->enabled = false; + this->curSpeed = 0; + this->parent = NULL; + this->moduleId = 0; + this->hardwarePort = NULL; + this->pwmSpeed = NULL; + this->pinForward = 0; + this->pinReverse = 0; + } + + Engine(uint32 engineId) + { + this->enabled = false; + this->curSpeed = 0; + this->parent = NULL; + this->moduleId = engineId; + + switch(engineId) + { + case IO_ENGINE_DRIVE_LEFT: + this->hardwarePort = &PORTB; + this->pwmSpeed = &OCR1A; + this->pinForward = (1 << 0); + this->pinReverse = (1 << 1); + break; + case IO_ENGINE_DRIVE_BACK: + this->hardwarePort = &PORTB; + this->pwmSpeed = &OCR1B; + this->pinForward = (1 << 2); + this->pinReverse = (1 << 3); + break; + case IO_ENGINE_DRIVE_RIGHT: + this->hardwarePort = &PORTD; + this->pwmSpeed = &OCR3A; + this->pinForward = (1 << 5); + this->pinReverse = (1 << 4); + break; + default: + this->hardwarePort = NULL; + this->pwmSpeed = NULL; + this->pinForward = 0; + this->pinReverse = 0; + break; + } + + *this->pwmSpeed = 0; + } + +protected: + bool enabled; + float curSpeed; + + //Hardware + volatile uint8* hardwarePort; + volatile uint16* pwmSpeed; + uint8 pinForward; + uint8 pinReverse; + + void UpdateDirection() + { + if(enabled) + { + if(curSpeed > 0) + { + *hardwarePort |= pinForward; + *hardwarePort &= ~pinReverse; + } + else if(curSpeed < 0) + { + *hardwarePort |= pinReverse; + *hardwarePort &= ~pinForward; + } + else + { + *hardwarePort |= pinForward; + *hardwarePort |= pinReverse; + } + } + else + { + *hardwarePort &= ~pinForward; + *hardwarePort &= ~pinReverse; + } + } + +public: + float GetSpeed() + { + return curSpeed; + } + + void SetSpeed(float newSpeed) + { + curSpeed = newSpeed; + + *pwmSpeed = (abs((int16)(newSpeed / SPEED_PER_PWM))); + + UpdateDirection(); + } + + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newStatus) + { + enabled = newStatus; + + UpdateDirection(); + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/kicker.c b/source/Concept/Framework/modules/output/kicker.c new file mode 100755 index 0000000..6670efb --- /dev/null +++ b/source/Concept/Framework/modules/output/kicker.c @@ -0,0 +1 @@ +#include "kicker.h" diff --git a/source/Concept/Framework/modules/output/kicker.h b/source/Concept/Framework/modules/output/kicker.h new file mode 100755 index 0000000..080666a --- /dev/null +++ b/source/Concept/Framework/modules/output/kicker.h @@ -0,0 +1,84 @@ +#ifndef _KICKER_H +#define _KICKER_H + +#include "../../stdafx.h" + +class Kicker : public IO_Module +{ +public: + Kicker() + { + this->enabled = false; + this->parent = NULL; + this->moduleId = 0; + this->portPower = NULL; + this->portForward = NULL; + this->portReverse = NULL; + this->pinPower = 0; + this->pinForward = 0; + this->pinReverse = 0; + } + + Kicker(uint32 kickerId) + { + this->enabled = false; + this->parent = NULL; + this->moduleId = kickerId; + + switch(kickerId) + { + case IO_KICKER_MAIN: + this->portPower = &PORTG; + this->portForward = &PORTA; + this->portReverse = &PORTE; + this->pinPower = (1 << 3); + this->pinForward = (1 << 2); + this->pinReverse = (1 << 6); + break; + default: + this->portPower = NULL; + this->portForward = NULL; + this->portReverse = NULL; + this->pinPower = 0; + this->pinForward = 0; + this->pinReverse = 0; + break; + } + + *this->portForward |= this->pinForward; + *this->portReverse &= ~this->pinReverse; + } + +protected: + bool enabled; + + //Hardware + volatile uint8* portPower; + volatile uint8* portForward; + volatile uint8* portReverse; + uint8 pinPower; + uint8 pinForward; + uint8 pinReverse; + +public: + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newStatus) + { + enabled = newStatus; + + if(enabled) + { + *portPower |= pinPower; + } + else + { + *portPower &= ~pinPower; + } + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/led.c b/source/Concept/Framework/modules/output/led.c new file mode 100755 index 0000000..687b2db --- /dev/null +++ b/source/Concept/Framework/modules/output/led.c @@ -0,0 +1 @@ +#include "led.h" diff --git a/source/Concept/Framework/modules/output/led.h b/source/Concept/Framework/modules/output/led.h new file mode 100755 index 0000000..08e7466 --- /dev/null +++ b/source/Concept/Framework/modules/output/led.h @@ -0,0 +1,65 @@ +#ifndef _LED_H +#define _LED_H + +#include "../../stdafx.h" + +class Led : public IO_Module +{ +public: + Led() + { + this->enabled = false; + this->parent = NULL; + this->moduleId = 0; + this->hardwarePort = NULL; + this->pinPower = 0; + } + + Led(uint32 ledId) + { + this->enabled = false; + this->parent = NULL; + this->moduleId = ledId; + + switch(ledId) + { + case IO_LED_MAIN: + this->hardwarePort = &PORTB; + this->pinPower = (1 << 1); + break; + default: + this->hardwarePort = NULL; + this->pinPower = 0; + break; + } + } + +protected: + bool enabled; + + //Hardware + volatile uint8* hardwarePort; + uint8 pinPower; + +public: + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newStatus) + { + enabled = newStatus; + + if(enabled) + { + *hardwarePort &= ~pinPower; + } + else + { + *hardwarePort |= pinPower; + } + } +}; + +#endif diff --git a/source/Concept/Framework/mouse_sensor.cpp b/source/Concept/Framework/mouse_sensor.cpp deleted file mode 100644 index 214a13e..0000000 --- a/source/Concept/Framework/mouse_sensor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "mouse_sensor.h" diff --git a/source/Concept/Framework/position_tracker.cpp b/source/Concept/Framework/position_tracker.cpp deleted file mode 100644 index 262069a..0000000 --- a/source/Concept/Framework/position_tracker.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "position_tracker.h" - -//----------------------------------------------------------------------------- -void Position_Tracker::Update() -{ - //insert code here -} diff --git a/source/Concept/Framework/robot.c b/source/Concept/Framework/robot.c new file mode 100755 index 0000000..d8ea1c2 --- /dev/null +++ b/source/Concept/Framework/robot.c @@ -0,0 +1,135 @@ +#include "robot.h" + +//----------------------------------------------------------------------------- +Robot::Robot() +{ + //Hardware + + //Set pin 1-6 output, 0 and 7 input + DDRA = (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6); + PORTA = 0; + + //All output + DDRB = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); + PORTB = (1 << 1); + + //All output except PC4/PC5 (mousesensor SDA) + DDRC = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7); + PORTC = 0; + + //All output except PD0+1(I2C) + 2+3(RS232) + DDRD = (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); + PORTD = (1 << 0) | (1 << 1);//Activate pullup at PD0+1 + + //PE5 for input + DDRE = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7); + PORTE = 0; + + //All input with pullup + DDRF = 0; + PORTF = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); + + //All input + DDRG = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4); + PORTG = (1 << 0) | (1 << 1); + + // activate channel A+B on PWM1 at 8Bit + TCCR1A = (1<< COM1A1) | (1<< COM1B1) | (1<< WGM10); + TCCR1B = (1< enable counter + + // activate Kanal A+B on PWM3 at 8Bit + TCCR3A = (1<< COM3A1) | (1<< COM3B1) | (1<< WGM10); + TCCR3B = (1< enable counter + + //Activate interrupt + sei(); + + //Interface + for(uint8 i = IO_START; i < IO_END; i++) + { + modules[i] = NULL; + } +} + +//----------------------------------------------------------------------------- +Robot::~Robot() +{ + for(uint8 i = 0; i < IO_END; i++) + { + if(!modules[i]) continue; + + delete modules[i]; + modules[i] = NULL; + } +} + +//----------------------------------------------------------------------------- +bool Robot::AddModule(IO_Module* newModule) +{ + if(modules[newModule->GetId()]) + return false; + + newModule->SetParent(this); + + modules[newModule->GetId()] = newModule; + + return true; +} + +//----------------------------------------------------------------------------- +bool Robot::RemoveModule(IO_Module* oldModule) +{ + return RemoveModule(oldModule->GetId()); +} + +//----------------------------------------------------------------------------- +void Robot::Update() +{ + GetModule(IO_BALL_TRACKER_MAIN)->Update(); + + GetModule(IO_POSITION_TRACKER_MAIN)->Update(); + + GetModule(IO_NAVIGATOR_MAIN)->Update(); + + //insert code here +} + +//----------------------------------------------------------------------------- +uint16 Robot::GetADCValue(uint8 channel) +{ + if(channel > 7) return 0; + + uint32 result = 0; + + //Activate ADC and set division factor to 8 + ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); + + //Set multiplexer channel + ADMUX = channel; + //Use internal referencevoltage (2,56 V for atmega32) + ADMUX |= (1 << REFS1) | (1 << REFS0); + + //Initialise ADC and start dummyreadout + ADCSRA |= (1 << ADSC); + while(ADCSRA & (1 << ADSC)); + + //Get voltage three times and calculate average value + for(uint8 i = 0; i < 3; i++) + { + // Eine Wandlung + ADCSRA |= (1 << ADSC); + // Auf Ergebnis warten... + while(ADCSRA & (1 << ADSC)); + + result += ADCW; + } + + //Disable ADC + ADCSRA &= ~(1 << ADEN); + + result /= 3; + + return (uint16)(result); +} + +//--- EOF --- diff --git a/source/Concept/Framework/robot.cpp b/source/Concept/Framework/robot.cpp deleted file mode 100644 index 5c673cb..0000000 --- a/source/Concept/Framework/robot.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "robot.h" - -//----------------------------------------------------------------------------- -Robot::Robot() -{ - //Hardware - - //Set pin 1-6 output, 0 and 7 input - DDRA = (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6); - PORTA = 0; - - //All output - DDRB = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); - PORTB = (1 << 1); - - //All output except PC4/PC5 (mousesensor SDA) - DDRC = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 6) | (1 << 7); - PORTC = 0; - - //All output except PD0+1(I2C) + 2+3(RS232) - DDRD = (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); - PORTD = (1 << 0) | (1 << 1);//Activate pullup at PD0+1 - - //PE5 for input - DDRE = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 6) | (1 << 7); - PORTE = 0; - - //All input with pullup - DDRF = 0; - PORTF = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); - - //All input - DDRG = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4); - PORTG = (1 << 0) | (1 << 1); - - // activate channel A+B on PWM1 at 8Bit - TCCR1A = (1<< COM1A1) | (1<< COM1B1) | (1<< WGM10); - TCCR1B = (1< enable counter - - // activate Kanal A+B on PWM3 at 8Bit - TCCR3A = (1<< COM3A1) | (1<< COM3B1) | (1<< WGM10); - TCCR3B = (1< enable counter - - //Activate interrupt - sei(); - - //Interface - for(uint8 i = 0; i < IO_END; i++) - { - modules[i] = NULL; - } -} - -//----------------------------------------------------------------------------- -Robot::~Robot() -{ - for(uint8 i = 0; i < IO_END; i++) - { - if(!modules[i]) continue; - - delete modules[i]; - modules[i] = NULL; - } -} - -//----------------------------------------------------------------------------- -bool Robot::AddModule(IO_Module* newModule) -{ - if(modules[newModule->GetId()]) - return false; - - newModule->SetParent(this); - - modules[newModule->GetId()] = newModule; - - return true; -} - -//----------------------------------------------------------------------------- -bool Robot::RemoveModule(IO_Module* oldModule) -{ - return RemoveModule(oldModule->GetId()); -} - -//----------------------------------------------------------------------------- -void Robot::Update() -{ - //insert code here -} - -//----------------------------------------------------------------------------- -uint16 Robot::GetADCValue(uint8 channel) -{ - if(channel > 7) return 0; - - uint32 result = 0; - - //Activate ADC and set division factor to 8 - ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); - - //Set multiplexer channel - ADMUX = channel; - //Use internal referencevoltage (2,56 V for atmega32) - ADMUX |= (1 << REFS1) | (1 << REFS0); - - //Initialise ADC and start dummyreadout - ADCSRA |= (1 << ADSC); - while(ADCSRA & (1 << ADSC)); - - //Get voltage three times and calculate average value - for(uint8 i = 0; i < 3; i++) - { - // Eine Wandlung - ADCSRA |= (1 << ADSC); - // Auf Ergebnis warten... - while(ADCSRA & (1 << ADSC)); - - result += ADCW; - } - - //Disable ADC - ADCSRA &= ~(1 << ADEN); - - result /= 3; - - return (uint16)(result); -} - -//--- EOF --- diff --git a/source/Concept/Framework/sensor.cpp b/source/Concept/Framework/sensor.cpp deleted file mode 100644 index b9b4936..0000000 --- a/source/Concept/Framework/sensor.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "sensor.h" \ No newline at end of file diff --git a/source/Concept/Framework/stdafx.h b/source/Concept/Framework/stdafx.h index 151d749..af60c6e 100644 --- a/source/Concept/Framework/stdafx.h +++ b/source/Concept/Framework/stdafx.h @@ -19,4 +19,6 @@ #include "ir_sensor.h" #include "mouse_sensor.h" #include "position_tracker.h" +#include "ball_tracker.h" +#include "navigator.h" #include "robot.h" diff --git a/source/Concept/Framework/tools.c b/source/Concept/Framework/tools.c new file mode 100755 index 0000000..6fd107c --- /dev/null +++ b/source/Concept/Framework/tools.c @@ -0,0 +1,17 @@ +#include "tools.h" + +#ifndef new + +//----------------------------------------------------------------------------- +void* operator new(size_t sz) +{ + return malloc(sz); +} + +//----------------------------------------------------------------------------- +void operator delete(void* p) +{ + free(p); +} + +#endif diff --git a/source/Concept/Framework/tools.cpp b/source/Concept/Framework/tools.cpp deleted file mode 100644 index 6fd107c..0000000 --- a/source/Concept/Framework/tools.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "tools.h" - -#ifndef new - -//----------------------------------------------------------------------------- -void* operator new(size_t sz) -{ - return malloc(sz); -} - -//----------------------------------------------------------------------------- -void operator delete(void* p) -{ - free(p); -} - -#endif diff --git a/source/Concept/Framework/tools.h b/source/Concept/Framework/tools.h index 6519a1b..0ca4dda 100644 --- a/source/Concept/Framework/tools.h +++ b/source/Concept/Framework/tools.h @@ -1,7 +1,8 @@ #ifndef _TOOLS_H #define _TOOLS_H -#include +#include +#include #ifndef new void* operator new(size_t sz); @@ -34,6 +35,11 @@ inline void usleep(int usec) asm volatile("nop"); } } -}; +}; + +inline float distance2d(float x1, float y1, float x2, float y2) +{ + return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); +} #endif -- cgit v1.2.3