forked from qaseleniumtesting01/GitHubJsNpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobot.cpp
48 lines (36 loc) · 866 Bytes
/
Robot.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
#include "Robot.h"
using namespace std;
Robot::Robot(Hamster *hamster) :hamster(hamster), prevX(0), prevY(0), prevYaw(0), currX(0), currY(0), currYaw(0) {
updatePose();
}
double Robot::getDeltaX() const {
return currX - prevX;
}
double Robot::getDeltaY() const {
return currY - prevY;
}
double Robot::getDeltaYaw() const {
return currYaw - prevYaw;
}
void Robot::robotMovement() {
LidarScan ld = hamster->getLidarScan();
if (ld.getDistance(180) < 0.4) {
hamster->sendSpeed(-0.5, 0);
} else if (ld.getDistance(180) < 0.8) {
hamster->sendSpeed(0.5, 45);
}
else
hamster->sendSpeed(1.0, 0);
}
void Robot::updatePose() {
// get the position of the robot
Pose pose = hamster->getPose();
prevX = currX;
prevY = currY;
prevYaw = currYaw;
currX = pose.getX();
currY = pose.getY();
currYaw = pose.getHeading();
}
Robot::~Robot() {
}