ASURO Library
2.80
Hauptseite
Dateien
Auflistung der Dateien
Datei-Elemente
lib
inc
asuro.h
gehe zur Dokumentation dieser Datei
1
45
/*****************************************************************************
46
* *
47
* it is not allowed to remove the nicknames of the contributers to this *
48
* software from the function header *
49
* *
50
*****************************************************************************/
51
/*****************************************************************************
52
* *
53
* This program is free software; you can redistribute it and/or modify *
54
* it under the terms of the GNU General Public License as published by *
55
* the Free Software Foundation; either version 2 of the License, or *
56
* any later version. *
57
* *
58
*****************************************************************************/
59
60
61
62
/****************************************************************************
63
*
64
* File Name: asuro.c
65
*
66
*
67
* Ver. Date Author Comments
68
* ------- ---------- -------------- ------------------------------
69
* 1.00 14.08.2003 Jan Grewe build
70
* 2.00 14.10.2003 Jan Grewe RIGHT_VEL -> MotorSpeed(unsigned char left_speed, unsigned char right_speed);
71
* LeftRwd(),LeftFwd(),RightRwd(), LEFT_VEL,
72
* RigthFwd() -> MotorDir(unsigned char left_dir, unsigned char right_dir);
73
* GREEN_ON,GREEN_OFF,RED_ON,RED_OFF -> StatusLED(unsigned char color);
74
* LED_RED_ON, LED_RED_OFF -> FrontLED(unsigned char color);
75
* Blink(unsigned char left, unsigned char right) ->
76
* BackLED(unsigned char left, unsigned char right);
77
* Alles in Funktionen gefasst => leichter verständlich ?!?!
78
* 2.10 17.10.2003 Jan Grewe new Timer funktion void Sleep(unsigned char time36kHz)
79
*
80
*
81
* Copyright (c) 2003 DLR Robotics & Mechatronics
82
*****************************************************************************/
83
/****************************************************************************
84
*
85
* File Name: asuro.c
86
* Project : asuro library "Robotrixer Buxtehude"
87
*
88
* Description: This file contains additional functions:
89
*
90
* signal (SIG_ADC) interrupt/signal routine for encoder-counter
91
* signal (SIG_INTERRUPT1) signal for switches
92
* EncoderInit() initializing encoder-counter
93
* EncoderStart() start autoencoding
94
* EncoderStop() stop autoencoding
95
* EncoderSet(int,int) set encodervalue
96
* Msleep(int delay) wait for delay in milliseconds
97
* Gettime() get systemtime in milliseconds
98
* PrintInt(int)
99
*
100
* modifications in Sleep, SIG_OUTPUT_COMPARE2, PollSwitch, LineData
101
*
102
* Ver. Date Author Comments
103
* ------- ---------- -------------- ------------------------------
104
* beta1 31.03.2005 Robotrixer asuro library
105
* ------- ---------- -------------- ------------------------------
106
* the encoder source is based on RechteckDemo.c ver 2.0 by Jan Grewe 22.10.2003
107
* Copyright (c) 2003 DLR Robotics & Mechatronics
108
109
*****************************************************************************/
110
/****************************************************************************
111
*
112
* File Name: asuro.c
113
* Project : asuro library modified for IR collision detector
114
*
115
* Description: modifications made in following functions:
116
*
117
* SIGNAL (SIG_OUTPUT_COMPARE2) -> SIGNAL (SIG_OVERFLOW2)
118
* Gettime() counts now 36kHz
119
* Init() timer2 modified for adjustable duty cycle
120
* Batterie() bug fixed
121
* Sleep() counts now 36kHz
122
* Msleep() counts now 36kHz
123
*
124
* Ver. Date Author Comments
125
* ------- ---------- -------------- ------------------------------
126
* beta2 11.06.2005 Waste asuro library
127
* ------- ---------- -------------- ------------------------------
128
*****************************************************************************/
129
/****************************************************************************
130
*
131
* File Name: asuro.c
132
* Project : asuro library
133
*
134
* Description: This file contains additional functions:
135
*
136
* motor control functions 29.7.2005 stochri
137
* void Go(int distance)
138
* void Turn(int degree)
139
*
140
* unsigned char Wheelspeed[2] measured Wheelspeed by interupt
141
*
142
* Ver. Date Author Comments
143
* ------- ---------- -------------- ------------------------------------------
144
* sto1 29.07.2005 stochri asuro library with motor control functions
145
* ------- ---------- -------------- ------------------------------------------
146
*****************************************************************************/
147
/****************************************************************************
148
*
149
* File Name: asuro.c
150
* Project : asuro library "Robotrixer Buxtehude"
151
*
152
* Description: modifications made in following function:
153
*
154
* Go (int distance, int speed) Added Speed and Odometrie
155
* Turn (int degree, int speed) Added Speed and Odometrie
156
*
157
* modifications in Sleep, SIG_OUTPUT_COMPARE2, PollSwitch, LineData
158
*
159
* Ver. Date Author Comments
160
* ------- ---------- -------------- ------------------------------
161
* And1 31.07.2005 Andun See above
162
* ------- ---------- -------------- ------------------------------
163
*
164
*****************************************************************************/
165
/****************************************************************************
166
*
167
* File Name: asuro.c
168
* Project : asuro library
169
*
170
* Description: modifications made in following functions:
171
*
172
* void PrintInt(int wert)
173
*
174
* unsigned char Wheelspeed[2] removed
175
*
176
* Ver. Date Author Comments
177
* ------- ---------- -------------- ------------------------------------------
178
* 2.60 28.09.2005 m.a.r.v.i.n doxygen comments
179
* ------- ---------- -------------- ------------------------------------------
180
*****************************************************************************/
181
/****************************************************************************
182
*
183
* File Name: asuro.c
184
* Project : asuro library
185
*
186
* Description: modifications made in following functions:
187
*
188
* SIGNAL (SIG_ADC)
189
* void PrintInt(int wert)
190
*
191
*
192
* Ver. Date Author Comments
193
* ------- ---------- -------------- ------------------------------------------
194
* 2.61 20.11.2006 m.a.r.v.i.n SIGNAL (SIG_ADC): static Variable toggle initialisiert
195
* auf False (Bug report von Rolf_Ebert)
196
* PrintInt: Initialisierung text String kann zu Fehler
197
* beim Flashen mit RS232/IR Adapter fuehren
198
* (Bug report von francesco)
199
* ------- ---------- -------------- ------------------------------------------
200
*****************************************************************************/
201
/****************************************************************************
202
*
203
* File Name: asuro.c
204
* Project : asuro library
205
*
206
* Description: new functions has been added:
207
*
208
* void uart_putc(unsigned char zeichen)
209
* void SerPrint(unsigned char *data)
210
* void SetMotorPower(int8_t left_speed, int8_t right_speed )
211
* void sound(uint16_t freq, uint16_t duration_msec, uint8_t amplitude)
212
*
213
* Description: modifications made in following functions:
214
*
215
* void Go(int distance, int power)
216
* void Turn(int degree, int speed)
217
* void PrintInt(int wert)
218
*
219
*
220
* Ver. Date Author Comments
221
* ------- ---------- -------------- ------------------------------------------
222
* 2.70 07.01.2007 stochri new functions:
223
* uart_putc: send single character
224
* SerPrint: send 0-terminated string
225
* SetMotorPower: set Motor speed and direction
226
* sound: Sound Ausgabe ueber Motor PWM
227
* Go: distance in mm
228
* Turn: comments
229
* m.a.r.v.i.n PrintInt: SerWrite ersetzt durch SerPrint
230
* ------- ---------- -------------- ------------------------------------------
231
*****************************************************************************/
232
233
234
#ifndef ASURO_H
235
#define ASURO_H
236
237
#include <avr/io.h>
238
#include <avr/interrupt.h>
239
#ifndef SIGNAL
240
#include <inttypes.h>
241
#endif
242
#include <avr/pgmspace.h>
243
#include <stdlib.h>
244
245
#define FALSE 0
246
#define TRUE 1
247
248
#define OFF 0
249
#define ON 1
250
251
#define GREEN 1
252
#define RED 2
253
#define YELLOW 3
254
255
/* neue Funktionen und Variablen*/
256
#define LEFT 0
257
#define RIGHT 1
258
#define CENTER 2
259
260
/* Definitionen fuer Taster
261
* (Zaehlweise der Taster erfolgt von libks nachs rechts,
262
* wenn der Asuro mit den Tastern nach oben zeigt) */
263
#define K1 (1<<5)
264
#define K2 (1<<4)
265
#define K3 (1<<3)
266
#define K4 (1<<2)
267
#define K5 (1<<1)
268
#define K6 (1<<0)
269
270
271
/****************************************************************************
272
273
Ablaufsteuerung für die ADC-Auswertung: die berechneten Werte der obigen defines
274
275
****************************************************************************/
276
277
#define ADC_CTRL_WHEEL_LEFT 0
278
#define ADC_CTRL_WHEEL_RIGHT 1
279
#define ADC_CTRL_SWITCHES 2
280
#define ADC_CTRL_IR_LEFT 3
281
#define ADC_CTRL_IR_RIGHT 4
282
#define ADC_CTRL_BATTERIE 5
283
#define ADC_CTRL_SWITCHED 6
284
285
extern
volatile
unsigned
int
adcValue
[];
286
287
288
289
/* --- Globale Variablen -----------------------------------*/
293
extern
const
char
version
[5];
294
295
/*
296
* Tastsensor Wert bei Interrupt Betrieb. 0=keine Taste, 1= Taste gedrueckt
297
*/
306
extern
volatile
int
switched
;
307
308
/*
309
* Odometriesensor Zaehler bei Interrupt Betrieb.
310
* encoder[0] links, encoder[1] = rechts.
311
*/
319
extern
volatile
int
encoder
[2];
320
321
/*
322
* Counter fuer 36kHz.
323
* Wird in der Interrupt Funktion TIMER2_OVF_vect hochgezaehlt\n
324
* und in der Sleep() Funktion abgefragt.
325
*/
326
extern
volatile
unsigned
char
count36kHz
;
327
328
/*
329
* Sytemzeit in ms.
330
* Wird in der Interrupt Funktion TIMER2_OVF_vect hochgezaehlt
331
* und in der Gettime() Funktion verwendet.
332
*/
333
extern
volatile
unsigned
long
timebase
;
334
335
/*
336
* Odometrie Sensor Abfrage im Interrupt Betrieb.
337
* Wird in der Interrupt Funktion ADC_vect abgefragt,
338
* in der EncoderInit() und EncoderStart() Funktion gesetzt
339
* und in der EncoderStop() Funktion geloescht.
340
*/
341
extern
volatile
int
autoencode
;
342
343
typedef
void (*
voidFuncPtr
)(void);
344
extern
volatile
voidFuncPtr
Ovr2IntFunc
;
345
extern
volatile
voidFuncPtr
AdcIntFunc
;
346
347
/* --- Funktions Prototypen -----------------------------------*/
348
354
void
Init
(
void
);
355
356
/**************** Zeit- und Delay Funktionen time.c *********/
362
unsigned
long
Gettime
(
void
);
368
void
Msleep
(
unsigned
int
ms);
374
void
Sleep
(
unsigned
char
time36kHz);
375
376
/**************** Low Level Encoder Funktionen encoder_low.c */
382
void
EncoderInit
(
void
);
389
void
EncoderSet
(
int
setl,
int
setr);
394
void
EncoderStop
(
void
);
399
void
EncoderStart
(
void
);
400
401
/**************** Encoder Funktionen encoder.c **************/
412
void
GoTurn
(
int
distance,
int
degree,
int
speed);
413
// aus Nostalgiegruenden Defines fuer alte Funktionsnamen
414
#define Go(distance,speed) GoTurn(distance,0,speed)
415
#define Turn(degree,speed) GoTurn(0,degree,speed)
416
417
/**************** A/D Wandler Funktionen adc.c **************/
423
int
Battery
(
void
);
429
void
LineData
(
unsigned
int
*data);
435
void
OdometryData
(
unsigned
int
*data);
436
437
unsigned
int
ReadADC
(
unsigned
int
mux,
unsigned
int
sleep);
438
439
// aus Nostalgiegruenden Defines fuer alte Funktionsnamen
440
#define Batterie Battery
441
#define OdometrieData OdometryData
442
443
/**************** LED Funktionen led.c **********************/
449
void
StatusLED
(
unsigned
char
color);
455
void
FrontLED
(
unsigned
char
status);
462
void
BackLED
(
unsigned
char
left,
unsigned
char
right);
463
464
/**************** Low Level Motorsteuerungs Funktionen motor_low.c */
472
void
MotorDir
(
unsigned
char
left_dir,
unsigned
char
right_dir);
480
void
MotorSpeed
(
unsigned
char
left_speed,
unsigned
char
right_speed);
481
489
void
MyMotorSpeed
(
unsigned
char
left_speed,
unsigned
char
right_speed);
490
/**************** Motorsteuerungs Funktionen motor.c **************/
497
void
SetMotorPower
(int8_t leftpwm, int8_t rightpwm);
498
499
/******************** Low Level UART Funktionen uart.c ************/
506
void
SerWrite
(
unsigned
char
*data,
unsigned
char
length);
514
void
SerRead
(
unsigned
char
*data,
unsigned
char
length,
unsigned
int
timeout);
515
516
/**************** Print Funktionen serielle Ausgabe print.c ********/
522
void
UartPutc
(
unsigned
char
zeichen);
528
void
SerPrint
(
char
*data);
534
void
PrintInt
(
int
wert);
540
void
PrintLong
(
long
wert);
546
void
SerPrint_p
(
const
char
*data);
547
#define SerPrint_P(_str) SerPrint_p(PSTR(_str))
548
/**************** Print Funktionen Floting Point printf.c ********/
556
void
PrintFloat
(
float
wert,
char
vorkomma,
char
nachkomma);
557
558
/**************** Taster Funktionen switches.c ******************/
564
unsigned
char
PollSwitch
(
void
);
571
void
StartSwitch
(
void
);
578
void
StopSwitch
(
void
);
579
580
/**************** Soundausgabe sound.c **************************/
588
void
Sound
(uint16_t freq, uint16_t duration_msec, uint8_t amplitude);
589
590
/* ----------- END ------------ */
591
592
593
/* --------------- INTERNAL ------------- */
594
#define GREEN_LED_ON PORTB |= GREEN_LED
595
#define GREEN_LED_OFF PORTB &= ~GREEN_LED
596
#define RED_LED_ON PORTD |= RED_LED
597
#define RED_LED_OFF PORTD &= ~RED_LED
599
#define FWD _BV(PB5)
600
#define RWD _BV(PB4)
601
#define BREAK 0x00
602
#define FREE _BV(PB4) | _BV(PB5)
604
#define IRTX _BV(PB3)
605
#define GREEN_LED _BV(PB0)
606
#define RED_LED _BV(PD2)
608
#define PWM _BV(PB1) | _BV(PB2)
609
#define RIGHT_DIR _BV(PB4) | _BV(PB5)
610
#define LEFT_DIR _BV(PD4) | _BV(PD5)
612
#define SWITCHES _BV(PD3)
613
#define SWITCH_ON PORTD |= SWITCHES
614
#define SWITCH_OFF PORTD &= ~SWITCHES
616
#define BATTERIE _BV(MUX0) | _BV(MUX2)
617
#define SWITCH _BV(MUX2)
618
#define IR_LEFT _BV(MUX0) | _BV(MUX1)
619
#define IR_RIGHT _BV(MUX1)
620
#define FRONT_LED _BV(PD6)
622
#define ODOMETRIE_LED _BV(PD7)
623
#define ODOMETRIE_LED_ON PORTD |= ODOMETRIE_LED
624
#define ODOMETRIE_LED_OFF PORTD &= ~ODOMETRIE_LED
626
#define WHEEL_LEFT _BV(MUX0)
627
#define WHEEL_RIGHT 0
629
#if defined(__AVR_ATmega168__)
630
#define UBRRH UBRR0H
631
#define UBRRL UBRR0L
632
#define UCSRA UCSR0A
633
#define UCSRB UCSR0B
634
#define UCSRC UCSR0C
635
#define TXEN TXEN0
636
#define RXEN RXEN0
637
#define RXCIE RXCIE0
638
#define URSEL UMSEL00
639
#define UCSZ0 UCSZ00
640
#define UDR UDR0
641
#define UDRE UDRE0
642
#define OCR2 OCR2A
643
644
#define ADFR ADATE
645
#define RXC RXC0
646
#define TXC TXC0
647
#endif
648
649
#endif
/* ASURO_H */
Erzeugt am Mit Nov 27 2013 22:55:08 für ASURO Library von
1.8.2