Revision 363
Add battery stuff to charging station
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_charging_station.c | ||
---|---|---|
45 | 45 |
void wl_charging_send_cancel(int dest); |
46 | 46 |
void wl_charging_send_seeking(int dest); |
47 | 47 |
void wl_charging_send_docked(int dest); |
48 |
void wl_charging_send_battery(int dest); |
|
48 | 49 |
|
49 | 50 |
// the handler |
50 | 51 |
PacketGroupHandler wl_charging_handler = |
... | ... | |
60 | 61 |
#define CANCEL_FRAME 4 |
61 | 62 |
#define SEEKING_FRAME 5 |
62 | 63 |
#define DOCKED_FRAME 6 |
64 |
#define BATTERY_FRAME 7 |
|
63 | 65 |
|
64 | 66 |
/** |
65 | 67 |
* Register this packet group with the wireless library. |
... | ... | |
159 | 161 |
} |
160 | 162 |
|
161 | 163 |
/** |
164 |
* Sends a packet to request for the robot's battery reading |
|
165 |
* |
|
166 |
* @param dest the robot to request |
|
167 |
**/ |
|
168 |
void wl_charging_send_battery(int dest) |
|
169 |
{ |
|
170 |
wl_send_robot_to_robot_global_packet(WL_RECHARGE_GROUP, WL_RECHARGE_BATTERY, NULL, 0, dest, BATTERY_FRAME); |
|
171 |
} |
|
172 |
|
|
173 |
/** |
|
162 | 174 |
* Called when this packet is unregistered with the wireless library. |
163 | 175 |
**/ |
164 | 176 |
void wl_charging_cleanup(void) |
... | ... | |
268 | 280 |
case WL_RECHARGE_DOCKED: |
269 | 281 |
wl_charging_docked(source); |
270 | 282 |
break; |
283 |
case WL_RECHARGE_BATTERY: |
|
284 |
wl_charging_battery(source,packet,length); |
|
271 | 285 |
default: |
272 | 286 |
STATION_DEBUG_PRINT("Error packet of unknown type received.\n"); |
273 | 287 |
break; |
... | ... | |
284 | 298 |
{ |
285 | 299 |
if (charging_is_space_available() && !charging_is_robot_seeking()) |
286 | 300 |
wl_charging_send_station_available(source); |
301 |
wl_charging_send_battery(source); |
|
287 | 302 |
} |
288 | 303 |
|
289 | 304 |
/** |
... | ... | |
424 | 439 |
charging_dock(source); |
425 | 440 |
} |
426 | 441 |
|
442 |
/** |
|
443 |
* Called when we recieve a packet with a battery reading |
|
444 |
* |
|
445 |
* @param source the robot that is sending the battery reading |
|
446 |
**/ |
|
447 |
void wl_charging_battery(int source, unsigned char* packet, int length) |
|
448 |
{ |
|
449 |
if (charging_get_robot_state(source)==STATE_NOT_CHARGING) |
|
450 |
check_battery(source, (int)packet[0]); |
|
451 |
else |
|
452 |
update_battery(source, (int)packet[0]); |
|
453 |
} |
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/charging.c | ||
---|---|---|
22 | 22 |
int state; |
23 | 23 |
int bay; |
24 | 24 |
int verifyCount; |
25 |
int battery; |
|
25 | 26 |
} ChargingRobot; |
26 | 27 |
|
27 | 28 |
ChargingRobot** robots; |
... | ... | |
300 | 301 |
r->state = STATE_SEEKING; |
301 | 302 |
r->bay = assign_bay(robot); |
302 | 303 |
r->verifyCount = VERIFY_DELAY; |
304 |
r->battery = 0; |
|
303 | 305 |
robots[robot] = r; |
304 | 306 |
numRobots++; |
305 | 307 |
is_seeking = 1; |
... | ... | |
375 | 377 |
} |
376 | 378 |
|
377 | 379 |
/** |
380 |
* Update battery reading of a robot |
|
381 |
* |
|
382 |
* @param robot the robot to update battery reading |
|
383 |
**/ |
|
384 |
void update_battery(int robot, int battery) |
|
385 |
{ |
|
386 |
if (robot < robotSize && robots[robot] != NULL) |
|
387 |
robots[robot]->battery = battery; |
|
388 |
} |
|
389 |
void check_battery(int robot, int battery) |
|
390 |
{ |
|
391 |
if (charging_is_space_available()) return; |
|
392 |
// 152 low voltage |
|
393 |
// 179 charging voltage |
|
394 |
// there's no way to tell the voltage of a charging robot, so we just eject the first one |
|
395 |
charging_robot_iterator_init(); |
|
396 |
int r = charging_robot_iterator_next(); |
|
397 |
int b = robots[r]->battery; |
|
398 |
if (battery<153){ |
|
399 |
//cancel robot r |
|
400 |
wl_charging_send_cancel(r); |
|
401 |
charging_cancel(r); |
|
402 |
//tell robot that charging station is now available |
|
403 |
wl_charging_send_station_available(robot); |
|
404 |
} |
|
405 |
} |
|
406 |
|
|
407 |
/** |
|
378 | 408 |
* Called when the BOM needs to be turned on for the |
379 | 409 |
* token ring. If a robot is seeking, only the BOM of |
380 | 410 |
* the bay that is being sought will turn on. If no |
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/charging.h | ||
---|---|---|
53 | 53 |
/** @brief Get the supposed state of a robot **/ |
54 | 54 |
int charging_get_robot_state(int robot); |
55 | 55 |
|
56 |
/** @brief Update battery reading of a robot **/ |
|
57 |
void update_battery(int robot, int battery); |
|
58 |
/** @brief Check if the robot has lower battery level than those already docked **/ |
|
59 |
void check_battery(int robot, int battery); |
|
60 |
|
|
56 | 61 |
/** @} **/ |
57 | 62 |
|
branches/autonomous_recharging/code/projects/autonomous_recharging/charging_station/wl_defs.h | ||
---|---|---|
78 | 78 |
#define WL_RECHARGE_CANCEL 6 |
79 | 79 |
#define WL_RECHARGE_SEEKING 7 |
80 | 80 |
#define WL_RECHARGE_DOCKED 8 |
81 |
#define WL_RECHARGE_BATTERY 11 |
|
81 | 82 |
|
82 | 83 |
#ifdef WL_DEBUG |
83 | 84 |
|
Also available in: Unified diff