Project

General

Profile

Revision 7

Added wireless library.

View differences:

trunk/code/lib/include/libdragonfly/battery.h
1
/**
2
 * @file battery.h
3
 * @brief Definitions for checking battery voltage.
4
 * 
5
 * Contains definitions for checking the voltage of the 
6
 * battery.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 **/
10

  
11
#ifndef _BATTERY_H_
12
#define _BATTERY_H_
13

  
14
/**
15
 * @addtogroup battery
16
 * @{
17
 **/
18

  
19
/** @brief Normal battery voltage. (6 V) **/
20
#define BATTERY_NORMALV 154
21
/** @brief Charging battery voltage. (7 V) **/
22
#define BATTERY_CHARINGV 179
23
/** @brief Low battery voltage. ( < 6 V) **/
24
#define BATTERY_LOWV 152
25

  
26
/** @brief Read the battery voltage. **/
27
int battery8(void);
28
/** @brief Read the battery voltage in deciVolts. **/
29
int battery(void);
30
/** @brief Check if the battery is low. **/
31
char battery_low(void);
32
/** @brief get an average battery voltage reading. **/
33
int battery8_avg(int n_samples);
34

  
35
/** @} **/ //end addtogroup
36

  
37
#endif
38

  
trunk/code/lib/include/libdragonfly/lights.h
1
/**
2
 * @file lights.h
3
 * @brief Contains declarations for managing the orbs.
4
 *
5
 * Contains declarations for using the orbs and PWM.
6
 *
7
 * @author Colony Project, CMU Robotics Club
8
 * Based on Firefly Library, by Tom Lauwers and Steven Shamlian
9
 **/
10

  
11
#ifndef _LIGHTS_H_
12
#define _LIGHTS_H_
13

  
14

  
15
/**
16
 * @addtogroup orbs
17
 * @{
18
 **/
19

  
20
//ORB Colors
21
/** @brief Red **/
22
#define RED       0xE0
23
/** @brief Orange **/
24
#define ORANGE    0xE4
25
/** @brief Yellow **/
26
#define YELLOW    0xE8
27
/** @brief Lime **/
28
#define LIME      0x68
29
/** @brief Green **/
30
#define GREEN     0x1C
31
/** @brief Cyan **/
32
#define CYAN      0x1F
33
/** @brief Blue **/
34
#define BLUE      0x03
35
/** @brief Pink **/
36
#define PINK      0xA6 
37
/** @brief Purple **/
38
#define PURPLE    0x41
39
/** @brief Magenta **/
40
#define MAGENTA   0xE3
41
/** @brief White **/
42
#define WHITE     0xFE
43
/** @brief Turn the orb off (White) **/
44
#define ORB_OFF   0xFE      //ORB_OFF->WHITE
45

  
46
/** @brief Enables the orbs **/
47
void orb_init(void);
48
/** @brief Set both orbs to a specified color **/
49
void orb_set(unsigned char red_led, unsigned char green_led,
50
	unsigned char blue_led);
51
/** @brief Set orb1 to a specified color **/
52
void orb1_set(unsigned char red_led, unsigned char green_led,
53
	unsigned char blue_led); 
54
/** @brief Set orb2 to a specified color **/
55
void orb2_set(unsigned char red_led, unsigned char green_led,
56
	unsigned char blue_led);
57

  
58
/** @brief Set both orbs to a specified color **/
59
void orb_set_color(int col);
60
/** @brief Set orb1 to a specified color **/
61
void orb1_set_color(int col);
62
/** @brief Set orb2 to a specified color **/
63
void orb2_set_color(int col);
64

  
65
/** @brief Disable the orbs **/
66
void orb_disable(void);
67
/** @brief Enable the orbs **/
68
void orb_enable(void);
69

  
70
/** @} **/ //end addtogroup
71

  
72
#endif
73

  
trunk/code/lib/include/libdragonfly/dio.h
1
/**
2
 * @file dio.h
3
 * @brief Definitions for digital input / output
4
 *
5
 * This file contains definitions and functions for dealing
6
 * with digital input and output.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 * Based on Tom Lauwer's Firefly Library
10
 **/
11

  
12
#ifndef _DIO_H
13
#define _DIO_H
14

  
15
/*
16
these are ALL the pins
17
don't use unless you know what you're doing
18
*/
19

  
20
/*
21
DIO pins on new dragonfly boards are shown below:
22
-----------------------------------------------
23
| _PIN_E6 | _PIN_E7 | _PIN_D2 | _PIN_D3 | VCC |
24
-----------------------------------------------
25
| _PIN_E2 | _PIN_E3 | _PIN_E4 | _PIN_E5 | GND |
26
-----------------------------------------------
27
*/
28

  
29
/** @brief Port A **/
30
#define _PORT_A 1
31
/** @brief Port B **/
32
#define _PORT_B 2
33
/** @brief Port C **/
34
#define _PORT_C 3
35
/** @brief Port D **/
36
#define _PORT_D 4
37
/** @brief Port E **/
38
#define _PORT_E 5
39
/** @brief Port F **/
40
#define _PORT_F 6
41
/** @brief Port G **/
42
#define _PORT_G 7
43

  
44
/** @brief Pin A0 **/
45
#define _PIN_A0 8
46
/** @brief Pin A1 **/
47
#define _PIN_A1 9
48
/** @brief Pin A2 **/
49
#define _PIN_A2 10
50
/** @brief Pin A3 **/
51
#define _PIN_A3 11
52
/** @brief Pin A4 **/
53
#define _PIN_A4 12
54
/** @brief Pin A5 **/
55
#define _PIN_A5 13
56
/** @brief Pin A6 **/
57
#define _PIN_A6 14 
58
/** @brief Pin A7 **/
59
#define _PIN_A7 15
60

  
61
/** @brief Pin B0 **/
62
#define _PIN_B0 16
63
/** @brief Pin B1 **/
64
#define _PIN_B1 17
65
/** @brief Pin B2 **/
66
#define _PIN_B2 18
67
/** @brief Pin B3 **/
68
#define _PIN_B3 19
69
/** @brief Pin B4 **/
70
#define _PIN_B4 20
71
/** @brief Pin B5 **/
72
#define _PIN_B5 21
73
/** @brief Pin B6 **/
74
#define _PIN_B6 22
75
/** @brief Pin B7 **/
76
#define _PIN_B7 23
77

  
78
/** @brief Pin C0 **/
79
#define _PIN_C0 24
80
/** @brief Pin C1 **/
81
#define _PIN_C1 25
82
/** @brief Pin C2 **/
83
#define _PIN_C2 26
84
/** @brief Pin C3 **/
85
#define _PIN_C3 27
86
/** @brief Pin C4 **/
87
#define _PIN_C4 28
88
/** @brief Pin C5 **/
89
#define _PIN_C5 29
90
/** @brief Pin C6 **/
91
#define _PIN_C6 30
92
/** @brief Pin C7 **/
93
#define _PIN_C7 31
94

  
95
/** @brief Pin D0 **/
96
#define _PIN_D0 32  // pin DIO6 on new dragonfly boards
97
/** @brief Pin D1 **/
98
#define _PIN_D1 33  // pin DIO7
99
/** @brief Pin D2 **/
100
#define _PIN_D2 34
101
/** @brief Pin D3 **/
102
#define _PIN_D3 35
103
/** @brief Pin D4 **/
104
#define _PIN_D4 36
105
/** @brief Pin D5 **/
106
#define _PIN_D5 37
107
/** @brief Pin D6 **/
108
#define _PIN_D6 38
109
/** @brief Pin D7 **/
110
#define _PIN_D7 39
111

  
112
/** @brief Pin E0 **/
113
#define _PIN_E0 40
114
/** @brief Pin E1 **/
115
#define _PIN_E1 41
116
/** @brief Pin E2 **/
117
#define _PIN_E2 42  // pin DIO0
118
/** @brief Pin E3 **/
119
#define _PIN_E3 43  // pin DIO1
120
/** @brief Pin E4 **/
121
#define _PIN_E4 44  // pin DIO2
122
/** @brief Pin E5 **/
123
#define _PIN_E5 45  // pin DIO3
124
/** @brief Pin E6 **/
125
#define _PIN_E6 46  // pin DIO4
126
/** @brief Pin E7 **/
127
#define _PIN_E7 47  // pin DIO5
128

  
129
/** @brief Pin F0 **/
130
#define _PIN_F0 48
131
/** @brief Pin F1 **/
132
#define _PIN_F1 49
133
/** @brief Pin F2 **/
134
#define _PIN_F2 50
135
/** @brief Pin F3 **/
136
#define _PIN_F3 51
137
/** @brief Pin F4 **/
138
#define _PIN_F4 52
139
/** @brief Pin F5 **/
140
#define _PIN_F5 53
141
/** @brief Pin F6 **/
142
#define _PIN_F6 54
143
/** @brief Pin F7 **/
144
#define _PIN_F7 55
145

  
146
/** @brief Pin G0 **/
147
#define _PIN_G0 56
148
/** @brief Pin WR **/
149
#define _PIN_WR 56
150
/** @brief Pin G1 **/
151
#define _PIN_G1 57
152
/** @brief Pin RD **/
153
#define _PIN_RD 57
154
/** @brief Pin G2 **/
155
#define _PIN_G2 58
156
/** @brief Pin ALE **/
157
#define _PIN_ALE 58
158
/** @brief Pin G3 **/
159
#define _PIN_G3 59
160
/** @brief Pin TOSC2 **/
161
#define _PIN_TOSC2 59
162
/** @brief Pin G4 **/
163
#define _PIN_G4 60
164
/** @brief Pin TOSC1 **/
165
#define _PIN_TOSC1 60
166
//#define _PIN_G5 61
167
//#define _PIN_G6 62
168
//#define _PIN_G7 63
169

  
170
/*
171
These are the header pins (the ones you can connect things to)
172
Feel free to use these
173
*/
174

  
175
/**
176
 * @addtogroup dio
177
 * @{
178
 **/
179
/** @brief Pin A0 **/
180
#define PIN_A0 8
181
/** @brief Pin A1 **/
182
#define PIN_A1 9
183
/** @brief Pin A2 **/
184
#define PIN_A2 10
185
/** @brief Pin A3 **/
186
#define PIN_A3 11
187
/** @brief Pin A4 **/
188
#define PIN_A4 12
189
/** @brief Pin A5 **/
190
#define PIN_A5 13
191
/** @brief Pin A6 **/
192
#define PIN_A6 14 
193
/** @brief Pin A7 **/
194
#define PIN_A7 15
195

  
196
/** @brief Pin SS **/
197
#define PIN_SS 16
198
/** @brief Pin SCK **/
199
#define PIN_SCK 17
200
/** @brief Pin MOSI **/
201
#define PIN_MOSI 18
202
/** @brief Pin MISO **/
203
#define PIN_MISO 19
204
/** @brief LCD Command Pin **/
205
#define PIN_LCD_COMMAND 20
206

  
207
/** @brief Pin C0 **/
208
#define PIN_C0 24
209
/** @brief Pin C1 **/
210
#define PIN_C1 25
211
/** @brief Pin C2 **/
212
#define PIN_C2 26
213
/** @brief Pin C3 **/
214
#define PIN_C3 27
215
/** @brief Pin C4 **/
216
#define PIN_C4 28
217
/** @brief Pin C5 **/
218
#define PIN_C5 29
219
/** @brief Pin C6 **/
220
#define PIN_C6 30
221
/** @brief Pin C7 **/
222
#define PIN_C7 31
223

  
224
/** @brief Pin SCL **/
225
#define PIN_SCL 32
226
/** @brief Pin SDA **/
227
#define PIN_SDA 33
228

  
229
/** @brief Pin RX0 **/
230
#define PIN_RX0 40
231
/** @brief Pin TX0 **/
232
#define PIN_TX0 41
233
/** @brief LCD Reset Pin **/
234
#define PIN_LCD_RESET 42
235
/** @brief Pin E6 **/
236
#define PIN_E6 46
237
/** @brief Pin EXT_DIO1 **/
238
#define PIN_EXT_DIO1 46
239
/** @brief Pin E7 **/
240
#define PIN_E7 47
241
/** @brief Pin EXT_DIO2 **/
242
#define PIN_EXT_DIO2 48
243

  
244
/** @brief Pin AN0 **/
245
#define PIN_AN0 48
246
/** @brief Pin ADC0 **/
247
#define PIN_ADC0 48
248
/** @brief Pin AN1 **/
249
#define PIN_AN1 49
250
/** @brief Pin ADC1 **/
251
#define PIN_ADC1 49
252
/** @brief Pin AN2 **/
253
#define PIN_AN2 50
254
/** @brief Pin ADC2 **/
255
#define PIN_ADC2 50
256
/** @brief Pin AN3 **/
257
#define PIN_AN3 51
258
/** @brief Pin ADC3 **/
259
#define PIN_ADC3 51
260
/** @brief Pin AN4 **/
261
#define PIN_AN4 52
262
/** @brief Pin ADC4 **/
263
#define PIN_ADC4 52
264
/** @brief Pin AN5 **/
265
#define PIN_AN5 53
266
/** @brief Pin ADC5 **/
267
#define PIN_ADC5 53
268
/** @brief Pin AN6 **/
269
#define PIN_AN6 54
270
/** @brief Pin ADC6 **/
271
#define PIN_ADC6 54
272
/** @brief Pin AN7 **/
273
#define PIN_AN7 55
274
/** @brief Pin ADC7 **/
275
#define PIN_ADC7 55
276

  
277
/** @brief Wheel Pin **/
278
#define PIN_WHEEL 54
279
/** @brief Battery Voltage Monitor Pin **/
280
#define PIN_BATT 55
281

  
282
/** @brief button1 Pin **/
283
#define PIN_BTN1 56
284
/** @brief button2 Pin **/
285
#define PIN_BTN2 57
286

  
287
/** @brief LED1 Pin **/
288
#define PIN_LED1 58
289

  
290
/* Buttons */
291
/** @brief Button Pin **/
292
#define PIN_BTN PING
293
/** @brief button2 Pin **/
294
#define BTN2 PING1
295
/** @brief button1 Pin **/
296
#define BTN1 PING0
297

  
298
/** @brief Read a portpin. **/
299
int digital_input(int);
300
/** @brief Output to a portpin. **/
301
void digital_output(int bit, int val);
302
/** @brief Pullup a portpin. **/
303
void digital_pull_up(int);
304

  
305
/** @brief Check if button1 is pressed. **/
306
int button1_read( void );
307
/** @brief Check if button1 is clicked. **/
308
int button1_click( void );
309
/** @brief Wait until button1 is pressed. **/
310
void button1_wait( void );
311

  
312
/** @brief Check if button2 is pressed. **/
313
int button2_read( void );
314
/** @brief Check if button2 is clicked. **/
315
int button2_click( void );
316
/** @brief Wait until button2 is pressed. **/
317
void button2_wait( void );
318

  
319
/** @} **/ // end addtogroup
320

  
321
#endif
322

  
trunk/code/lib/include/libdragonfly/dragonfly_lib.h
1
/**
2
 * @file dragonfly_lib.h
3
 * @brief Contains other include files
4
 * 
5
 * Include this file for all the functionality of libdragonfly.
6
 *
7
 * @author Colony Project, CMU Robotics Club
8
 **/
9

  
10
#ifndef _DRAGONFLY_LIB_H_
11
#define _DRAGONFLY_LIB_H_
12

  
13
/**
14
 * @addtogroup dragonfly
15
 * @{
16
 **/
17

  
18
// Configuration definitions
19
/** @brief Initialize analog **/
20
#define ANALOG 0x01
21
/** @brief Initialize serial communications **/
22
#define SERIAL 0x02
23
/** @brief Initialize USB communications **/
24
#define USB    0x02
25
/** @brief Initialize communications **/
26
#define COMM   0x02
27
/** @brief Initialize the orb **/
28
#define ORB    0x04
29
/** @brief Initialize the motors **/
30
#define MOTORS 0x08
31
/** @brief Initialize the servos **/
32
#define SERVOS 0x10
33
/** @brief Initialize I2C **/
34
#define I2C    0x20
35
/** @brief Initialize the buzzer **/
36
#define BUZZER 0x40
37
/** @brief Initialize the LCD screen **/
38
#define LCD    0x80
39
/** @brief Initialize everything **/
40
#define ALL_ON 0xFF
41

  
42

  
43
/** @brief Initialize the board **/
44
void dragonfly_init(int config);
45
/** @brief Reset the robot **/
46
void reset(void);
47

  
48
/** @} **/ //end addtogroup
49

  
50
#include <inttypes.h>
51
#include <stdio.h>
52
#include <stdlib.h>
53
#include <avr/io.h>
54
#include <avr/interrupt.h>
55
#include <util/delay.h>
56
#include <util/twi.h>
57

  
58
#include <analog.h>
59
#include <dio.h>
60
#include <time.h>
61
#include <lcd.h>
62
#include <lights.h>
63
#include <motor.h>
64
#include <serial.h>
65
#include <buzzer.h>
66
#include <rangefinder.h>
67
#include <bom.h>
68
#include <move.h>
69

  
70
#endif
71

  
trunk/code/lib/include/libdragonfly/bom.h
1
/**
2
 * @file bom.h
3
 * @brief Definitions for using the BOM
4
 * 
5
 * This file contains definitions for using the Bearing and 
6
 * Orientation Module (BOM).
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 *
10
 **/
11

  
12
#ifndef _BOM_H
13
#define _BOM_H
14

  
15
/**
16
 * @addtogroup bom
17
 * @{
18
 **/
19

  
20
/** @brief Returns the location of the maximum BOM reading. **/
21
int get_max_bom( void );
22
/** @brief Turns the BOM on. **/
23
void bom_on(void);
24
/** @brief Turns the BOM off. **/
25
void bom_off(void);
26

  
27
/** @} **/
28

  
29
#endif
30

  
trunk/code/lib/include/libdragonfly/time.h
1
/**
2
 * @file time.h
3
 * @brief Contains time-related functions and definitions
4
 *
5
 * Contains functions and definitions for dealing with time,
6
 * namely delay_ms and the realtime clock.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 **/
10

  
11
#ifndef _TIME_H_
12
#define _TIME_H_
13

  
14
/*	Predefined times for prescale_opt in time.c.
15
	To make you own, know that a pulse is 1/16th of a second. You cannot get less than this. To get more, you need
16
	to know how many 16ths of a second are in the time you want. (Time_desired * 16 = prescaler_opt)
17
*/
18
/**
19
 * @addtogroup time
20
 * @{
21
 **/
22
/** @brief A sixteenth of a second **/
23
#define SIXTEENTH_SECOND 1
24
/** @brief An eighth of a second **/
25
#define EIGTH_SECOND 2
26
/** @brief A quarter of a second **/
27
#define QUARTER_SECOND 4
28
/** @brief Half of a second **/
29
#define HALF_SECOND	8
30
/** @brief One second **/
31
#define SECOND 16
32
/** @brief Two seconds **/
33
#define TWO_SECOND 32
34
/** @brief Four seconds **/
35
#define FOUR_SECOND 64
36

  
37
/** @brief Delay execution for the specified time **/
38
void delay_ms(int ms) ;
39
/** @brief Enable the realtime clock **/
40
void rtc_init(int prescale_opt, void (*rtc_func)(void));
41
/** @brief Reset the counter of the realtime clock **/
42
void rtc_reset(void);
43
/** @brief Get the value of the realtime clock. **/
44
int rtc_get(void);
45

  
46
/** @} **/
47

  
48
#endif
49

  
trunk/code/lib/include/libdragonfly/serial.h
1
/**
2
 * @file serial.h
3
 * @brief Contains declarations for serial input and output
4
 *
5
 * Contains definitions for serial input and output.
6
 *
7
 * @author Colony Project, CMU Robotics Club
8
 * Based on Tom Lauwer's Firefly Library
9
 *
10
 **/
11

  
12
/*
13
	serial.h - Contains definitions and function prototypes for the RS232 serial port
14
  author(s): pkv
15
  
16
  Directions:
17
  Call the initialization function for the serial port you wish to use.  Then, use
18
  either the provided functions or the stdio functions (fprintf, etc) to read and
19
  write characters to the serial ports.
20
  
21
  UART Mapping:
22
    usb_*() -> UART0
23
    xbee_*() -> UART1
24
  
25
  Options: (Add the following defines to your code to configure this library)
26
    #define USB_BAUD { 115200 | 9600 } <= pick ONE value from in here
27
    #define XBEE_BAUD { 115200 | 9600 } <= pick ONE value from in here
28
    #define USE_STDIO
29
  
30
  Note: If you enable USE_STDIO, the first init function that is called will 
31
  automatically be linked to stdin, stdout, and stderr.  To use the baud rate 
32
  commands, add something like the following to your code:
33
  
34
  #define FOO_BAUD 9600
35
  
36
  **UNLESS YOU KNOW WHAT YOU ARE DOING, PLEASE DO NOT CHANGE THIS FILE**
37
  Many, many other people use this file in their code.  If you change it, you will
38
  probably break all of their nice code.  You should not need to change anything in
39
  here, except to accomodate new hardware.
40
*/
41

  
42
#ifndef _SERIAL_H
43
#define _SERIAL_H
44

  
45
/**
46
 * @defgroup usb USB Input / Output
47
 * @brief Functions for USB input / output
48
 *
49
 * Low level functions for USB input and output.
50
 *
51
 * @{
52
 **/
53

  
54
// if no baud rate is defined for usb, default is set here
55
#ifndef USB_BAUD
56
/** @brief the USB baud rate **/
57
#define USB_BAUD 115200
58
#endif
59

  
60
/** @brief Initialize the USB **/
61
void usb_init(void);
62
/** @brief Print a character to USB **/
63
int usb_putc(char c);
64
/** @brief Read a character from USB **/
65
int usb_getc(void);
66
/** @brief Read a character from USB without blocking **/
67
int usb_getc_nb(char *c);
68
/** @brief Print a string to USB **/
69
int usb_puts(char *s);
70
/** @brief Print an integer to USB **/
71
int usb_puti(int value);
72

  
73
/** @} **/ //end addtogroup
74

  
75
/**
76
 * @defgroup xbee XBee Input / Output
77
 * @brief Functions for XBee input / output
78
 *
79
 * Low level functions for XBee input and output.
80
 *
81
 * @{
82
 **/
83

  
84
// if no baud rate is defined for usb, default is set here
85

  
86
// if no baud rate is defined for xbee, default is set here
87
#ifndef XBEE_BAUD
88
/** @brief the XBee baud rate **/
89
#define XBEE_BAUD 9600
90
#endif
91

  
92
/** @brief Initialize the XBee **/
93
void xbee_init(void);
94
/** @brief Print a character to the XBee **/
95
int xbee_putc(char c);
96
/** @brief Read a character from the XBee **/
97
int xbee_getc(void);
98
/** @brief Read a character from the XBee without blocking **/
99
int xbee_getc_nb(char *c);
100

  
101
/** @} **/ //end addtogroup
102

  
103
#endif
104

  
trunk/code/lib/include/libdragonfly/motor.h
1
/**
2
 * @file motor.h
3
 * @brief Contains definitions for controlling the motors
4
 *
5
 * Contains definitions and functions for controlling
6
 * the motors.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 * Based on Tom Lauwer's Firefly Library
10
 **/
11

  
12
#ifndef _MOTOR_H
13
#define _MOTOR_H
14

  
15
#include <avr/io.h>
16
/**
17
 * @addtogroup motors
18
 * @{
19
 **/
20

  
21
/** @brief make the motors go forwards **/
22
#define FORWARD 1
23
/** @brief make the motors go backwards **/
24
#define BACKWARD 0
25

  
26
/** @brief Initialize the motors **/
27
void motors_init(void);
28
/** @brief Set speed and direction of motor1 **/
29
void motor1_set(int direction, int speed);
30
/** @brief Set speed and direction of motor2 **/
31
void motor2_set(int direction, int speed);
32
/** @brief Turn the motors off **/
33
void motors_off(void);
34

  
35
/**@}**/ // end addtogroup
36

  
37
#endif
38

  
trunk/code/lib/include/libdragonfly/analog.h
1
/**
2
 * 
3
 * @file analog.h
4
 * @brief Contains functions and definitions for using the ADC
5
 * 
6
 * Contains definitions and function prototypes for using the
7
 * ADC to detect analog signals on pins AN0 - AN7.
8
 * AN6 and AN7 are used for the wheel and battery.
9
	
10
 * The pins labeled E6 and E7 are external interrupt pins and are not related 
11
 * to analog.
12
	
13
 * @author Colony Project, CMU Robotics Club, based on firefly
14
 * code by Tom Lauwers
15
*/
16

  
17
#ifndef _ANALOG_H
18
#define _ANALOG_H
19

  
20
/**
21
 * @addtogroup analog
22
 * @{
23
 **/
24

  
25
/** @brief Analog port 0 **/
26
#define AN0 0x00
27
/** @brief Analog port 1 **/
28
#define AN1 0x01
29
/** @brief Analog port 2 **/
30
#define AN2 0x02
31
/** @brief Analog port 3 **/
32
#define AN3 0x03
33
/** @brief Analog port 4 **/
34
#define AN4 0x04
35
/** @brief Analog port 5 **/
36
#define AN5 0x05
37
/** @brief Analog port 6 **/
38
#define AN6 0x06
39
/** @brief Analog port 7 **/
40
#define AN7 0x07
41
/** @brief Analog port 8 **/
42
#define AN8 0x08
43
/** @brief Analog port 9 **/
44
#define AN9 0x09
45
/** @brief Analog port 10 **/
46
#define AN10 0x0a
47
/** @brief Analog port 11 **/
48
#define AN11 0x0b
49
/** @brief Analog port 12 **/
50
#define AN12 0x0c
51
/** @brief Analog port 13 **/
52
#define AN13 0x0d
53
/** @brief Analog port 14 **/
54
#define AN14 0x0e
55
/** @brief Analog port 15 **/
56
#define AN15 0x0f
57

  
58
/** @brief EXT_MUX analog port **/
59
#define EXT_MUX AN7
60
/** @brief Analog port for the wheel **/
61
#define WHEEL_PORT AN10
62
/** @brief Analog port for the battery voltage detector **/
63
#define BATT_PORT  AN11
64

  
65
/** @brief Initialize analog ports. **/
66
void analog_init(void);
67
/** @brief Read an 8-bit number from an analog port. **/
68
unsigned int analog8(int which);
69
/** @brief Read a 10-bit number from an analog port. **/
70
unsigned int analog10(int which);
71
/** @brief Read the position of the wheel. **/
72
int wheel(void);
73

  
74
/**@}**/ //end group
75

  
76
#endif
trunk/code/lib/include/libdragonfly/buzzer.h
1
/**
2
 * @file buzzer.h
3
 * @brief Contains definitions for using the buzzer.
4
 *
5
 * Contains definitions for using the buzzer built into
6
 * the colony robots.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 **/
10

  
11
#ifndef _BUZZER_H_
12
#define _BUZZER_H_
13

  
14
/**
15
 * @addtogroup buzzer
16
 * @{
17
 **/
18

  
19
//Musical note definitions
20
//Source: http://www.answers.com/topic/piano-key-frequencies
21
/** @brief Middle C **/
22
#define	C4	260 //Middle C
23
/** @brief C# **/
24
#define	C4s	277 //C sharp
25
/** @brief D **/
26
#define	D4	294
27
/** @brief D# **/
28
#define	D4s	311
29
/** @brief E **/
30
#define	E4	330
31
/** @brief F **/
32
#define	F4	349
33
/** @brief F# **/
34
#define	F4s	370
35
/** @brief G **/
36
#define	G4	392
37
/** @brief G# **/
38
#define	G4s	415
39
/** @brief A **/
40
#define	A4	440
41
/** @brief A# **/
42
#define	A4s	466
43
/** @brief B **/
44
#define	B4	494
45
/** @brief C **/
46
#define	C5	523
47

  
48
/** @brief Initialize the buzzer. **/
49
void buzzer_init(void);
50
/** @brief Set the value the buzzer plays. **/
51
void buzzer_set_val(unsigned int buzz_value);
52
/** @brief Set the frequency the buzzer plays. **/
53
void buzzer_set_freq(unsigned int buzz_freq);
54
/** @brief Play a frequency for a specified time. **/
55
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq);
56
/** @brief Turn the buzzer off. **/
57
void buzzer_off(void); 
58

  
59
/** @} **/ //end addtogroup
60

  
61
#endif
62

  
trunk/code/lib/include/libdragonfly/lcd.h
1
/**
2
 * @file lcd.h
3
 * @brief Contains definitions for dealing with the LCD screen.
4
 * 
5
 * Contains definitions and functions for dealing with the 
6
 * LCD screen.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 **/
10

  
11
#ifndef _LCD_H_
12
#define _LCD_H_
13

  
14
/**
15
 * @addtogroup lcd
16
 * @{
17
 **/
18

  
19
/** @brief Initialize the LCD screen **/
20
void lcd_init(void);
21
/** @brief Clear the LCD screen **/
22
void lcd_clear_screen( void );
23
/** @brief Print a char to the LCD screen **/
24
void lcd_putc(char c);
25
/** @brief Print a string to the LCD screen **/
26
void lcd_puts(char *s);
27
/** @brief Print an int to the LCD screen **/
28
void lcd_puti(int value);
29
/** @brief Set the current cursor position **/
30
void lcd_gotoxy(int x, int y);
31

  
32
/** @} **/
33

  
34
#endif
trunk/code/lib/include/libdragonfly/rangefinder.h
1
/**
2
 * @file rangefinder.h
3
 * @brief Contains rangefinder declarations and functions
4
 * 
5
 * Contains functions and definitions for the use of
6
 * IR rangefinders.
7
 *
8
 * @author Colony Project, CMU Robotics Club
9
 **/
10

  
11
#ifndef _RANGEFINDER_H_
12
#define _RANGEFINDER_H_
13

  
14
/**
15
 * @addtogroup rangefinder
16
 * @{
17
 **/
18

  
19
/** @brief IR Rangefinder 1 **/
20
#define IR1 6
21
/** @brief IR Rangefinder 2 **/
22
#define IR2 5
23
/** @brief IR Rangefinder 3 **/
24
#define IR3 4
25
/** @brief IR Rangefinder 4 **/
26
#define IR4 3
27
/** @brief IR Rangefinder 5 **/
28
#define IR5 2
29

  
30
/** @brief Initialize the rangefinders **/
31
void range_init(void);
32
/** @brief Read the distance from a rangefinder **/
33
int range_read_distance(int range_id);
34

  
35
/** @} **/ //end addtogroup
36

  
37
#endif
38

  
trunk/code/lib/include/libdragonfly/move.h
1
/**
2
 * @file move.h
3
 * @brief Contains definitions for controlling robot motion
4
 * 
5
 * This file offers higher-level functions for robot motion.
6
 *
7
 * @author Colony Project, CMU Robotics Club
8
 **/
9

  
10
#ifndef _MOVE_H_
11
#define _MOVE_H_
12

  
13
/**
14
 * @addtogroup move
15
 * @{
16
 **/
17

  
18
/** @brief Move forwards **/
19
#define FWD 0
20
/** @brief Move backwards **/
21
#define BCK 1
22

  
23
/** @brief A slow speed **/
24
#define SLOW_SPD 96
25
/** @brief Half of the full speed **/
26
#define HALF_SPD 128
27
/** @brief A normal speed **/
28
#define NRML_SPD 160
29
/** @brief A fast speed **/
30
#define FAST_SPD 192
31
/** @brief The maximum speed **/
32
#define FULL_SPD 255
33

  
34
/** @brief A slow turning speed **/
35
#define SLOW_TURN 64
36
/** @brief A medium turning speed **/
37
#define NRML_TURN 96
38
/** @brief A high turning speed **/
39
#define FAST_TURN 128
40

  
41
/** @brief Move the robot at the specified velocity **/
42
void move(int velocity, int omega);
43
/** @brief Move the robot while avoiding obstacles **/
44
void move_avoid(int velocity, int omega, int strength);
45

  
46
/** @} **/
47

  
48
#endif
49

  
trunk/code/lib/src/libdragonfly/time.c
1
/*
2
time.c
3
anything that requires a delay
4
mostly delay_ms
5

  
6
author: Robotics Club, Colony Project
7

  
8
Change Log:
9
	2.5.07 - Kevin
10
		Aaron fixed the orb/servo code and made them use timer3 but compare registers B and C. He hard set the prescaler
11
		to 8 so the RTC broke. Changed it so that we use a 8 prescaler which sets the compare match at 1/16th of a second.
12
		You now count how many 16ths of a second you want until you trigger your actual interrupt. Works. Changed defines
13
		for time so you can still call rtc_init with a scale but now it is defined in terms of actual time like second, quarter_second
14
		etc. Read that section in the time.h file for more information. Tested and works, though the clock drifts more than
15
		it used to
16
	1.30.07 - Kevin
17
		Modified the clock to run on timer3 on the Dragonfly. Works with decent accuracy. Using a prescaler of 256
18
	the timer counts up to a precomputer value which will trigger an interrupt and reset the timer. Multiples of
19
	256 change it by that multiple. Refer to the time.h file for all possible prescalers.
20
		The interrupt will call a specified function _rtc_func every pulse.
21
		All of it has been tested and it works.
22

  
23
*/
24
#include <avr/interrupt.h>
25
#include <util/delay.h>
26
#include <time.h>
27
#include <serial.h>
28

  
29
static volatile int _rtc_val = 0;
30
static volatile int _rtc_pulse = 0;
31
static volatile int _rtc_scale = 32;	//Defaults to 1 Second per pulse
32
static void (*_rtc_f)(void) = 0;
33

  
34
/**
35
 * @defgroup time Time
36
 * @brief Time functions
37
 * 
38
 * Functions dealing with time.
39
 * 
40
 * @{
41
 **/
42

  
43
/**
44
 * Delays for the specified number of milliseconds.
45
 * The accuracy of this function is unknown.
46
 *
47
 * @param ms the number of milliseconds to delay for
48
 **/
49
void delay_ms(int ms) 
50
{
51
	for(; ms > 15; ms-=15)
52
		_delay_ms(15);
53
	_delay_ms(ms);
54
}
55

  
56

  
57
/* 	Prescales defined in time.h. SECOND will give you 1 second.
58
	More scales are defined in the time.h file.
59
	rtc_func is the address to a function that you want called every clock tick. */
60
/**
61
 * Initializes the real time clock. Prescales are defined in time.h.
62
 * For example, SECOND will give 1 second. The specified function is
63
 * called every clock tick. For the real time clock to activate,
64
 * interrupts must be enabled. (through sei() )
65
 *
66
 * @param prescale_opt the period with which the timer is triggered
67
 * @param rtc_func the function called when the timer is triggered
68
 *
69
 * @see rtc_get, rtc_reset
70
 *
71
 **/
72
void rtc_init(int prescale_opt, void (*rtc_func)(void)) {
73
	
74
	//Clear timer register for Timer 3
75
	TCNT3 = 0;
76
	
77
	/* 	This sets the Waveform Generation Module to CTC (Clear Timer on Compare) Mode (100)
78
		See page135 in Atmega128 Docs for more modes and explanations */
79
	TCCR3B |= _BV(WGM32);
80
	
81
	/* 	This sets the prescaler for the system clock (8MHz) ie: divides the clock by some number.
82
		Currently set to a prescaler of 8 because that is what the orb and servos use (they are on this timer as well)
83
		See page137 in Atemga128 Docs for all the available prescalers */
84
	TCCR3B |= _BV(CS31);
85
	
86
	/* 	Sets the two regsiters that we compare against. So the timer counts up to this number and
87
		then resets back to 0 and calls the compare match interrupt.
88
		8x10^6 / 8 = 1/16 Second. All values are based off of this number. Do not change it unless you
89
		are l337*/
90
		
91
	OCR3A = 0xF424;	
92

  
93
	/* 	Enable Output Compare A Interrupt. When OCR3A is met by the timer TCNT3 this interrupt will be
94
		triggerd. (See page140 in Atmega128 Docs for more information */
95
	ETIMSK |= _BV(OCIE3A);
96
	
97
	/*	Store the pointer to the function to be used in the interrupt */
98
	_rtc_f = rtc_func;
99
	
100
	/*	Store how many 1/16ths of a second you want to let by before triggering an interrupt */
101
	_rtc_scale = prescale_opt;
102
}
103

  
104
/**
105
 * Returns the time elapsed in seconds since the last call to
106
 * rtc_init or rtc_reset.
107
 *
108
 * @return the number of seconds since the last call to rtc_init or rtc_reset
109
 *
110
 * @see rtc_init, rtc_reset
111
 **/
112
int rtc_get(void){
113
	return _rtc_val;
114
}
115

  
116
/**
117
 * Resets the real time clock counter to 0.
118
 *
119
 * @see rtc_init, rtc_get
120
 **/
121
void rtc_reset(void){
122
	_rtc_val = 0;
123
}
124

  
125
/** @} **/ //end defgroup
126

  
127
/*	Called every pulse. Function in _rtc_f is called every _rtc_scale and also the counter is updated.
128
	Bascially, since the pulse is hard set at 1/16s  you want to count how many 16ths of a second have passed
129
	and when it reaches the amount of time you want, execute the code. */
130
SIGNAL(TIMER3_COMPA_vect) {
131

  
132
	if (_rtc_pulse ==  _rtc_scale) {
133
		//Increment the real time clock counter
134
		_rtc_val++;
135
		
136
		//Calls the function tied to the real time clock if defined
137
		if(_rtc_f != 0)
138
			_rtc_f();
139
		
140
		//Resets the pulse until the next scale is matched
141
		_rtc_pulse = 0;
142
	}	
143
	
144
	//Updates the amount of pulses seen since the last scale match
145
	_rtc_pulse++;
146
	
147
}
148

  
trunk/code/lib/src/libdragonfly/serial.c
1
/*
2
	serial.c - Functions for using the RS232 serial port
3
	
4
	authors: Robotics Club, Colony Project, pkv
5
	much code taken from FWR's library, author: Tom Lauwers
6
*/
7

  
8
#include <avr/io.h>
9
#include <stdio.h>
10
#include "serial.h"
11

  
12
FILE *usb_fd;  //For use with fprintf() and related stdio functions
13
FILE *xbee_fd;  //For use with fprintf() and related stdio functions
14

  
15
/**
16
 * Initializes communication over the USB serial port.
17
 * This must be called before any other usb function
18
 * may be used.
19
 **/
20
void usb_init() {
21
  //Set baud rate
22
  // - 115200 (both wired and wireless) is UBRR=8, U2X=1
23
  // - 9600 is U2X =1, UBRR = 107.
24
	#if (USB_BAUD == 115200)
25
    UBRR0H = 0x00;
26
    UBRR0L = 8;
27
    UCSR0A |= _BV(U2X0);
28
  #elif (USB_BAUD == 9600)
29
    UBRR0H = 0x00;
30
    UBRR0L = 103;
31
    UCSR0A |= _BV(U2X0);
32
  #else //Baud rate is defined in the header file, we should not get here
33
    return;
34
  #endif
35

  
36
  /*Enable receiver and transmitter */
37
	UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
38
	
39
	/* Set frame format: 8data, 1stop bit, asynchronous normal mode */
40
	UCSR0C |= (1<<UCSZ00) | (1<<UCSZ01);
41
  
42
  // if we have enabled the stdio stuff, then we init it here
43
  #ifdef USE_STDIO
44
    /* Open the stdio stream corresponding to this port */
45
    usb_fd = fdevopen(usb_putc, usb_getc);
46
  #endif
47
}
48

  
49
/**
50
 * Initializes communication over the XBee.
51
 * This must be called before any other xbee function
52
 * may be used.
53
 **/
54
void xbee_init() {
55
  //Set baud rate
56
  // - 115200 (both wired and wireless) is UBRR=8, U2X=1
57
  // - 9600 is U2X =1, UBRR = 107.
58
	#if (XBEE_BAUD == 115200)
59
    UBRR1H = 0x00;
60
    UBRR1L = 8;
61
    UCSR1A |= _BV(U2X1);
62
  #elif (XBEE_BAUD == 9600)
63
    UBRR1H = 0x00;
64
    UBRR1L = 103;
65
    UCSR1A |= _BV(U2X1);
66
  #else //Baud rate is defined in the header file, we should not get here
67
    return;
68
  #endif
69

  
70
	//Enable receiver and transmitter
71
	UCSR1B |= (1<<RXEN1)|(1<<TXEN1);
72
	
73
	// Set frame format: 8data, 1stop bit, asynchronous normal mode
74
	UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11);
75
  
76
  // if we have enabled the stdio stuff, then we init it here
77
  #ifdef USE_STDIO
78
    /* Open the stdio stream corresponding to this port */
79
    xbee_fd = fdevopen(xbee_putc, xbee_getc);
80
  #endif
81
}
82

  
83
/**
84
 * Sends a character over USB.
85
 *
86
 * @param c the character to send
87
 * @return 0 for success, nonzero for failure
88
 **/
89
int usb_putc(char c) 
90
{
91
  // Wait until buffer is clear for sending
92
  loop_until_bit_is_set(UCSR0A, UDRE0);
93
	
94
  // Load buffer with your character
95
  UDR0 = c;
96
  return 0;
97
}
98

  
99
/**
100
 * Sends a character to the XBee.
101
 *
102
 * @param c the character to send
103
 * @return 0 for success, nonzero for failure
104
 **/
105
int xbee_putc(char c) 
106
{
107
  // Wait until buffer is clear for sending
108
  loop_until_bit_is_set(UCSR1A, UDRE1);
109
	
110
  // Load buffer with your character
111
  UDR1 = c;
112
  return 0;
113
}
114

  
115
/**
116
 * Sends a sequence of characters over USB.
117
 *
118
 * @param s the string to send
119
 * @return 0 for success, nonzero for failure
120
 **/
121
int usb_puts(char *s)
122
{
123
	char *t = s;
124
	while (*t != 0)
125
	{
126
		usb_putc(*t);
127
		t++;
128
	}
129
  return 0;
130
}
131

  
132
/**
133
 * Returns the first character in the buffer received from USB.
134
 * This function blocks execution until a character has been received.
135
 * xbee_init must be called before this function may be used.
136
 * 
137
 * @return the first character in the usb buffer
138
 *
139
 * @see usb_init, usb_getc_nb
140
 **/
141
int usb_getc(void)
142
{
143
  // Wait for the receive buffer to be filled
144
  loop_until_bit_is_set(UCSR0A, RXC0);
145
	
146
	// Read the receive buffer
147
	return UDR0;
148
}
149

  
150
/**
151
 * Returns the first character in the buffer received from USB.
152
 * This function blocks execution until a character has been
153
 * received. xbee_init must be called before this function
154
 * may be used.
155
 * 
156
 * @return the first character in the xbee buffer
157
 * 
158
 * @see xbee_init, xbee_getc_nb
159
 **/
160
int xbee_getc(void)
161
{
162
	// Wait for the receive buffer to be filled
163
    loop_until_bit_is_set(UCSR1A, RXC1);
164
	
165
	// Read the receive buffer
166
	return UDR1;
167
}
168

  
169
/**
170
 * Non blocking version of usb_getc. If a character is present in the buffer,
171
 * it is returned, otherwise -1 is returned immediately. usb_init must be
172
 * called before this function can be used.
173
 *
174
 * @param c the received character. This will be set if a character has
175
 * been received.
176
 * 
177
 * @return -1 if no character is available, 0 otherwise
178
 * 
179
 * @see usb_init, usb_getc
180
 **/
181
int usb_getc_nb(char *c)
182
{
183
	// check if the receive buffer is filled
184
  if (UCSR0A & _BV(RXC0)) {
185
    // Read the receive buffer
186
    (*c) = UDR0;
187
    return 0;
188
  }
189
  else {
190
    // Return empty
191
    return -1;
192
	}
193
}
194

  
195
/**
196
 * Non blocking version of xbee_getc. If a character is present in the buffer,
197
 * it is returned, otherwise -1 is returned immediately. xbee_init
198
 * must be called before this function can be used.
199
 *
200
 * @param c the received character. This will be set if a character has
201
 * been received.
202
 * 
203
 * @return -1 if no character is available, 0 otherwise
204
 *
205
 * @see xbee_init, xbee_getc
206
 **/
207
int xbee_getc_nb(char *c)
208
{
209
	// check if the receive buffer is filled
210
  if (UCSR1A & _BV(RXC1)) {
211
    // Read the receive buffer
212
    (*c) = UDR1;
213
    return 0;
214
  }
215
  else {
216
    // Return empty
217
    return -1;
218
	}
219
}
220

  
221

  
222
/*
223
prints an int to serial
224

  
225
code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
226
uses usb_putc
227
*/
228
/**
229
 * Prints an integer, converted to ASCII, to usb. usb_init must be called
230
 * before this function can be used.
231
 *
232
 * @param value the integer to print
233
 * 
234
 * @return 0 if successful, nonzero otherwise
235
 *
236
 * @see usb_init, usb_putc
237
 **/
238
int usb_puti(int value ) {
239
	unsigned char usb_data[6]={'0','0','0','0','0','0' }, position=sizeof(usb_data), radix=10; 
240

  
241
        /* convert int to ascii  */ 
242
        if(value<0) { usb_putc('-'); value=-value; }    
243
        do { position--; *(usb_data+position)=(value%radix)+'0'; value/=radix;  } while(value); 
244

  
245
    
246
        /* start displaying the number */
247
        for(;position<=(sizeof(usb_data)-1);position++)
248
          {
249
            
250
            usb_putc(usb_data[position]);
251
          }
252

  
253
	return 0;
254
}
255

  
256

  
trunk/code/lib/src/libdragonfly/motor.c
1
/*
2
	motor.c - Contains functions necessary for activating and driving the 
3
	H-bridge
4
	
5
	
6
	author: Robotics Club, Colony project
7
	
8
	much of this is taken from FWR's library, author: Tom Lauwers
9
	
10
*/
11

  
12
#include "motor.h"
13

  
14
/**
15
 * @defgroup motors Motors
16
 * @brief Functions for controlling the motors.
17
 * Functions for controlling the motors. Found in motor.h.
18
 * @{
19
 **/
20

  
21
/**
22
 * Initializes both motors so that they can be used with future
23
 * calls to motor1_set and motor2_set.
24
 *
25
 * @see motors_off, motor1_set, motor2_set
26
 **/
27
void motors_init( void ) {
28
	// Configure counter such that we use phase correct
29
	// PWM with 8-bit resolution
30
	PORTA &= 0x0F;
31
	DDRA |= 0xF0;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff