Project

General

Profile

Revision 434

Added by Rich Hong about 16 years ago

update assigning bay based on battery reading (seeking robot), also fix some bugs

View differences:

charging.c
8 8
#include <wl_token_ring.h>
9 9
#include "wl_charging_station.h"
10 10

  
11
#define BATTERY_LOWV 152
12

  
11 13
//set this to the number of bays
12 14
#define NUM_BAYS 2
13 15

  
......
383 385
 **/
384 386
void update_battery(int robot, int battery)
385 387
{
386
	if (robot < robotSize && robots[robot] != NULL)
388
	if (robot < robotsSize && robots[robot] != NULL)
387 389
		robots[robot]->battery = battery;
388 390
}
389 391
void check_battery(int robot, int battery)
390 392
{
391 393
	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
394
	// there's no way to read the voltage of a charging robot
395
	// so just eject the seeking robot if there's one, or the last charging robot
395 396
	charging_robot_iterator_init();
396
	int r = charging_robot_iterator_next();
397
	int b = robots[r]->battery;
398
	if (battery<153){
397
	int r,b;
398
	while (charging_robot_iterator_has_next())
399
	{
400
		r = charging_robot_iterator_next();
401
		b = robots[r]->battery;
402
		if (robots[r]->state==STATE_SEEKING) break;
403
	}
404
	if (battery<=BATTERY_LOWV&&b>BATTERY_LOWV)
405
	{
399 406
		//cancel robot r
400 407
		wl_charging_send_cancel(r);
401 408
		charging_cancel(r);

Also available in: Unified diff