summaryrefslogtreecommitdiff
path: root/i
diff options
context:
space:
mode:
Diffstat (limited to 'i')
-rw-r--r--i/marvin/runtime/rc/config8
-rw-r--r--i/marvin/src/ai/ai.cc34
-rw-r--r--i/marvin/src/ai/ai.hh9
-rw-r--r--i/marvin/src/ai/test_ai.cc38
-rw-r--r--i/marvin/src/es/es.cc49
-rw-r--r--i/marvin/src/es/es.hh12
-rw-r--r--i/marvin/src/es/test_es.cc171
7 files changed, 225 insertions, 96 deletions
diff --git a/i/marvin/runtime/rc/config b/i/marvin/runtime/rc/config
index 2331cba..224ef82 100644
--- a/i/marvin/runtime/rc/config
+++ b/i/marvin/runtime/rc/config
@@ -53,9 +53,11 @@ es.rvb_sniff_stat = 0
# Stats of RVB Ball data
es.rvb_ball_stat = 0
# Stats of others module (jack + colour selection)
-es.others_stat = 10
+es.others_stat = 0
# Stats for printing out key pressed onto the LCD keyboard
es.lcd_key_stat = 0
+# Print stat of front sensors
+es.rvb_sniff_front_stat = 0
### Log
# Default minimum level outputed
@@ -72,8 +74,8 @@ es.lcd_key_stat = 0
# network.
# log.logger.default = "ram"
# log.logger.asserv = "null"
-#log.logger.default = "stdout"
-#log.level.default = "debug"
+log.logger.default = "stdout"
+log.level.default = "debug"
### Exemples
foo = "toto"
diff --git a/i/marvin/src/ai/ai.cc b/i/marvin/src/ai/ai.cc
index d869eae..1ad1df3 100644
--- a/i/marvin/src/ai/ai.cc
+++ b/i/marvin/src/ai/ai.cc
@@ -38,13 +38,14 @@ Ai::~Ai(void)
{
// On réinitialise
// Initialise les moteurs
- motor_.init();
+ // XXX
+// motor_.init ();
// initialise la carte es
- es_.init();
+ es_.reset ();
// On sync
do
{
- scheduler_.schedule(500, true);
+ scheduler_.schedule (500, true);
}
while (!sync ());
}
@@ -53,9 +54,30 @@ void
Ai::init(void)
{
// Initialisation de motor
- motor_.init();
+ motor_.init ();
// Initialisation de la carte Es
- es_.init();
+ es_.reset ();
// Paf on sync
- while(!update());
+ while (!update ());
}
+
+/// Synchronize data of under class
+bool
+Ai::sync (void)
+{
+ return es_.sync () && motor_.sync ();
+}
+
+/// Wait for something to happened
+bool Ai::update (void)
+{
+ scheduler_.schedule (100, true);
+ bool retour = sync ();
+ // On vérifie que le match n'est pas fini
+ if (Timer::getRoundTime () > roundDuration_)
+ throw std::runtime_error ("Fin de match, merci d'avoir
+ participé !");
+ return retour;
+}
+
+
diff --git a/i/marvin/src/ai/ai.hh b/i/marvin/src/ai/ai.hh
index 89f2cd3..bde4c4a 100644
--- a/i/marvin/src/ai/ai.hh
+++ b/i/marvin/src/ai/ai.hh
@@ -25,12 +25,21 @@
// }}}
/// Intelligence supérieur(à celui d'une balle de ping-pong) artificielle
/// (comme une blonde) du robot.
+
+#include "motor/motor.hh"
+#include "es/es.hh"
+#include "scheduler/scheduler.hh"
+#include "scheduler/schedulable_read_fd.hh"
+#include "log/log.hh"
+
class Ai
{
private:
// Modules de contrôles du robot
Motor motor_;
Es es_;
+ /// Logger
+ Log log_;
// Le scheduler
scheduler::Scheduler scheduler_;
scheduler::SchedulableReadFd schedulableMotor_;
diff --git a/i/marvin/src/ai/test_ai.cc b/i/marvin/src/ai/test_ai.cc
new file mode 100644
index 0000000..9412277
--- /dev/null
+++ b/i/marvin/src/ai/test_ai.cc
@@ -0,0 +1,38 @@
+// test_ai.cc
+// marvin - programme du robot 2006. {{{
+//
+// Copyright (C) 2006 Dufour Jérémy
+//
+// Robot APB Team/Efrei 2004.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// }}}
+
+#include "tester/tester.hh"
+#include "ai/ai.hh"
+
+class TestAI : public Tester
+{
+ private:
+ Ai ai_;
+ /// Called after each command
+ void postcall (void)
+ {
+ // Update ?
+ }
+}
diff --git a/i/marvin/src/es/es.cc b/i/marvin/src/es/es.cc
index 567830f..8bc90ec 100644
--- a/i/marvin/src/es/es.cc
+++ b/i/marvin/src/es/es.cc
@@ -76,6 +76,7 @@ Es::loadConfig (const Config & config)
rvbSniffRefMask_ = config.get<int> ("es.rvb_sniff_ref_mask");
rvbSniffMaskStat_ = config.get<int> ("es.rvb_sniff_mask_stat");
rvbSniffStat_ = config.get<int> ("es.rvb_sniff_stat");
+ rvbSniffFrontStat_ = config.get<int> ("es.rvb_sniff_front_stat");
rvbBallStat_ = config.get<int> ("es.rvb_ball_stat");
othersStat_ = config.get<int> ("es.others_stat");
lcdKeyStat_ = config.get<int> ("es.lcd_key_stat");
@@ -100,6 +101,7 @@ Es::reset (void)
setRVBSniffStat (rvbSniffMaskStat_, rvbSniffStat_);
setRVBBallStat (rvbBallStat_);
setOthersStat (othersStat_);
+ setRVBSniffFrontStat (rvbSniffFrontStat_);
lcdGetKey (lcdKeyStat_);
// We want to reference some sensors
@@ -169,6 +171,13 @@ Es::setRVBBallStat (int freq)
proto_.send ('B', "b", freq);
}
+/// Set frequency of front sensor in analyse mode
+void
+Es::setRVBSniffFrontStat (int freq)
+{
+ proto_.send ('C', "b", freq);
+}
+
/// Enable all the sensors or just the 4 and 1 near the ground
void
Es::enableAllSensors (bool enable)
@@ -251,12 +260,18 @@ Es::barilletInit (void)
proto_.send ('i');
}
-// Init n°2 of barillet
-void Es::init2Barillet(void)
+/// Init turbine to minimal speed
+void Es::barilletDebutLancement (void)
{
proto_.send ('g');
}
+/// Init front turbine to full speed
+void Es::barilletLancement (void)
+{
+ proto_.send ('h');
+}
+
/// Put barillet in sleep mode
void
Es::barilletSleep (void)
@@ -282,6 +297,11 @@ void Es::rotationBarillet(int posFinal)
proto_.send ('t', "b", posFinal);
}
+/// Empty everything in the barillet
+void Es::barilletEmpty (void)
+{
+ proto_.send ('n');
+}
void Es::receive(char command, const Proto::Frame & frame)
{
@@ -294,7 +314,7 @@ void Es::receive(char command, const Proto::Frame & frame)
case 'Z':
if (proto_.decode (frame, "bbbb", stat1, stat2, stat3, stat4))
{
- log_ ("Stats main : ", Log::debug) << stat1 << " " << stat2 << " "
+ log_ ("Stats main", Log::debug) << stat1 << " " << stat2 << " "
<< stat3 << " " << stat4;
}
break;
@@ -302,6 +322,7 @@ void Es::receive(char command, const Proto::Frame & frame)
case 'F':
if (proto_.decode (frame, "b", errCode))
{
+ log_ ("Ack", Log::debug) << "ErrCode :" << errCode;
switch (errCode)
{
case 1:
@@ -315,7 +336,7 @@ void Es::receive(char command, const Proto::Frame & frame)
case 'S':
if (proto_.decode (frame, "wwwww", compt, red, blue, clear, green))
{
- log_ ("Stats RVB Raw : ", Log::debug) << "[" << compt << "] = {"
+ log_ ("Stats RVB Raw", Log::debug) << "[" << compt << "] = {"
<< red << "," << blue << "," << clear << "," << green << "}";
}
break;
@@ -323,15 +344,22 @@ void Es::receive(char command, const Proto::Frame & frame)
case 'A':
if (proto_.decode (frame, "bb", compt, value))
{
- log_ ("Stats RVB Sniff : ", Log::debug) << "[" << compt << "] = "
+ log_ ("Stats RVB Sniff", Log::debug) << "[" << compt << "] = "
<< decodeColor (value);
}
break;
+ case 'C':
+ if (proto_.decode (frame, "bb", stat1, stat2))
+ {
+ log_ ("Stats RVB Front", Log::debug) << decodeColor (stat1)
+ << " - " << decodeColor (stat2);
+ }
+ break;
/* RVB Balls */
case 'B':
if (proto_.decode (frame, "bb", stat1, stat2))
{
- log_ ("Stats RVB Ball : ", Log::debug) << "[" << decodeColor
+ log_ ("Stats RVB Ball", Log::debug) << "[" << decodeColor
(stat1) << "] [" << decodeColor (stat2) << "]";
rvbBall_[0] = stat1;
rvbBall_[1] = stat2;
@@ -359,7 +387,7 @@ void Es::receive(char command, const Proto::Frame & frame)
jack_ = colorModeBlue_ = true;
break;
}
- log_ ("Colour mode : ", Log::debug) << (colorModeBlue_ ? "Blue" : "Red")
+ log_ ("Others", Log::debug) << "Color mode " << (colorModeBlue_ ? "Blue" : "Red")
<< (jack_ ? ", jack in..." : ", jack out !!!");
}
break;
@@ -376,6 +404,13 @@ void Es::receive(char command, const Proto::Frame & frame)
sharps_[compt] = value;
}
break;
+ /* Barillet */
+ case 'W':
+ if (proto_.decode (frame, "bb", stat1, stat2))
+ {
+ log_ ("Barillet", Log::debug) << stat1 << " " << stat2;
+ }
+ break;
}
}
diff --git a/i/marvin/src/es/es.hh b/i/marvin/src/es/es.hh
index 46f1dc7..dd9ac1c 100644
--- a/i/marvin/src/es/es.hh
+++ b/i/marvin/src/es/es.hh
@@ -72,6 +72,8 @@ class Es : public Proto::Receiver
/// Others module, jack & colour
bool jack_, colorModeBlue_;
int othersStat_;
+ /// Stat of front sensors
+ int rvbSniffFrontStat_;
public:
/// Constructeur
@@ -108,6 +110,8 @@ class Es : public Proto::Receiver
void setRVBSniffStat (int mask_captor, int freq);
/// Configure statistic for the sensor of the ball
void setRVBBallStat (int freq);
+ /// Set frequency of front sensor in analyse mode
+ void setRVBSniffFrontStat (int freq);
/// Enable all the sensors or just the 4 and 1 near the ground
void enableAllSensors (bool enable);
@@ -136,8 +140,10 @@ class Es : public Proto::Receiver
void setTheMeaningOfRotationOfBarillet (int answer);
/// Init the barillet and put it at the right place
void barilletInit (void);
- /// Init n°2 of barillet
- void init2Barillet(void);
+ /// Init turbine to minimal speed
+ void barilletDebutLancement (void);
+ /// Init front turbine to full speed
+ void barilletLancement (void);
/// Put barillet in sleep mode
void barilletSleep (void);
/// Dépose une balle du barillet
@@ -146,6 +152,8 @@ class Es : public Proto::Receiver
void extraitBalle(void);
/// Rotation du barillet
void rotationBarillet(int posFinal);
+ /// Empty everything in the barillet
+ void barilletEmpty (void);
private:
/// Decode a color into a string
diff --git a/i/marvin/src/es/test_es.cc b/i/marvin/src/es/test_es.cc
index aa9ce6d..4213ebb 100644
--- a/i/marvin/src/es/test_es.cc
+++ b/i/marvin/src/es/test_es.cc
@@ -31,87 +31,102 @@
class TestEs : public Tester
{
- private:
- Es es_;
- /// Called after each command called.
- void postcall (void)
+ private:
+ Es es_;
+ /// Called after each command called.
+ void postcall (void)
+ {
+ while (!es_.wait ())
+ ;
+ }
+ /// Wait.
+ void wait (int ms)
+ {
+ int t, stop;
+ t = Timer::getProgramTime ();
+ stop = t + ms;
+ while (t < stop)
{
- while (!es_.wait ())
- ;
- }
- /// Wait.
- void wait (int ms)
- {
- int t, stop;
+ es_.wait (stop - t);
t = Timer::getProgramTime ();
- stop = t + ms;
- while (t < stop)
- {
- es_.wait (stop - t);
- t = Timer::getProgramTime ();
- }
}
- public:
- // Constructor
- TestEs (int argc, char ** argv)
- : Tester (argc, argv), es_(config_) { }
- void preRun (void)
- {
- Interpreter &interpreter = getInterpreter ();
- // Add functions.
- interpreter.add ("reset", Interpreter::memFunc (es_, &Es::reset),
- "Reset ()");
- interpreter.add ("wait", Interpreter::memFunc (*this, &TestEs::wait),
- "Blocking wait (time)\n"
- " - time : time to wait in ms");
- interpreter.add
- ("colorRef", Interpreter::memFunc (es_, &Es::setRefColor),
- "Reference current color as green for sensors (mask)");
- interpreter.add
- ("rvbAll", Interpreter::memFunc (es_, &Es::enableAllSensors),
- "Drop a ball at the rear ()");
- interpreter.add
- ("servoPos", Interpreter::memFunc (es_, &Es::setServoPos),
- "Set servo position (mask, pos)");
- interpreter.add
- ("sharpUp", Interpreter::memFunc (es_, &Es::setSharpUpdate),
- "Set sharp update frequency (mask, freq)");
- interpreter.add
- ("sharpStat", Interpreter::memFunc (es_, &Es::setSharpStat),
- "Set sharp stats (mask, freq)");
- interpreter.add
- ("sharpThreshold", Interpreter::memFunc (es_, &Es::setSharpThreshold),
- "Set sharp threshold (num, high, low)\n"
- " - num : sharp number (1-3)\n"
- " - high : high threshold\n"
- " - low : low threshold");
- interpreter.add
- ("lcdPrint", Interpreter::memFunc (es_, &Es::lcdPrint),
- "Print a message (32 char max) onto the LCD (message)");
- interpreter.add
- ("lcdKey", Interpreter::memFunc (es_, &Es::lcdGetKey),
- "Set stat for key if pressed (freq)");
- interpreter.add
- ("turbSpeed", Interpreter::memFunc (es_, &Es::setTurbineSpeed),
- "Set turbine speed (num, speed)\n"
- " - num : 1 front, 2 rear\n"
- " - speed : 256 - 819");
- interpreter.add
- ("turbMin", Interpreter::memFunc (es_, &Es::init2Barillet),
- "Turbine minimal speed ()");
- interpreter.add
- ("turbDep", Interpreter::memFunc (es_, &Es::deposeBalle),
- "Drop a ball at the rear ()");
- interpreter.add
- ("barGoTo", Interpreter::memFunc (es_, &Es::rotationBarillet),
- "Barillet go to position (pos)\n"
- " - pos : in 40° of a round");
- interpreter.add
- ("barSleep", Interpreter::memFunc (es_, &Es::barilletSleep),
- "Barillet in sleep mode (low speed turbine)");
- interpreter.add ("_postcall",
- Interpreter::memFunc (*this, &TestEs::postcall));
- }
+ }
+ public:
+ // Constructor
+ TestEs (int argc, char ** argv)
+ : Tester (argc, argv), es_(config_) { }
+ void preRun (void)
+ {
+ Interpreter &interpreter = getInterpreter ();
+ // Add functions.
+ interpreter.add ("reset", Interpreter::memFunc (es_, &Es::reset),
+ "Reset ()");
+ interpreter.add ("wait", Interpreter::memFunc (*this, &TestEs::wait),
+ "Blocking wait (time)\n"
+ " - time : time to wait in ms");
+ interpreter.add
+ ("colorRef", Interpreter::memFunc (es_, &Es::setRefColor),
+ "Reference current color as green for sensors (mask)");
+ interpreter.add
+ ("rvbAll", Interpreter::memFunc (es_, &Es::enableAllSensors),
+ "Drop a ball at the rear ()");
+ interpreter.add
+ ("servoPos", Interpreter::memFunc (es_, &Es::setServoPos),
+ "Set servo position (mask, pos)");
+ interpreter.add
+ ("sharpUp", Interpreter::memFunc (es_, &Es::setSharpUpdate),
+ "Set sharp update frequency (mask, freq)");
+ interpreter.add
+ ("sharpStat", Interpreter::memFunc (es_, &Es::setSharpStat),
+ "Set sharp stats (mask, freq)");
+ interpreter.add
+ ("sharpThreshold", Interpreter::memFunc (es_, &Es::setSharpThreshold),
+ "Set sharp threshold (num, high, low)\n"
+ " - num : sharp number (1-3)\n"
+ " - high : high threshold\n"
+ " - low : low threshold");
+ interpreter.add
+ ("lcdPrint", Interpreter::memFunc (es_, &Es::lcdPrint),
+ "Print a message (32 char max) onto the LCD (message)");
+ interpreter.add
+ ("lcdKey", Interpreter::memFunc (es_, &Es::lcdGetKey),
+ "Set stat for key if pressed (freq)");
+ interpreter.add
+ ("turbSpeed", Interpreter::memFunc (es_, &Es::setTurbineSpeed),
+ "Set turbine speed (num, speed)\n"
+ " - num : 1 front, 2 rear\n"
+ " - speed : 256 - 819");
+ interpreter.add
+ ("turbMinSpeed", Interpreter::memFunc (es_,
+ &Es::barilletDebutLancement),
+ "Turbine minimal speed ()");
+ interpreter.add
+ ("turbFrontFull", Interpreter::memFunc (es_,
+ &Es::barilletLancement),
+ "Turbine front full speed ()");
+ interpreter.add
+ ("barSleep", Interpreter::memFunc (es_, &Es::barilletSleep),
+ "Barillet in sleep mode (low speed turbine)");
+ interpreter.add
+ ("turbDepose", Interpreter::memFunc (es_, &Es::deposeBalle),
+ "Drop a ball at the rear ()");
+ interpreter.add
+ ("barExtract", Interpreter::memFunc (es_, &Es::extraitBalle),
+ "Extract a ball ()");
+ interpreter.add
+ ("barGoTo", Interpreter::memFunc (es_, &Es::rotationBarillet),
+ "Barillet go to position (pos)\n"
+ " - pos : in 40° of a round");
+ interpreter.add
+ ("barPurge", Interpreter::memFunc (es_, &Es::barilletEmpty),
+ "Extract a ball ()");
+ interpreter.add ("_postcall",
+ Interpreter::memFunc (*this, &TestEs::postcall));
+ }
+ void postRun (void)
+ {
+ es_.reset ();
+ }
};
int