root / scout / libscout / src / behaviors / WH_Robot.cpp @ ca164875
History | View | Annotate | Download (1.21 KB)
1 | bebd9bcb | Leon | #include "WH_Robot.h" |
---|---|---|---|
2 | |||
3 | |||
4 | /** @Brief: warehouse robot constructor **/
|
||
5 | 9b4328d7 | Priya | WH_Robot::WH_Robot(std::string scoutname):Behavior(scoutname, "Scheduler") |
6 | bebd9bcb | Leon | { |
7 | nav_map = navigationMap(scoutname); |
||
8 | 9b4328d7 | Priya | curr_task = DEFAULT_TASK; |
9 | scheduler = Scheduler(scoutname); |
||
10 | bebd9bcb | Leon | } |
11 | |||
12 | Time WH_Robot::get_wc_time(State dest) |
||
13 | { |
||
14 | //TODO: integrate Lalitha's code
|
||
15 | return 0.0; |
||
16 | } |
||
17 | |||
18 | 9b4328d7 | Priya | int WH_Robot::exec_task()
|
19 | bebd9bcb | Leon | { |
20 | 9b4328d7 | Priya | 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 | bebd9bcb | Leon | { |
26 | 9b4328d7 | Priya | return TASK_COMPLETED;
|
27 | bebd9bcb | Leon | } |
28 | 9b4328d7 | Priya | else
|
29 | { |
||
30 | return TASK_FAILED;
|
||
31 | bebd9bcb | Leon | } |
32 | } |
||
33 | |||
34 | void WH_Robot::run (){
|
||
35 | 9b4328d7 | Priya | Scheduler.get_task(*this);
|
36 | while(curr_task == DEFAULT_TASK)
|
||
37 | continue;
|
||
38 | int error = exec_task();
|
||
39 | if(error == TASK_COMPLETE)
|
||
40 | bebd9bcb | Leon | { |
41 | 9b4328d7 | Priya | schedule.task_complete(*curr_task); |
42 | bebd9bcb | Leon | } |
43 | 9b4328d7 | Priya | else //error == TASK_FAILED |
44 | bebd9bcb | Leon | { |
45 | 9b4328d7 | Priya | schedule.task_failed(*curr_task); |
46 | bebd9bcb | Leon | } |
47 | 9b4328d7 | Priya | curr_task = DEFAULT_TASK; |
48 | bebd9bcb | Leon | } |
49 | |||
50 | 9b4328d7 | Priya | void WH_Robot::set_task(Order order)
|
51 | { |
||
52 | ca164875 | Leon | 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 | 9b4328d7 | Priya | return;
|
55 | bebd9bcb | Leon | } |
56 | 9b4328d7 | Priya |