Project

General

Profile

Revision 363

Added by Rich Hong about 13 years ago

Add battery stuff to charging station

View differences:

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

Also available in: Unified diff