Revision 105
Recharging code for the robots now compiles. It is entirely untested.
seeking.c | ||
---|---|---|
1 | 1 |
#include "seeking.h" |
2 | 2 |
|
3 | 3 |
#include <move.h> |
4 |
#include <serial.h> |
|
4 | 5 |
|
6 |
#include "recharge_i2c.h" |
|
7 |
#include "recharge_defs.h" |
|
8 |
|
|
5 | 9 |
#include <wl_token_ring.h> |
6 | 10 |
|
7 | 11 |
#define SEEK_WITH_BOM 1 |
... | ... | |
22 | 26 |
int seek_station_with_bom(int station); |
23 | 27 |
int seek_station_with_homing_sensor(void); |
24 | 28 |
|
25 |
int state = SEEK_WITH_BOM; |
|
29 |
int seeking_state = SEEK_WITH_BOM;
|
|
26 | 30 |
|
27 | 31 |
void seek_station(int station) |
28 | 32 |
{ |
29 |
if (state == SEEK_WITH_BOM) |
|
30 |
state = seek_station_with_bom(station); |
|
33 |
if (seeking_state == SEEK_WITH_BOM)
|
|
34 |
seeking_state = seek_station_with_bom(station);
|
|
31 | 35 |
else |
32 |
state = seek_station_with_homing_sensor(); |
|
36 |
seeking_state = seek_station_with_homing_sensor();
|
|
33 | 37 |
} |
34 | 38 |
|
35 | 39 |
int seek_station_with_bom(int station) |
... | ... | |
55 | 59 |
move_avoid(v, w, 5); |
56 | 60 |
} |
57 | 61 |
|
58 |
//TODO: redesign i2c to make this cleaner and not use globals |
|
59 |
if(i2c_homing_sensor_data_dirty == I2C_DATA_DIRTY) |
|
60 |
return SEEK_WITH_BOM; |
|
61 |
|
|
62 | 62 |
//data is fresh, use it |
63 |
int widthcount = i2c_homing_sensor_data; |
|
64 |
i2c_homing_sensor_data_dirty = I2C_DATA_DIRTY; |
|
63 |
int widthcount = recharge_i2c_get_homing_reading(); |
|
65 | 64 |
|
66 | 65 |
if(widthcount>= 4) |
67 | 66 |
return SEEK_WITH_HOMING; |
... | ... | |
70 | 69 |
|
71 | 70 |
int seek_station_with_homing_sensor(void) |
72 | 71 |
{ |
73 |
//if you have no new data, just continue on our current path |
|
74 |
if(i2c_homing_sensor_data_dirty == I2C_DATA_DIRTY) |
|
75 |
return SEEK_WITH_HOMING; |
|
76 |
|
|
77 | 72 |
//TODO: create function in homing.h to return LEFT, FORWARD, RIGHT, or NONE |
78 |
int widthcount = i2c_homing_sensor_data; |
|
79 |
i2c_homing_sensor_data_dirty = I2C_DATA_DIRTY; |
|
73 |
int widthcount = recharge_i2c_get_homing_reading(); |
|
80 | 74 |
|
81 | 75 |
if (widthcount < LEFT_LOW) //can't use beacon, switch to BOM |
82 | 76 |
return SEEK_WITH_BOM; |
Also available in: Unified diff