Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / libscout / src / behaviors / WH_Robot.cpp @ 2f025967

History | View | Annotate | Download (1.31 KB)

1
#include "WH_Robot.h"
2
#include "Scheduler.h" 
3

    
4

    
5
/** @Brief: warehouse robot constructor **/
6
WH_Robot::WH_Robot(std::string scoutname, void* sched):Behavior(scoutname, "WH_Robot")
7
{
8
    nav_map = navigationMap(scoutname);
9
    curr_task = DEFAULT_TASK;
10
    scheduler = sched;
11
}
12

    
13
Duration WH_Robot::get_wc_time(State start_state, State target_state)
14
{
15
  return nav_map.get_worst_case_time(start_state, target_state);
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*)scheduler).get_task(this);
36
    while(curr_task == DEFAULT_TASK)
37
      continue;
38
    int error = exec_task();
39
    if(error == TASK_COMPLETE)
40
    {
41
        ((Scheduler*)scheduler).task_complete(*curr_task);
42
    }
43
    else //error == TASK_FAILED
44
    {
45
        ((Scheduler*)scheduler).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
}
56