Revision 481
moved robot code that we prob don't even use
trunk/code/projects/colonet/robot/dongle/robot_receiver/lights.h | ||
---|---|---|
1 |
/* |
|
2 |
lights.h |
|
3 |
|
|
4 |
most of this is shamelessly copied from FWR's orb.h (Tom Lauwers and Steven Shamlian) |
|
5 |
|
|
6 |
author: CMU Robotics Club, Colony Project |
|
7 |
|
|
8 |
*/ |
|
9 |
|
|
10 |
#ifndef _LIGHTS_H_ |
|
11 |
#define _LIGHTS_H_ |
|
12 |
|
|
13 |
//user LED |
|
14 |
#ifdef FFPP |
|
15 |
|
|
16 |
#define USERLED 15 |
|
17 |
#define USERLED1 15 |
|
18 |
#define USERLED2 31 |
|
19 |
|
|
20 |
#else |
|
21 |
|
|
22 |
#define USERLED PING2 |
|
23 |
#define USERLED1 PING2 |
|
24 |
#define USERLED2 PING2 //only have 1 |
|
25 |
|
|
26 |
//LEDs are on bank E |
|
27 |
#define REDLED PE3 |
|
28 |
#define GREENLED PE4 |
|
29 |
#define BLUELED PE5 |
|
30 |
|
|
31 |
#endif |
|
32 |
|
|
33 |
//ORB |
|
34 |
#define RED 0xE0 |
|
35 |
#define ORANGE 0xE8 |
|
36 |
#define YELLOW 0xFC |
|
37 |
#define LIME 0x7C |
|
38 |
#define GREEN 0x1C |
|
39 |
#define CYAN 0x1F |
|
40 |
#define BLUE 0x03 |
|
41 |
#define PINK 0x63 |
|
42 |
#define PURPLE 0x23 |
|
43 |
#define MAGENTA 0xE3 |
|
44 |
#define WHITE 0xFF |
|
45 |
#define ORB_OFF 0x00 |
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
//? |
|
50 |
#define COUNT_START 0x8000 |
|
51 |
|
|
52 |
|
|
53 |
//user LED |
|
54 |
void led_init( void ); |
|
55 |
void led_user(int value); |
|
56 |
|
|
57 |
|
|
58 |
// For function descriptions see orb.c |
|
59 |
void orb_init(void); |
|
60 |
void orb_set(unsigned int red_led, unsigned int green_led, unsigned int blue_led); |
|
61 |
void orb_set_color(int col); |
|
62 |
void orb_disable(void); |
|
63 |
void orb_enable(void); |
|
64 |
|
|
65 |
void orb_set_dio(int red, int green, int blue); |
|
66 |
|
|
67 |
#ifdef FFPP |
|
68 |
int orbs[32]; |
|
69 |
|
|
70 |
//send now |
|
71 |
void orb_set_num(unsigned char num, unsigned int red_led, unsigned int green_led, unsigned int blue_led); |
|
72 |
|
|
73 |
//no send |
|
74 |
void orb_set_num_ns(unsigned char num, unsigned int red_led, unsigned int green_led, unsigned int blue_led); |
|
75 |
|
|
76 |
//force send |
|
77 |
void orb_send(void); |
|
78 |
|
|
79 |
void tlc5940test(void); |
|
80 |
|
|
81 |
void tlc_clock1(int data);//may not need these 2 |
|
82 |
void tlc_clock2(int data); |
|
83 |
|
|
84 |
void tlc_send(void); |
|
85 |
void tlc_latch(void); |
|
86 |
|
|
87 |
|
|
88 |
void tlc5940init(void); |
|
89 |
#endif |
|
90 |
|
|
91 |
#endif |
trunk/code/projects/colonet/robot/dongle/robot_receiver/motor.c | ||
---|---|---|
1 |
/* |
|
2 |
motor.c - Contains functions necessary for activating and driving the |
|
3 |
H-bridge |
|
4 |
|
|
5 |
|
|
6 |
author: Robotics Club, Colony project |
|
7 |
|
|
8 |
much of this is taken from FWR's library, author: Tom Lauwers |
|
9 |
|
|
10 |
*/ |
|
11 |
|
|
12 |
#include "motor.h" |
|
13 |
|
|
14 |
/* |
|
15 |
motor initialization |
|
16 |
initializes both motors |
|
17 |
|
|
18 |
*/ |
|
19 |
void motors_init( void ) { |
|
20 |
|
|
21 |
#ifndef FFPP |
|
22 |
// Configure counter such that we use phase correct |
|
23 |
// PWM with 8-bit resolution |
|
24 |
DDRB |= 0x60; |
|
25 |
|
|
26 |
//timer 1A and 1B |
|
27 |
TCCR1A = 0xA1; |
|
28 |
TCCR1B = 0x04; |
|
29 |
OCR1AH=0; |
|
30 |
OCR1AL=0; |
|
31 |
OCR1BH=0; |
|
32 |
OCR1BL=0; |
|
33 |
#else |
|
34 |
// Configure counter such that we use phase correct |
|
35 |
// PWM with 8-bit resolution at a frequency of |
|
36 |
// PWM is mode 1, Freq = Clock I/O/1024. |
|
37 |
// OC1A and OC1B as pwm. |
|
38 |
OCR1A = 0x00; |
|
39 |
OCR1B = 0x00; |
|
40 |
|
|
41 |
PORTD &= 0x0F; |
|
42 |
DDRD |= 0xF0; |
|
43 |
DDRB |= 0x60; |
|
44 |
|
|
45 |
TCCR1A = 0xA1; |
|
46 |
TCCR1B = 0x05; |
|
47 |
#endif |
|
48 |
} |
|
49 |
|
|
50 |
// The following functions set the motor direction and speed |
|
51 |
void motor1_set(int direction, int speed) { |
|
52 |
#ifndef FFPP |
|
53 |
if(direction == 0) { |
|
54 |
PORTD |= 0x10; |
|
55 |
PORTD &= 0xBF; |
|
56 |
} |
|
57 |
else { |
|
58 |
PORTD |= 0x40; |
|
59 |
PORTD &= 0xEF; |
|
60 |
} |
|
61 |
|
|
62 |
// Set the timer to count up to speed, an 8-bit value |
|
63 |
OCR1AL = speed; |
|
64 |
#else |
|
65 |
|
|
66 |
if(direction == FORWARD) { |
|
67 |
PORTD = (PORTD & 0xCF) | 0x20; |
|
68 |
} |
|
69 |
else { |
|
70 |
PORTD = (PORTD & 0xCF) | 0x10; |
|
71 |
} |
|
72 |
|
|
73 |
// Set the timer to count up to speed, an 8-bit value |
|
74 |
OCR1A = speed; |
|
75 |
#endif |
|
76 |
|
|
77 |
} |
|
78 |
|
|
79 |
void motor2_set(int direction, int speed) { |
|
80 |
#ifndef FFPP |
|
81 |
if(direction == 0) { |
|
82 |
PORTD |= 0x20; |
|
83 |
PORTD &= 0x7F; |
|
84 |
} |
|
85 |
else { |
|
86 |
PORTD |= 0x80; |
|
87 |
PORTD &= 0xDF; |
|
88 |
} |
|
89 |
OCR1BL = speed; |
|
90 |
#else |
|
91 |
|
|
92 |
if(direction != FORWARD) { |
|
93 |
PORTD = (PORTD & 0x3F) | 0x80; |
|
94 |
} |
|
95 |
else { |
|
96 |
PORTD = (PORTD & 0x3F) | 0x40; |
|
97 |
} |
|
98 |
|
|
99 |
OCR1B = speed; |
|
100 |
#endif |
|
101 |
} |
|
102 |
|
|
103 |
// Just turns off both motors |
|
104 |
void motors_off( void ) { |
|
105 |
OCR1AL = 0x0; |
|
106 |
OCR1BL = 0x0; |
|
107 |
} |
trunk/code/projects/colonet/robot/dongle/robot_receiver/follow.c | ||
---|---|---|
1 |
|
|
2 |
#include "firefly+_lib.h" |
|
3 |
#include "follow.h" |
|
4 |
|
|
5 |
#define FWD 0 |
|
6 |
#define BCK 1 |
|
7 |
|
|
8 |
#define TOTAL 16 |
|
9 |
|
|
10 |
|
|
11 |
/* |
|
12 |
int find_max |
|
13 |
returns the index of the BOM with the highest reading |
|
14 |
* note: index, not value |
|
15 |
*/ |
|
16 |
|
|
17 |
void seek(int relative_position) |
|
18 |
{ |
|
19 |
int speed = 255; |
|
20 |
|
|
21 |
//MOTOR1 - left |
|
22 |
//MOTOR2 - right |
|
23 |
|
|
24 |
if(relative_position < 5 || relative_position > 13) |
|
25 |
{ //turn right |
|
26 |
motor2_set(BCK, 0); |
|
27 |
motor1_set(FWD, speed); |
|
28 |
} |
|
29 |
else if(relative_position > 5 && relative_position <= 13) |
|
30 |
{ //turn left |
|
31 |
motor2_set(FWD, speed); |
|
32 |
motor1_set(BCK, 0); |
|
33 |
} |
|
34 |
else |
|
35 |
{ //go forward |
|
36 |
//turn_off_motors(); |
|
37 |
motor1_set(FWD, speed); |
|
38 |
motor2_set(FWD, speed); |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
void drive_forward (void) |
|
43 |
{ |
|
44 |
int speed = 255; |
|
45 |
motor1_set(FWD, speed); |
|
46 |
motor2_set(FWD, speed); |
|
47 |
} |
trunk/code/projects/colonet/robot/dongle/robot_receiver/wireless.h | ||
---|---|---|
1 |
#ifndef WIRELESS_H |
|
2 |
#define WIRELESS_H |
|
3 |
|
|
4 |
/* |
|
5 |
Wireless - wireless functions for Colony |
|
6 |
|
|
7 |
Eugene Marinelli |
|
8 |
7/22/06 |
|
9 |
*/ |
|
10 |
|
|
11 |
#define WL_MSG_MAX_LEN 16 |
|
12 |
#define WL_PACKET_MAX_LEN (WL_MSG_MAX_LEN+5) |
|
13 |
|
|
14 |
#define GLOBAL_DEST 200 |
|
15 |
|
|
16 |
typedef struct { |
|
17 |
char prefix[2]; |
|
18 |
char src; |
|
19 |
char dest; |
|
20 |
char msg[WL_MSG_MAX_LEN]; |
|
21 |
char checksum; |
|
22 |
} WL_Packet; |
|
23 |
|
|
24 |
int wl_init(int msg_len, char listener_address); |
|
25 |
int wl_send(char* msg, char dest); |
|
26 |
int wl_recv(char* msgbuf, char* src, char* dest); |
|
27 |
// get most recent valid message - implement message queue later |
|
28 |
|
|
29 |
int wl_create_packet(char* msg, char src, char dest, WL_Packet* packet); |
|
30 |
char wl_get_checksum(WL_Packet* packet); |
|
31 |
|
|
32 |
#endif |
trunk/code/projects/colonet/robot/dongle/robot_receiver/motor.h | ||
---|---|---|
1 |
/* |
|
2 |
motor.h - Contains the function prototypes for controlling motors |
|
3 |
author: Tom Lauwers |
|
4 |
*/ |
|
5 |
|
|
6 |
#ifndef _MOTOR_H |
|
7 |
#define _MOTOR_H |
|
8 |
|
|
9 |
#include <avr/io.h> |
|
10 |
|
|
11 |
#define FORWARD 1 |
|
12 |
#define BACKWARD 0 |
|
13 |
|
|
14 |
#ifdef FFPP |
|
15 |
|
|
16 |
#define IN1A PD4 |
|
17 |
#define IN1B PD5 |
|
18 |
#define IN2A PD6 |
|
19 |
#define IN2B PD7 |
|
20 |
|
|
21 |
/* truth table for this robot (w/ 17529 and nand gates) |
|
22 |
PWM !A !B M+ M- |
|
23 |
L X X Z Z - coast |
|
24 |
H 0 0 Z Z - coast |
|
25 |
H 0 1 1 0 - forward |
|
26 |
H 1 0 0 1 - backward |
|
27 |
H 1 1 0 0 - fast brake |
|
28 |
|
|
29 |
*/ |
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
#endif |
|
35 |
|
|
36 |
// Function descriptions can be found in motor.c |
|
37 |
void motors_init(void); |
|
38 |
void motor1_set(int direction, int speed); |
|
39 |
void motor2_set(int direction, int speed); |
|
40 |
void motors_off( void ); |
|
41 |
|
|
42 |
|
|
43 |
#endif |
trunk/code/projects/colonet/robot/dongle/robot_receiver/follow.h | ||
---|---|---|
1 |
|
|
2 |
#ifndef _FOLLOW_H |
|
3 |
#define _FOLLOW_H |
|
4 |
|
|
5 |
|
|
6 |
void seek(int velocity); |
|
7 |
void drive_forward (void); |
|
8 |
|
|
9 |
#endif |
trunk/code/projects/colonet/robot/dongle/robot_receiver/robot_receiver.c | ||
---|---|---|
1 |
/* |
|
2 |
Eugene Marinelli |
|
3 |
7/22/06 |
|
4 |
*/ |
|
5 |
|
|
6 |
/* Includes */ |
|
7 |
#include <stdio.h> |
|
8 |
#include <string.h> |
|
9 |
|
|
10 |
#include <firefly+_lib.h> |
|
11 |
#include "pindefs_ff.h" |
|
12 |
|
|
13 |
#include <wireless.h> |
|
14 |
|
|
15 |
void init_hardware(void); |
|
16 |
|
|
17 |
/* Main */ |
|
18 |
int main(void){ |
|
19 |
char buf[80]; |
|
20 |
char src, dest; |
|
21 |
|
|
22 |
init_hardware(); |
|
23 |
wl_init(15,1); |
|
24 |
|
|
25 |
orb_set_color(BLUE); |
|
26 |
|
|
27 |
while(1){ |
|
28 |
if(wl_recv(buf, &src, &dest)){ |
|
29 |
printf("%s", buf); |
|
30 |
orb_set_color(RED); |
|
31 |
}else{ |
|
32 |
printf("."); |
|
33 |
orb_set_color(BLUE); |
|
34 |
} |
|
35 |
|
|
36 |
wl_send("ABC", 200); |
|
37 |
|
|
38 |
delay_ms(500); |
|
39 |
} |
|
40 |
|
|
41 |
return 0; |
|
42 |
} |
|
43 |
|
|
44 |
void init_hardware(){ |
|
45 |
motors_init(); |
|
46 |
orb_init(); |
|
47 |
led_init(); |
|
48 |
analog_init(); |
|
49 |
|
|
50 |
serial_init(BAUD9600); |
|
51 |
serial1_init(BAUD115200); |
|
52 |
lcd_init(); |
|
53 |
|
|
54 |
fdevopen(&serial1_putchar, &serial1_getchar); |
|
55 |
} |
trunk/code/projects/colonet/robot/dongle/robot_receiver/serial.c | ||
---|---|---|
1 |
/* |
|
2 |
serial.c - Functions for using the RS232 serial port |
|
3 |
|
|
4 |
author: Robotics Club, Colony Project |
|
5 |
|
|
6 |
much code taken from FWR's library, author: Tom Lauwers |
|
7 |
|
|
8 |
|
|
9 |
general note - serial -> uart |
|
10 |
serial1 -> uart1 |
|
11 |
this is done for clarity purposes |
|
12 |
*/ |
|
13 |
|
|
14 |
|
|
15 |
#include <avr/io.h> |
|
16 |
#include <stdio.h> |
|
17 |
#include "serial.h" |
|
18 |
|
|
19 |
//setup uart0 (serial) |
|
20 |
void serial_init(unsigned int ubrr) |
|
21 |
{ |
|
22 |
/*Set baud rate - baud rates under 4800bps unsupported */ |
|
23 |
UBRR0H = 0x00; |
|
24 |
UBRR0L = (unsigned char)ubrr; |
|
25 |
|
|
26 |
/*Enable receiver and transmitter */ |
|
27 |
UCSR0B |= (1<<RXEN0)|(1<<TXEN0); |
|
28 |
|
|
29 |
/* Set frame format: 8data, 1stop bit, asynchronous normal mode */ |
|
30 |
UCSR0C |= (1<<UCSZ00) | (1<<UCSZ01); |
|
31 |
} |
|
32 |
|
|
33 |
// uart_putchar - Low-level function which puts a value into the |
|
34 |
// Tx buffer for transmission. Automatically injects |
|
35 |
// a \r before all \n's |
|
36 |
int serial_putchar(char c) |
|
37 |
{ |
|
38 |
|
|
39 |
if (c == '\n') |
|
40 |
putchar('\r'); |
|
41 |
// Wait until buffer is clear for sending |
|
42 |
loop_until_bit_is_set(UCSR0A, UDRE0); |
|
43 |
// Load buffer with your character |
|
44 |
UDR0 = c; |
|
45 |
return 0; |
|
46 |
} |
|
47 |
|
|
48 |
// uart_getchar - Low-level function which waits for the Rx buffer |
|
49 |
// to be filled, and then reads one character out of it. |
|
50 |
// Note that this function blocks on read - it will wait until |
|
51 |
// something fills the Rx buffer. |
|
52 |
int serial_getchar(void) |
|
53 |
{ |
|
54 |
char c; |
|
55 |
// Wait for the receive buffer to be filled |
|
56 |
loop_until_bit_is_set(UCSR0A, RXC0); |
|
57 |
|
|
58 |
// Read the receive buffer |
|
59 |
c = UDR0; |
|
60 |
return c; |
|
61 |
} |
|
62 |
|
|
63 |
// uart_getchar_nb - Low-level function which checks if the Rx buffer |
|
64 |
// is filled, and then reads one character out of it. |
|
65 |
// This is a non blocking version uart_getchar |
|
66 |
int serial_getchar_nb(void) |
|
67 |
{ |
|
68 |
char c; |
|
69 |
// Wait for the receive buffer to be filled |
|
70 |
//loop_until_bit_is_set(UCSR0A, RXC0); |
|
71 |
if (UCSR0A & _BV(RXC0)){ |
|
72 |
// Read the receive buffer |
|
73 |
c = UDR0; |
|
74 |
return c; |
|
75 |
} |
|
76 |
return 0; |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
//setup uart1 (serial1) |
|
81 |
void serial1_init( unsigned int ubrr) |
|
82 |
{ |
|
83 |
/*Set baud rate - baud rates under 4800bps unsupported */ |
|
84 |
UBRR1H = 0x00; |
|
85 |
UBRR1L = (unsigned char)ubrr; |
|
86 |
|
|
87 |
/*Enable receiver and transmitter */ |
|
88 |
UCSR1B |= (1<<RXEN1)|(1<<TXEN1); |
|
89 |
|
|
90 |
/* Set frame format: 8data, 1stop bit, asynchronous normal mode */ |
|
91 |
UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11); |
|
92 |
|
|
93 |
/* For use with fprintf() and related functions */ |
|
94 |
serial1_stream = fdevopen(serial1_putchar, serial1_putchar); |
|
95 |
|
|
96 |
/* To use fprintf(): |
|
97 |
After calling serial1_init(BAUD115200); |
|
98 |
use the command fprintf(serial1_stream, "Hello World"); |
|
99 |
This call to fdevopen() does give a compile warning |
|
100 |
but works fine. |
|
101 |
-Greg Tress |
|
102 |
*/ |
|
103 |
} |
|
104 |
|
|
105 |
//put to uart1 (serial1) |
|
106 |
int serial1_putchar(char c) |
|
107 |
{ |
|
108 |
|
|
109 |
if (c == '\n') |
|
110 |
serial1_putchar('\r'); //changed from putchar aj |
|
111 |
// Wait until buffer is clear for sending |
|
112 |
loop_until_bit_is_set(UCSR1A, UDRE1); |
|
113 |
// Load buffer with your character |
|
114 |
UDR1 = c; |
|
115 |
return 0; |
|
116 |
} |
|
117 |
|
|
118 |
//get from uart1 (serial1) |
|
119 |
int serial1_getchar(void) |
|
120 |
{ |
|
121 |
char c; |
|
122 |
// Wait for the receive buffer to be filled |
|
123 |
loop_until_bit_is_set(UCSR1A, RXC1); |
|
124 |
|
|
125 |
// Read the receive buffer |
|
126 |
c = UDR1; |
|
127 |
return c; |
|
128 |
} |
|
129 |
|
|
130 |
//get from uart1 non-block |
|
131 |
int serial1_getchar_nb(void) |
|
132 |
{ |
|
133 |
char c; |
|
134 |
// Wait for the receive buffer to be filled |
|
135 |
//loop_until_bit_is_set(UCSR1A, RXC1); |
|
136 |
if (UCSR1A & _BV(RXC1)){ |
|
137 |
// Read the receive buffer |
|
138 |
c = UDR1; |
|
139 |
return c; |
|
140 |
} |
|
141 |
return 0; |
|
142 |
|
|
143 |
} |
trunk/code/projects/colonet/robot/dongle/robot_receiver/buzzer.c | ||
---|---|---|
1 |
/* |
|
2 |
buzzer.c - Contains the functions necessary for running the buzzer |
|
3 |
|
|
4 |
author: Robotics Club, Colony Project |
|
5 |
|
|
6 |
much taken from FWR's firefly library (author: Tom Lauwers) |
|
7 |
|
|
8 |
*/ |
|
9 |
|
|
10 |
#include <avr/io.h> |
|
11 |
#include <buzzer.h> |
|
12 |
#include <time.h> |
|
13 |
|
|
14 |
/* |
|
15 |
initializes buffer |
|
16 |
|
|
17 |
this function must be called before the buzzer can be used |
|
18 |
*/ |
|
19 |
void buzzer_init( void ) |
|
20 |
{ |
|
21 |
// Set pin D7 to output - D7 is buzzer pin |
|
22 |
DDRB |= 0x80; |
|
23 |
|
|
24 |
// Set to Fast PWM mode, toggle the OC0A pin (D6) on output compare |
|
25 |
// matches, and select a clock prescalar of 64 for the counter. |
|
26 |
// Counter FREQ = 8000000/64 = 125000 |
|
27 |
//01011000 |
|
28 |
TCCR2 = 0x1B; |
|
29 |
OCR2=100; |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
// Set the buzzer value - takes a value from 0-255 |
|
34 |
// Higher values are lower frequency. Take a look at |
|
35 |
// the buzzer frequency table to see how a given value |
|
36 |
// correlates to a frequency. |
|
37 |
void buzzer_set_val(unsigned int buzz_value) |
|
38 |
{ |
|
39 |
OCR2 = buzz_value; |
|
40 |
} |
|
41 |
|
|
42 |
// Set the buzzer frequency - takes any value and tries to find the nearest buzzer frequency |
|
43 |
void buzzer_set_freq(unsigned int buzz_freq) |
|
44 |
{ |
|
45 |
int buzz_value; |
|
46 |
|
|
47 |
buzz_value = 62500/buzz_freq - 1; |
|
48 |
|
|
49 |
if(buzz_value > 255) |
|
50 |
buzz_value = 255; |
|
51 |
else if(buzz_value < 0) |
|
52 |
buzz_value = 0; |
|
53 |
|
|
54 |
buzzer_set_val(buzz_value); |
|
55 |
} |
|
56 |
|
|
57 |
// Chirps the buzzer for a number of milliseconds |
|
58 |
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq) |
|
59 |
{ |
|
60 |
buzzer_set_freq(buzz_freq); |
|
61 |
|
|
62 |
delay_ms(ms); |
|
63 |
|
|
64 |
buzzer_off(); |
|
65 |
} |
|
66 |
|
|
67 |
// Disables timer0 clock counting, turning off the buzzer |
|
68 |
void buzzer_off() |
|
69 |
{ |
|
70 |
// Disable clock, to halt counter |
|
71 |
TCCR2 &= 0xF8; |
|
72 |
|
|
73 |
// Set buzzer pin low in case it's high |
|
74 |
PORTB &= 0x7F; |
|
75 |
} |
|
76 |
|
trunk/code/projects/colonet/robot/dongle/robot_receiver/serial.h | ||
---|---|---|
1 |
/* |
|
2 |
serial.h - Contains definitions and function prototypes for the RS232 serial port |
|
3 |
*/ |
|
4 |
|
|
5 |
#ifndef _SERIAL_H |
|
6 |
#define _SERIAL_H |
|
7 |
|
|
8 |
// Tested baud rates |
|
9 |
#define BAUD9600 103 |
|
10 |
#define BAUD115200 8 //Warning--3.5% error |
|
11 |
|
|
12 |
// Untested baud rates that might be right --aaron |
|
13 |
#define BAUD1M 0 |
|
14 |
#define BAUD500K 1 |
|
15 |
#define BAUD250K 3 |
|
16 |
#define BAUD230400 3 //Warning--8.5% error |
|
17 |
#define BAUD76800 12 |
|
18 |
#define BAUD57600 16 //Warning--2.1% error |
|
19 |
#define BAUD38400 25 |
|
20 |
#define BAUD28800 34 |
|
21 |
#define BAUD19200 51 |
|
22 |
#define BAUD14400 68 |
|
23 |
#define BAUD4800 207 |
|
24 |
#define BAUD2400 416 //Might not work, since it needs some high bits set |
|
25 |
|
|
26 |
#include <stdio.h> |
|
27 |
FILE *serial1_stream; //For use with fprintf() and related functions |
|
28 |
|
|
29 |
/* NOTE: To use fprintf(): |
|
30 |
After calling serial1_init(BAUD115200); |
|
31 |
use the command fprintf(serial1_stream, "Hello World"); */ |
|
32 |
|
|
33 |
// Function descriptions are available in serial.c |
|
34 |
|
|
35 |
//serial (serial0) is the ttl serial (wireless) |
|
36 |
void serial_init( unsigned int ubrr); |
|
37 |
int serial_putchar(char c); |
|
38 |
int serial_getchar(void); |
|
39 |
int serial_getchar_nb(void); |
|
40 |
|
|
41 |
//serial1 is the rs-232 port (db9 connector) (except on robot0 where both are serial0) |
|
42 |
void serial1_init( unsigned int ubrr); |
|
43 |
int serial1_putchar(char c); |
|
44 |
int serial1_getchar(void); |
|
45 |
int serial1_getchar_nb(void); |
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
#endif |
trunk/code/projects/colonet/robot/dongle/robot_receiver/buzzer.h | ||
---|---|---|
1 |
/* |
|
2 |
buzzer.h - Contains function prototypes for running the buzzer |
|
3 |
|
|
4 |
|
|
5 |
author: Robotics Club, Colony Project |
|
6 |
*/ |
|
7 |
#ifndef _BUZZER_H_ |
|
8 |
#define _BUZZER_H_ |
|
9 |
|
|
10 |
//Musical note definitions |
|
11 |
//Source: http://www.answers.com/topic/piano-key-frequencies |
|
12 |
#define C4 260 //Middle C |
|
13 |
#define C4s 277 //C sharp |
|
14 |
#define D4 294 |
|
15 |
#define D4s 311 |
|
16 |
#define E4 330 |
|
17 |
#define F4 349 |
|
18 |
#define F4s 370 |
|
19 |
#define G4 392 |
|
20 |
#define G4s 415 |
|
21 |
#define A4 440 |
|
22 |
#define A4s 466 |
|
23 |
#define B4 494 |
|
24 |
#define C5 523 |
|
25 |
|
|
26 |
// Function descriptions can be found in buzzer.c |
|
27 |
void buzzer_init(void); |
|
28 |
void buzzer_set_val(unsigned int buzz_value); |
|
29 |
void buzzer_set_freq(unsigned int buzz_freq); |
|
30 |
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq); |
|
31 |
void buzzer_off(void); |
|
32 |
|
|
33 |
#endif |
trunk/code/projects/colonet/robot/dongle/robot_receiver/localization.c | ||
---|---|---|
1 |
#include "localization.h" |
|
2 |
|
|
3 |
#include "firefly+_lib.h" |
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
void addSensor (int maxBom, int self, int other, int NUM_BOTS) |
|
9 |
{ |
|
10 |
//make sure you don't add to the diagonal |
|
11 |
if(self == other) { |
|
12 |
//lcd_putchar('w'); |
|
13 |
return; |
|
14 |
} |
|
15 |
if(self >= NUM_BOTS || other >= NUM_BOTS) |
|
16 |
{ |
|
17 |
// lcd_putchar('y'); |
|
18 |
return; |
|
19 |
} |
|
20 |
|
|
21 |
|
|
22 |
//lcd_putchar('a'); |
|
23 |
//lcd_putchar(self+48); |
|
24 |
//lcd_putchar(':'); |
|
25 |
//lcd_putchar(other+48); |
|
26 |
//lcd_putchar('.'); |
|
27 |
//add this robot to your own row's sensor numbers |
|
28 |
//row = your index |
|
29 |
//column = robotNum (input) |
|
30 |
sensors[self][other] = maxBom; |
|
31 |
|
|
32 |
} |
|
33 |
|
|
34 |
unsigned char getSelfSensor (unsigned char self, unsigned char other, int NUM_BOTS) |
|
35 |
{ |
|
36 |
|
|
37 |
if(other < NUM_BOTS){ |
|
38 |
return sensors[self][other]; |
|
39 |
} |
|
40 |
else { |
|
41 |
return 9; |
|
42 |
} |
|
43 |
|
|
44 |
} |
|
45 |
|
|
46 |
/* |
|
47 |
void printSensorsMatrix (void) |
|
48 |
{ |
|
49 |
|
|
50 |
|
|
51 |
//print table |
|
52 |
int y = 1; |
|
53 |
lcd_gotoxy(0, y); |
|
54 |
int i, j; |
|
55 |
for(i = 0; i < NUM_BOTS; i++) { |
|
56 |
for(j = 0; j < NUM_BOTS; j++) { |
|
57 |
lcd_putchar( getSelfSensor(i, j, NUM_BOTS) + 48); |
|
58 |
lcd_putchar(' '); |
|
59 |
} |
|
60 |
y++; |
|
61 |
lcd_gotoxy(0, y); |
|
62 |
} |
|
63 |
|
|
64 |
delay_ms(1000); |
|
65 |
|
|
66 |
} |
|
67 |
*/ |
|
68 |
|
|
69 |
/* |
|
70 |
SensorRow getSelfSensorRow (int self) |
|
71 |
{ |
|
72 |
|
|
73 |
SensorRow sr; |
|
74 |
int i; |
|
75 |
|
|
76 |
sr.len = NUM_BOTS; |
|
77 |
for(i = 0; i < NUM_BOTS; i++) { |
|
78 |
sr.row[i] = sensors[ |
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
*/ |
trunk/code/projects/colonet/robot/dongle/robot_receiver/Makefile | ||
---|---|---|
1 |
# Hey Emacs, this is a -*- makefile -*- |
|
2 |
#---------------------------------------------------------------------------- |
|
3 |
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al. |
|
4 |
# |
|
5 |
# Released to the Public Domain |
|
6 |
# |
|
7 |
# Additional material for this makefile was written by: |
|
8 |
# Peter Fleury |
|
9 |
# Tim Henigan |
|
10 |
# Colin O'Flynn |
|
11 |
# Reiner Patommel |
|
12 |
# Markus Pfaff |
|
13 |
# Sander Pool |
|
14 |
# Frederik Rouleau |
|
15 |
# |
|
16 |
#---------------------------------------------------------------------------- |
|
17 |
# On command line: |
|
18 |
# |
|
19 |
# make all = Make software. |
|
20 |
# |
|
21 |
# make clean = Clean out built project files. |
|
22 |
# |
|
23 |
# make coff = Convert ELF to AVR COFF. |
|
24 |
# |
|
25 |
# make extcoff = Convert ELF to AVR Extended COFF. |
|
26 |
# |
|
27 |
# make program = Download the hex file to the device, using avrdude. |
|
28 |
# Please customize the avrdude settings below first! |
|
29 |
# |
|
30 |
# make debug = Start either simulavr or avarice as specified for debugging, |
|
31 |
# with avr-gdb or avr-insight as the front end for debugging. |
|
32 |
# |
|
33 |
# make filename.s = Just compile filename.c into the assembler code only. |
|
34 |
# |
|
35 |
# make filename.i = Create a preprocessed source file for use in submitting |
|
36 |
# bug reports to the GCC project. |
|
37 |
# |
|
38 |
# To rebuild project do "make clean" then "make all". |
|
39 |
#---------------------------------------------------------------------------- |
|
40 |
|
|
41 |
#if you want your code to work on the Firefly++ and not Firefly+ |
|
42 |
#then add the -DFFPP line to CDEFS |
|
43 |
COLONYROOT = y: |
|
44 |
CDEFS = |
|
45 |
#-DFFPP |
|
46 |
|
|
47 |
# MCU name |
|
48 |
MCU = atmega128 |
|
49 |
|
|
50 |
|
|
51 |
# Processor frequency. |
|
52 |
# This will define a symbol, F_CPU, in all source code files equal to the |
|
53 |
# processor frequency. You can then use this symbol in your source code to |
|
54 |
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done |
|
55 |
# automatically to create a 32-bit value in your source code. |
|
56 |
F_CPU = 16000000 |
|
57 |
|
|
58 |
|
|
59 |
# Output format. (can be srec, ihex, binary) |
|
60 |
FORMAT = ihex |
|
61 |
|
|
62 |
|
|
63 |
# Target file name (without extension). |
|
64 |
TARGET = robot_receiver |
|
65 |
|
|
66 |
|
|
67 |
# List C source files here. (C dependencies are automatically generated.) |
|
68 |
SRC = $(wildcard *.c) |
|
69 |
#$(TARGET).c |
|
70 |
|
|
71 |
|
|
72 |
# List Assembler source files here. |
|
73 |
# Make them always end in a capital .S. Files ending in a lowercase .s |
|
74 |
# will not be considered source files but generated files (assembler |
|
75 |
# output from the compiler), and will be deleted upon "make clean"! |
|
76 |
# Even though the DOS/Win* filesystem matches both .s and .S the same, |
|
77 |
# it will preserve the spelling of the filenames, and gcc itself does |
|
78 |
# care about how the name is spelled on its command-line. |
|
79 |
ASRC = |
|
80 |
|
|
81 |
|
|
82 |
# Optimization level, can be [0, 1, 2, 3, s]. |
|
83 |
# 0 = turn off optimization. s = optimize for size. |
|
84 |
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) |
|
85 |
OPT = s |
|
86 |
|
|
87 |
|
|
88 |
# Debugging format. |
|
89 |
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs. |
|
90 |
# AVR Studio 4.10 requires dwarf-2. |
|
91 |
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run. |
|
92 |
DEBUG = dwarf-2 |
|
93 |
|
|
94 |
|
|
95 |
# List any extra directories to look for include files here. |
|
96 |
# Each directory must be seperated by a space. |
|
97 |
# Use forward slashes for directory separators. |
|
98 |
# For a directory that has spaces, enclose it in quotes. |
|
99 |
EXTRAINCDIRS = $(COLONYROOT)/code/firefly_plus_lib |
|
100 |
#C:\WinAVR\include\fwr |
|
101 |
|
|
102 |
|
|
103 |
# Compiler flag to set the C Standard level. |
|
104 |
# c89 = "ANSI" C |
|
105 |
# gnu89 = c89 plus GCC extensions |
|
106 |
# c99 = ISO C99 standard (not yet fully implemented) |
|
107 |
# gnu99 = c99 plus GCC extensions |
|
108 |
CSTANDARD = -std=gnu99 |
|
109 |
|
|
110 |
|
|
111 |
# Place -D or -U options here |
|
112 |
CDEFS += -DF_CPU=$(F_CPU)UL |
|
113 |
|
|
114 |
|
|
115 |
# Place -I options here |
|
116 |
CINCS = |
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
#---------------- Compiler Options ---------------- |
|
121 |
# -g*: generate debugging information |
|
122 |
# -O*: optimization level |
|
123 |
# -f...: tuning, see GCC manual and avr-libc documentation |
|
124 |
# -Wall...: warning level |
|
125 |
# -Wa,...: tell GCC to pass this to the assembler. |
|
126 |
# -adhlns...: create assembler listing |
|
127 |
CFLAGS = -g$(DEBUG) |
|
128 |
CFLAGS += $(CDEFS) $(CINCS) |
|
129 |
CFLAGS += -O$(OPT) |
|
130 |
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
|
131 |
CFLAGS += -Wall -Wstrict-prototypes |
|
132 |
CFLAGS += -Wa,-adhlns=$(<:.c=.lst) |
|
133 |
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) |
|
134 |
CFLAGS += $(CSTANDARD) |
|
135 |
|
|
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 |
|
|
172 |
MATH_LIB = -lm |
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
#---------------- External Memory Options ---------------- |
|
177 |
|
|
178 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
179 |
# used for variables (.data/.bss) and heap (malloc()). |
|
180 |
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff |
|
181 |
|
|
182 |
# 64 KB of external RAM, starting after internal RAM (ATmega128!), |
|
183 |
# only used for heap (malloc()). |
|
184 |
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff |
|
185 |
|
|
186 |
EXTMEMOPTS = |
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
#---------------- Linker Options ---------------- |
|
191 |
# -Wl,...: tell GCC to pass this to linker. |
|
192 |
# -Map: create map file |
|
193 |
# --cref: add cross reference to map file |
|
194 |
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref |
|
195 |
LDFLAGS += $(EXTMEMOPTS) |
|
196 |
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) |
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
#---------------- Programming Options (avrdude) ---------------- |
|
201 |
|
|
202 |
# Programming hardware: alf avr910 avrisp bascom bsd |
|
203 |
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500 |
|
204 |
# |
|
205 |
# Type: avrdude -c ? |
|
206 |
# to get a full listing. |
|
207 |
# |
|
208 |
AVRDUDE_PROGRAMMER = avrisp |
|
209 |
|
|
210 |
# com1 = serial port. Use lpt1 to connect to parallel port. |
|
211 |
AVRDUDE_PORT = com1 |
|
212 |
# programmer connected to serial device |
|
213 |
|
|
214 |
AVRDUDE_WRITE_FLASH = -b 9600 -U flash:w:$(TARGET).hex |
|
215 |
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep |
|
216 |
|
|
217 |
|
|
218 |
# Uncomment the following if you want avrdude's erase cycle counter. |
|
219 |
# Note that this counter needs to be initialized first using -Yn, |
|
220 |
# see avrdude manual. |
|
221 |
#AVRDUDE_ERASE_COUNTER = -y |
|
222 |
|
|
223 |
# Uncomment the following if you do /not/ wish a verification to be |
|
224 |
# performed after programming the device. |
|
225 |
AVRDUDE_NO_VERIFY = -V |
|
226 |
|
|
227 |
# Increase verbosity level. Please use this when submitting bug |
|
228 |
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> |
|
229 |
# to submit bug reports. |
|
230 |
#AVRDUDE_VERBOSE = -v -v |
|
231 |
|
|
232 |
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) |
|
233 |
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY) |
|
234 |
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE) |
|
235 |
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER) |
|
236 |
|
|
237 |
#don't check for device signature |
|
238 |
#AVRDUDE_FLAGS += -F |
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
#---------------- Debugging Options ---------------- |
|
243 |
|
|
244 |
# For simulavr only - target MCU frequency. |
|
245 |
DEBUG_MFREQ = $(F_CPU) |
|
246 |
|
|
247 |
# Set the DEBUG_UI to either gdb or insight. |
|
248 |
# DEBUG_UI = gdb |
|
249 |
DEBUG_UI = insight |
|
250 |
|
|
251 |
# Set the debugging back-end to either avarice, simulavr. |
|
252 |
DEBUG_BACKEND = avarice |
|
253 |
#DEBUG_BACKEND = simulavr |
|
254 |
|
|
255 |
# GDB Init Filename. |
|
256 |
GDBINIT_FILE = __avr_gdbinit |
|
257 |
|
|
258 |
# When using avarice settings for the JTAG |
|
259 |
JTAG_DEV = /dev/com1 |
|
260 |
|
|
261 |
# Debugging port used to communicate between GDB / avarice / simulavr. |
|
262 |
DEBUG_PORT = 4242 |
|
263 |
|
|
264 |
# Debugging host used to communicate between GDB / avarice / simulavr, normally |
|
265 |
# just set to localhost unless doing some sort of crazy debugging when |
|
266 |
# avarice is running on a different computer. |
|
267 |
DEBUG_HOST = localhost |
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
#============================================================================ |
|
272 |
|
|
273 |
|
|
274 |
# Define programs and commands. |
|
275 |
SHELL = sh |
|
276 |
CC = avr-gcc |
|
277 |
OBJCOPY = avr-objcopy |
|
278 |
OBJDUMP = avr-objdump |
|
279 |
SIZE = avr-size |
|
280 |
NM = avr-nm |
|
281 |
AVRDUDE = avrdude |
|
282 |
REMOVE = rm -f |
|
283 |
REMOVEDIR = rm -rf |
|
284 |
COPY = cp |
|
285 |
WINSHELL = cmd |
|
286 |
|
|
287 |
|
|
288 |
# Define Messages |
|
289 |
# English |
|
290 |
MSG_ERRORS_NONE = Errors: none |
|
291 |
MSG_BEGIN = -------- begin -------- |
|
292 |
MSG_END = -------- end -------- |
|
293 |
MSG_SIZE_BEFORE = Size before: |
|
294 |
MSG_SIZE_AFTER = Size after: |
|
295 |
MSG_COFF = Converting to AVR COFF: |
|
296 |
MSG_EXTENDED_COFF = Converting to AVR Extended COFF: |
|
297 |
MSG_FLASH = Creating load file for Flash: |
|
298 |
MSG_EEPROM = Creating load file for EEPROM: |
|
299 |
MSG_EXTENDED_LISTING = Creating Extended Listing: |
|
300 |
MSG_SYMBOL_TABLE = Creating Symbol Table: |
|
301 |
MSG_LINKING = Linking: |
|
302 |
MSG_COMPILING = Compiling: |
|
303 |
MSG_ASSEMBLING = Assembling: |
|
304 |
MSG_CLEANING = Cleaning project: |
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
# Define all object files. |
|
310 |
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) |
|
311 |
|
|
312 |
# Define all listing files. |
|
313 |
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) |
|
314 |
|
|
315 |
|
|
316 |
# Compiler flags to generate dependency files. |
|
317 |
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d |
|
318 |
|
|
319 |
|
|
320 |
# Combine all necessary flags and optional flags. |
|
321 |
# Add target processor to flags. |
|
322 |
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) |
|
323 |
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) |
|
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
# Default target. |
|
330 |
all: begin gccversion sizebefore build sizeafter end |
|
331 |
|
|
332 |
build: elf hex eep lss sym |
|
333 |
|
|
334 |
elf: $(TARGET).elf |
|
335 |
hex: $(TARGET).hex |
|
336 |
eep: $(TARGET).eep |
|
337 |
lss: $(TARGET).lss |
|
338 |
sym: $(TARGET).sym |
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
# Eye candy. |
|
343 |
# AVR Studio 3.x does not check make's exit code but relies on |
|
344 |
# the following magic strings to be generated by the compile job. |
|
345 |
begin: |
|
346 |
@echo |
|
347 |
@echo $(MSG_BEGIN) |
|
348 |
|
|
349 |
end: |
|
350 |
@echo $(MSG_END) |
|
351 |
@echo |
|
352 |
|
|
353 |
|
|
354 |
# Display size of file. |
|
355 |
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex |
|
356 |
ELFSIZE = $(SIZE) -A $(TARGET).elf |
|
357 |
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU) |
|
358 |
|
|
359 |
sizebefore: |
|
360 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \ |
|
361 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
362 |
|
|
363 |
sizeafter: |
|
364 |
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \ |
|
365 |
$(AVRMEM) 2>/dev/null; echo; fi |
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
# Display compiler version information. |
|
370 |
gccversion : |
|
371 |
@$(CC) --version |
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
# Program the device. |
|
376 |
program: $(TARGET).hex $(TARGET).eep |
|
377 |
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) |
|
378 |
|
|
379 |
|
|
380 |
# Generate avr-gdb config/init file which does the following: |
|
381 |
# define the reset signal, load the target file, connect to target, and set |
|
382 |
# a breakpoint at main(). |
|
383 |
gdb-config: |
|
384 |
@$(REMOVE) $(GDBINIT_FILE) |
|
385 |
@echo define reset >> $(GDBINIT_FILE) |
|
386 |
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE) |
|
387 |
@echo end >> $(GDBINIT_FILE) |
|
388 |
@echo file $(TARGET).elf >> $(GDBINIT_FILE) |
|
389 |
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE) |
|
390 |
ifeq ($(DEBUG_BACKEND),simulavr) |
|
391 |
@echo load >> $(GDBINIT_FILE) |
|
392 |
endif |
|
393 |
@echo break main >> $(GDBINIT_FILE) |
|
394 |
|
|
395 |
debug: gdb-config $(TARGET).elf |
|
396 |
ifeq ($(DEBUG_BACKEND), avarice) |
|
397 |
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays. |
|
398 |
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \ |
|
399 |
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) |
|
400 |
@$(WINSHELL) /c pause |
|
401 |
|
|
402 |
else |
|
403 |
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \ |
|
404 |
$(DEBUG_MFREQ) --port $(DEBUG_PORT) |
|
405 |
endif |
|
406 |
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE) |
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. |
|
412 |
COFFCONVERT=$(OBJCOPY) --debugging \ |
|
413 |
--change-section-address .data-0x800000 \ |
|
414 |
--change-section-address .bss-0x800000 \ |
|
415 |
--change-section-address .noinit-0x800000 \ |
|
416 |
--change-section-address .eeprom-0x810000 |
|
417 |
|
|
418 |
|
|
419 |
coff: $(TARGET).elf |
|
420 |
@echo |
|
421 |
@echo $(MSG_COFF) $(TARGET).cof |
|
422 |
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof |
|
423 |
|
|
424 |
|
|
425 |
extcoff: $(TARGET).elf |
|
426 |
@echo |
|
427 |
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof |
|
428 |
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof |
|
429 |
|
|
430 |
|
|
431 |
|
|
432 |
# Create final output files (.hex, .eep) from ELF output file. |
|
433 |
%.hex: %.elf |
|
434 |
@echo |
|
435 |
@echo $(MSG_FLASH) $@ |
|
436 |
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ |
|
437 |
|
|
438 |
%.eep: %.elf |
|
439 |
@echo |
|
440 |
@echo $(MSG_EEPROM) $@ |
|
441 |
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ |
|
442 |
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@ |
|
443 |
|
|
444 |
# Create extended listing file from ELF output file. |
|
445 |
%.lss: %.elf |
|
446 |
@echo |
|
447 |
@echo $(MSG_EXTENDED_LISTING) $@ |
|
448 |
$(OBJDUMP) -h -S $< > $@ |
|
449 |
|
|
450 |
# Create a symbol table from ELF output file. |
|
451 |
%.sym: %.elf |
|
452 |
@echo |
|
453 |
@echo $(MSG_SYMBOL_TABLE) $@ |
|
454 |
$(NM) -n $< > $@ |
|
455 |
|
|
456 |
|
|
457 |
|
|
458 |
# Link: create ELF output file from object files. |
|
459 |
.SECONDARY : $(TARGET).elf |
|
460 |
.PRECIOUS : $(OBJ) |
|
461 |
%.elf: $(OBJ) |
|
462 |
@echo |
|
463 |
@echo $(MSG_LINKING) $@ |
|
464 |
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS) |
|
465 |
|
|
466 |
|
|
467 |
# Compile: create object files from C source files. |
|
468 |
%.o : %.c |
|
469 |
@echo |
|
470 |
@echo $(MSG_COMPILING) $< |
|
471 |
$(CC) -c $(ALL_CFLAGS) $< -o $@ |
|
472 |
|
|
473 |
|
|
474 |
# Compile: create assembler files from C source files. |
|
475 |
%.s : %.c |
|
476 |
$(CC) -S $(ALL_CFLAGS) $< -o $@ |
|
477 |
|
|
478 |
|
|
479 |
# Assemble: create object files from assembler source files. |
|
480 |
%.o : %.S |
|
481 |
@echo |
|
482 |
@echo $(MSG_ASSEMBLING) $< |
|
483 |
$(CC) -c $(ALL_ASFLAGS) $< -o $@ |
|
484 |
|
|
485 |
# Create preprocessed source for use in sending a bug report. |
|
486 |
%.i : %.c |
|
487 |
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ |
|
488 |
|
|
489 |
|
|
490 |
# Target: clean project. |
|
491 |
clean: begin clean_list end |
|
492 |
|
|
493 |
clean_list : |
|
494 |
@echo |
|
495 |
@echo $(MSG_CLEANING) |
|
496 |
$(REMOVE) $(TARGET).hex |
|
497 |
$(REMOVE) $(TARGET).eep |
|
498 |
$(REMOVE) $(TARGET).cof |
|
499 |
$(REMOVE) $(TARGET).elf |
|
500 |
$(REMOVE) $(TARGET).map |
|
501 |
$(REMOVE) $(TARGET).sym |
|
502 |
$(REMOVE) $(TARGET).lss |
|
503 |
$(REMOVE) $(OBJ) |
|
504 |
$(REMOVE) $(LST) |
|
505 |
$(REMOVE) $(SRC:.c=.s) |
|
506 |
$(REMOVE) $(SRC:.c=.d) |
|
507 |
$(REMOVEDIR) .dep |
|
508 |
|
|
509 |
|
|
510 |
|
|
511 |
# Include the dependency files. |
|
512 |
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) |
|
513 |
|
|
514 |
|
|
515 |
# Listing of phony targets. |
|
516 |
.PHONY : all begin finish end sizebefore sizeafter gccversion \ |
|
517 |
build elf hex eep lss sym coff extcoff \ |
|
518 |
clean clean_list program debug gdb-config |
|
519 |
|
trunk/code/projects/colonet/robot/dongle/robot_receiver/localization.h | ||
---|---|---|
1 |
#ifndef _LOCALIZATION_H_ |
|
2 |
#define _LOCALIZATION_H_ |
|
3 |
|
|
4 |
|
|
5 |
// Max number of robots possible |
|
6 |
#define MAX_ROBOTS 4 |
|
7 |
|
|
8 |
|
|
9 |
unsigned char sensors[MAX_ROBOTS][MAX_ROBOTS]; |
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
typedef struct{ |
|
14 |
//actual row of sensor values -- need to be able to have up to |
|
15 |
//max_robots |
|
16 |
unsigned char row[MAX_ROBOTS]; |
|
17 |
//actual length of the row |
|
18 |
unsigned char len; |
|
19 |
//'index' value of the row -- which robot it's for |
|
20 |
unsigned char row_num; |
|
21 |
|
|
22 |
} SensorRow; |
|
23 |
|
|
24 |
|
|
25 |
void addSensor (int maxBom, int self, int other, int NUM_BOTS); |
|
26 |
unsigned char getSelfSensor (unsigned char self, unsigned char other, int NUM_BOTS); |
|
27 |
|
|
28 |
#endif |
trunk/code/projects/colonet/robot/dongle/robot_receiver/servo.c | ||
---|---|---|
1 |
/* |
|
2 |
servo.c - Contains functions and interrupts necessary to activate servos |
|
3 |
author: Tom Lauwers |
|
4 |
|
|
5 |
3/1/06 Iain |
|
6 |
Man, I don't know what a servo is. |
|
7 |
*/ |
|
8 |
#include <avr/io.h> |
|
9 |
#include <avr/interrupt.h> |
|
10 |
#include <servo.h> |
|
11 |
#include <dio.h> |
|
12 |
#include <lights.h> |
|
13 |
#include <lcd.h> |
|
14 |
//1677.7216 c/ms |
|
15 |
//i dunno must be 2^k |
|
16 |
//250 |
|
17 |
//9C40 ~ 20ms |
|
18 |
//#A000 ~ 20.48 but prolly wont work |
|
19 |
//div by 256: 6.55078125 c/ms 80 ~ 19.5ms |
|
20 |
#define SERVO_PERIOD 0x80 |
|
21 |
//needs be 1ms |
|
22 |
//is 1.22ms |
|
23 |
#define SERVO_CONSTANT 0x8 |
|
24 |
|
|
25 |
/* dirty dirty |
|
26 |
unsigned int servo_vals[4] = {0,0,0,0}; // Stores the set servo values |
|
27 |
int current_servo = 0; // Stores which servo is current in the interrupt routine |
|
28 |
*/ |
|
29 |
unsigned int servo_vals[8] = {0,0,0,0,0,0,0,0}; // Stores the set servo values |
|
30 |
int phase_time=0; |
|
31 |
int phase_base=0; |
|
32 |
int servos_on = 0; // Stores which servos are enabled |
|
33 |
int servos_enabled=0; //which are high |
|
34 |
int servo_flag = 0; // Stores whether or not servos are enabled |
|
35 |
|
|
36 |
/* Timer 1 output compare B interrupt. Does the following: |
|
37 |
Checks to see if the current servo is 4, in which case just need |
|
38 |
to set low servo 3's signal and return. |
|
39 |
Else, check to see if the current servo is enabled, and set it's signal high |
|
40 |
Then, set the previous servo's signal low |
|
41 |
Now, set the next output compare to occur for some time from now |
|
42 |
specified by the current servo's value |
|
43 |
*/ |
|
44 |
SIGNAL (SIG_OUTPUT_COMPARE3B) |
|
45 |
{ |
|
46 |
lcd_putchar('i'); |
|
47 |
if(servo_flag == 0) |
|
48 |
return; |
|
49 |
|
|
50 |
int i; |
|
51 |
if(phase_time == 0){ |
|
52 |
lcd_putchar('p'); |
|
53 |
for(i=0;i<8;i++){ |
|
54 |
if(servos_on & _BV(i)) |
|
55 |
digital_output((_PORT_E << 3) +i,1); |
|
56 |
} |
|
57 |
servos_enabled = servos_on; |
|
58 |
phase_base = OCR3B; |
|
59 |
} |
|
60 |
|
|
61 |
unsigned int min=~0; |
|
62 |
for(i=0;i<8;i++){ |
|
63 |
if(_BV(i) & servos_enabled){ |
|
64 |
if(SERVO_CONSTANT*servo_vals[i] <= phase_time){ |
|
65 |
digital_output((_PORT_E << 3) + i,0); |
|
66 |
servos_enabled &= ~_BV(i); |
|
67 |
} |
|
68 |
else if(SERVO_CONSTANT*servo_vals[i] < min) { |
|
69 |
min = servo_vals[i]; |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
if(!servos_enabled){ |
|
74 |
OCR3B = phase_base + SERVO_PERIOD; |
|
75 |
phase_time = 0; |
|
76 |
} |
|
77 |
else { |
|
78 |
OCR3B = phase_base + min; |
|
79 |
phase_time = min; |
|
80 |
} |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
void init_servo() |
|
85 |
{ |
|
86 |
//1010 1001 |
|
87 |
TCCR3A = 0; |
|
88 |
//0000 0100 |
|
89 |
TCCR3B = 0x4; //prescaler to 256 |
|
90 |
TCCR3C=0; |
|
91 |
lcd_init(); |
|
92 |
ETIMSK |= 0x08; |
|
93 |
servo_flag = 1; |
|
94 |
OCR3B = 0x0; |
|
95 |
lcd_putchar('i'); |
|
96 |
} |
|
97 |
|
|
98 |
// Enable a servo specified by config |
|
99 |
void enable_servo(int config) |
|
100 |
{ |
|
101 |
servos_on |= _BV(config); |
|
102 |
} |
|
103 |
|
|
104 |
// Disable a servo specified by config |
|
105 |
void disable_servo(int config) |
|
106 |
{ |
|
107 |
servos_on &= (0xFF-_BV(config)); |
|
108 |
} |
|
109 |
|
|
110 |
// Disables the timer1 interrupt, disabling the servos |
Also available in: Unified diff