Revision 9b4328d7
ID | 9b4328d7dc719f032ff4f4f3aceddea007668964 |
Merged WH_Robots with other files
scout/libscout/src/behaviors/Scheduler.h | ||
---|---|---|
17 | 17 |
void waiting_dance(); |
18 | 18 |
|
19 | 19 |
public: |
20 |
Scheduler();
|
|
20 |
Scheduler(std::string scoutname):Behavior(scoutname, "Scheduler"){};
|
|
21 | 21 |
~Scheduler(); |
22 | 22 |
|
23 | 23 |
void get_task(WH_Robot robot); |
... | ... | |
29 | 29 |
Order get_next_item(); |
30 | 30 |
|
31 | 31 |
void run(); |
32 |
//assumes a set_task(Order o) function in WH_Robot |
|
33 |
|
|
34 |
|
|
35 | 32 |
|
36 | 33 |
}; |
37 | 34 |
#endif |
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 |
|
scout/libscout/src/behaviors/WH_Robot.h | ||
---|---|---|
1 | 1 |
#ifndef _WH_ROBOT_ |
2 | 2 |
#define _WH_ROBOT_ |
3 | 3 |
|
4 |
#include <cstdlib> |
|
5 |
#include <string> |
|
4 |
#define DEFAULT_TASK NULL; |
|
5 |
#define TASK_COMPLETED 0 |
|
6 |
#define TASK_FAILED -1 |
|
6 | 7 |
|
7 |
//#include "../Behavior.h" //TODO: make wh_robots into Behaviors
|
|
8 |
//#include "navigationMap.h"
|
|
9 |
#include "Scheduler.h" //TODO: uncomment once these are in the repo
|
|
8 |
#include "../Behavior.h"
|
|
9 |
#include "navigationMap.h" |
|
10 |
#include "Scheduler.h" |
|
10 | 11 |
#include "../helper_classes/Order.h" |
12 |
#include <assert.h> |
|
13 |
#include <stdlib.h> |
|
11 | 14 |
|
12 |
#define TASK_COMPLETED 0 |
|
13 |
#define TASK_FAILED -1 |
|
15 |
class WH_Robot : Behavior{ |
|
14 | 16 |
|
15 |
typedef double Time;
|
|
16 |
// a single number representing a node's number
|
|
17 |
typedef int State;
|
|
17 |
Order* curr_task;
|
|
18 |
navigationMap nav_map;
|
|
19 |
Scheduler scheduler;
|
|
18 | 20 |
|
19 |
class WH_Robot{ |
|
21 |
Time get_wc_time(State dest); |
|
22 |
int exec_task(); |
|
20 | 23 |
|
21 | 24 |
public: |
22 |
WH_Robot(); |
|
23 | 25 |
WH_Robot(std::string scoutname); |
26 |
~WH_Robot(); |
|
24 | 27 |
void run(); |
25 |
|
|
26 |
private: |
|
27 |
Time get_wc_time(State dest); |
|
28 |
Order wh_get_task(); |
|
29 |
int exec_task(); |
|
30 |
|
|
31 |
Order curr_task; |
|
32 |
//navigationMap nav_map; |
|
33 |
Scheduler schedule; |
|
28 |
|
|
29 |
void set_task(Order order); |
|
30 |
|
|
34 | 31 |
}; |
35 | 32 |
|
36 | 33 |
#endif |
scout/libscout/src/helper_classes/Order.cpp | ||
---|---|---|
19 | 19 |
return id; |
20 | 20 |
} |
21 | 21 |
|
22 |
Address get_source() const |
|
22 |
Address Order::get_source() const
|
|
23 | 23 |
{ |
24 | 24 |
return source; |
25 | 25 |
} |
26 | 26 |
|
27 |
Address get_dest() const |
|
27 |
Address Order::get_dest() const
|
|
28 | 28 |
{ |
29 | 29 |
return dest; |
30 | 30 |
} |
31 | 31 |
|
32 |
Time get_start_time() const |
|
32 |
Time Order::get_start_time() const
|
|
33 | 33 |
{ |
34 | 34 |
return start_time; |
35 | 35 |
} |
36 | 36 |
|
37 |
Path get_path() const |
|
37 |
Path Order::get_path() const
|
|
38 | 38 |
{ |
39 | 39 |
return path; |
40 | 40 |
} |
41 | 41 |
|
42 |
void set_path(Path order_path) |
|
42 |
bool Order::operator==(Order& o1, Order& o2) |
|
43 |
{ |
|
44 |
return o1.id == o2.id; |
|
45 |
} |
|
46 |
|
|
47 |
void Order::set_path(Path order_path) |
|
43 | 48 |
{ |
44 | 49 |
path = order_path; |
45 | 50 |
return; |
scout/libscout/src/helper_classes/Order.h | ||
---|---|---|
22 | 22 |
Time get_start_time() const; |
23 | 23 |
Path get_path() const; |
24 | 24 |
void set_path(Path order_path); |
25 |
|
|
26 |
bool operator==(Order& o1, Order& o2); |
|
25 | 27 |
|
26 | 28 |
}; |
27 | 29 |
|
Also available in: Unified diff