Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (54 loc) · 1.41 KB
/
Copy pathmain.cpp
File metadata and controls
70 lines (54 loc) · 1.41 KB
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
#include <iostream>
class Robot{
public:
float x, y;
double theta; // Direction
Robot() = default;
Robot(float x, float y, double theta){
this->x = x;
this->y = y;
this->theta = theta;
}
void printRobotPose(){
std::cout << "Robot's Pose \nx : " << x << std::endl;
std::cout << "y: " << y << std::endl;
std::cout << "theta: " <<theta <<std::endl;
}
virtual void moveBot(){
std::cout << "Robot is moving..." << std::endl;
}
};
class diffDrive : public Robot{
public:
double vR; //right wheel velocity
double vL; //left wheel velocity
double v;
double omega; //Instan... angle of rotation
float W; //distance between left and rright wheel
diffDrive(double vR, double vL, float W): Robot(x, y, theta){
this->vR = vR;
this->vL = vL;
this->W = W;
this->omega = (vR - vL)/W;
this->v = (vR + vL)/2;
}
void moveBot(){
std::cout << "Differential drive bot is moving at " << v << "m/s, " << omega << " rad/s." <<std::endl;
}
};
int main(){
Robot robot1(1, 2, 60);
robot1.printRobotPose();
diffDrive dd1(10, 4, 6);
dd1.x = 5;
dd1.y = -3;
dd1.theta= 30;
Robot *r = &dd1;
r->printRobotPose();
r->moveBot();
/*
dd1.printRobotPose();
dd1.moveBot();
*/
return 0;
}