summaryrefslogtreecommitdiff
path: root/i/marvin/src/es/es.cc
diff options
context:
space:
mode:
authorhaller2006-05-25 01:53:31 +0000
committerhaller2006-05-25 01:53:31 +0000
commit4777e2a1e5211f015d760c1e8614d3936d6b9045 (patch)
tree626df45a410876bbeeb7a5952a12e97dcd199539 /i/marvin/src/es/es.cc
parent016484d07ca7c6516bb47464756b85bf664fc856 (diff)
* Gestion un peu plus avancé du barillet
Diffstat (limited to 'i/marvin/src/es/es.cc')
-rw-r--r--i/marvin/src/es/es.cc216
1 files changed, 212 insertions, 4 deletions
diff --git a/i/marvin/src/es/es.cc b/i/marvin/src/es/es.cc
index f26cf33..534b136 100644
--- a/i/marvin/src/es/es.cc
+++ b/i/marvin/src/es/es.cc
@@ -31,8 +31,8 @@
/// Constructeur
Es::Es (const Config & config)
- : proto_ (*this), log_ ("Es"), lcdKeyPressed_ (-1),
- front_sensor_ (false), jackIn_ (false), colorModeBlue_ (false),
+ : proto_ (*this), log_ ("Es"), lcdKeyPressed_ (-1), front_sensor_ (false),
+ jackIn_ (false), colorModeBlue_ (false),frontTurbineIsFull_(false),
unknownColor_ (-1), redColor_ (2), blueColor_ (1), greenColor_ (0),
whiteColor_ (5), blackColor_ (4), leftFrontRVB_ (0), rightFrontRVB_ (1),
holeRVB_ (2), frontBallRVB_ (3), rearBallRVB_ (4)
@@ -42,6 +42,9 @@ Es::Es (const Config & config)
proto_.open (tty_);
sharps_.resize (3);
+ // Normalement, le barillet est vide...
+ for(int i = 0; i < 5 ; i++)
+ stockBarillet[i] = empty;
for (int compt = 0; compt < 5; compt++)
{
@@ -115,6 +118,7 @@ Es::reset (void)
lcdGetKey (lcdKeyStat_);
enableAllSensors (true);
+ log_ ("Es", Log::debug) << "Reset Es done.";
}
/// Stat for the main ()
@@ -278,18 +282,22 @@ void
Es::barilletInit (void)
{
proto_.send ('i');
+ frontTurbineIsFull_ = false;
}
/// Init turbine to minimal speed
void Es::barilletDebutLancement (void)
{
proto_.send ('g');
+ frontTurbineIsFull_ = false;
}
/// Init front turbine to full speed
void Es::barilletLancement (void)
{
proto_.send ('h');
+ frontTurbineIsFull_ = true;
+ log_ ("Es::Barillet", Log::debug) << "Lancement turbine avant.";
}
/// Put barillet in sleep mode
@@ -297,30 +305,144 @@ void
Es::barilletSleep (void)
{
proto_.send ('s');
+ frontTurbineIsFull_ = false;
}
// Dépose une balle du barillet
-void Es::deposeBalle(void)
+void
+Es::deposeBalle(void)
{
proto_.send ('d');
+ frontTurbineIsFull_ = false;
+}
+
+/// Dépose une balle blanche
+bool
+Es::dropWhiteBall(void)
+{
+ for(int i = 0; i < 5; i++)
+ if(stockBarillet[i] == white)
+ {
+ switch (i)
+ {
+ case 0:
+ rotationBarillet(arriere0);
+ positionBarillet_ = arriere0;
+ break;
+ case 1:
+ rotationBarillet(arriere1);
+ positionBarillet_ = arriere1;
+ break;
+ case 2:
+ rotationBarillet(arriere2);
+ positionBarillet_ = arriere2;
+ break;
+ case 3:
+ rotationBarillet(arriere3);
+ positionBarillet_ = arriere3;
+ break;
+ case 4:
+ rotationBarillet(arriere4);
+ positionBarillet_ = arriere4;
+ break;
+ }
+ return true;
+ }
+ return false;
+}
+
+/// Dépose une balle noire
+bool
+Es::dropBlackBall(void)
+{
+ for(int i = 0; i < 5; i++)
+ if(stockBarillet[i] == black)
+ {
+ switch (i)
+ {
+ case 0:
+ rotationBarillet(arriere0);
+ positionBarillet_ = arriere0;
+ break;
+ case 1:
+ rotationBarillet(arriere1);
+ positionBarillet_ = arriere1;
+ break;
+ case 2:
+ rotationBarillet(arriere2);
+ positionBarillet_ = arriere2;
+ break;
+ case 3:
+ rotationBarillet(arriere3);
+ positionBarillet_ = arriere3;
+ break;
+ case 4:
+ rotationBarillet(arriere4);
+ positionBarillet_ = arriere4;
+ break;
+ }
+ return true;
+ }
+ return false;
}
+/// Place un trou vide à l'avant
+bool
+Es::setEmptyHoleFront(void)
+{
+ if(barilletIsFull())
+ return false;
+ for(int i = 0; i < 5; i++)
+ if(stockBarillet[i] == empty)
+ {
+ switch (i)
+ {
+ case 0:
+ rotationBarillet(avant0);
+ positionBarillet_ = avant0;
+ break;
+ case 1:
+ rotationBarillet(avant1);
+ positionBarillet_ = avant1;
+ break;
+ case 2:
+ rotationBarillet(avant2);
+ positionBarillet_ = avant2;
+ break;
+ case 3:
+ rotationBarillet(avant3);
+ positionBarillet_ = avant3;
+ break;
+ case 4:
+ rotationBarillet(avant4);
+ positionBarillet_ = avant4;
+ break;
+ }
+ return true;
+ }
+ return false;
+}
/// Extrait une balle
-void Es::extraitBalle(void)
+void
+Es::extraitBalle(void)
{
proto_.send ('e');
+ frontTurbineIsFull_ = false;
+ log_ ("Es::Barillet", Log::debug) << "Extraction baballe.";
}
/// Rotation du barillet
void Es::rotationBarillet(int posFinal)
{
proto_.send ('t', "b", posFinal);
+ frontTurbineIsFull_ = false;
}
/// Empty everything in the barillet
void Es::barilletEmpty (void)
{
proto_.send ('n');
+ frontTurbineIsFull_ = false;
}
void Es::receive(char command, const Proto::Frame & frame)
@@ -348,6 +470,12 @@ void Es::receive(char command, const Proto::Frame & frame)
case 1:
front_sensor_ = true;
break;
+ case 2: // une balle miam par l'avant
+ newBallFront();
+ break;
+ case 3: // une balle miam par l'arrière
+ newBallRear();
+ break;
}
shutUp ();
}
@@ -464,6 +592,77 @@ Es::decodeColor (int color)
}
}
+/// Analyse une balle arrivant par devant
+void
+Es::newBallFront(void)
+{
+ /// La turbine est off
+ frontTurbineIsFull_ = false;
+ /// On analyse la baballe
+ switch (positionBarillet_)
+ {
+ case avant0:
+ stockBarillet[0] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = avant4;
+ break;
+ case avant1:
+ stockBarillet[1] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = avant0;
+ break;
+ case avant2:
+ stockBarillet[2] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = avant1;
+ break;
+ case avant3:
+ stockBarillet[3] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = avant2;
+ break;
+ case avant4:
+ stockBarillet[4] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = avant3;
+ break;
+ default:
+ break;
+ }
+ /// On regarde si on redémarre la turbine
+ if(!barilletIsFull())
+ barilletLancement();
+ log_ ("Es::Barillet", Log::debug) << "gobage balle par l'avant.";
+}
+
+/// Analyse une balle arrivant par derrière
+void
+Es::newBallRear(void)
+{
+ /// On analyse la baballe
+ switch (positionBarillet_)
+ {
+ case arriere0:
+ stockBarillet[0] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = arriere4;
+ break;
+ case arriere1:
+ stockBarillet[1] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = arriere0;
+ break;
+ case arriere2:
+ stockBarillet[2] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = arriere1;
+ break;
+ case arriere3:
+ stockBarillet[3] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = arriere2;
+ break;
+ case arriere4:
+ stockBarillet[4] = colorSeen(frontBallRVB_)==whiteColor_?white:black;
+ positionBarillet_ = arriere3;
+ break;
+ default:
+ break;
+ }
+ log_ ("Es::Barillet", Log::debug) << "gobage balle par l'arriere.";
+}
+
/// Update system for one sensor
void
Es::updateAnalysisSensor (int value, int index, int threshold)
@@ -479,6 +678,15 @@ Es::updateAnalysisSensor (int value, int index, int threshold)
seenColors_[index] = lastSeenColors_[index];
}
+/// Say if barillet is full
+bool
+Es::barilletIsFull(void)
+{
+ for (int i = 0; i < 5; i++)
+ if (stockBarillet[0] == empty)
+ return false;
+ return true;
+}
/// What color do you see my lord ?
int
Es::colorSeen (int sensor_num)