Revision 1694

View differences:

demos/hunter_prey_john/Makefile
1
# This is the root makefile
2
#
3
# Make global makefile changes here
4
#
5
###################################
6

  
7
# Relative path to the root directory (containing lib directory)
8
ifndef COLONYROOT
9
COLONYROOT := .
10
else
11
COLONYROOT := $(COLONYROOT)
12
endif
13

  
14
# Hey Emacs, this is a -*- makefile -*-
15
#----------------------------------------------------------------------------
16
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al.
17
#
18
# Released to the Public Domain
19
#
20
# Additional material for this makefile was written by:
21
# Peter Fleury
22
# Tim Henigan
23
# Colin O'Flynn
24
# Reiner Patommel
25
# Markus Pfaff
26
# Sander Pool
27
# Frederik Rouleau
28
#
29
#----------------------------------------------------------------------------
30
# On command line:
31
#
32
# make all = Make software.
33
#
34
# make clean = Clean out built project files.
35
#
36
# make coff = Convert ELF to AVR COFF.
37
#
38
# make extcoff = Convert ELF to AVR Extended COFF.
39
#
40
# make program = Download the hex file to the device, using avrdude.
41
#                Please customize the avrdude settings below first!
42
#
43
# make debug = Start either simulavr or avarice as specified for debugging,
44
#              with avr-gdb or avr-insight as the front end for debugging.
45
#
46
# make library = Build the library, then make software
47
#
48
# make demo = copy this directory and all subdirectories to the demos folder
49
#
50
# make filename.s = Just compile filename.c into the assembler code only.
51
#
52
# make filename.i = Create a preprocessed source file for use in submitting
53
#                   bug reports to the GCC project.
54
#
55
# To rebuild project do "make clean" then "make all".
56
#----------------------------------------------------------------------------
57

  
58
#if you want your code to work on the Firefly++ and not Firefly+
59
#then add the -DFFPP line to CDEFS
60
CDEFS =
61
#-DFFPP
62

  
63
# MCU name
64
MCU = atmega128
65

  
66
# Processor frequency.
67
#     This will define a symbol, F_CPU, in all source code files equal to the
68
#     processor frequency. You can then use this symbol in your source code to
69
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
70
#     automatically to create a 32-bit value in your source code.
71
F_CPU = 8000000
72

  
73
# Output format. (can be srec, ihex, binary)
74
FORMAT = ihex
75

  
76
# List C source files here. (C dependencies are automatically generated.)
77
SRC = $(wildcard *.c)
78

  
79
# List Assembler source files here.
80
#     Make them always end in a capital .S.  Files ending in a lowercase .s
81
#     will not be considered source files but generated files (assembler
82
#     output from the compiler), and will be deleted upon "make clean"!
83
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
84
#     it will preserve the spelling of the filenames, and gcc itself does
85
#     care about how the name is spelled on its command-line.
86
ASRC =
87

  
88
# Optimization level, can be [0, 1, 2, 3, s].
89
#     0 = turn off optimization. s = optimize for size.
90
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
91
OPT = s
92

  
93
# Debugging format.
94
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
95
#     AVR Studio 4.10 requires dwarf-2.
96
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
97
DEBUG =
98

  
99
# Compiler flag to set the C Standard level.
100
#     c89   = "ANSI" C
101
#     gnu89 = c89 plus GCC extensions
102
#     c99   = ISO C99 standard (not yet fully implemented)
103
#     gnu99 = c99 plus GCC extensions
104
CSTANDARD = -std=gnu99
105

  
106
# Place -D or -U options here
107
CDEFS += -DF_CPU=$(F_CPU)UL
108
CDEFS += -DFFP
109
# for wireless library
110
ifdef USE_WIRELESS
111
	CDEFS += -DROBOT
112
endif
113

  
114
# Place -I, -L options here
115
CINCS = -I$(COLONYROOT)/lib/include/libdragonfly
116
CINCS += -L$(COLONYROOT)/lib/bin
117
ifdef USE_WIRELESS
118
  CINCS += -I$(COLONYROOT)/lib/include/libwireless
119
endif
120

  
121
#---------------- Compiler Options ----------------
122
#  -g*:          generate debugging information
123
#  -O*:          optimization level
124
#  -f...:        tuning, see GCC manual and avr-libc documentation
125
#  -Wall...:     warning level
126
#  -Wa,...:      tell GCC to pass this to the assembler.
127
#    -adhlns...: create assembler listing
128
CFLAGS =
129
# CFLAGS = -g$(DEBUG)
130
CFLAGS += $(CDEFS) $(CINCS)
131
CFLAGS += -O$(OPT)
132
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
133
CFLAGS += -Wall -Wstrict-prototypes
134
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
135
CFLAGS += $(CSTANDARD)
136

  
137
#---------------- Assembler Options ----------------
138
#  -Wa,...:   tell GCC to pass this to the assembler.
139
#  -ahlms:    create listing
140
#  -gstabs:   have the assembler create line number information; note that
141
#             for use in COFF files, additional information about filenames
142
#             and function names needs to be present in the assembler source
143
#             files -- see avr-libc docs [FIXME: not yet described there]
144
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
145

  
146

  
147
#---------------- Library Options ----------------
148
# Minimalistic printf version
149
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
150

  
151
# Floating point printf version (requires MATH_LIB = -lm below)
152
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
153

  
154
# If this is left blank, then it will use the Standard printf version.
155
PRINTF_LIB =
156
#PRINTF_LIB = $(PRINTF_LIB_MIN)
157
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
158

  
159

  
160
# Minimalistic scanf version
161
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
162

  
163
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
164
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
165

  
166
# If this is left blank, then it will use the Standard scanf version.
167
SCANF_LIB =
168
#SCANF_LIB = $(SCANF_LIB_MIN)
169
#SCANF_LIB = $(SCANF_LIB_FLOAT)
170

  
171
MATH_LIB = -lm
172

  
173
#---------------- External Memory Options ----------------
174

  
175
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
176
# used for variables (.data/.bss) and heap (malloc()).
177
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
178

  
179
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
180
# only used for heap (malloc()).
181
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
182

  
183
EXTMEMOPTS =
184

  
185
#---------------- Linker Options ----------------
186
#  -Wl,...:     tell GCC to pass this to linker.
187
#    -Map:      create map file
188
#    --cref:    add cross reference to  map file
189
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
190
LDFLAGS += $(EXTMEMOPTS)
191
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
192
ifdef USE_WIRELESS
193
	LDFLAGS += -lwireless
194
endif
195
LDFLAGS += -ldragonfly
196

  
197

  
198

  
199
#---------------- Programming Options (avrdude) ----------------
200

  
201
# Programming hardware: alf avr910 avrisp bascom bsd
202
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
203
#
204
# Type: avrdude -c ?
205
# to get a full listing.
206
#
207
AVRDUDE_PROGRAMMER = avrisp
208

  
209
# programmer connected to serial device
210

  
211
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
212
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
213

  
214

  
215
# Uncomment the following if you want avrdude's erase cycle counter.
216
# Note that this counter needs to be initialized first using -Yn,
217
# see avrdude manual.
218
#AVRDUDE_ERASE_COUNTER = -y
219

  
220
# Uncomment the following if you do /not/ wish a verification to be
221
# performed after programming the device.
222
#AVRDUDE_NO_VERIFY = -V
223

  
224
# Increase verbosity level.  Please use this when submitting bug
225
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
226
# to submit bug reports.
227
#AVRDUDE_VERBOSE = -v -v
228

  
229
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
230
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
231
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
232
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
233

  
234
#don't check for device signature
235
AVRDUDE_FLAGS += -F
236

  
237

  
238

  
239
#---------------- Debugging Options ----------------
240

  
241
# For simulavr only - target MCU frequency.
242
DEBUG_MFREQ = $(F_CPU)
243

  
244
# Set the DEBUG_UI to either gdb or insight.
245
# DEBUG_UI = gdb
246
DEBUG_UI = insight
247

  
248
# Set the debugging back-end to either avarice, simulavr.
249
DEBUG_BACKEND = avarice
250
#DEBUG_BACKEND = simulavr
251

  
252
# GDB Init Filename.
253
GDBINIT_FILE = __avr_gdbinit
254

  
255
# When using avarice settings for the JTAG
256
JTAG_DEV = /dev/com1
257

  
258
# Debugging port used to communicate between GDB / avarice / simulavr.
259
DEBUG_PORT = 4242
260

  
261
# Debugging host used to communicate between GDB / avarice / simulavr, normally
262
#     just set to localhost unless doing some sort of crazy debugging when
263
#     avarice is running on a different computer.
264
DEBUG_HOST = localhost
265

  
266

  
267

  
268
#============================================================================
269

  
270

  
271
# Define programs and commands.
272
SHELL = sh
273
CC = avr-gcc
274
OBJCOPY = avr-objcopy
275
OBJDUMP = avr-objdump
276
SIZE = avr-size
277
NM = avr-nm
278
AVRDUDE = avrdude
279
REMOVE = rm -f
280
REMOVEDIR = rm -rf
281
COPY = cp
282
WINSHELL = cmd
283

  
284

  
285
# Define Messages
286
# English
287
MSG_ERRORS_NONE = Errors: none
288
MSG_BEGIN = -------- begin --------
289
MSG_END = --------  end  --------
290
MSG_SIZE_BEFORE = Size before:
291
MSG_SIZE_AFTER = Size after:
292
MSG_COFF = Converting to AVR COFF:
293
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
294
MSG_FLASH = Creating load file for Flash:
295
MSG_EEPROM = Creating load file for EEPROM:
296
MSG_EXTENDED_LISTING = Creating Extended Listing:
297
MSG_SYMBOL_TABLE = Creating Symbol Table:
298
MSG_LINKING = Linking:
299
MSG_COMPILING = Compiling:
300
MSG_ASSEMBLING = Assembling:
301
MSG_CLEANING = Cleaning project:
302
MSG_LIBRARY_BUILD = Building library:
303
MSG_LIBRARY_CHECK = Checking if we need to rebuild the library:
304

  
305

  
306

  
307
# Define all object files.
308
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
309

  
310
# Define all listing files.
311
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst)
312

  
313

  
314
# Compiler flags to generate dependency files.
315
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
316

  
317

  
318
# Combine all necessary flags and optional flags.
319
# Add target processor to flags.
320
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
321
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
322

  
323

  
324

  
325

  
326

  
327
# Default target.
328
all: begin gccversion lib sizebefore build sizeafter checksize end
329

  
330
build: elf hex eep lss sym
331

  
332
elf: $(TARGET).elf
333
hex: $(TARGET).hex
334
eep: $(TARGET).eep
335
lss: $(TARGET).lss
336
sym: $(TARGET).sym
337

  
338

  
339

  
340
# Eye candy.
341
# AVR Studio 3.x does not check make's exit code but relies on
342
# the following magic strings to be generated by the compile job.
343
begin:
344
	@echo
345
	@echo $(MSG_BEGIN)
346

  
347
end:
348
	@echo $(MSG_END)
349
	@echo
350

  
351

  
352
# Display size of file.
353
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
354
ELFSIZE = $(SIZE) -A $(TARGET).elf
355
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
356

  
357
# Check RAM size (make sure under 4 kB)
358
AWK = $(shell if uname -s |grep -i w32 >/dev/null; then echo 'gawk'; else echo 'awk'; fi)
359
DATASIZE = avr-size -A main.elf | grep 'data' | $(AWK) '{ print $$2 }' > 1.tmp
360
BSSSIZE = avr-size -A main.elf | grep 'bss' | $(AWK) '{ print $$2 }' > 2.tmp
361
ADD = expr `cat 1.tmp` + `cat 2.tmp` > 3.tmp
362
CLEANSIZE = rm 1.tmp 2.tmp 3.tmp
363
checksize:
364
	@$(DATASIZE)
365
	@$(BSSSIZE)
366
	@$(ADD)
367
	@if test `cat 3.tmp` -gt 4096; \
368
	then echo "RAM size exceeded.  Make .data or .bss smaller.";echo;exit 1; \
369
	else echo ".data and .bss size fine";echo; fi
370
	@$(CLEANSIZE)
371

  
372
# Display size before
373
sizebefore:
374
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
375
	$(AVRMEM) 2>/dev/null; echo; fi
376

  
377
# Display size after
378
sizeafter:
379
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
380
	$(AVRMEM) 2>/dev/null; echo; fi
381

  
382

  
383

  
384
# Display compiler version information.
385
gccversion :
386
	@$(CC) --version
387
  
388
  
389
# Build the library
390
library:
391
	@echo $(MSG_LIBRARY_BUILD)
392
	make clean -C $(COLONYROOT)/projects/libdragonfly
393
	make dist -C $(COLONYROOT)/projects/libdragonfly
394
ifdef USE_WIRELESS
395
	make clean -C $(COLONYROOT)/projects/libwireless/lib
396
	make dist -C $(COLONYROOT)/projects/libwireless/lib
397
endif
398

  
399
# Check if library needs to be built
400
lib:
401
	@echo $(MSG_LIBRARY_CHECK)
402
	make dist -C $(COLONYROOT)/projects/libdragonfly
403
ifdef USE_WIRELESS
404
	make dist -C $(COLONYROOT)/projects/libwireless/lib
405
endif
406

  
407

  
408
# Program the device.
409
program: $(TARGET).hex $(TARGET).eep
410
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
411

  
412

  
413
# Generate avr-gdb config/init file which does the following:
414
#     define the reset signal, load the target file, connect to target, and set
415
#     a breakpoint at main().
416
gdb-config:
417
	@$(REMOVE) $(GDBINIT_FILE)
418
	@echo define reset >> $(GDBINIT_FILE)
419
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
420
	@echo end >> $(GDBINIT_FILE)
421
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
422
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
423
ifeq ($(DEBUG_BACKEND),simulavr)
424
	@echo load  >> $(GDBINIT_FILE)
425
endif
426
	@echo break main >> $(GDBINIT_FILE)
427

  
428
debug: gdb-config $(TARGET).elf
429
ifeq ($(DEBUG_BACKEND), avarice)
430
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
431
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
432
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
433
	@$(WINSHELL) /c pause
434

  
435
else
436
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
437
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
438
endif
439
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
440

  
441

  
442

  
443

  
444
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
445
COFFCONVERT=$(OBJCOPY) --debugging \
446
--change-section-address .data-0x800000 \
447
--change-section-address .bss-0x800000 \
448
--change-section-address .noinit-0x800000 \
449
--change-section-address .eeprom-0x810000
450

  
451

  
452
coff: $(TARGET).elf
453
	@echo
454
	@echo $(MSG_COFF) $(TARGET).cof
455
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
456

  
457

  
458
extcoff: $(TARGET).elf
459
	@echo
460
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
461
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
462

  
463

  
464

  
465
# Create final output files (.hex, .eep) from ELF output file.
466
%.hex: %.elf
467
	@echo
468
	@echo $(MSG_FLASH) $@
469
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
470

  
471
%.eep: %.elf
472
	@echo
473
	@echo $(MSG_EEPROM) $@
474
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
475
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
476

  
477
# Create extended listing file from ELF output file.
478
%.lss: %.elf
479
	@echo
480
	@echo $(MSG_EXTENDED_LISTING) $@
481
	$(OBJDUMP) -h -S $< > $@
482

  
483
# Create a symbol table from ELF output file.
484
%.sym: %.elf
485
	@echo
486
	@echo $(MSG_SYMBOL_TABLE) $@
487
	$(NM) -n $< > $@
488

  
489

  
490

  
491
# Link: create ELF output file from object files.
492
.SECONDARY : $(TARGET).elf
493
.PRECIOUS : $(OBJ)
494
%.elf: $(OBJ)
495
	@echo
496
	@echo $(MSG_LINKING) $@
497
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
498

  
499

  
500
# Compile: create object files from C source files.
501
%.o : %.c
502
	@echo
503
	@echo $(MSG_COMPILING) $<
504
	$(CC) -c $(ALL_CFLAGS) $< -o $@
505

  
506

  
507
# Compile: create assembler files from C source files.
508
%.s : %.c
509
	$(CC) -S $(ALL_CFLAGS) $< -o $@
510

  
511

  
512
# Assemble: create object files from assembler source files.
513
%.o : %.S
514
	@echo
515
	@echo $(MSG_ASSEMBLING) $<
516
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
517

  
518
# Create preprocessed source for use in sending a bug report.
519
%.i : %.c
520
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
521

  
522

  
523
# Target: clean project.
524
clean: begin clean_list end
525

  
526
clean_list :
527
	@echo
528
	@echo $(MSG_CLEANING)
529
	$(REMOVE) $(TARGET).hex
530
	$(REMOVE) $(TARGET).eep
531
	$(REMOVE) $(TARGET).cof
532
	$(REMOVE) $(TARGET).elf
533
	$(REMOVE) $(TARGET).map
534
	$(REMOVE) $(TARGET).sym
535
	$(REMOVE) $(TARGET).lss
536
	$(REMOVE) $(OBJ)
537
	$(REMOVE) $(LST)
538
	$(REMOVE) $(SRC:.c=.s)
539
	$(REMOVE) $(SRC:.c=.d)
540
	$(REMOVEDIR) .dep
541

  
542

  
543

  
544
# Include the dependency files.
545
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
546

  
547

  
548
# Listing of phony targets.
549
.PHONY : all begin finish end sizebefore sizeafter gccversion \
550
build elf hex eep lss sym coff extcoff \
551
clean clean_list program debug gdb-config
552

  
553
# copy to demo folder
554
DEMO_NAME := $(shell sh -c 'echo $${PWD\#\#*/}')
555
demo:
556
	@echo "Copying to demo folder..."
557
	@echo "$(DEMO_NAME)"
558
	@make clean
559
	@mkdir $(COLONYROOT)/../demos/$(DEMO_NAME)
560
	@mkdir $(COLONYROOT)/../demos/$(DEMO_NAME)/behavior
561
	@mkdir $(COLONYROOT)/../demos/$(DEMO_NAME)/projects
562
#	@mkdir $(COLONYROOT)/../demos/$(DEMO_NAME)/lib
563
	@cp -R * $(COLONYROOT)/../demos/$(DEMO_NAME)/behavior/
564
	@cp -R $(COLONYROOT)/code/projects/libdragonfly $(COLONYROOT)/../demos/$(DEMO_NAME)/projects/
565
	@cp -R $(COLONYROOT)/code/projects/libwireless $(COLONYROOT)/../demos/$(DEMO_NAME)/projects/
566
	@cp -R $(COLONYROOT)/code/lib $(COLONYROOT)/../demos/$(DEMO_NAME)
567
	@cp $(COLONYROOT)/../demos/inerMakefile $(COLONYROOT)/../demos/$(DEMO_NAME)/Makefile
568

  
demos/hunter_prey_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/hunter_prey_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/hunter_prey_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/hunter_prey_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/hunter_prey_john/lib/include/libwireless/sensor_matrix.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
 * @file sensor_matrix.h
28
 * @brief Definitions for sensor matrices
29
 *
30
 * Contains functions and declarations for using sensor matrices.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef SENSOR_MATRIX_H
36
#define SENSOR_MATRIX_H
37

  
38

  
39
/**
40
 * @defgroup sensormatrix Sensor Matrix
41
 * @brief the robot sensor matrix
42
 *
43
 * These functions and structures are used for localization
44
 * to determine the relative directions of robots.
45
 *
46
 * @{
47
 **/
48

  
49
#define MAXIMUM_XBEE_ID		0x10
50
#define READING_UNKNOWN		0xFF
51

  
52
/**
53
 * @struct SensorMatrix
54
 *
55
 * A sensor matrix.
56
 **/
57
//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
58
// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
59
// Thus, pointers should be first, followed by int, followed by char.
60
typedef struct
61
{
62
	/**
63
	 * The number of robots in the token ring.
64
	 **/
65
	int numJoined;
66
	/**
67
	 * The element representing a robot is true if that robot
68
	 * is in the token ring and false otherwise.
69
	 **/
70
	unsigned char joined[MAXIMUM_XBEE_ID];
71

  
72
	// on the bayboard, we don't include the matrix to save memory.
73
#ifndef BAYBOARD
74
	/**
75
	 * The matrix. Each row represents the readings of one
76
	 * robot.
77
	 **/
78
	unsigned char matrix[MAXIMUM_XBEE_ID][MAXIMUM_XBEE_ID];
79
#endif
80
} SensorMatrix;
81

  
82
/**@brief Create a sensor matrix **/
83
void sensor_matrix_create(void);
84
/**@brief Set a reading in a sensor matrix **/
85
void sensor_matrix_set_reading(int observer, int robot, int reading);
86
/**@brief Get a reading in a sensor matrix **/
87
int sensor_matrix_get_reading(int observer, int robot);
88
/**@brief Set whether the robot is in the token ring **/
89
void sensor_matrix_set_in_ring(int robot, int in);
90
/**@brief Get whether the robot is in the sensor ring **/
91
int sensor_matrix_get_in_ring(int robot);
92
/**@brief Get the number of robots which have joined the token ring **/
93
int sensor_matrix_get_joined(void);
94
/**@brief Get the maximum size of the sensor matrix **/
95
int sensor_matrix_get_size(void);
96

  
97
/** @} **/ //end defgroup
98

  
99

  
100
#endif
101

  
demos/hunter_prey_john/lib/include/libwireless/wireless.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
 * @file wireless.h
28
 * @brief Contains definitions for the wireless library.
29
 *
30
 * Contains functions for the wireless library.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WIRELESS_H
36
#define WIRELESS_H
37

  
38
//Note: If this is raised above 16, we will need to do
39
//something about frame numbers for TX Status packets.
40
/**
41
 * The maximum number of packet groups.
42
 **/
43
//TODO: a PacketGroupHandler is at least 10 bytes (I don't know if function pointers are 2 bytes
44
// or 4 bytes).  That means that in the c file, your array of packet groups is at least 160 bytes.
45
// Normally that might be fine (the robot's avr chips have 4k SRAM), but austin's chip only has
46
// 1k SRAM, so if this number can be reduced or if the size of the struct could be reduced, that would be a plus.
47
#define WL_MAX_PACKET_GROUPS 16
48

  
49
/**
50
 * @defgroup wireless Wireless
51
 * @brief Wireless definitions.
52
 *
53
 * Contains functions and definitions for dealing with wireless functionality.<br><br>
54
 *
55
 * The wireless library provides a modular method for dealing with
56
 * wireless packets, by allowing packet groups to be registered.
57
 * A packet group is a collection of packets which share a packet
58
 * group code. Each packet in the group also has a type. A packet
59
 * group code and type are sent with each packet. When a packet
60
 * with a group code registered in the wireless library is
61
 * received, the corresponding event handler is called. The
62
 * event handler uses the packet type and other information
63
 * stored in the packet to respond.<br><br>
64
 *
65
 * This architecture allows different wireless functionality to be
66
 * defined and handled separately, making it simpler and more
67
 * efficient to take advantage of the XBee's wireless functionality.
68
 *
69
 * @{
70
 **/
71

  
72
/**
73
 * @struct PacketGroupHandler
74
 * A PacketGroupHandler represents a packet group, and is used to
75
 * register a packet group with the wireless library. It contains
76
 * handlers for various events which can occur related to a packet
77
 * group.
78
 **/
79
//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
80
// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
81
// Thus, pointers should be first, followed by int, followed by char.
82
typedef struct
83
{
84
	/**
85
	 * The group code for this packet group. This number
86
	 * must be unique. The maximum number of packet groups
87
	 * is defined by WL_MAX_PACKET_GROUPS.
88
	 **/
89
  //TODO: if this number must be less than or equal to WL_MAX_PACKET_GROUPS, don't you only need
90
  // one byte for it and it can be made an unsigned char?
91
	unsigned int groupCode;
92

  
93
	/**
94
	 * Called every half second (not in interrupt,
95
	 * but in wl_do).
96
	 **/
97
	void (*timeout_handler) (void);
98

  
99
	/**
100
	 * Called when a transmit status packet is received
101
	 * from the XBee where the first four bits of the frame
102
	 * are  the group code.
103
	 *
104
	 * @param frame the last four bits of the frame
105
	 * @param received is true if we received an ack, 0 if
106
	 * we did not.
107
	 **/
108
	void (*handle_response) (int frame, int received);
109

  
110
	/**
111
	 * Called when we receive a packet from this group.
112
	 *
113
	 * @param type the packet type
114
	 * @param source the 16-bit address of the XBee this
115
	 * packet was sent from
116
	 * @param packet the packet received
117
	 * @param length the length of the packet
118
	 **/
119
	void (*handle_receive) (char type, int source, unsigned char* packet, int length);
120

  
121
	/**
122
	 * Called for any cleanup when the network is turned off.
123
	 **/
124
	void (*unregister) (void);
125

  
126
} PacketGroupHandler;
127

  
128
/**@brief Initialize the wireless library **/
129
int wl_init(void);
130
/**@brief Uninitialize the wireless library **/
131
void wl_terminate(void);
132
/**@brief Perform wireless library functionality **/
133
void wl_do(void);
134
/**@brief Register a packet group with the wireless library **/
135
void wl_register_packet_group(PacketGroupHandler* h);
136
/**@brief Unregister a packet group with the wireless library **/
137
void wl_unregister_packet_group(PacketGroupHandler* h);
138

  
139
/**@brief Send a packet to a specific robot in any PAN **/
140
int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame);
141
/**@brief Send a packet to a specific robot in our PAN **/
142
int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame);
143
/**@brief Send a packet to all robots **/
144
int wl_send_global_packet(char group, char type, char* data, int len, char frame);
145
/**@brief Send a packet to all robots in our PAN **/
146
void wl_send_pan_packet(char group, char type, char* data, int len, char frame);
147

  
148
/**@brief Set the PAN we are using **/
149
int wl_set_pan(int pan);
150
/**@brief Get the PAN we are using **/
151
int wl_get_pan(void);
152
/**@brief Set the channel we are using **/
153
int wl_set_channel(int channel);
154
/**@brief Get the channel we are using **/
155
int wl_get_channel(void);
156
/**@brief Get the 16-bit address of the XBee module **/
157
int wl_get_xbee_id(void);
158
/**@brief Set the com port on a computer, undefined on the robot.**/
159
void wl_set_com_port(char* port);
160

  
161
/** @} **/ // end defgroup
162

  
163
#endif
164

  
demos/hunter_prey_john/lib/include/libwireless/wl_token_ring.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
 * @file wl_token_ring.h
28
 * @brief Declarations for the token ring packet group
29
 * 
30
 * Contains declarations for the token ring packet group.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WL_TOKEN_RING_H
36
#define WL_TOKEN_RING_H
37

  
38
/**
39
 * @defgroup tokenring Token Ring
40
 * @brief Wireless library token ring implementation
41
 *
42
 * This packet group is used to form a token ring, which
43
 * keeps track of the relative directions of the robots
44
 * from one another.
45
 *
46
 * @{
47
 **/
48

  
49
/**@brief Register the token ring group with the wireless library.**/
50
int wl_token_ring_register(void);
51
/**@brief Unregister the token ring group with the wirelss library.**/
52
void wl_token_ring_unregister(void);
53
/**@brief Set the functions called to turn the bom on and off.**/
54
void wl_token_ring_set_bom_functions(void (*on_function) (void), void (*off_function) (void),
55
  int (*max_bom_function) (void));
56

  
57
/**@brief Join the token ring **/
58
int wl_token_ring_join(void);
59
/**@brief Leave the token ring **/
60
void wl_token_ring_leave(void);
61

  
62
/**@brief Return the number of robots in the token ring **/
63
int wl_token_get_robots_in_ring(void);
64
/**@brief Return whether a given robot is in the token ring **/
65
int wl_token_is_robot_in_ring(int robot);
66

  
67
/**@brief Begin iterating through robots in the token ring **/
68
void wl_token_iterator_begin(void);
69
/**@brief Returns whether there are more robots to iterate through **/
70
int wl_token_iterator_has_next(void);
71
/**@brief Returns the ID of the next robot in the token ring **/
72
int wl_token_iterator_next(void);
73

  
74
/**@brief Return the latest BOM reading between two robots **/
75
int wl_token_get_sensor_reading(int source, int dest);
76
/**@brief Return the latest BOM reading between us and another robot **/
77
int wl_token_get_my_sensor_reading(int dest);
78
/**@brief Return the number of robots in the sensor matrix.*/
79
int wl_token_get_num_robots(void);
80
/**@brief Return the number of non-null elements in the sensor matrix*/
81
int wl_token_get_matrix_size(void);
82

  
83
/** @} **/ //end token ring group
84

  
85
#endif
demos/hunter_prey_john/lib/include/libwireless/wl_basic.h
1
/**
2
 * @file wl_basic.h
3
 * @brief High Level Wireless Packet Sending-Receiving Functions
4
 *
5
 * Abstracted wireless functionality for sending and receiving packets
6
 *
7
 * @author Christopher Mar, Colony Project, CMU Robotics Club
8
 **/
9

  
10
/**
11
 * @defgroup wl_basic Wireless Basic
12
 * @brief Wireless abstraction for easily sending and receing packets.
13
 *
14
 * A high level abstraction of the wireless library.
15
 *
16
 * This will allow you to easily send and receive packets.
17
 *
18
 * @{
19
 **/
20

  
21
#ifndef WL_BASIC_H
22
#define WL_BASIC_H
23

  
24
#include "wireless.h"
25

  
26
/** @brief default wireless group for basic sending and receiving packets **/
27
#define WL_BASIC_GROUP 8
28

  
29
/** @brief PacketGroupHandler struct for Basic Group **/
30
PacketGroupHandler wl_basic_group_handler;
31

  
32
/**
33
 * @brief struct that contains relevant packet information
34
 **/
35
struct PacketInfo {
36
    char new_flag;
37
    char type;
38
    int source;
39
    unsigned char* data;
40
    int length;
41
};
42

  
43
/**
44
 * @brief current packet information, correct after wl_basic_do()
45
 **/
46
struct PacketInfo current_packet;
47

  
48
/** @brief init wireless for Basic Group **/
49
int wl_basic_init( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
50
/** @brief init wireless for Basic Group with default packet handling **/
51
int wl_basic_init_default( void );
52
/** @brief internal function to register a packet handler function **/
53
void wl_basic_register_handler( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
54
/** @brief send a packet to a single robot in Basic Group **/
55
void wl_basic_send_robot_packet( char type, char* data, int len, int dest );
56
/** @brief send a packet to all robots in Basic Group **/
57
void wl_basic_send_global_packet( char type, char* data, int len );
58
/** @brief internal default packet handler if none is specified on init **/
59
void wl_basic_packet_receive_handler( char type, int source, unsigned char* packet, int length );
60
/** @brief wrapper for wl_do() to return packet data buffer **/
61
unsigned char* wl_basic_do_default( int *length );
62
/** @} **/ // end defgroup
63

  
64
#endif
65

  
demos/hunter_prey_john/lib/include/libwireless/wl_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
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff