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