Project

General

Profile

Revision 1692

creating an instance of the hunter prey demo

View differences:

demos/john/behavior/hunter_prey.c
1
#include "hunter_prey.h"
2
#include <dragonfly_lib.h>
3

  
4
#define TAG_TIME 3
5
#define TAG_RANGE 150
6

  
7
/**** This file should not be edited! ****/
8

  
9

  
10
/*
11
 * The criteria for tagging are the following:
12
 *   * The max bom is betweed 1 and 7
13
 *   * The front rangefinder reads less than TAG_RANGE
14
 *   * -1 values from the rangefinder are ignored
15
 *   * These conditions are met across TAG_TIME calls to this function
16
 */
17

  
18
unsigned char hunter_prey_tagged(int max_bom, int frontRange) {
19

  
20
  static int onTarget = 0;
21

  
22
  if(max_bom < 7 && max_bom > 1 && frontRange > 0 && frontRange < TAG_RANGE) {
23
    if(onTarget == 0) {
24
      onTarget = TAG_TIME;
25
      usb_puts("On target!\n");
26
    }
27
    else {
28
      if(--onTarget <= 0) {
29
	onTarget = 0;
30
	usb_puts("TAG!\n");
31
	return 1;
32
      }
33
    }
34
  }
35
  else{
36
    //don't reset onTarget because the robot got too close
37
    if(frontRange > 0)
38
      onTarget = 0;
39
  }
40

  
41
  return 0;
42

  
43
}
demos/john/behavior/main.c
1
/*
2
 * Hunter-Prey main.c File - Implementation of Hunter-Prey behavior which
3
 * 		uses finite state machines to manage the behavior. A top level
4
 * 		state machine controls the high level behavior switches between
5
 * 		"hunter" and "prey" and manages the wireless communication. Two
6
 * 		additional state machines control the behavior of the robot when
7
 * 		it is in "prey" mode and when it is in "hunter" mode.
8
 *
9
 * Author: John Sexton, Colony Project, CMU Robotics Club
10
 */
11

  
12
#include <dragonfly_lib.h>
13
#include <wl_basic.h>
14
#include "hunter_prey.h"
15
#include "encoders.h"
16

  
17
#define WL_CHANNEL 					24
18

  
19
#define BACK_THRESHOLD 			-1000
20
#define TURN_DIST						1024
21
#define IR_DIST_THRESHOLD		150
22
#define WAIT_DELAY_MS				2000
23

  
24
/* State Macros */
25

  
26
/* Top Level FSM States */
27
#define TOP_INIT						0
28
#define TOP_HUNTER_HUNT			1
29
#define TOP_HUNTER_TAG			2
30
#define TOP_HUNTER_PURSUE		3
31
#define TOP_PREY_AVOID			4
32
#define TOP_HUNTER_WAIT			5
33
#define TOP_ERROR						6
34

  
35
/* Hunter FSM States */
36
#define HUNTER_SPIRAL				0
37
#define HUNTER_CHASE				1
38

  
39
/* Prey FSM States */
40
#define PREY_START_BACK			0
41
#define PREY_BACKING				1
42
#define PREY_TURN						2
43
#define PREY_AVOID					3
44

  
45

  
46
/* Function prototype declarations */
47
int hunter_FSM(int, int, int);
48
int prey_FSM(int);
49

  
50
/* Variables used to receive packets */
51
unsigned char* packet_data;
52
int data_length;
53

  
54
/*  Data buffer used to send packets */
55
char send_buffer[2];
56

  
57
int main(void)
58
{
59

  
60
    /* Initialize dragonfly board */
61
    dragonfly_init(ALL_ON);
62
		xbee_init();
63
		encoders_init();
64

  
65
    /* Initialize the basic wireless library */
66
    wl_basic_init_default();
67

  
68
    /* Set the XBee channel to assigned channel */
69
    wl_set_channel(WL_CHANNEL);
70

  
71

  
72
    /* ****** CODE HERE ******* */
73

  
74
		/* Initialize state machines */
75
		int state = TOP_INIT;
76
		int hunter_state = HUNTER_SPIRAL;
77
		int prey_state = PREY_AVOID;
78

  
79
		int frontIR = 0;
80
		int maxBOM = 0;
81
		int robotID = get_robotid();
82
		int oldTime = 0, curTime = 0;
83

  
84
		while (1) {
85

  
86
			/* Check if we've received a wireless packet */
87
			packet_data = wl_basic_do_default(&data_length);
88

  
89
			/* Top level state machines */
90
			switch(state) {
91

  
92
				case TOP_INIT:
93
					orbs_set_color(RED, GREEN);
94
					delay_ms(500);
95
					orbs_set_color(GREEN, RED);
96
					delay_ms(500);
97

  
98
					/* Allow user to pick the starting behavior */
99
					if (button1_read()) {
100
						state = TOP_PREY_AVOID;
101
						prey_state = PREY_AVOID;
102
					} else {
103
						state = TOP_HUNTER_HUNT;
104
						hunter_state = HUNTER_SPIRAL;
105
					}
106
					break;
107
				case TOP_HUNTER_HUNT:
108
					orbs_set_color(RED, RED);
109

  
110
					if (packet_data && data_length == 2
111
							&& packet_data[0] == HUNTER_PREY_ACTION_ACK) {
112
						/* If we've received an ACK, we need to wait */
113
						state = TOP_HUNTER_WAIT;
114
					} else {
115
						/* Record some sensor readings and check if we can TAG */
116
						bom_refresh(BOM_ALL);
117
						frontIR = range_read_distance(IR2);
118
						maxBOM = get_max_bom();
119
						if (hunter_prey_tagged(maxBOM, frontIR)) {
120
							state = TOP_HUNTER_TAG;
121
						} else {
122
							/* If we haven't tagged, then enter hunter FSM */
123
							hunter_state = hunter_FSM(hunter_state, maxBOM, frontIR);
124
						}
125
					}
126
					break;
127
				case TOP_HUNTER_TAG:
128
					orbs_set_color(RED, PURPLE);
129

  
130
					if (packet_data && data_length == 2
131
							&& packet_data[0] == HUNTER_PREY_ACTION_ACK) {
132
						/* If we've received an ACK, then someone beat us to the TAG and
133
 						 * we need to wait. */
134
						state = TOP_HUNTER_WAIT;
135
					} else {
136
						/* Prepare and send the TAG packet */
137
						send_buffer[0] = HUNTER_PREY_ACTION_TAG;
138
						send_buffer[1] = robotID;
139
						wl_basic_send_global_packet(42, send_buffer, 2);
140

  
141
						/* Record the time so we don't spam a TAG message on the network */
142
						oldTime = rtc_get();
143
						state = TOP_HUNTER_PURSUE;
144
					}
145
					break;
146
				case TOP_HUNTER_PURSUE:
147
					orbs_set_color(RED, BLUE);
148
					curTime = rtc_get();
149
					
150
					if (packet_data && data_length == 2
151
							&& packet_data[0] == HUNTER_PREY_ACTION_ACK) {
152
						/* Check if we've received a new wireless packet */
153

  
154
						if (packet_data[1] == robotID) {
155
							/* We've been ACKed, so we can now become the prey */
156
							state = TOP_PREY_AVOID;
157
							prey_state = PREY_START_BACK;
158
						} else {
159
							/* If we get an ACK with a different robotID, then someone beat us
160
							 * to the TAG, so we must wait */
161
							state = TOP_HUNTER_WAIT;
162
						}
163

  
164
					} else if (curTime - oldTime > 1) {
165
						/* If 1 second has ellapsed, return to normal hunting state (we can
166
						 * TAG again now) */
167
						state = TOP_HUNTER_HUNT;
168
					} else if (oldTime > curTime) {
169
						/* If for some reason the timer overflows, or the wireless library
170
						 * (which is also using the same timer) resets the timer,
171
						 * reinitialize the timer so that we don't wait too long for the
172
						 * timer to catch back up. */
173
						oldTime = curTime;
174
					} else {
175
						/* If no other behavioral changes need to be made, then continue
176
						 * with the hunter FSM where we left off */
177
						bom_refresh(BOM_ALL);
178
						frontIR = range_read_distance(IR2);
179
						maxBOM = get_max_bom();
180
						hunter_state = hunter_FSM(hunter_state, maxBOM, frontIR);
181
					}
182
					break;
183
				case TOP_PREY_AVOID:
184
					orbs_set_color(GREEN, GREEN);
185
					if (packet_data && data_length == 2
186
							&& packet_data[0] == HUNTER_PREY_ACTION_TAG) {
187
						/* Check if we've received a TAG yet. If so then send an ACK back */
188

  
189
						send_buffer[0] = HUNTER_PREY_ACTION_ACK;
190
						send_buffer[1] = packet_data[1];
191
						wl_basic_send_global_packet(42, send_buffer, 2);
192
						
193
						state = TOP_HUNTER_WAIT;
194
					} else {
195
						/* If we haven't received a TAG yet, continue with prey FSM */
196
						bom_on();
197
						prey_state = prey_FSM(prey_state);
198
					}					
199
					break;
200
				case TOP_HUNTER_WAIT:
201
					/* Set orb colors and wait to give the prey the 5 second head start */
202
					orbs_set_color(BLUE, BLUE);
203
					bom_off();
204
					motors_off();
205
					delay_ms(WAIT_DELAY_MS);
206
					state = TOP_HUNTER_HUNT;
207
					hunter_state = HUNTER_SPIRAL;
208
					break;
209
				case TOP_ERROR:
210
				default:
211
					orbs_set_color(PURPLE, PURPLE);
212
					state = TOP_ERROR;
213
					while(1);
214
					break;
215
			}
216

  
217
		}
218

  
219
    /* ****** END HERE ******* */
220

  
221
    while(1);
222

  
223
    return 0;
224

  
225
}
226

  
227

  
228
/*
229
 * prey_FSM - Prey finite state machine which starts by backing away, turning,
230
 * 		and then running and avoiding obstacles.
231
 *
232
 * Arguments:
233
 * 	prey_state - Current prey state.
234
 *
235
 * returns - The new state of the prey state machine.
236
 */
237

  
238
int prey_FSM(int prey_state) {
239

  
240
	/* Variable to store the front rangefinder readings */
241
	int rangeVals[3] = {0, 0, 0};
242

  
243
	switch (prey_state) {
244

  
245
		case PREY_START_BACK:
246
			motor_l_set(BACKWARD, 255);
247
			motor_r_set(BACKWARD, 255);
248
			encoder_rst_dx(LEFT);
249
			encoder_rst_dx(RIGHT);
250
			return PREY_BACKING;
251
			break;
252
		case PREY_BACKING:
253
			if (encoder_get_x(LEFT) < BACK_THRESHOLD
254
											|| encoder_get_x(RIGHT) < BACK_THRESHOLD) {
255
				motor_l_set(BACKWARD, 255);
256
				motor_r_set(FORWARD, 255);
257
				encoder_rst_dx(LEFT);
258
				encoder_rst_dx(RIGHT);
259
				return PREY_TURN;
260
			} else {
261
				return PREY_BACKING;
262
			}
263
			break;
264
		case PREY_TURN:
265
			if (encoder_get_x(LEFT) < -TURN_DIST
266
											|| encoder_get_x(RIGHT) > TURN_DIST) {
267
				return PREY_AVOID;				
268
			} else {
269
				return PREY_TURN;
270
			}
271
			break;
272
		case PREY_AVOID:
273
			rangeVals[0] = range_read_distance(IR1);
274
			rangeVals[1] = range_read_distance(IR2);
275
			rangeVals[2] = range_read_distance(IR3);
276

  
277
			/* Drive away if we detect obstacles using the rangefinders */
278
			if (rangeVals[1] > 0 && rangeVals[1] < IR_DIST_THRESHOLD) {
279
				if (rangeVals[0] < rangeVals[2]) {
280
					motor_l_set(FORWARD, 255);
281
					motor_r_set(BACKWARD, 255);
282
				} else {
283
					motor_l_set(BACKWARD, 255);
284
					motor_r_set(FORWARD, 255);
285
				}
286
				return PREY_AVOID;
287
			} else if (rangeVals[0] > 0 && rangeVals[0] < IR_DIST_THRESHOLD) {
288
				motor_l_set(FORWARD, 255);
289
				motor_r_set(FORWARD, 170);
290
				return PREY_AVOID;
291
			} else if (rangeVals[2] > 0 && rangeVals[2] < IR_DIST_THRESHOLD) {
292
				motor_l_set(FORWARD, 170);
293
				motor_r_set(FORWARD, 255);
294
				return PREY_AVOID;
295
			} else {			
296
				motor_l_set(FORWARD, 255);
297
				motor_r_set(FORWARD, 255);
298
				return PREY_AVOID;
299
			}
300
			break;
301
		default:
302
			return PREY_AVOID;
303
			break;
304

  
305
	}
306
	
307
	return prey_state;
308

  
309
}
310

  
311

  
312
/*
313
 * hunter_FSM - Hunter finite state machine which defaults to spiraling
314
 * 		outwards until the BOM can locate the prey. Once the BOM locates
315
 * 		the prey, chase the prey as fast as possible.
316
 *
317
 * Arguments:
318
 * 	hunter_state - Current hunter state.
319
 * 	maxBOM - Current maximum BOM value.
320
 * 	frontIR - Current front IR rangefinder reading value.
321
 *
322
 * returns - The new state of the hunter state machine.
323
 */
324

  
325
int hunter_FSM(int hunter_state, int maxBOM, int frontIR) {
326

  
327
	switch(hunter_state) {
328

  
329
		case HUNTER_SPIRAL:
330
			if (maxBOM != -1) {
331
				return HUNTER_CHASE;
332
			} else {
333
				motor_l_set(FORWARD, 170);
334
				motor_r_set(FORWARD, 190);
335
				return HUNTER_SPIRAL;
336
			}
337
			break;
338
		case HUNTER_CHASE:
339
						
340
			if (maxBOM == -1) {
341
				return HUNTER_CHASE;
342
			} else if (maxBOM == 4) {
343
				motor_l_set(FORWARD, 255);
344
				motor_r_set(FORWARD, 255);
345
				return HUNTER_CHASE;
346
			} else if (maxBOM == 3) {
347
				motor_l_set(FORWARD, 255);
348
				motor_r_set(FORWARD, 240);
349
				return HUNTER_CHASE;
350
			} else if (maxBOM == 5) {
351
				motor_l_set(FORWARD, 240);
352
				motor_r_set(FORWARD, 255);
353
				return HUNTER_CHASE;
354
			} else if (maxBOM < 3) {
355
				motor_l_set(FORWARD, 255);
356
				motor_r_set(FORWARD, 170);
357
				return HUNTER_CHASE;
358
			} else if (maxBOM > 5 && maxBOM <= 8) {
359
				motor_l_set(FORWARD, 170);
360
				motor_r_set(FORWARD, 255);
361
				return HUNTER_CHASE;
362
			} else if (maxBOM > 8 && maxBOM < 12) {
363
				motor_l_set(BACKWARD, 255);
364
				motor_r_set(FORWARD, 255);
365
				return HUNTER_CHASE;
366
			} else {
367
				motor_l_set(FORWARD, 255);
368
				motor_r_set(BACKWARD, 255);
369
				return HUNTER_CHASE;
370
			}
371
			break;
372
		default:
373
			return HUNTER_SPIRAL;
374
			break;
375

  
376
	}
377

  
378
	return hunter_state;
379

  
380
}
demos/john/behavior/hunter_prey.h
1
#ifndef _HUNTER_PREY_H
2
#define _HUNTER_PREY_H
3

  
4
#include <inttypes.h>
5

  
6
/**** This file should not be edited! ****/
7

  
8
/*
9
 * The packet structure is 2 bytes
10
 * byte 0 is the action, which is one of the values below
11
 * byte 1 is the robot id
12
 */
13

  
14
#define HUNTER_PREY_ACTION_TAG 'T'
15
#define HUNTER_PREY_ACTION_ACK 'A'
16

  
17
unsigned char hunter_prey_tagged(int max_bom, int front_rangefinder);
18

  
19
#endif
demos/john/behavior/Makefile
1
# this is a local makefile
2

  
3
# Relative path to the root directory (containing lib directory)
4
ifndef COLONYROOT
5
COLONYROOT := ..
6

  
7
# Target file name (without extension).
8
TARGET = main
9

  
10
# Uncomment this to use the wireless library
11
USE_WIRELESS = 1
12

  
13
# com1 = serial port. Use lpt1 to connect to parallel port.
14
AVRDUDE_PORT = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'COM4:'; else echo '/dev/ttyUSB0'; fi)
15

  
16
else
17
COLONYROOT := ../$(COLONYROOT)
18
endif
19

  
20
include $(COLONYROOT)/Makefile
demos/john/lib/include/libdragonfly/bom.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file bom.h
29
 * @brief Definitions for using the BOM
30
 * 
31
 * This file contains definitions for using the Bearing and 
32
 * Orientation Module (BOM).
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 *
36
 **/
37

  
38
#ifndef _BOM_H
39
#define _BOM_H
40

  
41
/**
42
 * @addtogroup bom
43
 * @{
44
 **/
45
 
46
/** @brief Include all elements in the 16-bit bitfield **/
47
#define BOM_ALL 0xFFFF
48

  
49
/** @brief Original BOM - No Range, No Individual LED control **/
50
#define BOM10     0
51

  
52
/** @brief BOM 1.5 - No Range, Individual LED control **/
53
#define BOM15   1
54

  
55
/** @brief RBOM - Range, Individual LED control **/
56
#define RBOM    2
57

  
58

  
59
/** @brief Struct for storing x and y component vector data. Used by bom_get_vector() functions **/
60
typedef struct vector {
61
	int x;
62
	int y;
63
} Vector;
64

  
65

  
66
/** @brief Initialize the bom according to bom type **/
67
void bom_init(char type);
68

  
69
/** @brief Refresh bom_val[] with new values from analog8.  analog_init and bom_init must be called for this to work. **/
70
void bom_refresh(int bit_field);
71

  
72
/** @brief Gets the bom reading from bom_val[which].  Call bom_refresh beforehand to read new bom values. **/
73
int bom_get(int which);
74

  
75
/** @brief Compares all the values in bom_val[] and returns the index to the highest value element. **/
76
int bom_get_max(void);
77

  
78
/** @brief Computes the net resultant BOM IR vector. **/
79
int bom_get_vector(Vector*, int*);
80

  
81
/** @brief Computes the normalized net resultant BOM IR vector. **/
82
int bom_get_norm_vector(Vector*, int*);
83

  
84
/** @brief Print snapshot of BOM intensity histogram over USB connection **/
85
int bom_print_usb(int*);
86

  
87
/** @brief Computes the weighted average of all the bom readings to estimate the position and distance of another robot. **/
88
int bom_get_max10(int *dist);
89

  
90
/** @brief Enables the selected bom leds on a BOM1.5 **/
91
void bom_set_leds(int bit_field);
92

  
93
/** @brief (DEPRECATED) Gets and compares all bom values.  Returns the index to the highest value element since last refresh. **/
94
int get_max_bom(void);
95

  
96
/** @brief Turns on all BOM leds, or turns on enabled leds on a BOM1.5. **/
97
void bom_on(void);
98

  
99
/** @brief Turns off all bom leds. **/
100
void bom_off(void);
101

  
102
/** @} **/
103

  
104
#endif
105

  
demos/john/lib/include/libdragonfly/rangefinder.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file rangefinder.h
29
 * @brief Contains rangefinder declarations and functions
30
 * 
31
 * Contains functions and definitions for the use of
32
 * IR rangefinders.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _RANGEFINDER_H_
38
#define _RANGEFINDER_H_
39

  
40
/**
41
 * @addtogroup rangefinder
42
 * @{
43
 **/
44

  
45
/** @brief IR Rangefinder 1 **/
46
#define IR1 6
47
/** @brief IR Rangefinder 2 **/
48
#define IR2 5
49
/** @brief IR Rangefinder 3 **/
50
#define IR3 4
51
/** @brief IR Rangefinder 4 **/
52
#define IR4 3
53
/** @brief IR Rangefinder 5 **/
54
#define IR5 2
55
/** @brief smallest meaningful rangefinder reading (logarithmic scale) **/
56
#define MIN_IR_ADC8 27
57
/** @brief largest meaningful rangefinder reading (logarithmic scale) **/
58
#define MAX_IR_ADC8 98
59

  
60
/** @brief Initialize the rangefinders **/
61
void range_init(void);
62
/** @brief Read the distance from a rangefinder **/
63
int range_read_distance(int range_id);
64
/** @brief Convert logarithmic-scale distance readings to a linear scale **/
65
int linearize_distance(int value);
66

  
67
/** @} **/ //end addtogroup
68

  
69
#endif
70

  
demos/john/lib/include/libdragonfly/spi.h
1
/**
2
 * @file spi.h
3
 * @brief Definitions for SPI
4
 * @author Colony Project, CMU Robotics Club
5
 **/
6

  
7
/**
8
 * @addtogroup spi
9
 * @{
10
 **/
11

  
12
#ifndef __SPI_H__
13
#define __SPI_H__
14

  
15
#define DOUBLE_SCK 1
16
#define SPR0_BIT 1
17

  
18
#define MASTER 1
19
#define SLAVE 0
20

  
21
#define MOSI _BV(PB2)
22
#define MISO _BV(PB3)
23
#define SS   _BV(PB0)
24
#define SCLK _BV(PB1)
25

  
26
typedef void (*spi_fun_recv_t)(char);
27
typedef void (*spi_fun_recv_complete_t)(void);
28

  
29
/** 
30
* @brief Initialize SPI
31
* 
32
* @param spi_fun_recv_t The function that handles SPI data, byte for byte.
33
* @param spi_fun_recv_complete_t  Called on a completed transmission - typically for cleaning up.
34
*/
35
void spi_init (spi_fun_recv_t, spi_fun_recv_complete_t);
36

  
37
/** 
38
* @brief Initialize SPI transfer.
39
* 
40
* @param char The number of bytes to transfer.
41
*/
42
void spi_transfer (char);
43

  
44
/**@}**/ //end group
45

  
46
#endif
demos/john/lib/include/libdragonfly/time.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file time.h
29
 * @brief Contains time-related functions and definitions
30
 *
31
 * Contains functions and definitions for dealing with time,
32
 * namely delay_ms and the realtime clock.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _TIME_H_
38
#define _TIME_H_
39

  
40
/*	Predefined times for prescale_opt in time.c.
41
	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
42
	to know how many 16ths of a second are in the time you want. (Time_desired * 16 = prescaler_opt)
43
*/
44
/**
45
 * @addtogroup time
46
 * @{
47
 **/
48
/** @brief A sixteenth of a second **/
49
#define SIXTEENTH_SECOND 1
50
/** @brief An eighth of a second **/
51
#define EIGTH_SECOND 2
52
/** @brief A quarter of a second **/
53
#define QUARTER_SECOND 4
54
/** @brief Half of a second **/
55
#define HALF_SECOND	8
56
/** @brief One second **/
57
#define SECOND 16
58
/** @brief Two seconds **/
59
#define TWO_SECOND 32
60
/** @brief Four seconds **/
61
#define FOUR_SECOND 64
62

  
63
/** @brief Delay execution for the specified time **/
64
void delay_ms(int ms) ;
65
/** @brief Enable the realtime clock **/
66
void rtc_init(int prescale_opt, void (*rtc_func)(void));
67
/** @brief Reset the counter of the realtime clock **/
68
void rtc_reset(void);
69
/** @brief Get the value of the realtime clock. **/
70
int rtc_get(void);
71

  
72
/** @} **/
73

  
74
#endif
75

  
demos/john/lib/include/libdragonfly/motor.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file motor.h
29
 * @brief Contains definitions for controlling the motors
30
 *
31
 * Contains definitions and functions for controlling
32
 * the motors.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 * Based on Tom Lauwer's Firefly Library
36
 **/
37

  
38
#ifndef _MOTOR_H
39
#define _MOTOR_H
40

  
41
#include <avr/io.h>
42
/**
43
 * @addtogroup motors
44
 * @{
45
 **/
46

  
47
/** @brief make the motors go forwards **/
48
#define FORWARD 1
49
/** @brief make the motors go backwards **/
50
#define BACKWARD 0
51

  
52
/** @brief Initialize the motors **/
53
void motors_init(void);
54
/** @brief Set speed and direction of motor1 
55
 *  @deprecated use the left motor function instead. it's more intuitive and easier to read.**/
56
void motor1_set(int direction, int speed);
57
/** @brief Set speed and direction of motor2 
58
 *  @deprecated use the right motor function instead. it's more intuitive and easier to read.**/
59
void motor2_set(int direction, int speed);
60
/** @brief Set speed and direction of left motor **/
61
void motor_l_set(int direction, int speed);
62
/** @brief Set speed and direction of right motor **/
63
void motor_r_set(int direction, int speed);
64
/** @brief Turn the motors off **/
65
void motors_off(void);
66

  
67
/**@}**/ // end addtogroup
68

  
69
#endif
70

  
demos/john/lib/include/libdragonfly/analog.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26
/**
27
 * 
28
 * @file analog.h
29
 * @brief Contains functions and definitions for using the ADC
30
 * 
31
 * Contains definitions and function prototypes for using the
32
 * ADC to detect analog signals on pins AN0 - AN7.
33
 * AN6 and AN7 are used for the wheel and battery.
34
	
35
 * The pins labeled E6 and E7 are external interrupt pins and are not related 
36
 * to analog.
37
	
38
 * @author Colony Project, CMU Robotics Club, based on firefly
39
 * originally taken from fwr analog file (author: Tom Lauwers)
40
 * loop code written by Kevin Woo and James Kong
41
 */
42

  
43
#ifndef _ANALOG_H
44
#define _ANALOG_H
45

  
46
#include <inttypes.h>
47

  
48
/**
49
 * @addtogroup analog
50
 * @{
51
 **/
52

  
53
/** @brief Analog port 0 **/
54
#define AN0 0x00
55
/** @brief Analog port 1 **/
56
#define AN1 0x01
57
/** @brief Analog port 2 **/
58
#define AN2 0x02
59
/** @brief Analog port 3 **/
60
#define AN3 0x03
61
/** @brief Analog port 4 **/
62
#define AN4 0x04
63
/** @brief Analog port 5 **/
64
#define AN5 0x05
65
/** @brief Analog port 6 **/
66
#define AN6 0x06
67
/** @brief Analog port 7 **/
68
#define AN7 0x07
69
/** @brief Analog port 8 **/
70
#define AN8 0x08
71
/** @brief Analog port 9 **/
72
#define AN9 0x09
73
/** @brief Analog port 10 **/
74
#define AN10 0x0A
75
/** @brief Analog port 11 **/
76
#define AN11 0x0B
77
/** @brief Analog port 12 **/
78
#define AN12 0x0C
79
/** @brief Analog port 13 **/
80
#define AN13 0x0D
81
/** @brief Analog port 14 **/
82
#define AN14 0x0E
83
/** @brief Analog port 15 **/
84
#define AN15 0x0F
85

  
86
/** @brief BOM_PORT analog port for BOM **/
87
#define BOM_PORT AN0
88
/** @brief EXT_MUX analog port **/
89
#define EXT_MUX AN7
90
/** @brief Analog port for the wheel **/
91
#define WHEEL_PORT AN10
92
/** @brief Analog port for the battery voltage detector **/
93
#define BATT_PORT  AN11
94

  
95
/** @brief Analog loop status. ADC conversion running. **/
96
#define ADC_LOOP_RUNNING 1
97
/** @brief Analog loop status.  No ADC conversion running.**/
98
#define ADC_LOOP_STOPPED 0
99

  
100
/** @brief Analog init parameter. Start the analog loop. **/
101
#define ADC_START 1
102
/** @brief Analog init parameter. Don't start the analog loop. **/
103
#define ADC_STOP  0
104

  
105
#define ADMUX_OPT 0x60
106

  
107
/** @brief Struct to hold the value of a particular analog port **/
108
typedef struct {
109
  uint8_t adc8;
110
  uint16_t adc10;
111
} adc_t;
112

  
113

  
114
/** @brief Initialize analog ports. Will start running a loop
115
    if start_conversion is ADC_START.**/
116
void analog_init(int start_conversion);
117
/** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/
118
void analog_start_loop(void);
119
/** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/
120
void analog_stop_loop(void);
121
/** @brief Returns the status of the analog loop. **/
122
int analog_loop_status(void);
123
/** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8. **/
124
unsigned int analog8(int which);
125
/** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10. **/
126
unsigned int analog10(int which);
127
/** @brief Read the position of the wheel. **/
128
int wheel(void);
129
/** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/
130
unsigned int analog_get8(int which);
131
/** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/
132
unsigned int analog_get10(int which);
133

  
134

  
135
/**@}**/ //end group
136

  
137
#endif
138

  
demos/john/lib/include/libdragonfly/encoders.h
1
/**
2
 * 
3
 * @file encoders.h
4
 * @brief Contains functions for reading encoder values.
5
 *
6
 * Contains high and low level functions for reading encoders
7
 * including reading out total distance covered, and 
8
 * eventually velocity.
9
 *	
10
 * @author Colony Project, CMU Robotics Club
11
*/
12

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

  
18
#ifndef __ENCODERS_H__
19
#define __ENCODERS_H__
20

  
21

  
22
#ifndef LEFT
23
	/** @brief Left wheel **/
24
	#define LEFT 0
25
#endif
26
#ifndef RIGHT
27
	/** @brief Right wheel **/
28
	#define RIGHT 1
29
#endif
30

  
31
/** @brief Max value of valid encoder reading. **/
32
#define ENCODER_MAX 1024
33

  
34
/** @brief Magnet misaligned - likely distance from encoder problem. **/
35
#define ENCODER_MAGNET_FAILURE 1025
36
/** @brief Encoder misaligned - likely on XY plane. **/
37
#define ENCODER_MISALIGNED 1027
38
/** @brief Not enough time has passed - encoders not initialized in hardware. **/
39
#define ENCODER_DATA_NOT_READY 1026
40

  
41
/** @brief delay_ms argument after a full read is complete **/
42
#define ENCODER_DELAY 20
43

  
44
//Data invalid flags (hardware failure):
45
#define OCF _BV(4)
46
#define COF _BV(3)
47

  
48
//Data invalid alarm (May be invalid):
49
#define LIN _BV(2)
50

  
51
#define MagINCn _BV(1)
52
#define MagDECn _BV(0)
53

  
54
/** @brief Buffer size **/
55
#define BUFFER_SIZE 46
56

  
57
#define ERR_VEL 1024
58

  
59
/** @brief Initialize encoders. **/
60
void encoders_init(void);
61
/** @brief Read instantaneous encoder value. **/
62
int encoder_read(char encoder);
63

  
64
/** @brief Get total distance traveled.
65
 *  @note  Simply calls encoder_get_dx.
66
 **/
67
int encoder_get_x(char encoder);
68

  
69
/** @brief Get instantaneous velocity. **/
70
int encoder_get_v(char encoder);
71

  
72
/** @brief Get total distance traveled. **/
73
int encoder_get_dx(char encoder);
74
/** @brief Reset distance counter. **/
75
void encoder_rst_dx(char encoder);
76
/** @brief Get time count: The number of encoder reads that have occurred. **/
77
int encoder_get_tc(void);
78
/** @brief Reset the time count. **/
79
void encoder_rst_tc(void);
80

  
81
/** @brief Waits for the next n encoder reading, then returns. **/
82
void encoder_wait( int nReadings );
83

  
84
/**@}**/ //end group
85

  
86
#endif
demos/john/lib/include/libdragonfly/dragonfly_lib.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file dragonfly_lib.h
29
 * @brief Contains other include files
30
 * 
31
 * Include this file for all the functionality of libdragonfly.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 **/
35

  
36
#ifndef _DRAGONFLY_LIB_H_
37
#define _DRAGONFLY_LIB_H_
38

  
39
/**
40
 * @addtogroup dragonfly
41
 * @{
42
 **/
43

  
44
// Configuration definitions
45
/** @brief Initialize analog **/
46
#define ANALOG 0x01
47
/** @brief Initialize serial communications **/
48
#define SERIAL 0x02
49
/** @brief Initialize USB communications **/
50
#define USB    0x02
51
/** @brief Initialize communications **/
52
#define COMM   0x02
53
/** @brief Initialize the orb **/
54
#define ORB    0x04
55
/** @brief Initialize the motors **/
56
#define MOTORS 0x08
57
/** @brief Initialize I2C **/
58
#define I2C    0x20
59
/** @brief Initialize the buzzer **/
60
#define BUZZER 0x40
61
/** @brief Initialize the LCD screen **/
62
#define LCD    0x80
63
/** @brief Initialize the rangefinders **/
64
#define RANGE  0x0100
65
/** @brief Initialize the BOM **/
66
#define BOM  0x0200
67
/** @brief Initilize encoders **/
68
#define ENCODERS 0x400
69
/** @brief Initialize everything  **/
70
#define ALL_ON 0x07FF
71

  
72
/** @brief Initialize the board **/
73
void dragonfly_init(int config);
74

  
75
/** @} **/ //end addtogroup
76

  
77
#include <inttypes.h>
78
#include <avr/io.h>
79
#include <avr/interrupt.h>
80
#include <util/delay.h>
81
#include <util/twi.h>
82

  
83
// This file is included from the libdragonfly directory because it seems to be
84
// missing from the AVR libc distribution.
85
#include "atomic.h"
86

  
87
#include "analog.h"
88
#include "dio.h"
89
#include "time.h"
90
#include "lcd.h"
91
#include "lights.h"
92
#include "motor.h"
93
#include "serial.h"
94
#include "buzzer.h"
95
#include "rangefinder.h"
96
#include "bom.h"
97
#include "encoders.h"
98
#include "move.h"
99
#include "reset.h"
100
#include "math.h"
101
#include "eeprom.h"
102

  
103
#include <stddef.h>
104
#include <stdbool.h>
105

  
106
/** @brief shortcut for ATOMIC_BLOCK(ATOMIC_RESTORESTATE) **/
107
#define SYNC ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
108

  
109
/** @brief atomically grab a lock if it is free, return otherwise **/
110
#define REQUIRE_LOCK_OR_RETURN(LOCK) do { SYNC { if (LOCK) return; LOCK=1; } } while (0)
111

  
112
/** @brief atomically release a lock **/
113
#define RELEASE_LOCK(LOCK) do { LOCK=0; } while (0)
114

  
115

  
116

  
117
#endif
118

  
demos/john/lib/include/libdragonfly/serial.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file serial.h
29
 * @brief Contains declarations for serial input and output
30
 *
31
 * Contains definitions for serial input and output.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * Based on Tom Lauwer's Firefly Library
35
 *
36
 **/
37

  
38
/*
39
  serial.h - Contains definitions and function prototypes for the RS232 serial port
40
  author(s): pkv
41
  
42
  Directions:
43
  Call the initialization function for the serial port you wish to use.  Then, use
44
  either the provided functions or the stdio functions (fprintf, etc) to read and
45
  write characters to the serial ports.
46
  
47
  UART Mapping:
48
  usb_*() -> UART0
49
  xbee_*() -> UART1
50
  
51
  Options: (Add the following defines to your code to configure this library)
52
  #define USB_BAUD { 115200 | 9600 } <= pick ONE value from in here
53
  #define XBEE_BAUD { 115200 | 9600 } <= pick ONE value from in here
54
  #define USE_STDIO
55
  
56
  Note: If you enable USE_STDIO, the first init function that is called will 
57
  automatically be linked to stdin, stdout, and stderr.  To use the baud rate 
58
  commands, add something like the following to your code:
59
  
60
  #define FOO_BAUD 9600
61
  
62
  **UNLESS YOU KNOW WHAT YOU ARE DOING, PLEASE DO NOT CHANGE THIS FILE**
63
  Many, many other people use this file in their code.  If you change it, you will
64
  probably break all of their nice code.  You should not need to change anything in
65
  here, except to accomodate new hardware.
66
*/
67

  
68
#ifndef _SERIAL_H
69
#define _SERIAL_H
70

  
71
#include <inttypes.h>
72
#include <avr/pgmspace.h>
73

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

  
83
// if no baud rate is defined for usb, default is set here
84
#ifndef USB_BAUD
85
/** @brief the USB baud rate **/
86
#define USB_BAUD 115200
87
#endif
88

  
89
/** @brief Initialize the USB **/
90
void usb_init(void);
91
/** @brief Print a character to USB **/
92
int usb_putc(char c);
93
/** @brief Read a character from USB **/
94
int usb_getc(void);
95
/** @brief Read a character from USB without blocking **/
96
int usb_getc_nb(char *c);
97
/** @brief Print a string to USB **/
98
int usb_puts(char *s);
99
/** @brief Print a string from program space to USB **/
100
void usb_puts_P (PGM_P s);
101
/** @brief Print an integer to USB **/
102
int usb_puti(int value);
103
/** @brief Determine a hexadecimal digit **/
104
uint8_t hex_digit (uint8_t value);
105
/** @brief Print a fixed width hexadecimal representation to USB **/
106
void usb_puth16 (uint16_t value);
107
/** @brief Print a fixed width hexadecimal representation to USB **/
108
void usb_puth8(uint8_t value);
109
/** @brief Alias for usb_puth16 **/
110
static inline void usb_puth (uint16_t value) { usb_puth16 (value); };
111

  
112

  
113
/** @} **/ //end addtogroup
114

  
115
/**
116
 * @defgroup xbee XBee Input / Output
117
 * @brief Functions for XBee input / output
118
 *
119
 * Low level functions for XBee input and output.
120
 *
121
 * @{
122
 **/
123

  
124
// if no baud rate is defined for usb, default is set here
125

  
126
// if no baud rate is defined for xbee, default is set here
127
#ifndef XBEE_BAUD
128
/** @brief the XBee baud rate **/
129
#define XBEE_BAUD 9600
130
#endif
131

  
132
/** @brief Initialize the XBee **/
133
void xbee_init(void);
134
/** @brief Print a character to the XBee **/
135
int xbee_putc(char c);
136
/** @brief Read a character from the XBee **/
137
int xbee_getc(void);
138
/** @brief Read a character from the XBee without blocking **/
139
int xbee_getc_nb(char *c);
140

  
141

  
142

  
143
/** @} **/ //end addtogroup
144

  
145
#endif
146

  
demos/john/lib/include/libdragonfly/eeprom.h
1
/**
2
 * @file eeprom.h
3
 * @brief handles eeprom storage for persistent data
4
 *
5
 * Contains functions and definitions for reading and writing to eeprom
6
 *
7
 * @author Colony Project, Brad Neuman
8
 */
9
 
10
 #ifndef _EEPROM_H_
11
 #define _EEPROM_H_
12
 
13
 #define EEPROM_ROBOT_ID_ADDR 0x10
14
 #define EEPROM_BOM_TYPE_ADDR 0x14
15
 
16
 /** @brief store a byte to eeproem
17
  *  @return 0 if success, nonzero on failure
18
  */
19
 int eeprom_put_byte(unsigned int addr, unsigned char byte);
20
 
21
 /** @brief reads a byte from eeprom
22
  *
23
  *  Pass it thge address and a pointer to a byte where the byte at the
24
  *  address will be stored
25
  *
26
  *  @return 0 if successful (byte is set to the eeprom value at addr), 
27
  *  nonzero if there was a problem
28
   */
29
 int eeprom_get_byte(unsigned int addr, unsigned char *byte);
30
 
31
 /** @brief get stored robot ID
32
  *
33
  *  checks that EEPROM has been programed with an ID and returns it
34
  *
35
  *  @return the robot id, if it is stored. If it returns 0xFF it is probably invalid
36
  */
37
 unsigned char get_robotid(void);
38
  
39
   /** @brief get stored robot ID
40
  *
41
  * checks that EEPROM has been programed with an BOM type and returns it
42
  *
43
  *  @return the robot bom type as defined in bom.h, if it is stored. If it returns 0xFF it is probably invalid
44
  */
45
 unsigned char get_bom_type(void);
46
 
47
 #endif
demos/john/lib/include/libdragonfly/dragonfly_defs.h
1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

  
26

  
27
/**
28
 * @file dragonfly_def.h
29
 * @brief Contains definitions for dragonfly library
30
 * 
31
 * Should be included in all dragonfly library source files.
32
 * Does not need to be included by user programs.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _DRAGONFLY_DEFS_H_
38
#define _DRAGONFLY_DEFS_H_
39

  
40
/**
41
 * @addtogroup dragonfly
42
 * @{
43
 **/
44
 
45
//return value definitions
46
/** @brief Error code for init failure **/
47
#define ERROR_INIT_FAILED 1
48
/** @brief Error code for duplicate init calls **/
49
#define ERROR_INIT_ALREADY_INITD 2
50
/** @brief Error code for not calling init **/
51
#define ERROR_LIBRARY_NOT_INITD 3
52

  
53
// Configuration definitions
54
/** @brief Initialize analog **/
55
#define ANALOG 0x01
56
/** @brief Initialize serial communications **/
57
#define SERIAL 0x02
58
/** @brief Initialize USB communications **/
59
#define USB    0x02
60
/** @brief Initialize communications **/
61
#define COMM   0x02
62
/** @brief Initialize the orb **/
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff