root / trunk / code / projects / warehouse / WH_Robot.cpp @ 2002
History | View | Annotate | Download (1.21 KB)
1 | 2002 | jmcarrol | #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 | Time WH_Robot::get_wc_time(State dest) |
||
13 | { |
||
14 | //TODO: integrate Lalitha's code
|
||
15 | return 0.0; |
||
16 | } |
||
17 | |||
18 | int WH_Robot::exec_task()
|
||
19 | { |
||
20 | assert(curr_task != DEFAULT_TASK); |
||
21 | //TODO: do task
|
||
22 | srand(0xDEADBEEF);
|
||
23 | int error = rand() % 12; |
||
24 | if(error < 9) //Fail with 1/4 probability |
||
25 | { |
||
26 | return TASK_COMPLETED;
|
||
27 | } |
||
28 | else
|
||
29 | { |
||
30 | return TASK_FAILED;
|
||
31 | } |
||
32 | } |
||
33 | |||
34 | void WH_Robot::run (){
|
||
35 | Scheduler.get_task(*this);
|
||
36 | while(curr_task == DEFAULT_TASK)
|
||
37 | continue;
|
||
38 | int error = exec_task();
|
||
39 | if(error == TASK_COMPLETE)
|
||
40 | { |
||
41 | schedule.task_complete(*curr_task); |
||
42 | } |
||
43 | else //error == TASK_FAILED |
||
44 | { |
||
45 | schedule.task_failed(*curr_task); |
||
46 | } |
||
47 | curr_task = DEFAULT_TASK; |
||
48 | } |
||
49 | |||
50 | void WH_Robot::set_task(Order order)
|
||
51 | { |
||
52 | curr_task = new Order(order.getid(), order.get_source(), order.get_dest(),
|
||
53 | order.get_start_time(), order.get_path(), order.get_est_time()); |
||
54 | return;
|
||
55 | } |