Skip to content

Commit a013ac5

Browse files
committed
added pose
1 parent f0222ce commit a013ac5

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/robotics/kinematics.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ class Kinematics{
1212
float wheel_track;
1313
float wheel_diameter;
1414
float wheel_radius;
15+
float wheel_circumference;
1516
float rads_to_rpm;
1617
float rpm_to_rads;
1718
float rads_to_degs;
1819
float degs_to_rads;
1920
float w;
2021

22+
float theta, delta_theta;
23+
float x, y;
24+
float delta_left, delta_right;
25+
float delta_travel;
26+
float delta_x, delta_y;
27+
float travel;
28+
29+
2130

2231
public:
2332
Kinematics(const float _wheel_track, const float _wheel_diameter){
@@ -29,13 +38,26 @@ class Kinematics{
2938
wheel_track=_wheel_track;
3039
wheel_diameter=_wheel_diameter;
3140
wheel_radius=wheel_diameter/2.0;
41+
wheel_circumference=wheel_diameter*PI;
3242

3343
rads_to_rpm=60.0/(2.0*PI);
3444
rpm_to_rads=2.0*PI/60.0;
3545

3646
rads_to_degs=180.0/PI;
3747
degs_to_rads=PI/180.0;
3848

49+
theta=0.0;
50+
x=0.0;
51+
y=0.0;
52+
53+
delta_x=0.0;
54+
delta_y=0.0;
55+
delta_theta=0.0;
56+
delta_left=0.0;
57+
delta_right=0.0;
58+
delta_travel=0.0;
59+
travel=0.0;
60+
3961
}
4062

4163
void forward(const float linear, const float angular){
@@ -67,6 +89,62 @@ class Kinematics{
6789
return angular_velocity;
6890
}
6991

92+
void updatePose(const float left_rotation, const float right_rotation){
93+
delta_left=left_rotation*wheel_circumference;
94+
delta_right=right_rotation*wheel_circumference;
95+
delta_travel=(delta_left+delta_right)/2.0;
96+
delta_theta=(-delta_left+delta_right)/(2.0*wheel_track);
97+
delta_x=delta_travel*cos(theta+delta_theta/2.0);
98+
delta_y=delta_travel*sin(theta+delta_theta/2.0);
99+
x+=delta_x;
100+
y+=delta_y;
101+
travel+=delta_travel;
102+
}
103+
104+
void resetPose(const float initial_x=0.0, const float initial_y=0.0, const float initial_theta=0.0){
105+
x=initial_x;
106+
y=initial_y;
107+
theta=initial_theta;
108+
travel=0.0;
109+
delta_x=0.0;
110+
delta_y=0.0;
111+
delta_theta=0.0;
112+
delta_left=0.0;
113+
delta_right=0.0;
114+
delta_travel=0.0;
115+
116+
}
117+
118+
float getX(){
119+
return x;
120+
}
121+
122+
float getY(){
123+
return y;
124+
}
125+
126+
float getTheta(){
127+
return theta;
128+
}
129+
130+
float getTravel(){
131+
return travel;
132+
}
133+
134+
float getDeltaX(){
135+
return delta_x;
136+
}
137+
138+
float getDeltaY(){
139+
return delta_y;
140+
}
141+
142+
float getDeltaTheta(){
143+
return delta_theta;
144+
}
145+
146+
147+
70148

71149
};
72150

0 commit comments

Comments
 (0)