-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathManager.cpp
92 lines (70 loc) · 1.59 KB
/
Manager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Manager.cpp
*
* Created on: Mar 25, 2014
* Author: user
*/
#include "Manager.h"
Manager::Manager(Robot* robot, Plan* plan)
{
_robot = robot;
_plan = plan;
_currentBehavior = plan->startBehavior();
_running = false;
}
void Manager::run()
{
_running = true;
_robot->refresh();
if (_currentBehavior->startCondition() == false)
{
_currentBehavior = _currentBehavior->getNextBehavior();
// If there are no more behaviors
if (!_currentBehavior)
{
std::cout << "The robot fail to start! there isn't any legal step! Please take the robot to other position" << std::endl;
return;
}
}
double previewsX = 0;
double previewsY = 0;
double previewsYaw = 0;
int runNum=0;
while (_running)
{
_robot->refresh();
// ------------
// Calculate deltas
double deltaX = _robot->getX() - previewsX;
double deltaY = _robot->getY() - previewsY;
double deltaYaw = _robot->getYaw() - previewsYaw;
if (_currentBehavior->stopCondition())
{
_currentBehavior = _currentBehavior->getNextBehavior();
// If there are no more behaviors
if (!_currentBehavior)
{
std::cout << "Can't move! there isn't any legal step!" << std::endl;
return;
}
}
// ------------
// Save this iteration x, y ,yaw
previewsX = _robot->getX();
previewsY = _robot->getY();
previewsYaw = _robot->getYaw();
_currentBehavior->action();
Laser& laser = _robot->getLaser();
Map& map = _slamManager.update(deltaX, deltaY, deltaYaw, laser);
// -----------
// Print the map
if (runNum % 10 == 0)
{
cout << map << endl;
}
runNum++;
}
}
Manager::~Manager()
{
}