diff --git a/stm32/include/KJ2016Tempo.h b/stm32/include/KJ2016Tempo.h index 26f1cb5f03671e1cb47349b2d772a39c2b14cd97..e99be6a3598ef77f80dab5a09d66a18c618777a2 100644 --- a/stm32/include/KJ2016Tempo.h +++ b/stm32/include/KJ2016Tempo.h @@ -32,6 +32,8 @@ class KJ2016Tempo void move(int distance); + void waitForArrival(unsigned int duration); + KJ2016Tempo(unsigned int leftServoID, unsigned int rightServoID); }; diff --git a/stm32/src/KJ2016Tempo.cpp b/stm32/src/KJ2016Tempo.cpp index d63b3f4bf42e2632db0ffc4382863a742701ef62..ad05f487e57faca0041a52c8eabfaa695bdeeb71 100644 --- a/stm32/src/KJ2016Tempo.cpp +++ b/stm32/src/KJ2016Tempo.cpp @@ -4,6 +4,7 @@ #include "actionneurs/fishingNet.h" #include "clock.h" +#include "actionneurs/sensors.h" KJ2016Tempo::KJ2016Tempo(unsigned int leftServoID, unsigned int rightServoID): LEFT_SERVO_ID(leftServoID), RIGHT_SERVO_ID(rightServoID), SERVO_SPEED_FACTOR((KJ2016Tempo::SERVO_MAX_RPM / 1024.f) * 60.f / (2.f*3.1415)) @@ -25,9 +26,9 @@ void KJ2016Tempo::run(bool isYellow) KJ2016Tempo KJ(isYellow?SERVO_ONE_ID:SERVO_TWO_ID, isYellow?SERVO_TWO_ID:SERVO_ONE_ID); /** KJ Strategy **/ - KJ.move(100); // Leave the start area + KJ.move(750); // Leave the start area KJ.turn90(true); // First turn (now heading toward the tanks) - KJ.move(500); // Drive into the wall + KJ.move(1050); // Drive into the wall KJ.move(-50); // Back up for the turn KJ.turn90(false); // Second turn (now parallel the tanks) KJ.move(200); // Drive along the wall to the tanks @@ -35,7 +36,7 @@ void KJ2016Tempo::run(bool isYellow) FishingNet::getSingleton()->deploy(); // Deploy the arm FishingNet::getSingleton()->lowerNet(); // Deploy the net in the tank - KJ.move(100); // Drag the net in the tank + KJ.move(300); // Drag the net in the tank FishingNet::getSingleton()->raiseNet(); // Raise the net FishingNet::getSingleton()->raiseArm(); // Raise the arm a little (to avoid the tank's sides @@ -72,7 +73,7 @@ void KJ2016Tempo::turn90(bool toLeft) ServosNumeriques::moveAtSpeed(0x0400 + angularSpeed, LEFT_SERVO_ID); ServosNumeriques::moveAtSpeed(0x0400 + angularSpeed, RIGHT_SERVO_ID); - Clock::delay(static_cast( alpha/(float)angularSpeed )); + waitForArrival(static_cast( alpha/(float)angularSpeed )); enginesStop(); } @@ -90,6 +91,23 @@ void KJ2016Tempo::move(int distance) ServosNumeriques::moveAtSpeed(0x0400 - angularSpeed, LEFT_SERVO_ID); ServosNumeriques::moveAtSpeed(0x0400 + angularSpeed, RIGHT_SERVO_ID); - Clock::delay(static_cast( beta * (float)distance / (float)angularSpeed )); + waitForArrival(static_cast( beta * (float)distance / (float)angularSpeed )); enginesStop(); } + +void KJ2016Tempo::waitForArrival(unsigned int duration) +{ + static const unsigned int sensorCheckDelay = Clock::MS_PER_TICK * 10; + + while(true) + { + unsigned int t = Clock::delay(sensorCheckDelay); + + if(t >= duration) + break; + + duration -= t; + + while(Sensors::getSingleton()->sharpDetect()); // We wait for all sharps to be clear + } +}