Project

General

Profile

Revision 1843

Added the traffic_navigation directory to projects in trunk, and inserted my preliminary main function. As of now, it relies on the linefollowing code in the other project directory.

View differences:

trunk/code/projects/traffic_navigation/main.c
1
/*
2
 * main.c for Traffic Navigation
3
 * Runs the highest level behavior for the Dynamic Traffic Navigation (DTM) SURG
4
 *
5
 * Author: Colony Project, CMU Robotics Club
6
 */
7

  
8
#include <dragonfly_lib.h>
9
#include <wl_basic.h>
10
#include "../linefollowing/lineFollow.h"
11

  
12
/*States*/
13
#define SROAD 0
14
#define SINTERSECTION 10
15
#define SHIGHWAY 20
16

  
17
/*Sign Codes
18
 * bitwise OR labels to create a barcode or read one
19
 * There should be macros to extract these probably
20
 * The bits will be stored in some variable (char or short)
21
 * Bits if road: ? ? ? NAME NAME NAME TYPE CROAD
22
 * Bits if intersection: ? ? ? ? DIR DIR #WAYS CINTERSECTION
23
 */
24
#define CROAD 0x0 //0b
25
#define CINTERSECTION 0x1 //1b
26
#define CNORMALROAD 0x0 //00b
27
#define CHIGHWAYROAD 0x2 //10b
28
#define C4WAY 0x0 //00b
29
#define C3WAY 0x2 //10b
30
#define CNORTH 0x0 //0000b
31
#define CEAST 0x4 //0100b
32
#define CSOUTH 0x8 //1000b
33
#define CWEST 0x12 //1100b
34

  
35

  
36
int main (void) {
37

  
38
	int state, sign;
39

  
40
	/* Initialize the dragonfly boards, the xbee, encoders, lineFollowing */
41
	dragonfly_init(ALL_ON);
42
	xbee_init();
43
	encoders_init();
44
	lineFollow_init();
45
	
46
	sign = 0;
47
	
48
	while (1) {
49
		/*DTM Finite State Machine*/
50
		switch(state){
51
		case SROAD:/*Following a normal road*/
52
			linefollow();
53
			//other road behaviors
54
				//tailgating?
55
			//read barcode
56
			if(sign & CINTERSECTION){
57
				state = SINTERSECTION;
58
			}
59
			break;
60
		case SINTERSECTION:/*Entering, and in intersection*/
61
			//Intersection behaviors
62
				//queueing
63
				//no-stop?
64
			//check wireless
65
			//read barcode
66
			if(!(sign & CINTERSECTION)){
67
				if(sign & CHIGHWAYROAD){
68
					state = SHIGHWAY;
69
				}else{
70
					state = SROAD;
71
				}
72
			}
73
			break;
74
		case SHIGHWAY:/*On highway*/
75
			linefollow();
76
			//highway behaviors
77
				//merging
78
				//passing
79
			//read barcode
80
			break;
81
		default:
82
			usb_puts("I got stuck in an unknown state! My state is ");
83
			usb_puti(state);
84
		}
85
	}
86

  
87
}
trunk/code/projects/traffic_navigation/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

Also available in: Unified diff