Revision 156
Updated robot_slave code; reformatted a lot of stuff
trunk/code/lib/include/libdragonfly/lights.h | ||
---|---|---|
1 |
/** |
|
2 |
* @file lights.h |
|
3 |
* @brief Contains declarations for managing the orbs. |
|
4 |
* |
|
5 |
* Contains declarations for using the orbs and PWM. |
|
6 |
* |
|
7 |
* @author Colony Project, CMU Robotics Club |
|
8 |
* Based on Firefly Library, by Tom Lauwers and Steven Shamlian |
|
9 |
**/ |
|
10 |
|
|
11 |
#ifndef _LIGHTS_H_ |
|
12 |
#define _LIGHTS_H_ |
|
13 |
|
|
14 |
|
|
15 |
/** |
|
16 |
* @addtogroup orbs |
|
17 |
* @{ |
|
18 |
**/ |
|
19 |
|
|
20 |
//ORB Colors |
|
21 |
/** @brief Red **/ |
|
22 |
#define RED 0xE0 |
|
23 |
/** @brief Orange **/ |
|
24 |
#define ORANGE 0xE4 |
|
25 |
/** @brief Yellow **/ |
|
26 |
#define YELLOW 0xE8 |
|
27 |
/** @brief Lime **/ |
|
28 |
#define LIME 0x68 |
|
29 |
/** @brief Green **/ |
|
30 |
#define GREEN 0x1C |
|
31 |
/** @brief Cyan **/ |
|
32 |
#define CYAN 0x1F |
|
33 |
/** @brief Blue **/ |
|
34 |
#define BLUE 0x03 |
|
35 |
/** @brief Pink **/ |
|
36 |
#define PINK 0xA6 |
|
37 |
/** @brief Purple **/ |
|
38 |
#define PURPLE 0x41 |
|
39 |
/** @brief Magenta **/ |
|
40 |
#define MAGENTA 0xE3 |
|
41 |
/** @brief White **/ |
|
42 |
#define WHITE 0xFE |
|
43 |
/** @brief Turn the orb off (White) **/ |
|
44 |
#define ORB_OFF 0xFE //ORB_OFF->WHITE |
|
45 |
|
|
46 |
/** @brief Enables the orbs **/ |
|
47 |
void orb_init(void); |
|
48 |
/** @brief Set both orbs to a specified color **/ |
|
49 |
void orb_set(unsigned char red_led, unsigned char green_led, |
|
50 |
unsigned char blue_led); |
|
51 |
/** @brief Set orb1 to a specified color **/ |
|
52 |
void orb1_set(unsigned char red_led, unsigned char green_led, |
|
53 |
unsigned char blue_led); |
|
54 |
/** @brief Set orb2 to a specified color **/ |
|
55 |
void orb2_set(unsigned char red_led, unsigned char green_led, |
|
56 |
unsigned char blue_led); |
|
57 |
|
|
58 |
/** @brief Set both orbs to a specified color **/ |
|
59 |
void orb_set_color(int col); |
|
60 |
/** @brief Set orb1 to a specified color **/ |
|
61 |
void orb1_set_color(int col); |
|
62 |
/** @brief Set orb2 to a specified color **/ |
|
63 |
void orb2_set_color(int col); |
|
64 |
|
|
65 |
/** @brief Disable the orbs **/ |
|
66 |
void orb_disable(void); |
|
67 |
/** @brief Enable the orbs **/ |
|
68 |
void orb_enable(void); |
|
69 |
|
|
70 |
/** @} **/ //end addtogroup |
|
71 |
|
|
72 |
#endif |
|
73 |
|
|
1 |
/** |
|
2 |
* @file lights.h |
|
3 |
* @brief Contains declarations for managing the orbs. |
|
4 |
* |
|
5 |
* Contains declarations for using the orbs and PWM. |
|
6 |
* |
|
7 |
* @author Colony Project, CMU Robotics Club |
|
8 |
* Based on Firefly Library, by Tom Lauwers and Steven Shamlian |
|
9 |
**/ |
|
10 |
|
|
11 |
#ifndef _LIGHTS_H_ |
|
12 |
#define _LIGHTS_H_ |
|
13 |
|
|
14 |
|
|
15 |
/** |
|
16 |
* @addtogroup orbs |
|
17 |
* @{ |
|
18 |
**/ |
|
19 |
|
|
20 |
//ORB Colors |
|
21 |
/** @brief Red **/ |
|
22 |
#define RED 0xE0 |
|
23 |
/** @brief Orange **/ |
|
24 |
#define ORANGE 0xE4 |
|
25 |
/** @brief Yellow **/ |
|
26 |
#define YELLOW 0xE8 |
|
27 |
/** @brief Lime **/ |
|
28 |
#define LIME 0x68 |
|
29 |
/** @brief Green **/ |
|
30 |
#define GREEN 0x1C |
|
31 |
/** @brief Cyan **/ |
|
32 |
#define CYAN 0x1F |
|
33 |
/** @brief Blue **/ |
|
34 |
#define BLUE 0x03 |
|
35 |
/** @brief Pink **/ |
|
36 |
#define PINK 0xA6 |
|
37 |
/** @brief Purple **/ |
|
38 |
#define PURPLE 0x41 |
|
39 |
/** @brief Magenta **/ |
|
40 |
#define MAGENTA 0xE3 |
|
41 |
/** @brief White **/ |
|
42 |
#define WHITE 0xFE |
|
43 |
/** @brief Turn the orb off (White) **/ |
|
44 |
#define ORB_OFF 0xFE //ORB_OFF->WHITE |
|
45 |
|
|
46 |
/** @brief Enables the orbs **/ |
|
47 |
void orb_init(void); |
|
48 |
/** @brief Set both orbs to a specified color **/ |
|
49 |
void orb_set(unsigned char red_led, unsigned char green_led, |
|
50 |
unsigned char blue_led); |
|
51 |
/** @brief Set orb1 to a specified color **/ |
|
52 |
void orb1_set(unsigned char red_led, unsigned char green_led, |
|
53 |
unsigned char blue_led); |
|
54 |
/** @brief Set orb2 to a specified color **/ |
|
55 |
void orb2_set(unsigned char red_led, unsigned char green_led, |
|
56 |
unsigned char blue_led); |
|
57 |
|
|
58 |
/** @brief Set both orbs to a specified color **/ |
|
59 |
void orb_set_color(int col); |
|
60 |
/** @brief Set orb1 to a specified color **/ |
|
61 |
void orb1_set_color(int col); |
|
62 |
/** @brief Set orb2 to a specified color **/ |
|
63 |
void orb2_set_color(int col); |
|
64 |
|
|
65 |
/** @brief Disable the orbs **/ |
|
66 |
void orb_disable(void); |
|
67 |
/** @brief Enable the orbs **/ |
|
68 |
void orb_enable(void); |
|
69 |
|
|
70 |
/** @} **/ //end addtogroup |
|
71 |
|
|
72 |
#endif |
trunk/code/projects/colonet/lib/colonet_wireless/colonet_wireless.h | ||
---|---|---|
3 | 3 |
* @brief Wireless library for communicating with colony robots |
4 | 4 |
* |
5 | 5 |
* @author Eugene Marinelli |
6 |
* @date 10/26/06 |
|
7 |
* |
|
8 |
* @bug gtkterm must be running for the library to work... |
|
6 |
* @date 10/10/07 |
|
9 | 7 |
*/ |
10 | 8 |
|
11 | 9 |
#ifndef COLONET_WIRELESS_H_ |
trunk/code/projects/colonet/lib/colonet_dragonfly/Makefile | ||
---|---|---|
1 |
COLONYROOT = ../../../../.. |
|
2 |
|
|
1 | 3 |
# colonet_wireless_test makefile |
2 | 4 |
MCU = atmega128 |
3 | 5 |
F_CPU = 8000000 |
... | ... | |
14 | 16 |
|
15 | 17 |
colonet_dragonfly.o: colonet_dragonfly.c colonet_dragonfly.h |
16 | 18 |
$(CC) $(CDEFS) $(CFLAGS) $(INCLUDES) -c colonet_dragonfly.c |
17 |
ar rc ../libcolonet_dragonfly.a colonet_dragonfly.o |
|
18 |
ranlib ../libcolonet_dragonfly.a |
|
19 |
ar rc libcolonet_dragonfly.a colonet_dragonfly.o |
|
20 |
ranlib libcolonet_dragonfly.a |
|
21 |
cp libcolonet_dragonfly.a $(COLONYROOT)/code/lib/bin/ |
|
19 | 22 |
|
20 | 23 |
clean: |
21 | 24 |
rm -rf *.o |
trunk/code/projects/colonet/ColonetServer/Command.cpp | ||
---|---|---|
10 | 10 |
* and sends it to the appropriate client |
11 | 11 |
*/ |
12 | 12 |
|
13 |
#include <colonet_wireless.h> |
|
14 |
#include <ctype.h> |
|
15 |
#include <stdio.h> |
|
13 | 16 |
#include <stdlib.h> |
14 |
#include <stdio.h> |
|
15 | 17 |
#include <string.h> |
16 |
#include <ctype.h> |
|
18 |
|
|
17 | 19 |
#include "includes/Command.h" |
18 | 20 |
#include "includes/ConnectionPool.h" |
19 | 21 |
|
... | ... | |
55 | 57 |
} |
56 | 58 |
|
57 | 59 |
if (command_id == SEND_TO_ROBOT) { |
58 |
if (parse_send_to_robot(number_tokens, tokens)) { |
|
60 |
if (parse_send_to_robot(number_tokens, tokens, pool_index)) {
|
|
59 | 61 |
return -1; |
60 | 62 |
} |
61 | 63 |
} else if (command_id == REQUEST_FROM_SERVER) { |
... | ... | |
142 | 144 |
return 0; |
143 | 145 |
} |
144 | 146 |
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
int Command::parse_send_to_robot(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]) { |
|
147 |
int Command::parse_send_to_robot(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) { |
|
151 | 148 |
int i; |
152 | 149 |
unsigned char int_tokens[MAX_TOKENS]; |
153 | 150 |
int number_int_tokens = number_tokens; |
... | ... | |
161 | 158 |
} |
162 | 159 |
|
163 | 160 |
// Fill arguments buffer with arguments |
164 |
for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET; |
|
165 |
i++) { |
|
161 |
for (i = ROBOT_COMMAND_LEN; i < number_int_tokens-ROBOT_COMMAND_OFFSET; i++) { |
|
166 | 162 |
arguments[i-ROBOT_COMMAND_LEN] = int_tokens[i]; |
167 | 163 |
} |
168 | 164 |
|
... | ... | |
172 | 168 |
return -1; |
173 | 169 |
} |
174 | 170 |
|
175 |
/* |
|
176 | 171 |
// Send packet to robot |
177 |
fprintf(stderr, "Calling colonet_wl_send(%d, %d, %d, arguments)\n", |
|
178 |
int_tokens[0], int_tokens[1], int_tokens[2]); |
|
179 |
colonet_wl_send(pool_index, int_tokens[0], |
|
180 |
(ColonetMessageType)int_tokens[1], int_tokens[2], |
|
181 |
arguments); |
|
182 |
*/ |
|
172 |
fprintf(stderr, "Calling colonet_wl_send(%d, %d, %d, arguments)\n", int_tokens[0], int_tokens[1], int_tokens[2]); |
|
173 |
colonet_wl_send(pool_index, int_tokens[0], (ColonetMessageType)int_tokens[1], int_tokens[2], arguments); |
|
174 |
|
|
183 | 175 |
return 0; |
184 | 176 |
} |
185 | 177 |
|
186 |
|
|
187 | 178 |
int Command::parse_request_from_server(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index) { |
188 | 179 |
char* end_pointer = NULL; |
189 | 180 |
|
... | ... | |
191 | 182 |
return -1; |
192 | 183 |
} |
193 | 184 |
|
194 |
if (number_tokens < 2) |
|
185 |
if (number_tokens < 2) {
|
|
195 | 186 |
return -1; |
187 |
} |
|
196 | 188 |
|
197 | 189 |
end_pointer=NULL; |
198 | 190 |
int second_token = strtol(tokens[1], &end_pointer, 10); |
trunk/code/projects/colonet/ColonetServer/wirelessMessageHandler.cpp | ||
---|---|---|
21 | 21 |
/* Globals */ |
22 | 22 |
extern ColonetServer colonet_server; |
23 | 23 |
|
24 |
|
|
25 | 24 |
/* Public functions */ |
26 | 25 |
int wirelessMessageHandler(unsigned char type, short source, int dest, |
27 | 26 |
unsigned char* data, int len) { |
28 | 27 |
printf("Server received wireless message!!!\n"); |
29 | 28 |
|
30 | 29 |
return colonet_server.process_received_wireless_message(type, source, dest, |
31 |
data, len);
|
|
30 |
data, len);
|
|
32 | 31 |
} |
trunk/code/projects/colonet/ColonetServer/includes/Command.h | ||
---|---|---|
20 | 20 |
int check_tokens(unsigned char* tokens, int number_tokens); |
21 | 21 |
|
22 | 22 |
private: |
23 |
int parse_send_to_robot(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE]); |
|
23 |
int parse_send_to_robot(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index);
|
|
24 | 24 |
int parse_request_from_server(int number_tokens, char tokens[MAX_TOKENS][MAX_TOKEN_SIZE], int pool_index); |
25 | 25 |
|
26 | 26 |
int parse_request_bom_matrix(int pool_index); |
trunk/code/projects/colonet/utilities/robot_slave/bom.h | ||
---|---|---|
1 |
|
|
2 |
#ifndef _BOM_H |
|
3 |
#define _BOM_H |
|
4 |
|
|
5 |
|
|
6 |
/* |
|
7 |
|
|
8 |
|
|
9 |
Bk R Y (Analog) |
|
10 |
--------- |
|
11 |
Green |
|
12 |
Blue |
|
13 |
White |
|
14 |
--------- |
|
15 |
Blue |
|
16 |
White |
|
17 |
|
|
18 |
*/ |
|
19 |
|
|
20 |
|
|
21 |
/* |
|
22 |
the analog pin definitions from dio.h DO NOT work here, |
|
23 |
so we must use PF0 from avrgcc (as opposed to _PIN_F0). |
|
24 |
BUT the dio pin definitions from dio.h must be used (no PE...). |
|
25 |
|
|
26 |
also, _PIN_E2 is initialized to high for some reason, |
|
27 |
which turns the BOM on when the robot is turned on. |
|
28 |
WORK-AROUND: call digital_output(_PIN_E2,0) at some point. |
|
29 |
|
|
30 |
*/ |
|
31 |
|
|
32 |
#define MONKI PF0 //analog (yellow) |
|
33 |
//------------------------// |
|
34 |
#define MONKL _PIN_E2 //green |
|
35 |
#define MONK1 _PIN_E3 //blue |
|
36 |
#define MONK0 _PIN_E4 //white |
|
37 |
//------------------------// |
|
38 |
#define MONK3 _PIN_E6 //blue |
|
39 |
#define MONK2 _PIN_E7 //white |
|
40 |
|
|
41 |
|
|
42 |
int getMaxBom( void ); |
|
43 |
|
|
44 |
int printAllBoms(void); |
|
45 |
char bytetosymb(unsigned int c); |
|
46 |
|
|
47 |
void bom_on(void); |
|
48 |
void bom_off(void); |
|
49 |
|
|
50 |
void output_high(int which); |
|
51 |
void output_low(int which); |
|
52 |
|
|
53 |
|
|
54 |
#endif |
|
55 |
|
trunk/code/projects/colonet/utilities/robot_slave/time.h | ||
---|---|---|
1 |
/* |
|
2 |
time.h |
|
3 |
*/ |
|
4 |
|
|
5 |
#ifndef _TIME_H_ |
|
6 |
#define _TIME_H_ |
|
7 |
|
|
8 |
/* Predefined times for prescale_opt in time.c. |
|
9 |
To make you own, know that a pulse is 1/16th of a second. You cannot get less than this. To get more, you need |
|
10 |
to know how many 16ths of a second are in the time you want. (Time_desired * 16 = prescaler_opt) |
|
11 |
*/ |
|
12 |
#define SIXTEENTH_SECOND 1 |
|
13 |
#define EIGTH_SECOND 2 |
|
14 |
#define QUARTER_SECOND 4 |
|
15 |
#define HALF_SECOND 8 |
|
16 |
#define SECOND 16 |
|
17 |
#define TWO_SECOND 32 |
|
18 |
#define FOUR_SECOND 64 |
|
19 |
/* |
|
20 |
delay_ms(int ms) |
|
21 |
pause_ms(int ms) |
|
22 |
sleep_ms(int ms) |
|
23 |
pause(int ms) |
|
24 |
sleep(int ms) |
|
25 |
|
|
26 |
all have the same behavior |
|
27 |
pauses the calling process for the specified |
|
28 |
amount of time in milliseconds |
|
29 |
*/ |
|
30 |
void delay_ms(int ms) ; |
|
31 |
void pause_ms(int ms); |
|
32 |
void pause(int ms); |
|
33 |
void sleep_ms(int ms); |
|
34 |
void sleep(int ms); |
|
35 |
|
|
36 |
/* |
|
37 |
void rtc_init(void) |
|
38 |
call this function to initialize the real time clock |
|
39 |
real time clock requires global interrupts to be enabled |
|
40 |
*/ |
|
41 |
void rtc_init(int prescale_opt, void (*rtc_func)(void)); |
|
42 |
/* |
|
43 |
void rtc_reset(void) |
|
44 |
use this to reset the real time value |
|
45 |
rtc_init() should be called beforehand |
|
46 |
*/ |
|
47 |
void rtc_reset(void); |
|
48 |
|
|
49 |
/* |
|
50 |
int rtc(void) |
|
51 |
returns the current value of the real time clock (in seconds) |
|
52 |
rtc_init() should be called beforehand |
|
53 |
|
|
54 |
the returned amount is the number of seconds that have past since the |
|
55 |
last call to rtc_init() or rtc_reset() |
|
56 |
*/ |
|
57 |
int rtc(void); |
|
58 |
|
|
59 |
#endif |
trunk/code/projects/colonet/utilities/robot_slave/lcd.c | ||
---|---|---|
1 |
/* |
|
2 |
|
|
3 |
lcd-ar2.c - implementation for lcd functions |
|
4 |
|
|
5 |
Author: CMU Robotics Club, Colony Project |
|
6 |
|
|
7 |
This uses SPI. |
|
8 |
|
|
9 |
lcd_init MUST be called before anything can be used. |
|
10 |
|
|
11 |
*/ |
|
12 |
|
|
13 |
#include <avr/io.h> |
|
14 |
#include <lcd.h> |
|
15 |
#include <time.h> |
|
16 |
|
|
17 |
// data bus for LCD, pins on port 0 |
|
18 |
//#define D0 16 |
|
19 |
//#define D1 17 |
|
20 |
//#define D2 18 |
|
21 |
//#define D3 19 |
|
22 |
//#define D4 20 |
|
23 |
//#define D5 21 |
|
24 |
//#define D6 22 |
|
25 |
//#define D7 23 |
|
26 |
|
|
27 |
// OLED data port |
|
28 |
//#define LCD_DATA 0x00FF0000 |
|
29 |
|
|
30 |
// other OLED pins |
|
31 |
//#define LCD_RW 0x00000080 |
|
32 |
#define LCD_RS PB4 // Command/Data |
|
33 |
//#define LCD_RD 0x00008000 |
|
34 |
#define LCD_RSTB PE2 // reset line |
|
35 |
#define LCD_CS PB0 |
|
36 |
|
|
37 |
// inialize OLED and SPI |
|
38 |
void OLED_init(void); |
|
39 |
|
|
40 |
// reset Controller |
|
41 |
void Reset_SSD1339(void); |
|
42 |
|
|
43 |
// write command or data |
|
44 |
void write_c(unsigned char out_command); |
|
45 |
void write_d(unsigned char out_data); |
|
46 |
|
|
47 |
// these write data to the OLED on 8 bit data bus, depends on MCU |
|
48 |
void LCD_out(unsigned char cmd); |
|
49 |
|
|
50 |
// these functions set / clear pins for OLED control lines. they accecpt a 0 or 1 |
|
51 |
//void RD(char stat); |
|
52 |
//void RW(char stat); |
|
53 |
void DC(char stat); |
|
54 |
void RES(char stat); |
|
55 |
void CS(char stat); |
|
56 |
|
|
57 |
// a stupid delay |
|
58 |
//void delay_ms(int count); |
|
59 |
|
|
60 |
// LPC 2138 MCU initialization |
|
61 |
//void Initialize(void); |
|
62 |
//void feed(void); |
|
63 |
|
|
64 |
void crazycircle (void) { |
|
65 |
/* int i; |
|
66 |
// draw 100 random circles |
|
67 |
for(i = 0;i < 100;i++){ |
|
68 |
write_c(0x86); // draw circle command |
|
69 |
write_d(rand() % 130); |
|
70 |
write_d(rand() % 130); |
|
71 |
write_d(rand() % 64); |
|
72 |
write_d(rand()); |
|
73 |
write_d(rand()); |
|
74 |
write_d(rand()); |
|
75 |
write_d(rand()); |
|
76 |
|
|
77 |
delay_ms(10); |
|
78 |
} |
|
79 |
*/ |
|
80 |
} |
|
81 |
|
|
82 |
void OLEDtest (void) { |
|
83 |
//int i = 0; |
|
84 |
|
|
85 |
// Initialize |
|
86 |
//Initialize(); |
|
87 |
OLED_init(); |
|
88 |
|
|
89 |
delay_ms(120); |
|
90 |
|
|
91 |
write_c(0x8e); // clear window command |
|
92 |
write_d(0); |
|
93 |
write_d(0); |
|
94 |
write_d(130); |
|
95 |
write_d(130); |
|
96 |
|
|
97 |
delay_ms(100); |
|
98 |
|
|
99 |
write_c(0x92); // fill enable command |
|
100 |
write_d(0x01); |
|
101 |
|
|
102 |
delay_ms(10); |
|
103 |
|
|
104 |
crazycircle(); |
|
105 |
/* |
|
106 |
// write directly to ram, this fills up bottom 1/3 of display with color pattern |
|
107 |
write_c(0x5c); |
|
108 |
for (i = 0; i < 2000; i++){ |
|
109 |
write_c(0x5c); |
|
110 |
write_d(i); |
|
111 |
write_d(i); |
|
112 |
write_d(i); |
|
113 |
} |
|
114 |
*/ |
|
115 |
} |
|
116 |
|
|
117 |
/********************************************************** |
|
118 |
Initialize |
|
119 |
**********************************************************/ |
|
120 |
|
|
121 |
void OLED_init(void) |
|
122 |
{ |
|
123 |
// Setup SPI here |
|
124 |
SPCR = 0x5D; // enable SPI, master, SPI mode 3 |
|
125 |
DDRB |= 0x06; // enable MOSI and SCK as outputs |
|
126 |
|
|
127 |
LCD_out(0); |
|
128 |
DC(0); |
|
129 |
CS(0); |
|
130 |
Reset_SSD1339(); |
|
131 |
write_c(0xa0); // Set Re-map / Color Depth |
|
132 |
write_d(0x34);//0xb4); // 262K 8bit R->G->B |
|
133 |
write_c(0xa1); // Set display start line |
|
134 |
write_d(0x00); // 00h start |
|
135 |
//write_c(0xa2); // Set display offset |
|
136 |
//write_d(0x80); // 80h start |
|
137 |
write_c(0xA6); // Normal display |
|
138 |
write_c(0xad); // Set Master Configuration |
|
139 |
write_d(0x8e); // DC-DC off & external VcomH voltage & external pre-charge voltage |
|
140 |
write_c(0xb0); // Power saving mode |
|
141 |
write_d(0x05); |
|
142 |
write_c(0xb1); // Set pre & dis_charge |
|
143 |
write_d(0x11); // pre=1h dis=1h |
|
144 |
write_c(0xb3); // clock & frequency |
|
145 |
write_d(0xf0); // clock=Divser+1 frequency=fh |
|
146 |
write_c(0xbb); // Set pre-charge voltage of color A B C |
|
147 |
write_d(0xff); // color A was 1c |
|
148 |
write_d(0xff); // color B was 1c |
|
149 |
write_d(0xff); // color C was 1c |
|
150 |
write_c(0xbe); // Set VcomH |
|
151 |
write_d(0x1f); // |
|
152 |
write_c(0xc1); // Set contrast current for A B C |
|
153 |
write_d(0xCa); // Color A was AA |
|
154 |
write_d(0xD4); // Color B was B4 |
|
155 |
write_d(0xF8); // Color C was C8 |
|
156 |
write_c(0xc7); // Set master contrast |
|
157 |
write_d(0x0f); // no change |
|
158 |
write_c(0xca); // Duty |
|
159 |
write_d(0x7f); // 127+1 |
|
160 |
write_c(0xaf); // Display on |
|
161 |
} |
|
162 |
|
|
163 |
void Reset_SSD1339(void) |
|
164 |
{ |
|
165 |
RES(0); |
|
166 |
delay_ms(100); |
|
167 |
RES(1); |
|
168 |
} |
|
169 |
void write_c(unsigned char out_command) |
|
170 |
{ |
|
171 |
DC(0);CS(0); |
|
172 |
//delay_ms(1); |
|
173 |
|
|
174 |
LCD_out(out_command); |
|
175 |
// delay_ms(1); |
|
176 |
|
|
177 |
DC(1); |
|
178 |
// potentially add NOP |
|
179 |
CS(1); |
|
180 |
|
|
181 |
} |
|
182 |
|
|
183 |
void write_d(unsigned char out_data) |
|
184 |
{ |
|
185 |
DC(1);CS(0); |
|
186 |
// delay_ms(1); |
|
187 |
|
|
188 |
LCD_out(out_data); |
|
189 |
// delay_ms(1); |
|
190 |
DC(1); |
|
191 |
//potentially add NOP |
|
192 |
CS(1); |
|
193 |
} |
|
194 |
|
|
195 |
// these functions set / clear pins for LCD control lines. they accecpt a 0 or 1 |
|
196 |
void DC(char stat) |
|
197 |
{ |
|
198 |
DDRB |= _BV(LCD_RS); // RS is P0.30, set to output |
|
199 |
if (stat) |
|
200 |
PORTB |= _BV(LCD_RS); |
|
201 |
else |
|
202 |
PORTB &= ~(_BV(LCD_RS)); |
|
203 |
} |
|
204 |
|
|
205 |
void RES(char stat) |
|
206 |
{ |
|
207 |
DDRE |= _BV(LCD_RSTB); // RSTB is P0.7, set to output |
|
208 |
if (stat) |
|
209 |
PORTE |= _BV(LCD_RSTB); |
|
210 |
else |
|
211 |
PORTE &= ~(_BV(LCD_RSTB)); |
|
212 |
} |
|
213 |
|
|
214 |
void CS(char stat) |
|
215 |
{ |
|
216 |
DDRB |= _BV(LCD_CS); // RSTB is P0.7, set to output |
|
217 |
if (stat) |
|
218 |
PORTB |= _BV(LCD_CS); |
|
219 |
else |
|
220 |
PORTB &= ~(_BV(LCD_CS)); |
|
221 |
} |
|
222 |
|
|
223 |
// send to the LCD |
|
224 |
void LCD_out(unsigned char cmd) |
|
225 |
{ |
|
226 |
SPDR = cmd; |
|
227 |
// could also do this via interrupts |
|
228 |
loop_until_bit_is_set(SPSR, SPIF); |
|
229 |
} |
|
230 |
|
|
231 |
|
|
232 |
//**************************************Old shit below!***************** |
|
233 |
/* |
|
234 |
FontLookup - a lookup table for all characters |
|
235 |
*/ |
|
236 |
static const unsigned char FontLookup [][5] = |
|
237 |
{ |
|
238 |
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp |
|
239 |
{ 0x00, 0x00, 0x5f, 0x00, 0x00 }, // ! |
|
240 |
{ 0x00, 0x07, 0x00, 0x07, 0x00 }, // " |
|
241 |
{ 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # |
|
242 |
{ 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ |
|
243 |
{ 0x23, 0x13, 0x08, 0x64, 0x62 }, // % |
|
244 |
{ 0x36, 0x49, 0x55, 0x22, 0x50 }, // & |
|
245 |
{ 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' |
|
246 |
{ 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( |
|
247 |
{ 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) |
|
248 |
{ 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * |
|
249 |
{ 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + |
|
250 |
{ 0x00, 0x00, 0x50, 0x30, 0x00 }, // , |
|
251 |
{ 0x10, 0x10, 0x10, 0x10, 0x10 }, // - |
|
252 |
{ 0x00, 0x60, 0x60, 0x00, 0x00 }, // . |
|
253 |
{ 0x20, 0x10, 0x08, 0x04, 0x02 }, // / |
|
254 |
{ 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 |
|
255 |
{ 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 |
|
256 |
{ 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 |
|
257 |
{ 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 |
|
258 |
{ 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 |
|
259 |
{ 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 |
|
260 |
{ 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 |
|
261 |
{ 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 |
|
262 |
{ 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 |
|
263 |
{ 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 |
|
264 |
{ 0x00, 0x36, 0x36, 0x00, 0x00 }, // : |
|
265 |
{ 0x00, 0x56, 0x36, 0x00, 0x00 }, // ; |
|
266 |
{ 0x08, 0x14, 0x22, 0x41, 0x00 }, // < |
|
267 |
{ 0x14, 0x14, 0x14, 0x14, 0x14 }, // = |
|
268 |
{ 0x00, 0x41, 0x22, 0x14, 0x08 }, // > |
|
269 |
{ 0x02, 0x01, 0x51, 0x09, 0x06 }, // ? |
|
270 |
{ 0x32, 0x49, 0x59, 0x51, 0x3E }, // @ |
|
271 |
{ 0x7E, 0x11, 0x11, 0x11, 0x7E }, // A |
|
272 |
{ 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B |
|
273 |
{ 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C |
|
274 |
{ 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D |
|
275 |
{ 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E |
|
276 |
{ 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F |
|
277 |
{ 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G |
|
278 |
{ 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H |
|
279 |
{ 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I |
|
280 |
{ 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J |
|
281 |
{ 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K |
|
282 |
{ 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L |
|
283 |
{ 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M |
|
284 |
{ 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N |
|
285 |
{ 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O |
|
286 |
{ 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P |
|
287 |
{ 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q |
|
288 |
{ 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R |
|
289 |
{ 0x46, 0x49, 0x49, 0x49, 0x31 }, // S |
|
290 |
{ 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T |
|
291 |
{ 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U |
|
292 |
{ 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V |
|
293 |
{ 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W |
|
294 |
{ 0x63, 0x14, 0x08, 0x14, 0x63 }, // X |
|
295 |
{ 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y |
|
296 |
{ 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z |
|
297 |
{ 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ |
|
298 |
{ 0x02, 0x04, 0x08, 0x10, 0x20 }, // backslash |
|
299 |
{ 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ] |
|
300 |
{ 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^ |
|
301 |
{ 0x40, 0x40, 0x40, 0x40, 0x40 }, // _ |
|
302 |
{ 0x00, 0x01, 0x02, 0x04, 0x00 }, // ' |
|
303 |
{ 0x20, 0x54, 0x54, 0x54, 0x78 }, // a |
|
304 |
{ 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b |
|
305 |
{ 0x38, 0x44, 0x44, 0x44, 0x20 }, // c |
|
306 |
{ 0x38, 0x44, 0x44, 0x48, 0x7F }, // d |
|
307 |
{ 0x38, 0x54, 0x54, 0x54, 0x18 }, // e |
|
308 |
{ 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f |
|
309 |
{ 0x0C, 0x52, 0x52, 0x52, 0x3E }, // g |
|
310 |
{ 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h |
|
311 |
{ 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i |
|
312 |
{ 0x20, 0x40, 0x44, 0x3D, 0x00 }, // j |
|
313 |
{ 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k |
|
314 |
{ 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l |
|
315 |
{ 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m |
|
316 |
{ 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n |
|
317 |
{ 0x38, 0x44, 0x44, 0x44, 0x38 }, // o |
|
318 |
{ 0x7C, 0x14, 0x14, 0x14, 0x08 }, // p |
|
319 |
{ 0x08, 0x14, 0x14, 0x18, 0x7C }, // q |
|
320 |
{ 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r |
|
321 |
{ 0x48, 0x54, 0x54, 0x54, 0x20 }, // s |
|
322 |
{ 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t |
|
323 |
{ 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u |
|
324 |
{ 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v |
|
325 |
{ 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w |
|
326 |
{ 0x44, 0x28, 0x10, 0x28, 0x44 }, // x |
|
327 |
{ 0x0C, 0x50, 0x50, 0x50, 0x3C }, // y |
|
328 |
{ 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z |
|
329 |
{ 0x00, 0x08, 0x36, 0x41, 0x41 }, // { |
|
330 |
{ 0x00, 0x00, 0x7F, 0x00, 0x00 }, // | |
|
331 |
{ 0x41, 0x41, 0x36, 0x08, 0x00 }, // } |
|
332 |
{ 0x02, 0x01, 0x01, 0x02, 0x01 }, // ~ |
|
333 |
{ 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // del |
|
334 |
}; |
|
335 |
|
|
336 |
|
|
337 |
/* |
|
338 |
initializes the LCD |
|
339 |
*/ |
|
340 |
void lcd_init(void) |
|
341 |
{ |
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
LCDDDR |= (SCE | SDI | SCK); |
|
346 |
LCDRESETDDR |= (RST|D_C); |
|
347 |
|
|
348 |
LCDPORT &= ~( SCE | SDI | SCK); |
|
349 |
LCDRESETPORT &=~(D_C); |
|
350 |
|
|
351 |
SPCR |= 0x50; // no SPI int, SPI en, Master, sample on rising edge, fosc/2 |
|
352 |
SPSR |= 0x01; // a continuation of the above |
|
353 |
|
|
354 |
LCDRESETPORT |= RST; |
|
355 |
delay_ms(10); |
|
356 |
LCDRESETPORT &= (~RST); |
|
357 |
delay_ms(100); |
|
358 |
LCDRESETPORT |= RST; |
|
359 |
|
|
360 |
lcd_putbyte( 0x21 ); // LCD Extended Commands. |
|
361 |
lcd_putbyte( 0xC8 ); // Set LCD Vop (Contrast). |
|
362 |
lcd_putbyte( 0x06 ); // Set Temp coefficent. |
|
363 |
lcd_putbyte( 0x13 ); // LCD bias mode 1:48. |
|
364 |
lcd_putbyte( 0x20 ); // LCD Standard Commands, Horizontal addressing mode. |
|
365 |
lcd_putbyte( 0x0C ); // LCD in normal mode. |
|
366 |
|
|
367 |
LCDRESETPORT |= D_C; //put it in init instead of main |
|
368 |
|
|
369 |
lcd_clear_screen(); |
|
370 |
|
|
371 |
} |
|
372 |
|
|
373 |
/* |
|
374 |
clear the lcd screen |
|
375 |
*/ |
|
376 |
void lcd_clear_screen( void ) { |
|
377 |
|
|
378 |
|
|
379 |
int i; |
|
380 |
for (i = 0; i < 504; i++) |
|
381 |
lcd_putbyte(0x0); |
|
382 |
|
|
383 |
lcd_gotoxy(0,0); |
|
384 |
|
|
385 |
|
|
386 |
} |
|
387 |
|
|
388 |
|
|
389 |
/* |
|
390 |
print a byte on the lcd screen |
|
391 |
*/ |
|
392 |
void lcd_putbyte(unsigned char b) |
|
393 |
{ |
|
394 |
|
|
395 |
|
|
396 |
SPDR = b; |
|
397 |
while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */ |
|
398 |
|
|
399 |
|
|
400 |
} |
|
401 |
|
|
402 |
/* |
|
403 |
print a character on the lcd |
|
404 |
*/ |
|
405 |
void lcd_putchar(char c) |
|
406 |
{ |
|
407 |
|
|
408 |
|
|
409 |
int i; |
|
410 |
|
|
411 |
for (i = 0; i < 5; i++) |
|
412 |
lcd_putbyte(FontLookup[c-32][i]); |
|
413 |
lcd_putbyte(0); |
|
414 |
|
|
415 |
|
|
416 |
} |
|
417 |
|
|
418 |
/* |
|
419 |
print an entire string to the lcd |
|
420 |
*/ |
|
421 |
void lcd_putstr(char *s) |
|
422 |
{ |
|
423 |
char *t = s; |
|
424 |
while (*t != 0) |
|
425 |
{ |
|
426 |
lcd_putchar(*t); |
|
427 |
t++; |
|
428 |
} |
|
429 |
} |
|
430 |
|
|
431 |
/* |
|
432 |
go to coordinate x, y |
|
433 |
y: vertically - 1 char |
|
434 |
x: horizontally - 1 pixel |
|
435 |
|
|
436 |
multiply x by 6 if want to move 1 entire character |
|
437 |
|
|
438 |
origin (0,0) is at top left corner of lcd screen |
|
439 |
*/ |
|
440 |
void lcd_gotoxy(int x, int y) |
|
441 |
{ |
|
442 |
|
|
443 |
LCDRESETPORT &= ~(D_C); |
|
444 |
lcd_putbyte(0x40 | (y & 0x07)); |
|
445 |
lcd_putbyte(0x80 | (x & 0x7f)); |
|
446 |
LCDRESETPORT |= D_C; |
|
447 |
|
|
448 |
} |
|
449 |
|
|
450 |
/* |
|
451 |
prints an int to the lcd |
|
452 |
|
|
453 |
code adapted from Chris Efstathiou's code (hendrix@otenet.gr) |
|
454 |
*/ |
|
455 |
void lcd_putint(int value ) { |
|
456 |
unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; |
|
457 |
|
|
458 |
/* convert int to ascii */ |
|
459 |
if(value<0) { lcd_putchar('-'); value=-value; } |
|
460 |
do { position--; *(lcd_data+position)=(value%radix)+'0'; value/=radix; } while(value); |
|
461 |
|
|
462 |
|
|
463 |
/* start displaying the number */ |
|
464 |
for(;position<=(sizeof(lcd_data)-1);position++) |
|
465 |
{ |
|
466 |
|
|
467 |
lcd_putchar(lcd_data[position]); |
|
468 |
} |
|
469 |
|
|
470 |
return; |
|
471 |
} |
trunk/code/projects/colonet/utilities/robot_slave/pindefs_ff.h | ||
---|---|---|
1 |
// Motors |
|
2 |
#define RIGHT 0 /* PIN_D0 output */ |
|
3 |
#define LEFT 1 /* PIN_D1 output */ |
|
4 |
|
|
5 |
// Sensors |
|
6 |
|
|
7 |
/// Monkey |
|
8 |
/* analog input */ |
|
9 |
#define MONKI AN0 /* input */ |
|
10 |
//#define MONKI 0x00 /* input */ |
|
11 |
|
|
12 |
//white |
|
13 |
#define MONK0 PIN_C4 /*0b01100*/ /* output A4 <- */ |
|
14 |
//blue |
|
15 |
#define MONK1 PIN_C3 /*0b01011*/ /* output A3 <- */ |
|
16 |
//green - on/off |
|
17 |
#define MONKL PIN_C2 /*0b01010*/ /* output A2 <- */ |
|
18 |
|
|
19 |
//white2 |
|
20 |
#define MONK2 PIN_C6 /*0b01110*/ /* white output A6 */ |
|
21 |
//blue2 |
|
22 |
#define MONK3 PIN_C5 /*0b01101*/ /* blue output A5 */ |
|
23 |
|
|
24 |
|
|
25 |
//old constants |
|
26 |
|
|
27 |
//data pin |
|
28 |
//#define MONKI 0 /* PIN_A5 input */ |
|
29 |
|
|
30 |
//white |
|
31 |
//#define MONK0 3/* PIN_E0 output */ |
|
32 |
//blue |
|
33 |
//#define MONK1 2/* PIN_E1 output */ |
|
34 |
//white2 |
|
35 |
//#define MONK2 5/* PIN_D2 white output */ |
|
36 |
//blue2 |
|
37 |
//#define MONK3 4/* PIN_D3 blue output */ |
|
38 |
|
|
39 |
//green - on/off |
|
40 |
//#define MONKL 1/*PIN_E2 output */ |
|
41 |
|
|
42 |
/// Bump |
|
43 |
//#define BMPBL PIN_D4 /* input */ |
|
44 |
//#define BMPBR PIN_D5 /* input */ |
|
45 |
//#define BMPFL PIN_D6 /* input */ |
|
46 |
//#define BMPFR PIN_D7 /* input */ |
|
47 |
|
|
48 |
/// Other Sensors |
|
49 |
//#define PYRO 0 /* PIN_A0 input */ |
|
50 |
//#define RANGE 1 /* PIN_A1 input */ |
|
51 |
|
|
52 |
// Wireless |
|
53 |
//#define RXPOW 2 /* PIN_A2 input */ |
|
54 |
//#define TX_EN PIN_A3 /* output */ //// might be trouble |
trunk/code/projects/colonet/utilities/robot_slave/localization.c | ||
---|---|---|
1 |
#include "localization.h" |
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
void addSensor (int maxBom, int self, int other, int NUM_BOTS) |
|
8 |
{ |
|
9 |
//make sure you don't add to the diagonal |
|
10 |
if(self == other) { |
|
11 |
//lcd_putchar('w'); |
|
12 |
return; |
|
13 |
} |
|
14 |
if(self >= NUM_BOTS || other >= NUM_BOTS) |
|
15 |
{ |
|
16 |
// lcd_putchar('y'); |
|
17 |
return; |
|
18 |
} |
|
19 |
|
|
20 |
|
|
21 |
//lcd_putchar('a'); |
|
22 |
//lcd_putchar(self+48); |
|
23 |
//lcd_putchar(':'); |
|
24 |
//lcd_putchar(other+48); |
|
25 |
//lcd_putchar('.'); |
|
26 |
//add this robot to your own row's sensor numbers |
|
27 |
//row = your index |
|
28 |
//column = robotNum (input) |
|
29 |
sensors[self][other] = maxBom; |
|
30 |
|
|
31 |
} |
|
32 |
|
|
33 |
unsigned char getSelfSensor (unsigned char self, unsigned char other, int NUM_BOTS) |
|
34 |
{ |
|
35 |
|
|
36 |
if(other < NUM_BOTS){ |
|
37 |
return sensors[self][other]; |
|
38 |
} |
|
39 |
else { |
|
40 |
return 9; |
|
41 |
} |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
/* |
|
46 |
void printSensorsMatrix (void) |
|
47 |
{ |
|
48 |
|
|
49 |
|
|
50 |
//print table |
|
51 |
int y = 1; |
|
52 |
lcd_gotoxy(0, y); |
|
53 |
int i, j; |
|
54 |
for(i = 0; i < NUM_BOTS; i++) { |
|
55 |
for(j = 0; j < NUM_BOTS; j++) { |
|
56 |
lcd_putchar( getSelfSensor(i, j, NUM_BOTS) + 48); |
|
57 |
lcd_putchar(' '); |
|
58 |
} |
|
59 |
y++; |
|
60 |
lcd_gotoxy(0, y); |
|
61 |
} |
|
62 |
|
|
63 |
delay_ms(1000); |
|
64 |
|
|
65 |
} |
|
66 |
*/ |
|
67 |
|
|
68 |
/* |
|
69 |
SensorRow getSelfSensorRow (int self) |
|
70 |
{ |
|
71 |
|
|
72 |
SensorRow sr; |
|
73 |
int i; |
|
74 |
|
|
75 |
sr.len = NUM_BOTS; |
|
76 |
for(i = 0; i < NUM_BOTS; i++) { |
|
77 |
sr.row[i] = sensors[ |
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
*/ |
trunk/code/projects/colonet/utilities/robot_slave/i2c.h | ||
---|---|---|
1 |
#ifndef _I2C_H_ |
|
2 |
#define _I2C_H_ |
|
3 |
|
|
4 |
void i2c_init(char address); |
|
5 |
char i2c_putc(char dest, char data); |
|
6 |
char i2c_getc(char * c); |
|
7 |
|
|
8 |
#endif |
trunk/code/projects/colonet/utilities/robot_slave/lcd.h | ||
---|---|---|
1 |
#ifndef _LCD_H_ |
|
2 |
#define _LCD_H_ |
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
//////lcd defines |
|
7 |
#define RST _BV(4) // pd4 (GPIO) |
|
8 |
#define SCE _BV(0) // pb0 (~SS) |
|
9 |
#define D_C _BV(5) // pd5 (GPIO?) |
|
10 |
#define SDI _BV(2) // pb2 (MOSI) |
|
11 |
#define SCK _BV(1) // pb1 (SCK) |
|
12 |
|
|
13 |
#define LCDPORT PORTB |
|
14 |
#define LCDDDR DDRB |
|
15 |
|
|
16 |
#define LCDRESETPORT PORTD |
|
17 |
#define LCDRESETDDR DDRD |
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
void lcd_init(void); |
|
22 |
void lcd_clear_screen( void ); |
|
23 |
void lcd_putbyte(unsigned char c); |
|
24 |
void lcd_putchar(char c); |
|
25 |
void lcd_putstr(char *s); |
|
26 |
void lcd_gotoxy(int x, int y); |
|
27 |
void lcd_putint(int value); |
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
#endif |
trunk/code/projects/colonet/utilities/robot_slave/localization.h | ||
---|---|---|
1 |
#ifndef _LOCALIZATION_H_ |
|
2 |
#define _LOCALIZATION_H_ |
|
3 |
|
|
4 |
// Max number of robots possible |
|
5 |
#define MAX_ROBOTS 4 |
|
6 |
|
|
7 |
unsigned char sensors[MAX_ROBOTS][MAX_ROBOTS]; |
|
8 |
|
|
9 |
typedef struct{ |
|
10 |
//actual row of sensor values -- need to be able to have up to |
|
11 |
//max_robots |
|
12 |
unsigned char row[MAX_ROBOTS]; |
|
13 |
//actual length of the row |
|
14 |
unsigned char len; |
|
15 |
//'index' value of the row -- which robot it's for |
|
16 |
unsigned char row_num; |
|
17 |
|
|
18 |
} SensorRow; |
|
19 |
|
|
20 |
void addSensor (int maxBom, int self, int other, int NUM_BOTS); |
|
21 |
unsigned char getSelfSensor (unsigned char self, unsigned char other, |
|
22 |
int NUM_BOTS); |
|
23 |
|
|
24 |
#endif |
trunk/code/projects/colonet/utilities/robot_slave/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 |
|
|
22 |
// Configure counter such that we use phase correct |
|
23 |
// PWM with 8-bit resolution |
|
24 |
PORTA &= 0x0F; |
|
25 |
DDRA |= 0xF0; |
|
26 |
DDRB |= 0x60; |
|
27 |
|
|
28 |
//timer 1A and 1B |
|
29 |
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10); |
|
30 |
TCCR1B = _BV(WGM12) | _BV(CS10); |
|
31 |
// TCCR1A = 0xA1; |
|
32 |
// TCCR1B = 0x04; |
|
33 |
OCR1AH=0; |
|
34 |
OCR1AL=0; |
|
35 |
OCR1BH=0; |
|
36 |
OCR1BL=0; |
|
37 |
} |
|
38 |
|
|
39 |
// The following functions set the motor direction and speed |
|
40 |
void motor1_set(int direction, int speed) { |
|
41 |
|
|
42 |
if(direction == 0) { |
|
43 |
// turn off PWM first if switching directions |
|
44 |
if((PORTA & 0x30) != 0x10) |
|
45 |
{ |
|
46 |
OCR1A = 0; |
|
47 |
} |
|
48 |
PORTA = (PORTA & 0xCF) | 0x10; |
|
49 |
// PORTD |= 0x10; |
|
50 |
// PORTD &= 0xBF; |
|
51 |
} |
|
52 |
else { |
|
53 |
// turn off PWM first if switching directions |
|
54 |
if((PORTA & 0x30) != 0x20) |
|
55 |
{ |
|
56 |
OCR1A = 0; |
|
57 |
} |
|
58 |
PORTA = (PORTA & 0xCF) | 0x20; |
|
59 |
// PORTD |= 0x40; |
|
60 |
// PORTD &= 0xEF; |
|
61 |
} |
|
62 |
|
|
63 |
// Set the timer to count up to speed, an 8-bit value |
|
64 |
OCR1AL = speed; |
|
65 |
|
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
void motor2_set(int direction, int speed) { |
|
70 |
|
|
71 |
if(direction == 0) { |
|
72 |
// PORTD |= 0x20; |
|
73 |
// PORTD &= 0x7F; |
|
74 |
// turn off PWM first if switching directions |
|
75 |
if((PORTA & 0xC0) != 0x80) |
|
76 |
{ |
|
77 |
OCR1B = 0; |
|
78 |
} |
|
79 |
|
|
80 |
PORTA = (PORTA & 0x3F) | 0x80; |
|
81 |
} |
|
82 |
else { |
|
83 |
// PORTD |= 0x80; |
|
84 |
// PORTD &= 0xDF; |
|
85 |
|
|
86 |
// turn off PWM first if switching directions |
|
87 |
if((PORTA & 0xC0) != 0x40) |
|
88 |
{ |
|
89 |
OCR1B = 0; |
|
90 |
} |
|
91 |
|
|
92 |
PORTA = (PORTA & 0x3F) | 0x40; |
|
93 |
} |
|
94 |
OCR1BL = speed; |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
// Just turns off both motors |
|
99 |
void motors_off( void ) { |
|
100 |
OCR1AL = 0x0; |
|
101 |
OCR1BL = 0x0; |
|
102 |
} |
trunk/code/projects/colonet/utilities/robot_slave/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 |
|
|
15 |
|
|
16 |
// Function descriptions can be found in motor.c |
|
17 |
void motors_init(void); |
|
18 |
void motor1_set(int direction, int speed); |
|
19 |
void motor2_set(int direction, int speed); |
|
20 |
void motors_off(void); |
|
21 |
|
|
22 |
#endif |
trunk/code/projects/colonet/utilities/robot_slave/reset.c | ||
---|---|---|
1 |
/* |
|
2 |
reset.h - contains reset() function that resets the AVR |
|
3 |
author: James Kong |
|
4 |
|
|
5 |
Last Modified: |
|
6 |
|
|
7 |
3.7.2007 - James |
|
8 |
created reset.c |
|
9 |
*/ |
|
10 |
|
|
11 |
#include <avr/interrupt.h> |
|
12 |
#include <util/delay.h> |
|
13 |
#include <reset.h> |
|
14 |
|
|
15 |
/* |
|
16 |
Resets the AVR when called. Sets the watchdog timer and lets it overflow |
|
17 |
to reset the AVR. The reset clears all memory and resets all registers |
|
18 |
with the exception of the Watchdog Reset Flag (WDRF) in the MCU Control |
|
19 |
and Status Register (MCUCSR). |
|
20 |
*/ |
|
21 |
void reset(void) |
|
22 |
{ |
|
23 |
WDTCR &= 0xF8; |
|
24 |
WDTCR |= 0x08; |
|
25 |
_delay_ms(15); |
|
26 |
} |
|
27 |
|
trunk/code/projects/colonet/utilities/robot_slave/wl_adhoc.c | ||
---|---|---|
1 |
/** |
|
2 |
\file wl_adhoc.c |
|
3 |
Wireless ad hoc networking. |
|
4 |
NOW WITH SENSORS |
|
5 |
Robots can come in and out of the ring. |
|
6 |
*/ |
|
7 |
|
|
8 |
|
|
9 |
#include <dragonfly_lib.h> |
|
10 |
#include "wl_adhoc.h" |
|
11 |
#include <avr/interrupt.h> |
|
12 |
|
|
13 |
#include "ring_buffer.h" |
|
14 |
#include "bom.h" |
|
15 |
|
|
16 |
#include <colonet_dragonfly.h> |
|
17 |
#include <colonet_defs.h> |
|
18 |
|
|
19 |
#define MAX(a, b) ((a) > (b) ? (a) : (b)) |
|
20 |
#define MIN(a, b) ((a) < (b) ? (a) : (b)) |
|
21 |
|
|
22 |
//#define USB_DEBUG |
|
23 |
|
|
24 |
#ifdef USB_DEBUG |
|
25 |
#define USB_PUTC( c ) usb_putc( c ) |
|
26 |
#define USB_PUTS( s ) usb_puts( s ) |
|
27 |
#define USB_PUTI( i ) usb_puti( i ) |
|
28 |
#else |
|
29 |
#define USB_PUTC( c ) |
|
30 |
#define USB_PUTS( s ) |
|
31 |
#define USB_PUTI( i ) |
|
32 |
#endif |
|
33 |
|
|
34 |
|
|
35 |
RING_BUFFER_NEW(ring_buffer, 256, char, buffer); |
|
36 |
volatile int buffer_size = 0; |
|
37 |
|
|
38 |
void led_user(int x) {} |
|
39 |
|
|
40 |
void usb_putstr(char *s) |
|
41 |
{ |
|
42 |
char *t = s; |
|
43 |
while (*t != 0) |
|
44 |
{ |
|
45 |
usb_putc(*t); |
|
46 |
t++; |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
unsigned char set_orb_wireless = 1; |
|
51 |
unsigned char crazy_debug = 0; |
|
52 |
int max_bom = -1; |
|
53 |
|
|
54 |
|
|
55 |
/* |
|
56 |
\fn wl_timeout_handler |
|
57 |
Handles the timeout case. |
|
58 |
|
|
59 |
A time out occurs about every 1/4 second. This function is called each time |
|
60 |
one occurs. In the case where a robot first turns on, it will wait for a |
|
61 |
long time before declaring itself the leader. Otherwise, if enough |
|
62 |
time-outs occur in a row, wl_to_flag will be set to 1. This will cause a |
|
63 |
timeout packet to be sent next time around |
|
64 |
|
|
65 |
*/ |
|
66 |
void wl_timeout_handler( void ) { |
|
67 |
|
|
68 |
if(crazy_debug) { |
|
69 |
return; |
|
70 |
} |
|
71 |
|
|
72 |
//increment the total number of wireless time-outs |
|
73 |
wl_to_count++; |
|
74 |
//lcd_putchar('w'); |
|
75 |
USB_PUTC('w'); |
|
76 |
|
|
77 |
static int wl_first_to_count = 0; |
|
78 |
|
|
79 |
//first time time out routine - listen for a long time |
|
80 |
if(first_time) { |
|
81 |
if(wl_to_count > WL_TO_INITIAL){ |
|
82 |
//increment the counter for first timeouts |
|
83 |
wl_first_to_count++; |
|
84 |
|
|
85 |
//lcd_putchar('Z'); |
|
86 |
|
|
87 |
//you don't actually want to send out a packet -- you would confuse |
|
88 |
//other robots |
|
89 |
wl_to_flag = 0; |
|
90 |
wl_to_count = 0; |
|
91 |
} |
|
92 |
}else{ |
|
93 |
//not the first time - regular time out routine |
|
94 |
|
|
95 |
// |
|
96 |
if ((wl_sent_cs || wl_sent_depart || wl_sent_dock) && wl_to_count > 3) |
|
97 |
{ |
|
98 |
usb_puts("Charging station timed out. \n\r"); |
|
99 |
wl_sent_cs = 0; |
|
100 |
wl_sent_depart = 0; |
|
101 |
wl_sent_dock = 0; |
|
102 |
wl_create_packet(); |
|
103 |
wl_send(); |
|
104 |
} |
|
105 |
|
|
106 |
//if you have enough timeouts |
|
107 |
if(wl_to_count > WL_TIMEOUT){ |
|
108 |
//lcd_putchar('z'); |
|
109 |
|
|
110 |
USB_PUTS("|time.out|"); |
|
111 |
//change the time-out flag to 1 |
|
112 |
wl_to_flag = 1; |
|
113 |
wl_to_count = 0; |
|
114 |
|
|
115 |
//increment the count for robot death |
|
116 |
if(NUM_BOTS > 1) { |
|
117 |
//only increase death count if there are robots that can die |
|
118 |
//if numbots = 1, you are the only robot (no suicidal robots... yet) |
|
119 |
wl_to_death_count++; |
|
120 |
} |
|
121 |
|
|
122 |
//check for a robot death |
|
123 |
if(wl_to_death_count > WL_TO_DEATH) { |
|
124 |
//a robot has died :( |
|
125 |
wl_to_death_flag = 1; |
|
126 |
wl_death_handler(); |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
//take care of the case where you time out so much that you become the leader |
|
132 |
if(wl_first_to_count > WL_TO_LEADER) { |
|
133 |
//you are now the leader |
|
134 |
//lcd_putchar('L'); |
|
135 |
|
|
136 |
first_time = 0; |
|
137 |
|
|
138 |
NUM_BOTS = 1; //there are (1) robot in the ring |
|
139 |
SRC = 0; //you are robot # 1 |
|
140 |
DEST = 1; //you are 'speaking' to (nonexistent) robot #1 |
|
141 |
|
|
142 |
/* |
|
143 |
lcd_putchar('['); |
|
144 |
lcd_putchar(SRC+48); |
|
145 |
lcd_putchar('|'); |
|
146 |
lcd_putchar(DEST+48); |
|
147 |
lcd_putchar('|'); |
|
148 |
lcd_putchar(NUM_BOTS+48); |
|
149 |
lcd_putchar('|'); |
|
150 |
lcd_putint(wl_to_death_count); |
|
151 |
lcd_putchar(']'); |
|
152 |
*/ |
|
153 |
usb_putc('t'); |
|
154 |
|
|
155 |
//create a a packet and send it |
|
156 |
wl_create_packet(); |
|
157 |
wl_send(); |
|
158 |
|
|
159 |
//change the timeout count to 0 |
|
160 |
wl_to_count = 0; |
|
161 |
wl_first_to_count = 0; |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
\fn wl_error_handler(int errcode) |
|
167 |
Handles error codes. |
|
168 |
\param errcode The error code. |
|
169 |
At the time, the only real error that happens is robot death. |
|
170 |
|
|
171 |
Robot death requires that wl_buf have been set (either by receiving a |
|
172 |
error packet or by calling wl_death_handler. |
|
173 |
|
|
174 |
Robot death: |
|
175 |
Number of robots will decrement. |
|
176 |
Robots above the dead robot will decrement their ID and their source. |
|
177 |
The loop remains closed. |
|
178 |
|
|
179 |
*/ |
|
180 |
void wl_error_handler(unsigned char errcode) |
|
181 |
{ |
|
182 |
USB_PUTS("Error Code: "); |
|
183 |
USB_PUTI(errcode); |
|
184 |
//which robot is dead |
|
185 |
int dead_robot; |
|
186 |
|
|
187 |
//print debug information |
|
188 |
/* |
|
189 |
lcd_clear_screen(); |
|
190 |
lcd_gotoxy(0,0); |
|
191 |
lcd_putstr("error handler "); |
|
192 |
lcd_putint(errcode); |
|
193 |
lcd_gotoxy(0,1); |
|
194 |
*/ |
|
195 |
|
|
196 |
USB_PUTS("|error handler|"); |
|
197 |
|
|
198 |
switch(errcode) { |
|
199 |
case WL_ERRCODE_ROBOTDEATH: |
|
200 |
orb_set_color(RED); |
|
201 |
buzzer_chirp(1000, C5); |
Also available in: Unified diff