Project

General

Profile

Revision 9b4328d7

ID9b4328d7dc719f032ff4f4f3aceddea007668964

Added by Priya about 12 years ago

Merged WH_Robots with other files

View differences:

scout/libscout/src/behaviors/WH_Robot.cpp
1 1
#include "WH_Robot.h"
2 2

  
3
/** @brief default warehouse robot constructor **/
4
WH_Robot::WH_Robot()
5
{
6
    nav_map = navigationMap("nyan");
7
    curr_task = NULL;
8
    schedule = Scheduler();
9
}
10 3

  
11 4
/** @Brief: warehouse robot constructor **/
12
WH_Robot::WH_Robot(std::string scoutname)
5
WH_Robot::WH_Robot(std::string scoutname):Behavior(scoutname, "Scheduler")
13 6
{
14 7
    nav_map = navigationMap(scoutname);
15
    // this probably won't work :x
16
    curr_task = NULL;
17
    schedule = Scheduler();
8
    curr_task = DEFAULT_TASK;
9
    scheduler = Scheduler(scoutname);
18 10
}
19 11

  
20 12
Time WH_Robot::get_wc_time(State dest)
......
23 15
    return 0.0;
24 16
}
25 17

  
26
Order WH_Robot::wh_get_task()
18
int WH_Robot::exec_task()
27 19
{
28
    schedule.get_task(this);
29
    while (curr_task == NULL) //waits for get_task process to return a task
30
        continue;        
31
    return curr_task;    
32
}
33

  
34
int WH_Robot::exec_task(){
35
    if (curr_task == NULL)
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
36 25
    {
37
        //TODO: raise error
38
        return TASK_FAILED;
26
      return TASK_COMPLETED;
39 27
    }
40
    else{
41
        //TODO: do task
42
        return TASK_COMPLETED;
28
    else
29
    {
30
      return TASK_FAILED;
43 31
    }
44 32
}
45 33

  
46 34
void WH_Robot::run (){
47
    wh_get_task();
48
    bool error = (exec_task() == TASK_FAILED);
49
    if(!error)
35
    Scheduler.get_task(*this);
36
    while(curr_task == DEFAULT_TASK)
37
      continue;
38
    int error = exec_task();
39
    if(error == TASK_COMPLETE)
50 40
    {
51
        schedule.task_complete(curr_task);
41
        schedule.task_complete(*curr_task);
52 42
    }
53
    else
43
    else //error == TASK_FAILED
54 44
    {
55
        schedule.task_failed(curr_task);
45
        schedule.task_failed(*curr_task);
56 46
    }
57
    curr_task = NULL;
47
    curr_task = DEFAULT_TASK;
58 48
}
59 49

  
60

  
61
int main(){
62
    return 0;
50
void WH_Robot::set_task(Order order)
51
{
52
    curr_task = new Order(order.getid(), order.get_source(), order.get_dest(), order.get_deadline(), order.get_start_time(), order.get_path(), order.get_est_time()); 
53
    return;
63 54
}
55

  

Also available in: Unified diff