forked from StevensDeptECE/robosim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.cc
81 lines (73 loc) · 2.85 KB
/
robot.cc
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
#include "robot.hh"
#include "random.hh"
using namespace std;
/*
Author:Wang,YenHsiang and Aleksandar Dimoski and Tim Demetriades
version : 1.1
date : Dec 16th, 2021
Robot is the base class all of the vehicles will inherit from.
It takes the following:
- name = The name of the robot to tell the different robots apart
- loc = The real location as vector 3D object constisting of the x, y, and z positions
- horizontal_variance = Needed to determine error in estimated location
- vertical_variance = Needed to determine error in estimated location
- heading = horizontal direction from 0 to 2pi (in radians) of the robot
- speed = speed in the forward direction
- batteryLife = current battery life of the robot
For the estimated location, it is calculated by taking the real location and adding some Gaussian error,
which is a vector 3D consisting where each x, y, and z component is Gaussian with a mean of 0 and variance
that is passed to the object (horizontal variance and vertical variance).
*/
// Constructor
robot::robot(string name, double x, double y, double z, double posVarHoriz,
double posVarVert, double heading, double speed,
double headingVert, double BatteryLife = 100)
: name(name),
location(vec_3d(x, y, z)),
estLocation(location + vec_3d(N(0, posVarHoriz), N(0, posVarHoriz), N(0, posVarVert))),
posVarHoriz(posVarHoriz),
posVarVert(posVarVert),
heading(heading),
speed(speed),
headingVert(headingVert),
BatteryLife(BatteryLife) {}
robot::robot(string name, const vec_3d& pos, double posVarHoriz,
double posVarVert, double heading, double speed,
double headingVert, double BatteryLife = 100)
: name(name),
location(pos),
estLocation(location + vec_3d(N(0, posVarHoriz), N(0, posVarHoriz), N(0, posVarVert))),
posVarHoriz(posVarHoriz),
posVarVert(posVarVert),
heading(heading),
speed(speed),
headingVert(headingVert),
BatteryLife(BatteryLife) {}
void robot::move(double time) {
double velX = time * speed * cos(heading);
double velY = time * speed * sin(heading);
double velZ = time * headingVert;
location.x += velX;
location.y += velY;
location.z += velZ;
}
vec_3d robot::getEstLocation(vector<beacon> beacons) {
vector<double> dists;
for (beacon b : beacons) {
dists.push_back(location.dist(b));
}
// TODO Calculate estimated position and return it; for now just returns
// actual position
return location;
}
std::ostream& robot::operator<<(std::ostream& s, robot& r) {
s << "The object " << r.getName() << " is "
<< "Location= " << r.getLocation() << "\tBattery Life= " << r.getBatLife()
<< endl;
return s;
}
// Displaying battery life
ostream& operator<< (std::ostream& a, robot & xyz) {
a << xyz.location << "batterylife=" << xyz.BatteryLife << endl;
return a;
}