Commit b8fc410f authored by Arnaud Cadot's avatar Arnaud Cadot

Added SHARP checks for KJ

parent b35b8a4e
......@@ -32,6 +32,8 @@ class KJ2016Tempo
void move(int distance);
void waitForArrival(unsigned int duration);
KJ2016Tempo(unsigned int leftServoID, unsigned int rightServoID);
};
......
......@@ -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<unsigned int>( alpha/(float)angularSpeed ));
waitForArrival(static_cast<unsigned int>( 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<unsigned int>( beta * (float)distance / (float)angularSpeed ));
waitForArrival(static_cast<unsigned int>( 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
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment