Skip to content

Commit ee503d1

Browse files
committed
updated kinematics
1 parent 866e898 commit ee503d1

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

examples/kinematics/kinematics.ino

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,42 @@
22

33
Arduino_Alvik_Firmware alvik;
44

5+
unsigned long tmotor=0;
6+
unsigned long ttask=0;
7+
uint8_t task=0;
8+
59
void setup() {
610
alvik.begin();
11+
ttask=millis();
12+
tmotor=millis();
13+
task=0;
714
}
815

916
void loop() {
10-
alvik.drive(1,1);
11-
17+
if (millis()-tmotor>20){
18+
tmotor=millis();
19+
alvik.updateMotors();
20+
}
21+
22+
if (millis()-ttask>2000){
23+
ttask=millis();
24+
switch (task){
25+
case 0:
26+
alvik.drive(0,90);
27+
break;
28+
case 1:
29+
alvik.drive(0,0);
30+
break;
31+
case 2:
32+
alvik.drive(0,-90);
33+
break;
34+
case 3:
35+
alvik.drive(0,0);
36+
break;
37+
}
38+
task++;
39+
if (task>3){
40+
task=0;
41+
}
42+
}
1243
}

src/Arduino_Alvik_Firmware.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,4 +608,5 @@ void Arduino_Alvik_Firmware::errorLed(const int error_code){
608608

609609
void Arduino_Alvik_Firmware::drive(const float linear, const float angular){
610610
kinematics->forward(linear, angular);
611+
setRpm(kinematics->getLeftVelocity(),kinematics->getRightVelocity());
611612
}

src/robotics/kinematics.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ class Kinematics{
1616
float rpm_to_rads;
1717
float rads_to_degs;
1818
float degs_to_rads;
19+
float w;
1920

2021

2122
public:
2223
Kinematics(const float _wheel_track, const float _wheel_diameter){
24+
w=0.0;
2325
left_velocity=0.0;
2426
right_velocity=0.0;
2527
linear_velocity=0.0;
@@ -37,8 +39,11 @@ class Kinematics{
3739
}
3840

3941
void forward(const float linear, const float angular){
40-
left_velocity=(2*linear-angular*wheel_track)/(wheel_diameter);
41-
right_velocity=(2*linear+angular*wheel_track)/(wheel_diameter);
42+
w = angular*degs_to_rads;
43+
left_velocity=(2*linear-w*wheel_track)/(wheel_diameter);
44+
left_velocity=rads_to_rpm*left_velocity;
45+
right_velocity=(2*linear+w*wheel_track)/(wheel_diameter);
46+
right_velocity=rads_to_rpm*right_velocity;
4247
}
4348

4449
void inverse(const float left_vel, const float right_vel){

0 commit comments

Comments
 (0)