File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed
Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ unsigned long ttask=0;
77uint8_t task=0 ;
88
99void setup () {
10+ Serial.begin (115200 );
1011 alvik.begin ();
1112 ttask=millis ();
1213 tmotor=millis ();
@@ -17,13 +18,21 @@ void loop() {
1718 if (millis ()-tmotor>20 ){
1819 tmotor=millis ();
1920 alvik.updateMotors ();
21+ alvik.kinematics ->updatePose (alvik.motor_control_left ->getTravel (), alvik.motor_control_right ->getTravel ());
22+ Serial.print (" \t " );
23+ Serial.print (alvik.kinematics ->getDeltaX ());
24+ Serial.print (" \t " );
25+ Serial.print (alvik.kinematics ->getDeltaY ());
26+ Serial.print (" \t " );
27+ Serial.print (alvik.kinematics ->getTheta ());
28+ Serial.print (" \n " );
2029 }
2130
2231 if (millis ()-ttask>2000 ){
2332 ttask=millis ();
2433 switch (task){
2534 case 0 :
26- alvik.drive (0 , 90 );
35+ alvik.drive (50 , 0 );
2736 break ;
2837 case 1 :
2938 alvik.drive (0 ,0 );
@@ -40,4 +49,5 @@ void loop() {
4049 task=0 ;
4150 }
4251 }
52+
4353}
Original file line number Diff line number Diff line change @@ -606,7 +606,35 @@ void Arduino_Alvik_Firmware::errorLed(const int error_code){
606606}
607607
608608
609+
610+ /* *****************************************************************************************************/
611+ /* Kinematics */
612+ /* *****************************************************************************************************/
613+
609614void Arduino_Alvik_Firmware::drive (const float linear, const float angular){
610615 kinematics->forward (linear, angular);
611616 setRpm (kinematics->getLeftVelocity (),kinematics->getRightVelocity ());
612617}
618+
619+ void Arduino_Alvik_Firmware::rotate (const float angle){
620+ float initial_angle=kinematics->getTheta ();
621+ float error=angle-initial_angle;
622+ unsigned long t=millis ();
623+ while (abs (error)>0 ){
624+ if (millis ()-t>20 ){
625+ t=millis ();
626+ updateMotors ();
627+ }
628+ if (error>0 ){
629+ drive (0 ,90 );
630+ }else {
631+ drive (0 ,-90 );
632+ }
633+ kinematics->updatePose (motor_control_left->getTravel (),motor_control_right->getTravel ());
634+ error=kinematics->getTheta ()-initial_angle;
635+ Serial.println (error);
636+ }
637+ drive (0 ,0 );
638+ updateMotors ();
639+ }
640+
Original file line number Diff line number Diff line change @@ -75,11 +75,11 @@ class Arduino_Alvik_Firmware{
7575 uint8_t version_mid;
7676 uint8_t version_low;
7777
78- Kinematics * kinematics;
7978
8079
8180 public:
82-
81+ Kinematics * kinematics;
82+
8383 MotorControl * motor_control_right;
8484 MotorControl * motor_control_left;
8585
@@ -203,6 +203,7 @@ class Arduino_Alvik_Firmware{
203203 // Kinematics
204204 void drive (const float linear, const float angular);
205205
206+ void rotate (const float angle);
206207
207208
208209
You can’t perform that action at this time.
0 commit comments