summaryrefslogtreecommitdiff
path: root/i/marvin
diff options
context:
space:
mode:
authordufourj2006-05-24 04:17:12 +0000
committerdufourj2006-05-24 04:17:12 +0000
commit84ed888b09f0a4bb430b156eebc0afe5de7a8981 (patch)
tree492ebb5091e5e69c82258c7485138036a455f0e5 /i/marvin
parent6eb802cdd87ebac5fa1c5eb129827ed1149fdb2e (diff)
Es :
- ajout des paramêtres chargés à la création de la classe ; - mise à niveau avec le code avr. ES : - quelques corrections au niveau protocolaire (c, j, k sont disponnibles) ; - ajout de quelques commentaires de questions.
Diffstat (limited to 'i/marvin')
-rw-r--r--i/marvin/runtime/rc/config27
-rw-r--r--i/marvin/src/data/Makefile.defs6
-rw-r--r--i/marvin/src/es/es.cc264
-rw-r--r--i/marvin/src/es/es.hh68
-rw-r--r--i/marvin/src/es/test_es.cc16
5 files changed, 265 insertions, 116 deletions
diff --git a/i/marvin/runtime/rc/config b/i/marvin/runtime/rc/config
index 320d121..2331cba 100644
--- a/i/marvin/runtime/rc/config
+++ b/i/marvin/runtime/rc/config
@@ -29,6 +29,33 @@ asserv.timer_stat = 0
### ES
es.tty = "/dev/ttyS1"
+# Frequency of ack when something important happened
+es.ack_freq = 10
+# Frequency of main stats
+es.main_stat = 0
+# Max false input capture before the sensor is ready for a real capture
+es.rvb_sensors_false_ic = 3
+# Max overflow of the TC1 before though the sensor is dead
+es.rvb_sensors_max_ov = 250
+# Ratio for the algorithm that choose if the color is green or not
+es.rvb_sniff_ref_ratio = 3
+# Limits for the algorithm of choosing between a black or white ball
+es.rvb_sniff_green_limit = 3700
+es.rvb_sniff_clear_limit = 4000
+# Stats of RVB Sensor raw data
+es.rvb_sensor_mask_stat = 0xFFFF
+es.rvb_sensor_stat = 0
+# Reference which sensor at boot time
+es.rvb_sniff_ref_mask = 127
+# Stats of RVB Sniff data
+es.rvb_sniff_mask_stat = 0xFFFF
+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
+# Stats for printing out key pressed onto the LCD keyboard
+es.lcd_key_stat = 0
### Log
# Default minimum level outputed
diff --git a/i/marvin/src/data/Makefile.defs b/i/marvin/src/data/Makefile.defs
index aa64e47..c0fe78d 100644
--- a/i/marvin/src/data/Makefile.defs
+++ b/i/marvin/src/data/Makefile.defs
@@ -8,3 +8,9 @@ test_data_OBJECTS = test_data.o $(data_OBJECTS)
test_data_buffer_OBJECTS = test_data_buffer.o data_buffer.o
test_data_circular_buffer_OBJECTS = test_data_circular_buffer.o data_circular_buffer.o
+
+#UTESTS += data
+
+#data.utest: test_data
+
+#data_UTEST = ./test_data /tmp/toto.tar.gz > /dev/null
diff --git a/i/marvin/src/es/es.cc b/i/marvin/src/es/es.cc
index b397cef..567830f 100644
--- a/i/marvin/src/es/es.cc
+++ b/i/marvin/src/es/es.cc
@@ -31,55 +31,104 @@
/// Constructeur
Es::Es (const Config & config)
- : proto_ (*this), log_ ("Es"), lcd_key_pressed_ (-1),
- front_sensor_ (false)
+ : proto_ (*this), log_ ("Es"), lcdKeyPressed_ (-1),
+ front_sensor_ (false), jack_ (false), colorModeBlue_ (false)
{
// Rcupration des valeurs de configuration dans le fichier
loadConfig (config);
proto_.open (tty_);
- sensorsRvb_.resize (9);
- for (int compt = 0; compt < 9; compt++)
- sensorsRvb_[0].resize (4);
- sniffRvb_.resize (9);
+ rvbBall_[0] = rvbBall_[1] = -1;
sharps_.resize (3);
}
+bool
+Es::wait (int timeout /*-1*/)
+{
+ return proto_.wait (timeout);
+}
+
+/// Rcupre le File Descriptor
+int
+Es::getFd (void)
+{
+ return proto_.getFd();
+}
+
+bool Es::sync (void)
+{
+ return proto_.sync ();
+}
+
+void
+Es::loadConfig (const Config & config)
+{
+ tty_ = config.get<std::string>("es.tty");
+ ackFreq_ = config.get<int> ("es.ack_freq");
+ mainStat_ = config.get<int> ("es.main_stat");
+ rvbSensorFalseIC_ = config.get<int> ("es.rvb_sensors_false_ic");
+ rvbSensorMaxOv_ = config.get<int> ("es.rvb_sensors_max_ov");
+ rvbSniffRefRatio_ = config.get<int> ("es.rvb_sniff_ref_ratio");
+ rvbSniffGreenLimit_ = config.get<int> ("es.rvb_sniff_green_limit");
+ rvbSniffClearLimit_ = config.get<int> ("es.rvb_sniff_clear_limit");
+ rvbSensorMaskStat_ = config.get<int> ("es.rvb_sensor_mask_stat");
+ rvbSensorStat_ = config.get<int> ("es.rvb_sensor_stat");
+ 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");
+ rvbBallStat_ = config.get<int> ("es.rvb_ball_stat");
+ othersStat_ = config.get<int> ("es.others_stat");
+ lcdKeyStat_ = config.get<int> ("es.lcd_key_stat");
+}
+
void
Es::reset (void)
{
// On reset l'AVR
proto_.send ('z');
- // Send configuration TODO
- // We want to reference some sensors
+
// First, enable all sensors
+ setRVBSensorsConfig (rvbSensorFalseIC_, rvbSensorMaxOv_);
enableAllSensors (true);
- /// XXX Is it to often ?
-// setAckStat (1);
+
+ // Send configurations
+ setMainStat (mainStat_);
+ setAckStat (ackFreq_);
+ setRVBSniffConfig (rvbSniffRefRatio_, rvbSniffGreenLimit_,
+ rvbSniffClearLimit_);
+ setRVBSensorsStat (rvbSensorMaskStat_, rvbSensorStat_);
+ setRVBSniffStat (rvbSniffMaskStat_, rvbSniffStat_);
+ setRVBBallStat (rvbBallStat_);
+ setOthersStat (othersStat_);
+ lcdGetKey (lcdKeyStat_);
+
+ // We want to reference some sensors
// XXX We should wait !
- // Reference sensors 1-7
- setRefColor (127, 0);
+ setRefColor (rvbSniffRefMask_);
// Disable useless sensors
enableAllSensors (false);
}
-bool
-Es::wait (int timeout /*-1*/)
+/// Stat for the main ()
+void
+Es::setMainStat (int freq)
{
- return proto_.wait (timeout);
+ proto_.send ('Z', "b", freq);
}
-/// Rcupre le File Descriptor
-int
-Es::getFd (void)
+/// Shut up !
+void
+Es::shutUp (void)
{
- return proto_.getFd();
+ proto_.send ('f');
}
+/// Set frequency of ack
void
-Es::loadConfig (const Config & config)
+Es::setAckStat (int freq)
{
- tty_ = config.get<std::string>("es.tty");
+ ackFreq_ = freq;
+ proto_.send ('F', "b", ackFreq_);
}
// Envoie de la config des sensors RVB
@@ -101,7 +150,7 @@ void Es::setRVBSensorsStat(int mask_captor, int freq)
}
// rgle la couleur actuelle comme rfrente
-void Es::setRefColor(int mask_captor, int mode = 0)
+void Es::setRefColor(int mask_captor, int mode)
{
proto_.send ('r', "wb", mask_captor, mode);
}
@@ -115,9 +164,26 @@ Es::setRVBSniffStat (int mask_captor, int freq)
/// Configure statistic for the sensor of the ball
void
-Es::setRVBBallStat (int sensor_num, int freq)
+Es::setRVBBallStat (int freq)
+{
+ proto_.send ('B', "b", freq);
+}
+
+/// Enable all the sensors or just the 4 and 1 near the ground
+void
+Es::enableAllSensors (bool enable)
+{
+ if (enable)
+ proto_.send ('u', "b", 1);
+ else
+ proto_.send ('u', "b", 0);
+}
+
+/// Set frequency of jack, selectoul printed out function
+void
+Es::setOthersStat (int freq)
{
- proto_.send ('B', "bb", sensor_num, freq);
+ proto_.send ('O', "b", freq);
}
// Discute avec les servo...
@@ -156,14 +222,14 @@ Es::lcdPrint (const std::string &message)
std::memset (lcd_mess_char_, '\0', 32);
int size = message.size ();
std::memcpy (lcd_mess_char_, message.data (), size > 32 ? 32 : size);
- proto_.send ('L', lcd_mess_char_, 32);
+ proto_.send ('l', lcd_mess_char_, 32);
}
/// Get the current pressed keys of the LCD
void
Es::lcdGetKey (int freq)
{
- proto_.send ('l', "b", freq);
+ proto_.send ('L', "b", freq);
}
// Rgle la vitesse des turbines
@@ -178,12 +244,26 @@ void Es::setTheMeaningOfRotationOfBarillet(int answer)
proto_.send ('w', "b", answer);
}
+/// Init the barillet and put it at the right place
+void
+Es::barilletInit (void)
+{
+ proto_.send ('i');
+}
+
// Init n2 of barillet
void Es::init2Barillet(void)
{
proto_.send ('g');
}
+/// Put barillet in sleep mode
+void
+Es::barilletSleep (void)
+{
+ proto_.send ('s');
+}
+
// Dpose une balle du barillet
void Es::deposeBalle(void)
{
@@ -202,50 +282,23 @@ void Es::rotationBarillet(int posFinal)
proto_.send ('t', "b", posFinal);
}
-/// Put barillet in sleep mode
-void
-Es::barilletSleep (void)
-{
- proto_.send ('s');
-}
-
-/// Enable all the sensors or just the 4 and 1 near the ground
-void
-Es::enableAllSensors (bool enable)
-{
- if (enable)
- proto_.send ('u', "b", 1);
- else
- proto_.send ('u', "b", 0);
-}
-
-/// Shut up !
-void
-Es::shutUp (void)
-{
- proto_.send ('f', "b", 0);
-}
-
-/// Set frequency of ack
-void
-Es::setAckStat (int freq)
-{
- proto_.send ('F', "b", freq);
-}
-
-/// Stat for the main ()
-void
-Es::setMainStat (int freq)
-{
- proto_.send ('Z', "b", freq);
-}
void Es::receive(char command, const Proto::Frame & frame)
{
int errCode, red, blue, clear, green, compt, value;
+ int stat1, stat2, stat3, stat4;
switch (command)
{
+ /* Main stat */
+ case 'Z':
+ if (proto_.decode (frame, "bbbb", stat1, stat2, stat3, stat4))
+ {
+ log_ ("Stats main : ", Log::debug) << stat1 << " " << stat2 << " "
+ << stat3 << " " << stat4;
+ }
+ break;
+ /* Ack */
case 'F':
if (proto_.decode (frame, "b", errCode))
{
@@ -258,30 +311,64 @@ void Es::receive(char command, const Proto::Frame & frame)
shutUp ();
}
break;
- case 'Z':
- // TODO
- break;
- case 'S':
+ /* RVB Sensors raw stat */
+ case 'S':
if (proto_.decode (frame, "wwwww", compt, red, blue, clear, green))
{
- sensorsRvb_[compt][0] = red;
- sensorsRvb_[compt][1] = blue;
- sensorsRvb_[compt][2] = clear;
- sensorsRvb_[compt][3] = green;
+ log_ ("Stats RVB Raw : ", Log::debug) << "[" << compt << "] = {"
+ << red << "," << blue << "," << clear << "," << green << "}";
}
break;
+ /* RVB Sniff stats */
case 'A':
if (proto_.decode (frame, "bb", compt, value))
{
- sniffRvb_[compt] = value;
+ log_ ("Stats RVB Sniff : ", Log::debug) << "[" << compt << "] = "
+ << decodeColor (value);
}
break;
+ /* RVB Balls */
case 'B':
- if (proto_.decode (frame, "bb", compt, value))
+ if (proto_.decode (frame, "bb", stat1, stat2))
{
- sniffRvb_[compt] = value;
+ log_ ("Stats RVB Ball : ", Log::debug) << "[" << decodeColor
+ (stat1) << "] [" << decodeColor (stat2) << "]";
+ rvbBall_[0] = stat1;
+ rvbBall_[1] = stat2;
}
break;
+ /* Others */
+ case 'O':
+ if (proto_.decode (frame, "b", value))
+ {
+ // XXX Use a decallage please
+ switch (value)
+ {
+ case 0:
+ jack_ = colorModeBlue_ = false;
+ break;
+ case 1:
+ jack_ = true;
+ colorModeBlue_ = false;
+ break;
+ case 2:
+ jack_ = false;
+ colorModeBlue_ = true;
+ break;
+ case 3:
+ jack_ = colorModeBlue_ = true;
+ break;
+ }
+ log_ ("Colour mode : ", Log::debug) << (colorModeBlue_ ? "Blue" : "Red")
+ << (jack_ ? ", jack in..." : ", jack out !!!");
+ }
+ break;
+ /* LCD */
+ case 'L':
+ if (proto_.decode (frame, "b", value))
+ lcdKeyPressed_ = value;
+ break;
+ /* Sharps */
case 'H':
if (proto_.decode (frame, "ww", compt, value))
{
@@ -292,8 +379,31 @@ void Es::receive(char command, const Proto::Frame & frame)
}
}
-bool Es::sync (void)
+/// Decode a color into a string
+std::string
+Es::decodeColor (int color)
{
- return proto_.sync ();
+ switch (color)
+ {
+ case 0:
+ return "green";
+ break;
+ case 1:
+ return "blue";
+ break;
+ case 2:
+ return "red";
+ break;
+ case 3:
+ return "other";
+ break;
+ case 4:
+ return "black";
+ break;
+ case 5:
+ return "white";
+ break;
+ default:
+ return "unknow";
+ }
}
-
diff --git a/i/marvin/src/es/es.hh b/i/marvin/src/es/es.hh
index ecdcd08..46f1dc7 100644
--- a/i/marvin/src/es/es.hh
+++ b/i/marvin/src/es/es.hh
@@ -35,9 +35,6 @@ class Config;
/// Gre la carte es et ses capteurs et actionneurs
class Es : public Proto::Receiver
{
- typedef std::vector<int> SensorRVB;
- typedef std::vector<SensorRVB> SensorsRVB;
- typedef std::vector<int> SniffRVB;
typedef std::vector<int> Sharps;
private:
// Objet Proto de communication vers la carte es
@@ -49,21 +46,36 @@ class Es : public Proto::Receiver
/// For LCD communication
char lcd_mess_char_[32];
/// Key pressed by the LCD Keyboard
- int lcd_key_pressed_;
+ int lcdKeyPressed_, lcdKeyStat_;
/// Frontal choc !
bool front_sensor_;
- /// Vector of sensors
- SensorsRVB sensorsRvb_;
- /// Sniff RVB
- SniffRVB sniffRvb_;
+ /// Ack frequency
+ int ackFreq_;
+ /// Main stat frequency
+ int mainStat_;
+ /// Config of RVB sensors
+ int rvbSensorFalseIC_, rvbSensorMaxOv_;
+ /// Config of RVB sniff
+ int rvbSniffRefRatio_, rvbSniffGreenLimit_, rvbSniffClearLimit_;
+ /// RVB Sensors raw stats
+ int rvbSensorMaskStat_, rvbSensorStat_;
+ /// Reference which sensor at boot time
+ int rvbSniffRefMask_;
+ /// RVB Sniff stats
+ int rvbSniffMaskStat_, rvbSniffStat_;
+ /// RVB Sensors raw stats
+ int rvbBallStat_;
+ /// Balls RVB
+ int rvbBall_[2];
/// Sharps
Sharps sharps_;
+ /// Others module, jack & colour
+ bool jack_, colorModeBlue_;
+ int othersStat_;
public:
/// Constructeur
Es (const Config & config);
- /// Initialise les capteurs et actionneurs, reset
- void reset (void);
/// On attend ...
bool wait (int timeout = -1);
/// Rcupre le File Descriptor
@@ -72,9 +84,18 @@ class Es : public Proto::Receiver
void receive (char command, const Proto::Frame & frame);
/// sync..
bool sync (void);
-
/// Charge les paramtre du fichier de config
void loadConfig (const Config & config);
+
+ /// Initialise les capteurs et actionneurs, reset
+ void reset (void);
+ /// Stat for the main ()
+ void setMainStat (int freq);
+ /// Shut up !
+ void shutUp (void);
+ /// Set frequency of ack
+ void setAckStat (int freq);
+
/// Envoie de la config des sensors RVB
void setRVBSensorsConfig(int false_ic, int max_ov);
/// Envoie de la config des sniff RVB
@@ -82,16 +103,19 @@ class Es : public Proto::Receiver
/// Rgle les stats des sensors RVB
void setRVBSensorsStat(int mask_captor, int freq);
/// rgle la couleur actuelle comme rfrente
- void setRefColor(int mask_captor, int mode);
+ void setRefColor(int mask_captor, int mode = 0);
/// Rgle les stats d'affichage de la couleur
void setRVBSniffStat (int mask_captor, int freq);
/// Configure statistic for the sensor of the ball
- void setRVBBallStat (int sensor_num, int freq);
+ void setRVBBallStat (int freq);
/// Enable all the sensors or just the 4 and 1 near the ground
void enableAllSensors (bool enable);
+ /// Set frequency of jack, selectoul printed out function
+ void setOthersStat (int freq);
+
/// Discute avec les servo...
- void setServoPos (int servoNb, int servoPos);
+ void setServoPos (int servo_mask, int servoPos);
/// Set update frequency of sharps
void setSharpUpdate (int sharp_mask, int freq);
@@ -110,23 +134,21 @@ class Es : public Proto::Receiver
void setTurbineSpeed (int turbNb, int speed);
/// Rgle le sens de rotation du barillet
void setTheMeaningOfRotationOfBarillet (int answer);
+ /// Init the barillet and put it at the right place
+ void barilletInit (void);
/// Init n2 of barillet
void init2Barillet(void);
+ /// Put barillet in sleep mode
+ void barilletSleep (void);
/// Dpose une balle du barillet
void deposeBalle(void);
/// Extrait une balle
void extraitBalle(void);
/// Rotation du barillet
void rotationBarillet(int posFinal);
- /// Put barillet in sleep mode
- void barilletSleep (void);
- /// Shut up !
- void shutUp (void);
- /// Set frequency of ack
- void setAckStat (int freq);
-
- /// Stat for the main ()
- void setMainStat (int freq);
+ private:
+ /// Decode a color into a string
+ std::string decodeColor (int color);
};
#endif // es_hh
diff --git a/i/marvin/src/es/test_es.cc b/i/marvin/src/es/test_es.cc
index 13ca8a3..aa9ce6d 100644
--- a/i/marvin/src/es/test_es.cc
+++ b/i/marvin/src/es/test_es.cc
@@ -64,16 +64,6 @@ class TestEs : public Tester
interpreter.add ("wait", Interpreter::memFunc (*this, &TestEs::wait),
"Blocking wait (time)\n"
" - time : time to wait in ms");
- interpreter.add
- ("rvbStat", Interpreter::memFunc (es_, &Es::setRVBSensorsStat),
- "Enable RVB Sensors raw stats (mask, freq)");
- interpreter.add
- ("colorStat", Interpreter::memFunc (es_, &Es::setRVBSniffStat),
- "Enable RVB Sensors color stats (mask, freq)");
- interpreter.add
- ("ballStat", Interpreter::memFunc (es_, &Es::setRVBBallStat),
- "Enable Ball stats (num, freq)\n"
- " - num : sensor number (7 or 8)");
interpreter.add
("colorRef", Interpreter::memFunc (es_, &Es::setRefColor),
"Reference current color as green for sensors (mask)");
@@ -119,12 +109,6 @@ class TestEs : public Tester
interpreter.add
("barSleep", Interpreter::memFunc (es_, &Es::barilletSleep),
"Barillet in sleep mode (low speed turbine)");
- interpreter.add
- ("statAck", Interpreter::memFunc (es_, &Es::setAckStat),
- "Set ack stat (freq)");
- interpreter.add
- ("statMain", Interpreter::memFunc (es_, &Es::setMainStat),
- "Set main stat (freq)");
interpreter.add ("_postcall",
Interpreter::memFunc (*this, &TestEs::postcall));
}