root / scout / libscout / src / behaviors / WH_Robot.cpp @ 92d4adda
History | View | Annotate | Download (1.25 KB)
1 |
#include "WH_Robot.h" |
---|---|
2 |
|
3 |
|
4 |
/** @Brief: warehouse robot constructor **/
|
5 |
WH_Robot::WH_Robot(std::string scoutname):Behavior(scoutname, "Scheduler") |
6 |
{ |
7 |
nav_map = navigationMap(scoutname); |
8 |
curr_task = DEFAULT_TASK; |
9 |
scheduler = Scheduler(scoutname); |
10 |
} |
11 |
|
12 |
Duration WH_Robot::get_wc_time(State start_state, State target_state) |
13 |
{ |
14 |
return nav_map.get_worst_case_time(start_state, target_state);
|
15 |
} |
16 |
|
17 |
int WH_Robot::exec_task()
|
18 |
{ |
19 |
assert(curr_task != DEFAULT_TASK); |
20 |
//TODO: do task
|
21 |
srand(0xDEADBEEF);
|
22 |
int error = rand() % 12; |
23 |
if(error < 9) //Fail with 1/4 probability |
24 |
{ |
25 |
return TASK_COMPLETED;
|
26 |
} |
27 |
else
|
28 |
{ |
29 |
return TASK_FAILED;
|
30 |
} |
31 |
} |
32 |
|
33 |
void WH_Robot::run (){
|
34 |
Scheduler.get_task(*this);
|
35 |
while(curr_task == DEFAULT_TASK)
|
36 |
continue;
|
37 |
int error = exec_task();
|
38 |
if(error == TASK_COMPLETE)
|
39 |
{ |
40 |
schedule.task_complete(*curr_task); |
41 |
} |
42 |
else //error == TASK_FAILED |
43 |
{ |
44 |
schedule.task_failed(*curr_task); |
45 |
} |
46 |
curr_task = DEFAULT_TASK; |
47 |
} |
48 |
|
49 |
void WH_Robot::set_task(Order order)
|
50 |
{ |
51 |
curr_task = new Order(order.getid(), order.get_source(), order.get_dest(),
|
52 |
order.get_start_time(), order.get_path(), order.get_est_time()); |
53 |
return;
|
54 |
} |
55 |
|