Guten Abend, ich versuche seit Stunden verzweifelt zwei Asuros dazu zu bringen beide Motoren mal zum drehen zu bringen. Leider klappt es nicht. Ich habe es mit dem Standard-Header "asuro.h" probiert und der Funktion MotorDir() mit Parametern FWD,FWD und MotorSpeed() mit Parametern von 0-255. Leider tut sich gar nichts. Die Asuros hat jemand anders aufgebaut, angeblich sind diese bereits gefahren. LED's lassen sich nach Aufruf der Init-Funktion steuern, die Motoren schweigen. Kann es sein, dass ich einen Befehl vergessen habe, so dass die Motoren starten? Letztendlich habe ich in main nur Init, dann MotorDir, dann Motorspeed und dann eine Warteschleife vor dem return... ich kann es mir nicht erklären. Auch Beispielprogramme wie der Kollisionstest machen nichts :( Hat jemand eine Idee?
Hab auch einen von den Dingern. Aus der Ferne natürlich schlecht eine Diagnose durchzuführen. Sind die Batterien voll? Kann nämlich gut sein, dass noch alles funktioniert, außer eben die Motoren. Mit nem Multimeter kannst ja auch mal nachmessen, ob die PWM-Ausgänge zur Ansteuerung der H-Brücke der Motoren das PWM-Signal ausgeben.
Also ich gehe stark davon aus, dass die Batterien voll sind (gerade neue gekauft gehabt und diese ersetzt, vergaß das zu schreiben) Ich bin gerade umgezogen und habe noch keine Messgeräte hier. Soll denen nur etwas beibringen und testen, habe leider auch kein Multimeter griffbereit...
Kannst du mal deine asuro.c, asuro.h und den selftest posten? Also als C-Code einbetten.
Ich habe gerade eine Idee gehabt, wie ich das PWM-Signal noch auf Existenz / die H-Brücke noch auf Funktion testen kann. Ich habe eine LED an den PWM Pin (linker Motor) gehalten und gegen GND, sie leuchtet nicht. Kann es vielleicht sein, dass der Mega irgendwie irgenwo festfrisst? Denn: Nach MotorDir(x,y) bzw. MotorSpeed(x,y) reagiert er auch nicht auf nachfolgende LED-Funktionen aus der Bibliothek, vorher jedoch schon...
Kann gut sein. Also man braucht deine asuro.c,h, selftest.c,h und test.c,h. Sonst kann ich wenig sagen.
1 | /*************************************************************************** |
2 | * |
3 | * File Name: kollisiontest.c |
4 | * Project : ASURO |
5 | * |
6 | * Description: Kollisionstest mit Hilfe der Tastensensoren |
7 | * |
8 | * Ver. Date Author Comments |
9 | * ------- ---------- ----------------- ------------------------------ |
10 | * 1.0 10.09.2005 Peter initial build |
11 | * 1.1 08.01.2006 Peter 2x PollSwitch + Vergleich, |
12 | * anstelle 8x PollSwitch |
13 | * |
14 | * benoetigt die modifizierte Asuro Bibliothek 'asuro.c' |
15 | * von waste, stochri und andun. Zu finden bei www.roboternetz.de |
16 | */ |
17 | #include "asuro.c" |
18 | #include "asuro.h" |
19 | |
20 | #define FULL_L 250 |
21 | #define FULL_R 220 |
22 | |
23 | /* Motor vorwärts */ |
24 | void MotorFwd(void) |
25 | { |
26 | MotorDir(FWD,FWD); |
27 | MotorSpeed(FULL_L,FULL_R); |
28 | } |
29 | |
30 | /* Motor rückwärts */ |
31 | void MotorRwd(void) |
32 | { |
33 | MotorDir(RWD,RWD); |
34 | MotorSpeed(FULL_L,FULL_R); |
35 | } |
36 | |
37 | /* Motor rückwärts Links */ |
38 | void MotorRwdL(void) |
39 | { |
40 | MotorDir(RWD,RWD); |
41 | MotorSpeed(FULL_L,0); |
42 | } |
43 | |
44 | /* Motor rückwärts Rechts */ |
45 | void MotorRwdR(void) |
46 | { |
47 | MotorDir(RWD,RWD); |
48 | MotorSpeed(0, FULL_R); |
49 | } |
50 | |
51 | /* Motor stop */ |
52 | void MotorStop(void) |
53 | { |
54 | MotorSpeed(0,0); |
55 | } |
56 | |
57 | int main(void) |
58 | { |
59 | unsigned char t1, t2; |
60 | |
61 | Init(); |
62 | while(1) |
63 | { |
64 | t1 = PollSwitch(); |
65 | t2 = PollSwitch(); |
66 | if(t1 == 0 && t2 == 0) /* keine Taste */ |
67 | { |
68 | MotorFwd(); /* vorwärts fahren */ |
69 | FrontLED(ON); |
70 | BackLED(OFF,OFF); |
71 | } |
72 | else if (t1 && t2 && t1 == t2) |
73 | { |
74 | MotorStop(); |
75 | if(t1 & 0x07) /* Tasten links gedrückt? */ |
76 | { |
77 | MotorRwdL(); /* Rückwärtskurve links fahren */ |
78 | FrontLED(OFF); |
79 | BackLED(ON,OFF); |
80 | } |
81 | if (t1 & 0x38) /* Tasten rechts gedrückt? */ |
82 | { |
83 | MotorRwdR(); /* Rückwärtskurve rechts fahren */ |
84 | FrontLED(OFF); |
85 | BackLED(OFF,ON); |
86 | } |
87 | |
88 | } |
89 | } |
90 | return 0; |
91 | } |
main.c
1 | /******************************************************************************* |
2 | * |
3 | * File Name: asuro.c |
4 | * Project : ASURO |
5 | * |
6 | * Description: This file contains ASURO main features |
7 | * |
8 | * Ver. Date Author Comments |
9 | * ------- ---------- -------------- ------------------------------ |
10 | * 1.00 14.08.2003 Jan Grewe build |
11 | * 2.00 14.10.2003 Jan Grewe LEFT_VEL, RIGHT_VEL -> MotorSpeed(unsigned char left_speed, unsigned char right_speed); |
12 | * LeftRwd(),LeftFwd(),RightRwd(),RigthFwd() -> MotorDir(unsigned char left_dir, unsigned char right_dir); |
13 | * GREEN_ON,GREEN_OFF,RED_ON,RED_OFF -> StatusLED(unsigned char color); |
14 | * LED_RED_ON, LED_RED_OFF -> FrontLED(unsigned char color); |
15 | * Blink(unsigned char left, unsigned char right) -> BackLED(unsigned char left, unsigned char right); |
16 | * Alles in Funktionen gefasst => leichter verständlich ?!?! |
17 | * 2.10 17.10.2003 Jan Grewe new Timer funktion void Sleep(unsigned char time36kHz) |
18 | * |
19 | * Copyright (c) 2003 DLR Robotics & Mechatronics |
20 | *****************************************************************************/ |
21 | /*************************************************************************** |
22 | * * |
23 | * This program is free software; you can redistribute it and/or modify * |
24 | * it under the terms of the GNU General Public License as published by * |
25 | * the Free Software Foundation; either version 2 of the License, or * |
26 | * any later version. * |
27 | ***************************************************************************/ |
28 | |
29 | #include "asuro.h" |
30 | volatile unsigned char count72kHz; |
31 | |
32 | /* uses timer2 (36kHz for IR communication */ |
33 | /* counts falling and rising edge => 36kHz*2 = 72kHz */ |
34 | //SIGNAL (SIG_OUTPUT_COMPARE2) |
35 | //{ |
36 | //count72kHz ++; |
37 | //} |
38 | |
39 | /* Init function Processor will be initalized to work correctly */ |
40 | void Init (void) |
41 | { |
42 | //-------- seriell interface programmed in boot routine and already running ------- |
43 | // prepare 36kHz for IR - Communication |
44 | TCCR2 = (1 << WGM21) | (1 << COM20) | (1 << CS20); |
45 | OCR2 = 0x6E; // 36kHz @8MHz |
46 | TIMSK |= (1 << OCIE2); // 36kHz counter for sleep |
47 | |
48 | // prepare RS232 |
49 | UCSRA = 0x00; |
50 | UCSRB = 0x00; |
51 | UCSRC = 0x86; // No Parity | 1 Stop Bit | 8 Data Bit |
52 | UBRRL = 0xCF; // 2400bps @ 8.00MHz |
53 | |
54 | // I/O Ports |
55 | DDRB = IRTX | LEFT_DIR | PWM | GREEN_LED; |
56 | DDRD = RIGHT_DIR | FRONT_LED | ODOMETRIE_LED | RED_LED; |
57 | |
58 | // for PWM (8-Bit PWM) on OC1A & OC1B |
59 | TCCR1A = (1 << WGM10) | (1 << COM1A1) | (1 << COM1B1); |
60 | // tmr1 running on MCU clock/8 |
61 | TCCR1B = (1 << CS11); |
62 | |
63 | // A/D Conversion |
64 | ADCSRA = (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1); // clk/64 |
65 | ODOMETRIE_LED_OFF; |
66 | |
67 | FrontLED(OFF); |
68 | BackLED(ON,ON); |
69 | BackLED(OFF,OFF); |
70 | StatusLED(GREEN); |
71 | |
72 | MotorDir(FWD,FWD); |
73 | MotorSpeed(0,0); |
74 | sei(); |
75 | } |
76 | |
77 | /* Set motor speed */ |
78 | inline void MotorSpeed(unsigned char left_speed, unsigned char right_speed) |
79 | { |
80 | OCR1A = left_speed; |
81 | OCR1B = right_speed; |
82 | } |
83 | |
84 | /* Set motor direction */ |
85 | inline void MotorDir(unsigned char left_dir, unsigned char right_dir) |
86 | { |
87 | PORTD = (PORTD &~ ((1 << PD4) | (1 << PD5))) | left_dir; |
88 | PORTB = (PORTB &~ ((1 << PB4) | (1 << PB5))) | right_dir; |
89 | } |
90 | |
91 | /* Status LED (OFF,GREEN,YELLOW,RED)*/ |
92 | /* example code set StatusLED GREEN */ |
93 | /* StatusLED(GREEN); */ |
94 | inline void StatusLED(unsigned char color) |
95 | { |
96 | if (color == OFF) {GREEN_LED_OFF; RED_LED_OFF;} |
97 | if (color == GREEN) {GREEN_LED_ON; RED_LED_OFF;} |
98 | if (color == YELLOW) {GREEN_LED_ON; RED_LED_ON;} |
99 | if (color == RED) {GREEN_LED_OFF; RED_LED_ON;} |
100 | } |
101 | |
102 | /* Front LED */ |
103 | /* example code FrontLED ON */ |
104 | /* FrontLED(ON); */ |
105 | inline void FrontLED(unsigned char status) |
106 | { |
107 | PORTD = (PORTD &~(1 << PD6)) | (status << PD6); |
108 | } |
109 | |
110 | /* function for Break LEDs */ |
111 | /* example code right LED On left LED Off */ |
112 | /* BackLED(OFF,ON); */ |
113 | void BackLED(unsigned char left, unsigned char right) |
114 | { |
115 | if (left || right) { |
116 | PORTD &= ~(1 << PD7); // Wheel LED OFF |
117 | DDRC |= (1 << PC0) | (1 << PC1); // Output => no odometrie |
118 | PORTC |= (1 << PC0) | (1 << PC1); |
119 | } |
120 | if (!left) PORTC &= ~(1 << PC1); |
121 | if (!right) PORTC &= ~(1 << PC0); |
122 | } |
123 | |
124 | /* function to read out line follow phototransistors (left,rigth) */ |
125 | void LineData(unsigned int *data) |
126 | { |
127 | ADMUX = (1 << REFS0) | IR_LEFT; // AVCC reference with external capacitor |
128 | ADCSRA |= (1 << ADSC); // Start conversion |
129 | while (!(ADCSRA & (1 << ADIF))); // wait for conversion complete |
130 | ADCSRA |= (1 << ADIF); // clear ADCIF |
131 | data[0] = ADCL + (ADCH << 8); |
132 | |
133 | ADMUX = (1 << REFS0) | IR_RIGHT; // AVCC reference with external capacitor |
134 | ADCSRA |= (1 << ADSC); // Start conversion |
135 | while (!(ADCSRA & (1 << ADIF))); // wait for conversion complete |
136 | ADCSRA |= (1 << ADIF); // clear ADCIF |
137 | data[1] = ADCL + (ADCH << 8); |
138 | } |
139 | |
140 | /* function to read out odometrie phototransistors (left,rigth) */ |
141 | void OdometrieData(unsigned int *data) |
142 | { |
143 | DDRC &= ~((1 << PC0) | (1 << PC1)); // Input => no break LED |
144 | ODOMETRIE_LED_ON; |
145 | |
146 | ADMUX = (1 << REFS0) | WHEEL_LEFT; // AVCC reference with external capacitor |
147 | ADCSRA |= (1 << ADSC); // Start conversion |
148 | while (!(ADCSRA & (1 << ADIF))); // wait for conversion complete |
149 | ADCSRA |= (1 << ADIF); // clear ADCIF |
150 | data[0] = ADCL + (ADCH << 8); |
151 | |
152 | ADMUX = (1 << REFS0) | WHEEL_RIGHT; // AVCC reference with external capacitor |
153 | ADCSRA |= (1 << ADSC); // Start conversion |
154 | while (!(ADCSRA & (1 << ADIF))); // wait for conversion complete |
155 | ADCSRA |= (1 << ADIF); // clear ADCIF |
156 | data[1] = ADCL + (ADCH << 8); |
157 | } |
158 | |
159 | /* function for serial communication */ |
160 | void SerWrite(unsigned char *data,unsigned char length) |
161 | { |
162 | unsigned char i = 0; |
163 | UCSRB = 0x08; // enable transmitter |
164 | while (length > 0) { |
165 | if (UCSRA & 0x20) { // wait for empty transmit buffer |
166 | UDR = data[i++]; |
167 | length --; |
168 | } |
169 | } |
170 | while (!(UCSRA & 0x40)); |
171 | for (i = 0; i < 0xFE; i++) |
172 | for(length = 0; length < 0xFE; length++); |
173 | } |
174 | |
175 | void SerRead(unsigned char *data, unsigned char length,unsigned int timeout) |
176 | { |
177 | unsigned char i = 0; |
178 | unsigned int time = 0; |
179 | UCSRB = 0x10; // enable receiver |
180 | /* non blocking */ |
181 | if (timeout != 0) { |
182 | while (i < length && time++ < timeout) { |
183 | if (UCSRA & 0x80) { |
184 | data[i++] = UDR; |
185 | time = 0; |
186 | } |
187 | } |
188 | if (time > timeout) data[0] = 'T'; |
189 | } |
190 | /* blocking */ |
191 | else { |
192 | while (i < length) { |
193 | if (UCSRA & 0x80) |
194 | data[i++] = UDR; |
195 | } |
196 | } |
197 | } |
198 | |
199 | /* function to read out switches */ |
200 | unsigned char PollSwitch (void) |
201 | { |
202 | unsigned int i; |
203 | |
204 | DDRD |= SWITCHES; // Switches as Output |
205 | SWITCH_ON; // Output HIGH for measurement |
206 | ADMUX = (1 << REFS0) | SWITCH; // AVCC reference with external capacitor |
207 | Sleep(10); |
208 | |
209 | ADCSRA |= (1 << ADSC); // Start conversion |
210 | while (!(ADCSRA & (1 << ADIF)));// wait for conversion complete |
211 | ADCSRA |= (1 << ADIF); // clear ADCIF |
212 | i = ADCL + (ADCH << 8); |
213 | |
214 | SWITCH_OFF; |
215 | |
216 | return ((unsigned char) ((( 1024.0/(float)i - 1.0)) * 63.0 + 0.5)); |
217 | } |
218 | |
219 | /* for working with Interrupt */ |
220 | void StartSwitch(void) |
221 | { |
222 | SWITCH_OFF; |
223 | DDRD &= ~SWITCHES; // Switches as Input => ext. Int 1 |
224 | MCUCR &= ~((1 << ISC11) | (1 << ISC10));// Low level generates interrupt |
225 | GICR |= (1 << INT1); // Enable external Interrupt 1 |
226 | } |
227 | |
228 | void StopSwitch(void) |
229 | { |
230 | GICR &= ~(1 << INT1); |
231 | } |
232 | |
233 | /* uses 72kHz timer => Sleep(x) = x/72kHz [sec] */ |
234 | void Sleep(unsigned char time72kHz) |
235 | { |
236 | count72kHz = 0; |
237 | while (count72kHz < time72kHz); |
238 | } |
1 | /******************************************************************************* |
2 | * |
3 | * File Name: asuro.h |
4 | * Project : ASURO |
5 | * |
6 | * |
7 | * Ver. Date Author Comments |
8 | * ------- ---------- -------------- ------------------------------ |
9 | * 1.00 14.08.2003 Jan Grewe build |
10 | * 2.00 14.10.2003 Jan Grewe LEFT_VEL, RIGHT_VEL -> MotorSpeed(unsigned char left_speed, unsigned char right_speed); |
11 | * LeftRwd(),LeftFwd(),RightRwd(),RigthFwd() -> MotorDir(unsigned char left_dir, unsigned char right_dir); |
12 | * GREEN_ON,GREEN_OFF,RED_ON,RED_OFF -> StatusLED(unsigned char color); |
13 | * LED_RED_ON, LED_RED_OFF -> FrontLED(unsigned char color); |
14 | * Blink(unsigned char left, unsigned char right) -> BackLED(unsigned char left, unsigned char right); |
15 | * Alles in Funktionen gefasst => leichter verständlich ?!?! |
16 | * 2.10 17.10.2003 Jan Grewe new Timer funktion void Sleep(unsigned char time36kHz) |
17 | * |
18 | * |
19 | * Copyright (c) 2003 DLR Robotics & Mechatronics |
20 | *****************************************************************************/ |
21 | /*************************************************************************** |
22 | * * |
23 | * This program is free software; you can redistribute it and/or modify * |
24 | * it under the terms of the GNU General Public License as published by * |
25 | * the Free Software Foundation; either version 2 of the License, or * |
26 | * any later version. * |
27 | ***************************************************************************/ |
28 | |
29 | #ifndef ASURO_H |
30 | #define ASURO_H |
31 | |
32 | #include <avr/io.h> |
33 | #include <avr/interrupt.h> |
34 | #include <avr/signal.h> |
35 | |
36 | #define FALSE 0 |
37 | #define TRUE 1 |
38 | |
39 | #define OFF 0 |
40 | #define ON 1 |
41 | |
42 | #define GREEN 1 |
43 | #define RED 2 |
44 | #define YELLOW 3 |
45 | |
46 | /* Init function Processor will be initalized to work correctly */ |
47 | void Init(void); |
48 | |
49 | /* Set Status LED (OFF,GREEN,RED,YELLOW)*/ |
50 | /* example code set Status LED GREEN */ |
51 | /* StatusLED(GREEN); */ |
52 | inline void StatusLED(unsigned char color); |
53 | /* function for front LED */ |
54 | /* example code front LED On */ |
55 | /* FrontLED(ON); */ |
56 | inline void FrontLED(unsigned char status); |
57 | |
58 | /* function for Back LEDs */ |
59 | /* example code right LED On left LED Off */ |
60 | /* BackLED(OFF,ON); */ |
61 | void BackLED(unsigned char left, unsigned char right); |
62 | |
63 | /* Set motor direction (FWD,RWD,BREAK,FREE)*/ |
64 | /* example code set Direction for right motor to rewind */ |
65 | /* MotorDir(BREAK,RWD); */ |
66 | inline void MotorDir(unsigned char left_dir, unsigned char right_dir); |
67 | |
68 | /* range for motor speed 0..255 */ |
69 | /* example code set speed for left motor to 150 */ |
70 | /* MotorSpeed(150,0); */ |
71 | inline void MotorSpeed(unsigned char left_speed, unsigned char right_speed); |
72 | |
73 | /* function for serial communication */ |
74 | void SerWrite(unsigned char *data,unsigned char length); |
75 | /* timeout = 0 => bloking mode !!! */ |
76 | void SerRead(unsigned char *data, unsigned char length, unsigned int timeout); |
77 | |
78 | /* function to read out line follow phototransistors (left,rigth) */ |
79 | void LineData(unsigned int *data); |
80 | |
81 | /* function to read out odometrie phototransistors (left,rigth) */ |
82 | void OdometrieData(unsigned int *data); |
83 | |
84 | /* function to read out switches */ |
85 | unsigned char PollSwitch (void); |
86 | /* for working with Interrupt */ |
87 | void StartSwitch(void); |
88 | void StopSwitch(void); |
89 | |
90 | /* Sleep function using 36kHz counter */ |
91 | void Sleep(unsigned char timer36kHz); |
92 | /* ----------- END ------------ */ |
93 | |
94 | |
95 | /* --------------- INTERNAL ------------- */ |
96 | #define GREEN_LED_ON PORTB |= GREEN_LED |
97 | #define GREEN_LED_OFF PORTB &= ~GREEN_LED |
98 | #define RED_LED_ON PORTD |= RED_LED |
99 | #define RED_LED_OFF PORTD &= ~RED_LED |
100 | |
101 | #define FWD (1 << PB5) /* (1 << PD5) */ |
102 | #define RWD (1 << PB4) /* (1 << PD4) */ |
103 | #define BREAK 0x00 |
104 | #define FREE (1 << PB4) | (1 << PB5) /* (1 << PD4) | (1 << PD5)*/ |
105 | |
106 | #define IRTX (1 << PB3) |
107 | #define GREEN_LED (1 << PB0) |
108 | #define RED_LED (1 << PD2) |
109 | |
110 | #define PWM (1 << PB1) | (1 << PB2) |
111 | #define RIGHT_DIR (1 << PB4) | (1 << PB5) |
112 | #define LEFT_DIR (1 << PD4) | (1 << PD5) |
113 | |
114 | #define SWITCHES (1 << PD3) |
115 | #define SWITCH_ON PORTD |= SWITCHES |
116 | #define SWITCH_OFF PORTD &= ~SWITCHES |
117 | |
118 | #define BATTERIE (1 << MUX0) | (1 << MUX2) //ADC5 |
119 | #define SWITCH (1 << MUX2) //ADC4 |
120 | #define IR_LEFT (1 << MUX0) | (1 << MUX1) //ADC3 |
121 | #define IR_RIGHT (1 << MUX1) //ADC2 |
122 | #define FRONT_LED (1 << PD6) |
123 | |
124 | #define ODOMETRIE_LED (1 << PD7) |
125 | #define ODOMETRIE_LED_ON PORTD |= ODOMETRIE_LED |
126 | #define ODOMETRIE_LED_OFF PORTD &= ~ODOMETRIE_LED |
127 | |
128 | #define WHEEL_LEFT (1 << MUX0) //ADC1 |
129 | #define WHEEL_RIGHT 0 //ADC0 |
130 | |
131 | #endif /* ASURO_H */ |
Selftest ist gerade noch am flashen..
Achso, du verwendest die SelfTest-Demo gar nicht. Dann musst du dein Programm posten. Also mit main.c
Du solltest C-Code so posten wie unter "Formatierung" über dem Postfenster beschrieben. Dann wirds übersichtlicher.
Also einen meiner Fehler habe ich gerade entdeckt, ich habe nicht die Library aus dem Roboternetz genutzt, die die oben gepostete main.c benötigt. Jedoch funktionierte es so, wie ihc es gepostet habe Fehlerfrei (bis auf Warnung wegen interrupts) zu kompilieren... Mit der geforderten Library bekomme ich diesen Fehler und Folgefehler: Severity Code Description Project File Line Warning 'SIG_OVERFLOW2' appears to be a misspelled signal handler, missing __vector prefix [-Wmisspelled-isr] APP1 XXXXX\asuro.c 222
Also ich kenn die Lib aus dem Roboternetz nicht. Die müsstest du auch posten. Allgemein ist SIG_OVERFLOW2 ein veralteter Name für eine Interrupt-Serivce-Routine. Das sollte aber keine Probleme machen, da die Asuro Sourcen auch die alten Bezeichnungen verwendent (SIG statt ISR). Weist du denn, in welchen Codeabschnitt du in der Main reinkommst? Also Tasten gedrückt, Tasten nicht gedrückt, etc. Würde vermuten du kommst in gar keinen rein.
Hier in gar keinen, ich habe daher zuvor in der Main folgendes gemacht: StatusLED in Grün gewechselt, danach in Gelb, dann: MotorDir(FWD,FWD); MotorSpeed(125,125); Status LED Grün.... die blieb dann aber immer gelb.. asuro.c Roboternetz
1 | /****************************************************************************/
|
2 | /*!
|
3 | \file asuro.c
|
4 | |
5 | \brief Init- und Interrupt-Funktionen der Asuro Library.\n
|
6 | Timer2 wird mit 36 kHz betrieben, im Gegensatz zur ausgelieferten\n
|
7 | Version mit 72 kHz.
|
8 | |
9 | \par Interrupt-Doku nur ueber die Datei zu sehen:
|
10 | Bitte ueber den oben ausgegebenen Link \b 'gehe \b zum \b Quellcode \n
|
11 | \b dieser \b Datei' direkt in der Datei nachsehen.\n
|
12 | DoxyGen ist nicht zur Erkennung von Interrupt-Funktionen 'bereit'.\n
|
13 | Behandelt werden folgende Interrupts:\n
|
14 | - SIG_OVERFLOW2 : Timer 2 (fest mit 36 kHz belegt)\n
|
15 | - SIG_INTERRUPT1 : Switches (Taster) im Interruptmode\n
|
16 | - SIG_ADC : Analog-Digital-Wandler
|
17 | |
18 | \par Wichtiger Hinweis:
|
19 | Die Init()-Funktion muss von jedem Programm beim Start\n
|
20 | aufgerufen werden.\n
|
21 | |
22 | \see Defines zum setzen von Port's und Konfigurationen in asuro.h\n
|
23 | IRTX, LEFT_DIR, PWM, GREEN_LED, RIGHT_DIR, FRONT_LED,\n
|
24 | ODOMETRIE_LED, RED_LED, ON, OFF, GREEN, FWD, TRUE, FALSE
|
25 | |
26 | \version V--- - 10.11.2003 - Jan Grewe - DLR\n
|
27 | Original Version von der ASURO CD\n
|
28 | \version V--- - 20.11.2006 - m.a.r.v.i.n\n
|
29 | +++ SIGNAL (SIG_ADC)\n
|
30 | static Variable toggle mit FALSE initialisiert.\n
|
31 | (Bug report von Rolf_Ebert)
|
32 | \version V--- - bis zum 07.01.2007 - \n
|
33 | Bitte in Datei CHANGELOG nachsehen.\n
|
34 | \version V001 - 13.01.2007 - m.a.r.v.i.n\n
|
35 | +++ Alle Funktionen\n
|
36 | Zerlegte Sourcen in einzelne Dateien fuer eine echte Library.
|
37 | \version V002 - 27.01.2007 - Sternthaler\n
|
38 | +++ Alle Funktionen\n
|
39 | Kommentierte Version (KEINE Funktionsaenderung)
|
40 | \version V003 - 20.02.2007 - m.a.r.v.i.n\n
|
41 | Defines fuer Dometrie High/Low Werte aus myasuro.h verwenden
|
42 | StopSwitch ersetzt. Deshalb wurde immer die komplette switches.o
|
43 | mitgelinkt
|
44 | \version V004 - 15.11.2007 - m.a.r.v.i.n\n
|
45 | RIGHT_DIR und LEFT_DIR waren in der Init Funktion vertauscht
|
46 | \version V005 - 29.01.2008 - m.a.r.v.i.n\n
|
47 | Initialisierung fuer ATmega168\n
|
48 | UART Baudrate einstellbar durch Define\n
|
49 | Interrupt User Funktionen für Timer und A/D Wandler
|
50 |
|
51 | *****************************************************************************/
|
52 | /*****************************************************************************
|
53 | * *
|
54 | * This program is free software; you can redistribute it and/or modify *
|
55 | * it under the terms of the GNU General Public License as published by *
|
56 | * the Free Software Foundation; either version 2 of the License, or *
|
57 | * any later version. *
|
58 | * *
|
59 | *****************************************************************************/
|
60 | #include "asuro.h" |
61 | #include "myasuro.h" |
62 | |
63 | #define BAUD_RATE 2400
|
64 | #define F_CPU 8000000
|
65 | /****************************************************************************/
|
66 | /*!
|
67 | \brief
|
68 | Initialisiert die Hardware: Ports, A/D Wandler, Serielle Schnittstelle, PWM\n
|
69 | Die Init Funktion muss von jeden Programm beim Start aufgerufen werden
|
70 | |
71 | \see
|
72 | Die Funktionen Sleep() und Msleep() in time.c werden mit dem hier\n
|
73 | eingestellten 36 kHz-Takt betrieben.\n
|
74 | |
75 | \par Funktionsweise der Zeitfunktionen:
|
76 | Msleep() ruft Sleep() auf. In Sleep() wird die globale Variable count36kHz\n
|
77 | zur Zeitverzoegerung benutzt. Diese Variable wird jedesmal im Interrupt\n
|
78 | SIG_OVERFLOW2 um 1 hochgezaehlt.\n
|
79 | Der Interrupt selber wird durch den hier eingestellten Timer ausgeloesst.\n
|
80 | Somit ist dieser Timer fuer die Zeitverzoegerung zustaendig.
|
81 | |
82 | \see
|
83 | Die globale Variable autoencode fuer die automatische Bearbeitung der\n
|
84 | Odometrie-ADC-Wandler wird hier auf FALSE gesetzt.
|
85 | |
86 | \par Hinweis zur 36 kHz-Frequenz vom Timer 2
|
87 | Genau diese Frequenz wird von dem Empfaengerbaustein benoetigt und kann\n
|
88 | deshalb nicht geaendert werden.\n
|
89 | In der urspruenglichen, vom Hersteller ausgelieferten LIB, war diese\n
|
90 | Frequenz allerdings auf 72 kHz eingestellt. Durch eine geschickte\n
|
91 | Umkonfigurierung durch waste konnte diese aber halbiert werden.\n
|
92 | Sinnvoll ist dies, da der durch diesen Timer2 auch ausgeloesste Timer-\n
|
93 | Interrupt dann nur noch die Haelfte an Rechenzeit in Anspruch nimmt.
|
94 | |
95 | \par Beispiel:
|
96 | (Nur zur Demonstration der Parameter/Returnwerte)
|
97 | \code
|
98 | // Die Init()-Funktion MUSS IMMER zu Anfang aufgerufen werden.
|
99 | int main (void)
|
100 | {
|
101 | int wert;
|
102 | |
103 | Init ();
|
104 | |
105 | while (1)
|
106 | (
|
107 | // Dein Programm
|
108 | }
|
109 | return 0;
|
110 | }
|
111 | \endcode
|
112 | *****************************************************************************/
|
113 | void Init ( |
114 | void) |
115 | {
|
116 | /*
|
117 | Timer2, zum Betrieb mit der seriellen Schnittstelle, fuer die
|
118 | IR-Kommunikation auf 36 kHz eingestellt.
|
119 | */
|
120 | #if defined(__AVR_ATmega168__)
|
121 | // fast PWM, set OC2A on compare match, clear OC2A at bottom, clk/1
|
122 | TCCR2A = _BV(WGM20) | _BV(WGM21) | _BV(COM2A0) | _BV(COM2A1); |
123 | TCCR2B = _BV(CS20); |
124 | // interrupt on timer overflow
|
125 | TIMSK2 |= _BV(TOIE2); |
126 | #else
|
127 | // fast PWM, set OC2A on compare match, clear OC2A at bottom, clk/1
|
128 | TCCR2 = _BV(WGM20) | _BV(WGM21) | _BV(COM20) | _BV(COM21) | _BV(CS20); |
129 | // interrupt on timer overflow
|
130 | TIMSK |= _BV(TOIE2); |
131 | #endif
|
132 | // 36kHz carrier/timer
|
133 | OCR2 = 0x91; |
134 | |
135 | /*
|
136 | Die serielle Schnittstelle wurde waerend der Boot-Phase schon
|
137 | programmiert und gestartet. Hier werden die Parameter auf 2400 1N8 gesetzt.
|
138 | */
|
139 | #if defined(__AVR_ATmega168__)
|
140 | UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1); |
141 | UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8; |
142 | UCSR0B = (1<<RXEN0) | (1<<TXEN0); |
143 | UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); |
144 | #else
|
145 | UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate |
146 | UBRRL = (((F_CPU/BAUD_RATE)/16)-1); |
147 | UCSRB = (1<<RXEN)|(1<<TXEN); // enable Rx & Tx |
148 | UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // config USART; 8N1 |
149 | #endif
|
150 | |
151 | /*
|
152 | Datenrichtung der I/O-Ports festlegen. Dies ist durch die Beschaltung der
|
153 | Asuro-Hardware nicht aenderbar.
|
154 | Port B: Seriell Senden; Richtungsvorgabe Motor links; Takt fuer die
|
155 | Geschwindigkeit beider Motoren; Grueneanteil-Status-LED
|
156 | Port D: Richtungsvorgabe Motor rechts; Vordere LED;
|
157 | Odometrie-LED (Radsensor); Rotanteil-Status-LED
|
158 | */
|
159 | DDRB = IRTX | RIGHT_DIR | PWM | GREEN_LED; |
160 | DDRD = LEFT_DIR | FRONT_LED | ODOMETRIE_LED | RED_LED; |
161 | |
162 | /*
|
163 | PWM-Kanaele OC1A und OC1B auf 8-Bit einstellen.
|
164 | Sie werden fuer die Geschwindigkeitsvorgaben der Motoren benutzt.
|
165 | */
|
166 | TCCR1A = _BV(WGM10) | _BV(COM1A1) | _BV(COM1B1); |
167 | TCCR1B = _BV(CS11); // tmr1-Timer mit MCU-Takt/8 betreiben. |
168 | |
169 | /*
|
170 | Einstellungen des A/D-Wandlers auf MCU-Takt/64
|
171 | */
|
172 | ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1); |
173 | |
174 | /*
|
175 | Sonstige Vorbereitungen.
|
176 | - Alle LED's ausschalten
|
177 | - Motoren stoppen und schon mal auf Vorwaerts einstellen.
|
178 | - Globale Variable autoencoder ausschalten.
|
179 | */
|
180 | ODOMETRIE_LED_OFF; |
181 | FrontLED (OFF); |
182 | BackLED (ON, ON); |
183 | BackLED (OFF, OFF); |
184 | StatusLED (GREEN); |
185 | |
186 | MotorDir (FWD, FWD); |
187 | MotorSpeed (0, 0); |
188 | |
189 | autoencode = FALSE; |
190 | |
191 | Ovr2IntFunc = 0; |
192 | AdcIntFunc = 0; |
193 | /*
|
194 | Funktion zum ALLGEMEINEN ZULASSEN von Interrupts.
|
195 | */
|
196 | sei (); |
197 | }
|
198 | |
199 | |
200 | |
201 | /****************************************************************************/
|
202 | /*
|
203 | \brief
|
204 | Interrupt-Funktion fuer Timer-2-Ueberlauf.
|
205 | |
206 | \see
|
207 | count36kHz, timebase
|
208 | |
209 | \par
|
210 | Der zum Timer gehoerende Zaehler TCNT2 wird so justiert, dass damit die\n
|
211 | gewuenschten 36 kHz erreicht werden.\n
|
212 | Fuer die Zeitfunktionen werden die globalen Variablen count36kHz und\n
|
213 | timebase hochgezaehlt.
|
214 | |
215 | \par
|
216 | Die Variable Ovr2IntFunc kann als Zeiger auf eine User Funktion benutzt werden\n
|
217 | und wird dann, falls ungleich 0, von der Interrupt Funktion aus angesprungen.
|
218 | |
219 | \par Beispiel:
|
220 | (Nicht vorhanden)
|
221 | *****************************************************************************/
|
222 | SIGNAL (SIG_OVERFLOW2) |
223 | {
|
224 | TCNT2 += 0x25; |
225 | count36kHz ++; |
226 | if (!count36kHz) |
227 | timebase ++; |
228 | if (Ovr2IntFunc) |
229 | Ovr2IntFunc(); |
230 | }
|
231 | |
232 | |
233 | /**
|
234 | * being used insted TIMER2_OVF_vect during ultrasonic polling
|
235 | */
|
236 | #if defined(__AVR_ATmega168__)
|
237 | SIGNAL(SIG_OUTPUT_COMPARE2A) |
238 | #else
|
239 | SIGNAL(SIG_OUTPUT_COMPARE2) |
240 | #endif
|
241 | {
|
242 | count36kHz++; |
243 | if (!count36kHz) |
244 | timebase ++; |
245 | }
|
246 | |
247 | /****************************************************************************/
|
248 | /*
|
249 | \brief
|
250 | Interrupt-Funktion fuer den externen Interrupt 1.
|
251 | |
252 | \see switched
|
253 | |
254 | \par
|
255 | Hier wird 'nur' in der globalen Variablen switched vermerkt, dass ein\n
|
256 | Switch (Taster) gedrueckt wurde und dieser Interrupt soeben aufgetreten ist.\n
|
257 | Damit dieser Interrupt aber nicht permanent aufgerufen wird, solange der\n
|
258 | Taster gedrueckt bleibt, wird die Funktion, dass ein Interrupt erzeugt wird,\n
|
259 | ueber StopSwitch() abgeschaltet.\n
|
260 | Nach einer Bearbeitung im eigenen Hauptprogramm, muss also die Funktion\n
|
261 | StartSwitch() wieder Aufgerufen werden, um einen Tastendruck wieder ueber\n
|
262 | einen Interrupt zu erkennen.
|
263 | |
264 | \par Beispiel:
|
265 | (Nicht vorhanden)
|
266 | *****************************************************************************/
|
267 | SIGNAL (SIG_INTERRUPT1) |
268 | {
|
269 | switched = 1; |
270 | #if defined(__AVR_ATmega168__)
|
271 | EIMSK &= ~_BV(INT1); // Externen Interrupt 1 sperren |
272 | #else
|
273 | GICR &= ~_BV(INT1); // Externen Interrupt 1 sperren |
274 | #endif
|
275 | // StopSwitch ();
|
276 | }
|
277 | |
278 | |
279 | |
280 | /****************************************************************************/
|
281 | /*
|
282 | \brief
|
283 | Interrupt-Funktion fuer den AD-Wandler. Kann ueber autoencode gesteuert\n
|
284 | die Odometrie-Zaehler in encoder hochzaehlen.
|
285 | |
286 | \see
|
287 | Die globale Variable autoencode wird hier ausgewertet. Ist sie nicht FALSE,\n
|
288 | dann wird der AD-Wandler-Wert zum Zaehlen der Odometriewerte in der globalen\n
|
289 | Variablen encoder benutzt.\n
|
290 | Es wird auch der AD-Wandler-Kanal auf die 'andere' Seite der Odometrie\n
|
291 | umgeschaltete und der AD-Wandler neu gestartet.\n
|
292 | Somit wird erreicht, dass zumindest die Odometriemessung automatisch erfolgt.
|
293 | |
294 | \par
|
295 | Die Variable AdcIntFunc kann als Zeiger auf eine User Funktion benutzt werden\n
|
296 | und wird dann, falls ungleich 0, von der Interrupt Funktion aus angesprungen.
|
297 | |
298 | \par Beispiel:
|
299 | (Nicht vorhanden)
|
300 | *****************************************************************************/
|
301 | SIGNAL (SIG_ADC) |
302 | {
|
303 | if (AdcIntFunc) |
304 | AdcIntFunc(); |
305 | }
|
asuro.h Roboternetz: [c] /*! * \file asuro.h * \brief Definitionen und Funktionen der ASURO Bibliothek * * $Revision: 2.70 $ * $Date: 07. Januar 2007 $ * $Author: Jan Grewe, Robotrixer, Waste, Stochri, Andun, m.a.r.v.i.n $ * \version V001 - 10.02.2007 - m.a.r.v.i.n\n +++ my_t Neue Datenstruktur\n Datenstruktur fuer die Asuro-Hardwareabhaengigen Parameter die jeder User fuer seinen Asuro in der Datei myasuro.h selber einstellen kann um die Asuro-Typischen Eigenschaften zu definieren. \version V002 - 18.02.2007 - Sternthaler\n +++ my_t\n - Neue Variable fuer MY_MOTOR_DIFF zum ausgleichen unterschiedlicher\n Motoren. - Aendern aller enthaltenen Variablen auf einen moeglichst kleinen\n Speicherbedarf. Notwendige Typumwandlungen muessen im Code durch\n casten erfolgen. \version V003 - 20.02.2007 - m.a.r.v.i.n\n +++ my_t Datenstruktur wieder entfernt\n Es werden direkt die Defines aus der myasuro.h verwendet. \version V004 - 06.04.2007 - m.a.r.v.i.n\n Batterie und OdometrieData Funktionen umbenannt in Battery und OdometryData.\n Alte Funktionsnamen ueber Defines beibehalten \version V005 - 07.06.2007 - Sternthaler\n Funktionen Go() und Turn() aus encoder.c zusammengefasst in GoTurn().\n Alte Funktionsnamen ueber Defines beibehalten \version V006 - 11.07.2007 - Sternthaler\n Externe Variable encoder als volatile angegeben, da sie im Interrupt SIGNAL (SIG_ADC) benutzt wird. \version V007 - 15.11.2007 - m.a.r.v.i.n\n Variable switched als volatile definiert, da sie im Interrupt SIGNAL (SIG_INTERRUPT1) benutzt wird. ************************************************************************ *****/ /*********************************************************************** ****** * * * it is not allowed to remove the nicknames of the contributers to this * * software from the function header * * * ************************************************************************ *****/ /*********************************************************************** ****** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * any later version. * * * ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------ * 1.00 14.08.2003 Jan Grewe build * 2.00 14.10.2003 Jan Grewe RIGHT_VEL -> MotorSpeed(unsigned char left_speed, unsigned char right_speed); * LeftRwd(),LeftFwd(),RightRwd(), LEFT_VEL, * RigthFwd() -> MotorDir(unsigned char left_dir, unsigned char right_dir); * GREEN_ON,GREEN_OFF,RED_ON,RED_OFF -> StatusLED(unsigned char color); * LED_RED_ON, LED_RED_OFF -> FrontLED(unsigned char color); * Blink(unsigned char left, unsigned char right) -> * BackLED(unsigned char left, unsigned char right); * Alles in Funktionen gefasst => leichter verständlich ?!?! * 2.10 17.10.2003 Jan Grewe new Timer funktion void Sleep(unsigned char time36kHz) * * * Copyright (c) 2003 DLR Robotics & Mechatronics ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * Project : asuro library "Robotrixer Buxtehude" * * Description: This file contains additional functions: * * signal (SIG_ADC) interrupt/signal routine for encoder-counter * signal (SIG_INTERRUPT1) signal for switches * EncoderInit() initializing encoder-counter * EncoderStart() start autoencoding * EncoderStop() stop autoencoding * EncoderSet(int,int) set encodervalue * Msleep(int delay) wait for delay in milliseconds * Gettime() get systemtime in milliseconds * PrintInt(int) * * modifications in Sleep, SIG_OUTPUT_COMPARE2, PollSwitch, LineData * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------ * beta1 31.03.2005 Robotrixer asuro library * ------- ---------- -------------- ------------------------------ * the encoder source is based on RechteckDemo.c ver 2.0 by Jan Grewe 22.10.2003 * Copyright (c) 2003 DLR Robotics & Mechatronics ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * Project : asuro library modified for IR collision detector * * Description: modifications made in following functions: * * SIGNAL (SIG_OUTPUT_COMPARE2) -> SIGNAL (SIG_OVERFLOW2) * Gettime() counts now 36kHz * Init() timer2 modified for adjustable duty cycle * Batterie() bug fixed * Sleep() counts now 36kHz * Msleep() counts now 36kHz * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------ * beta2 11.06.2005 Waste asuro library * ------- ---------- -------------- ------------------------------ ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * Project : asuro library * * Description: This file contains additional functions: * * motor control functions 29.7.2005 stochri * void Go(int distance) * void Turn(int degree) * * unsigned char Wheelspeed[2] measured Wheelspeed by interupt * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------------------ * sto1 29.07.2005 stochri asuro library with motor control functions * ------- ---------- -------------- ------------------------------------------ ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * Project : asuro library "Robotrixer Buxtehude" * * Description: modifications made in following function: * * Go (int distance, int speed) Added Speed and Odometrie * Turn (int degree, int speed) Added Speed and Odometrie * * modifications in Sleep, SIG_OUTPUT_COMPARE2, PollSwitch, LineData * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------ * And1 31.07.2005 Andun See above * ------- ---------- -------------- ------------------------------ * ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * Project : asuro library * * Description: modifications made in following functions: * * void PrintInt(int wert) * * unsigned char Wheelspeed[2] removed * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------------------ * 2.60 28.09.2005 m.a.r.v.i.n doxygen comments * ------- ---------- -------------- ------------------------------------------ ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * Project : asuro library * * Description: modifications made in following functions: * * SIGNAL (SIG_ADC) * void PrintInt(int wert) * * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------------------ * 2.61 20.11.2006 m.a.r.v.i.n SIGNAL (SIG_ADC): static Variable toggle initialisiert * auf False (Bug report von Rolf_Ebert) * PrintInt: Initialisierung text String kann zu Fehler * beim Flashen mit RS232/IR Adapter fuehren * (Bug report von francesco) * ------- ---------- -------------- ------------------------------------------ ************************************************************************ *****/ /*********************************************************************** ***** * * File Name: asuro.c * Project : asuro library * * Description: new functions has been added: * * void uart_putc(unsigned char zeichen) * void SerPrint(unsigned char *data) * void SetMotorPower(int8_t left_speed, int8_t right_speed ) * void sound(uint16_t freq, uint16_t duration_msec, uint8_t amplitude) * * Description: modifications made in following functions: * * void Go(int distance, int power) * void Turn(int degree, int speed) * void PrintInt(int wert) * * * Ver. Date Author Comments * ------- ---------- -------------- ------------------------------------------ * 2.70 07.01.2007 stochri new functions: * uart_putc: send single character * SerPrint: send 0-terminated string * SetMotorPower: set Motor speed and direction * sound: Sound Ausgabe ueber Motor PWM * Go: distance in mm * Turn: comments * m.a.r.v.i.n PrintInt: SerWrite ersetzt durch SerPrint * ------- ---------- -------------- ------------------------------------------ ************************************************************************ *****/ #ifndef ASURO_H #define ASURO_H #include <avr/io.h> #include <avr/interrupt.h> #ifndef SIGNAL #include <avr/signal.h> // header file obsolete in actual avr-libc #include <inttypes.h> #endif #include <avr/pgmspace.h> #include <stdlib.h> #define FALSE 0 #define TRUE 1 #define OFF 0 #define ON 1 #define GREEN 1 #define RED 2 #define YELLOW 3 /* neue Funktionen und Variablen*/ #define LEFT 0 #define RIGHT 1 #define CENTER 2 /* Definitionen fuer Taster * (Zaehlweise der Taster erfolgt von libks nachs rechts, * wenn der Asuro mit den Tastern nach oben zeigt) */ #define K1 (1<<5) #define K2 (1<<4) #define K3 (1<<3) #define K4 (1<<2) #define K5 (1<<1) #define K6 (1<<0) /* --- Globale Variablen -----------------------------------*/ /*! * Asuro Lib Versions String */ extern const char version[5]; /* * Tastsensor Wert bei Interrupt Betrieb. 0=keine Taste, 1= Taste gedrueckt */ /*! * \~english * \brief any switch pressed? * * is being set to TRUE by interrupt if a switch is pressed\n * remember to set it to false again, since it is not reset automatically * \see StartSwitch */ extern volatile int switched; /* * Odometriesensor Zaehler bei Interrupt Betrieb. * encoder[0] links, encoder[1] = rechts. */ /*! * \~english * \brief odometry sensors tick count * access: encoder[LEFT], encoder[RIGHT]\n * range: 0..255 * \see EncoderInit */ extern volatile int encoder[2]; /* * Counter fuer 36kHz. * Wird in der Interrupt Funktion SIG_OVERFLOW2 hochgezaehlt\n * und in der Sleep() Funktion abgefragt. */ extern volatile unsigned char count36kHz; /* * Sytemzeit in ms. * Wird in der Interrupt Funktion SIG_OVERFLOW2 hochgezaehlt * und in der Gettime() Funktion verwendet. */ extern volatile unsigned long timebase; /* * Odometrie Sensor Abfrage im Interrupt Betrieb. * Wird in der Interrupt Funktion SIG_ADC abgefragt, * in der EncoderInit() und EncoderStart() Funktion gesetzt * und in der EncoderStop() Funktion geloescht. */ extern volatile int autoencode; typedef void (*voidFuncPtr)(void); extern volatile voidFuncPtr Ovr2IntFunc; extern volatile voidFuncPtr AdcIntFunc; /* --- Funktions Prototypen -----------------------------------*/ /*! * \~english * initialises the hardware (ports, ADC, PWM) * this function has to be called by every program first */ void Init(void); /**************** Zeit- und Delay Funktionen time.c *********/ /*! * \~english * \brief return time since system start in ms * \return current system time in ms */ unsigned long Gettime(void); /*! * \~english * \brief sleep function (ms) * \param ms time in ms */ void Msleep(int ms); /*! * \~english * \brief sleep function (36Khz) * \param time36kHz time in 1/36k (sec) */ void Sleep(unsigned char time36kHz); /**************** Low Level Encoder Funktionen encoder_low.c */ /*! * \~english * \brief initialise and starts odometry mesurement * uses interrupt(ADC_vect) */ void EncoderInit(void); /*! * \~english * \brief set odometry tick counter * \param setl left tick counter * \param setr left tick counter */ void EncoderSet(int setl,int setr); /*! * \~english * \brief stop counting odometry sensor ticks */ void EncoderStop(void); /*! * \~english * \brief stop counting odometry sensor ticks */ void EncoderStart(void); /**************** Encoder Funktionen encoder.c **************/ /*! * \~english * \brief moves the robot forward/backward OR turns the robot using the * odometry sensors. * You can use the old function-names Go() and Turn() * \param distance travalling distance in cm. positive = forward, negative = backward * if distanse is zero, then the function will work as Turn. * \param degree degrees to turn. positive = turn right, negative = turn left. range: -360..360 * \param speed motor speed. range: 0..255 */ void GoTurn(int distance, int degree, int speed); // aus Nostalgiegruenden Defines fuer alte Funktionsnamen #define Go(distance,speed) GoTurn(distance,0,speed) #define Turn(degree,speed) GoTurn(0,degree,speed) /**************** A/D Wandler Funktionen adc.c **************/ /*! * \~english * \brief returns the battery voltage * \return ADC value. range: 0..1023 */ int Battery(void); /*! * \~english * \brief reads out the phototransistors * \param data pointer to the data destination. access: data[LEFT], data[RIGHT] */ void LineData(unsigned int *data); /*! * \~english * \brief reads out the odometry phototransistors * \param data pointer to the data destination. access: data[LEFT], data[RIGHT] */ void OdometryData(unsigned int *data); unsigned int ReadADC(unsigned int mux, unsigned int sleep); // aus Nostalgiegruenden Defines fuer alte Funktionsnamen #define Batterie Battery #define OdometrieData OdometryData /**************** LED Funktionen led.c **********************/ /*! * \~english * \brief controls the StatusLED * \param color values: OFF, GREEN, RED, YELLOW */ inline void StatusLED(unsigned char color); /*! * \~english * \brief controls the FrontLED * \param status values: ON, OFF */ inline void FrontLED(unsigned char status); /*! * \~english * \brief values: ON, OFF * \param left leftLED status * \param right rightLED status */ void BackLED(unsigned char left, unsigned char right); /**************** Low Level Motorsteuerungs Funktionen motor_low.c */ /*! * \~english * \brief Motor configuration. values: FWD, RWD, BREAK, FREE * \param left_dir left motor direction * \param right_dir right motor direction */ inline void MotorDir(unsigned char left_dir, unsigned char right_dir); /*! * \~english * \brief sets motor speed. range: 0..255 * \param left_speed left motor * \param right_speed right motor */ inline void MotorSpeed(unsigned char left_speed, unsigned char right_speed); /*! * \~english * \brief sets motor speed. range: 0..255 * \param left_speed left motor speed * \param right_speed right motor speed */ inline void MyMotorSpeed(unsigned char left_speed, unsigned char right_speed); /**************** Motorsteuerungs Funktionen motor.c **************/ /*! * \~english * \brief sets motor speed and direcction. range: -128..+128 * \param leftpwm left motor speed (negative sign meens backward) * \param rightpwm right motor speed (negative sign meens backward) */ void SetMotorPower(int8_t leftpwm, int8_t rightpwm); /******************** Low Level UART Funktionen uart.c ************/ /*! * \~english * \brief Send Data to UART * \param data pointer to data * \param length data count */ void SerWrite(unsigned char *data,unsigned char length); /*! * \~english * \brief Receive Data from UART * \param data pointer to data * \param length data count * \param timeout count, 0 meens blocking mode */ void SerRead(unsigned char *data, unsigned char length, unsigned int timeout); /**************** Print Funktionen serielle Ausgabe print.c ********/ /*! * \~english * \brief Send a single character to UART * \param zeichen data to send */ void UartPutc(unsigned char zeichen); /*! * \~english * \brief Send a 0-terminated string to UART * \param data Pointer to string */ void SerPrint(char *data); /*! * \~english * \brief Send a Integer value converted to a string to UART * \param wert Integer value */ void PrintInt(int wert); /*! * \~english * \brief Send a Long value converted to a string to UART * \param wert long value */ void PrintLong(long wert); /*! * \~english * \brief Send a 0-terminated string from program space to UART * \param data Pointer to string */ void SerPrint_p(const char *data); #define SerPrint_P(_str) SerPrint_p(PSTR(_str)) /**************** Print Funktionen Floting Point printf.c ********/ /*! * \~english * \brief Send a Float value converted to a string to UART * \param wert float value * \param vorkomma number of chars before the commata * \param nachkomma number of chars behind the commata */ void PrintFloat (float wert, char vorkomma, char nachkomma); /**************** Taster Funktionen switches.c ******************/ /*! * \~english * \brief function to read out switches * \return bitfield of switch value bit0 = K6, ... , bit5 = K1 */ unsigned char PollSwitch (void); /*! * \~english * \brief binds switch press to external Interrupt 1 * catch it with ISR(INT1_vect) * see avr-libc documentation for details */ void StartSwitch(void); /*! * \~english * \brief stop sending switch interrupt * clears INT1_vect * \see StartSwitch */ void StopSwitch(void); /**************** Soundausgabe sound.c **************************/ /*! * \~english * \brief Genrates a sound via the motors * \param freq frequence * \param duration_msec duration in milli seconds * \param amplitude amplitude */ void Sound(uint16_t freq, uint16_t duration_msec, uint8_t amplitude); /* ----------- END ------------ */ /* --------------- INTERNAL ------------- */ #define GREEN_LED_ON PORTB |= GREEN_LED /*!< Gruene Status LED an */ #define GREEN_LED_OFF PORTB &= ~GREEN_LED /*!< Gruene Status LED aus */ #define RED_LED_ON PORTD |= RED_LED /*!< Rote Status LED an */ #define RED_LED_OFF PORTD &= ~RED_LED /*!< Rote Status LED aus */ #define FWD _BV(PB5) /*!< Motor vorwaerts */ #define RWD _BV(PB4) /*!< Motor rueckwaerts */ #define BREAK 0x00 /*!< Motor bremsen */ #define FREE _BV(PB4) | _BV(PB5) /*!< Motor freilaufend */ #define IRTX _BV(PB3) /*!< PB3 Port fuer Infrarot Transmitter LED */ #define GREEN_LED _BV(PB0) /*!< PB0 Port fuer Gruene Status LED */ #define RED_LED _BV(PD2) /*!< PD2 Port fuer Rote Status LED */ #define PWM _BV(PB1) | _BV(PB2) /*!< PB1, PB2 Ports fuer Pulsweitenmodulation der Motor Geschwindigkeit */ #define RIGHT_DIR _BV(PB4) | _BV(PB5) /*!< PB4, PB5 Ports fuer Drehrichtung rechter Motor */ #define LEFT_DIR _BV(PD4) | _BV(PD5) /*!< PD4, PD5 Ports fuer Drehrichtung linker Motor */ #define SWITCHES _BV(PD3) /*!< PD3 Port fuer Tastsensor */ #define SWITCH_ON PORTD |= SWITCHES /*!< Tastsensor an */ #define SWITCH_OFF PORTD &= ~SWITCHES /*!< Tastsensor aus */ #define BATTERIE _BV(MUX0) | _BV(MUX2) /*!< ADC5 A/D Wandler Port fuer Batterie Abfrage */ #define SWITCH _BV(MUX2) /*!< ADC4 A/D Wandler Port fuer Tastsensor */ #define IR_LEFT _BV(MUX0) | _BV(MUX1) /*!< ADC3 A/D Wandler Port fuer Linienfolger Fototransistor links */ #define IR_RIGHT _BV(MUX1) /*!< ADC2 A/D Wandler Port fuer Linienfolger Fototransistor rechts */ #define FRONT_LED _BV(PD6) /*!< PD6 Port fuer Front LED */ #define ODOMETRIE_LED _BV(PD7) /*!< PD7 Port fuer Odometrie LED */ #define ODOMETRIE_LED_ON PORTD |= ODOMETRIE_LED /*!< Odometrie LED an */ #define ODOMETRIE_LED_OFF PORTD &= ~ODOMETRIE_LED /*!< Odometrie LED aus */ #define WHEEL_LEFT _BV(MUX0) /*!< ADC1 A/D Wandler Port fuer Odometrie Sensor links*/ #define WHEEL_RIGHT 0 /*!< ADC0 A/D Wandler Port fuer Odometrie Sensor rechts */ #if defined(_AVR_ATmega168_) #define UBRRH UBRR0H #define UBRRL UBRR0L #define UCSRA UCSR0A #define UCSRB UCSR0B #define UCSRC UCSR0C #define TXEN TXEN0 #define RXEN RXEN0 #define RXCIE RXCIE0 #define URSEL UMSEL00 #define UCSZ0 UCSZ00 #define UDR UDR0 #define UDRE UDRE0 #define OCR2 OCR2A #define ADFR ADATE #define RXC RXC0 #define TXC TXC0 #endif #endif /* ASURO_H */ [c/]
Hi, dann poste lieber mal dein richtiges Programm. Wenn du mir hier irgendein Kollisionstest postest, dann weiß ich nicht was du meinst. [c/] <- slash vor das c
1 | #include "asuro.c" |
2 | #include "asuro.h" |
3 | uint8_t taster1, taster2; |
4 | |
5 | int main(void) |
6 | {
|
7 | Init(); |
8 | StatusLED(GREEN); |
9 | StatusLED(YELLOW); |
10 | MotorDir(FWD,FWD); |
11 | StatusLED(GREEN); |
12 | MotorSpeed(125,125); |
13 | StatusLED(RED); |
14 | BackLED(OFF,OFF); |
15 | |
16 | return 0; |
17 | }
|
Ich denke nicht, denn mit diesen bekomme ich folgenden Fehler: Severity Code Description Project File Line Error attempt to use poisoned "SIG_OUTPUT_COMPARE2" XXX XXX\asuro.c 34 den habe ich mit meiner Version nicht bekommen bei dem Programm..
Wenn du Teamviewer hast, kann ich dir schneller helfen. Gibts auch als Version, die man nicht installieren muss. https://www.teamviewer.com/de/download/windows/
Der Fehler bleibt, ich verzweifel hier gerade total an einer vermutlich dermaßen simplen Sache....
Also hier wirds zu kompliziert dir zu helfen. Mit Teamviewer kannst du es mir zeigen. Was für einen ATmega Mikrocontroller hast du denn? Was steht auf dem Chip auf dem Asuro?
Ich habe dir die teamviewer ID via PM / E-Mail geschickt, und mich nun auch mal registriert..
Der NiboBee (Konkurrenz zum Asuro) wird mit einem vorinstalliertem Testprogramm geliefert. Damit kann man die Hardware prüfen, ohne sich mit irgendwelcher PC Software herum zu schlagen. Ist das beim Asuro nicht der Fall? Im Moment hast du wohl eine vermutlich defekte Hardware kombiniert mit Quelltexten die nicht zum Compiler passen, unzureichenden Messmitteln und unzureichenden Programmierkenntnissen. Das sind 4 Baustellen zugleich. Reduziere das auf eine Baustelle, und du kommst viel besser voran. Ich sehe gerade, dass man auf der Asuro Webseite kein HEX File herunterladen kann. Aber immerhin kann man dort zwei Testprogramme als Quelltext runterladen, sowie alle nötigen Tools, um es zu compilieren und zu flashen. Nutze dieses Angebot! Wenn du das alles zusammen verwendest, kannst du das Programm mit Sicherheit compilieren und dann hast du dein ganz sicher funktionierendes HEX File.
Hi, hab dem Kollegen mit Teamviewer geholfen und es hat sich herausgestellt, dass er mit AtmelStudio 7 die veralteten Sourcen der mitgelieferten SelfTests mit dem neuen Compiler nicht kompilieren konnte (Problem mit inline-Funktionen, alte Interrupt-Handler-Bezeichnung, etc). Die von Asuro empfohlene Toolchain mit WinAVR und dem PN geht leider mit neuem Windows nicht mehr. Nach erfolgreichem Aufspielen eines Hex-Files hat sich nun herausgestellt, dass doch ein Hardwaredefekt (wahrscheinlich der Schaltung) vorliegen muss. Bootloader für Infrarot-Transfer des Hexfiles auf den Asuro und Teile des Programms haben ja noch funktioniert. Kann mir also nur schwer vorstellen, dass der µC kaputt ist. Bei meinem Asuro funktioniert das Programm.
> Die von Asuro empfohlene Toolchain mit WinAVR und dem PN > geht leider mit neuem Windows nicht mehr. WinAVR habe ich allerdings erst vor einer Woche ohne Probleme auf einem frisch installiertem Laptop getestet. Wo hakte es denn?
Gibt scheins Probleme mit Win10 64bit *> "C:\Users\Desktop\GccApplication1\test\Test\\Test-all.bat" all C:\Users\Desktop\GccApplication1\test\Test>make all set -e; avr-gcc -MM -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=asuro.lst asuro.c \ | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > asuro.d; \ [ -s asuro.d ] || rm -f asuro.d 0 [main] sh 11668 sync_with_child: child 12396(0x190) died before initialization with status code 0xC0000142 41556 [main] sh 11668 sync_with_child: *** child state waiting for longjmp /usr/bin/sh: fork: Resource temporarily unavailable set -e; avr-gcc -MM -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=main.lst main.c \ | sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > main.d; \ [ -s main.d ] || rm -f main.d 0 [main] sh 11956 sync_with_child: child 10468(0x190) died before initialization with status code 0xC0000142 3813 [main] sh 11956 sync_with_child: *** child state waiting for longjmp /usr/bin/sh: fork: Resource temporarily unavailable -------- begin -------- avr-gcc --version avr-gcc (WinAVR 20100110) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. avr-gcc -c -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=main.lst main.c -o main.o avr-gcc -c -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=asuro.lst asuro.c -o asuro.o asuro.h:71: warning: 'MotorSpeed' declared inline after being called asuro.h:71: warning: previous declaration of 'MotorSpeed' was here asuro.h:66: warning: 'MotorDir' declared inline after being called asuro.h:66: warning: previous declaration of 'MotorDir' was here asuro.h:52: warning: 'StatusLED' declared inline after being called asuro.h:52: warning: previous declaration of 'StatusLED' was here asuro.h:56: warning: 'FrontLED' declared inline after being called asuro.h:56: warning: previous declaration of 'FrontLED' was here avr-gcc -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=main.o main.o asuro.o --output main.elf -Wl,-Map=main.map,--cref -lm avr-objcopy -O ihex -R .eeprom main.elf main.hex avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \ --change-section-lma .eeprom=0 -O ihex main.elf main.eep make: [main.eep] Error -1073741502 (ignored) avr-objdump -h -S main.elf > main.lss 0 [main] sh 12716 sync_with_child: child 11376(0x184) died before initialization with status code 0xC0000142 41895 [main] sh 12716 sync_with_child: *** child state waiting for longjmp /usr/bin/sh: fork: Resource temporarily unavailable make: *** [main.lss] Error 128 > Process Exit Code: 2 > Time Taken: 00:05*
Du musst die Datei utils\bin\msys-1.0.dll erneuern. https://www.mikrocontroller.net/attachment/252194/msys-1.0.dll Oder verwende eine andere Version von "make", falls du irgendwo eine installiert hast.
Dann wechsle auf Linux um, ggf. als virtuelle Maschine. In Ubuntu funktioniert die Toolchain ohne Zicken.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.