summaryrefslogtreecommitdiff
path: root/2004/i/nono
diff options
context:
space:
mode:
authorschodet2004-04-07 07:58:15 +0000
committerschodet2004-04-07 07:58:15 +0000
commit8485bdc953e02971680aa52311af3c6e72759296 (patch)
tree81c69dad299ca3d75c4e0f37d53cd6fb6a912ef3 /2004/i/nono
parent3301c331bb5e1d27cfab47a7e856ba56781cca99 (diff)
serial: 9600 par default.
motor: MovementRotation, début de fonctionnement. Asserv: utilisation de Log.
Diffstat (limited to '2004/i/nono')
-rw-r--r--2004/i/nono/src/GNUmakefile1
-rw-r--r--2004/i/nono/src/config/config_lex.ll6
-rw-r--r--2004/i/nono/src/logger/log.cc7
-rw-r--r--2004/i/nono/src/logger/log.h1
-rw-r--r--2004/i/nono/src/motor/Makefile.defs8
-rw-r--r--2004/i/nono/src/motor/asserv.cc26
-rw-r--r--2004/i/nono/src/motor/asserv.h3
-rw-r--r--2004/i/nono/src/motor/movement_types.h1
-rw-r--r--2004/i/nono/src/motor/test_motor.cc11
-rw-r--r--2004/i/nono/src/motor/tracker.cc21
-rw-r--r--2004/i/nono/src/motor/tracker.h3
-rw-r--r--2004/i/nono/src/serial/serial_dev.cc2
12 files changed, 64 insertions, 26 deletions
diff --git a/2004/i/nono/src/GNUmakefile b/2004/i/nono/src/GNUmakefile
index 4b3ac24..3992ff1 100644
--- a/2004/i/nono/src/GNUmakefile
+++ b/2004/i/nono/src/GNUmakefile
@@ -39,6 +39,5 @@ alltargets: $(TARGETS)
clean:
rm -f $(TARGETS) $(extra_clean) *.o *.a
- rm -rf .dep
.PHONY: all clean test alltargets
diff --git a/2004/i/nono/src/config/config_lex.ll b/2004/i/nono/src/config/config_lex.ll
index 1387203..e4397af 100644
--- a/2004/i/nono/src/config/config_lex.ll
+++ b/2004/i/nono/src/config/config_lex.ll
@@ -96,7 +96,10 @@ int
config_yyopen (const char *filename, config_wrap_f wrap, void *data)
{
if (config_yyin && config_yyin != stdin)
+ {
fclose (config_yyin);
+ config_yyin = 0;
+ }
config_yyin = fopen (filename, "r");
if (!config_yyin) return -1;
wrap_f = wrap;
@@ -109,7 +112,10 @@ void
config_yyclose (void)
{
if (config_yyin && config_yyin != stdin)
+ {
fclose (config_yyin);
+ config_yyin = 0;
+ }
wrap_f = 0;
wrap_data = 0;
}
diff --git a/2004/i/nono/src/logger/log.cc b/2004/i/nono/src/logger/log.cc
index a5c4c83..4dc4f59 100644
--- a/2004/i/nono/src/logger/log.cc
+++ b/2004/i/nono/src/logger/log.cc
@@ -60,7 +60,8 @@ static const char *levelTab[] =
"error",
"warning",
"info",
- "debug"
+ "debug",
+ "verydebug"
};
/// Traduit le niveau de log.
@@ -86,7 +87,7 @@ Log::toLevel (const std::string &level)
int
Log::overflow (int c)
{
- if (c == '\n')
+/* if (c == '\n')
{
if (curLevel_ <= maxLevel_)
logger_.log (module_, instance_, curLevel_, buffer_);
@@ -96,7 +97,7 @@ Log::overflow (int c)
{
buffer_ += c;
}
- return c;
+ return c;*/
}
/// Partie commune des constructeurs.
diff --git a/2004/i/nono/src/logger/log.h b/2004/i/nono/src/logger/log.h
index d089a3b..d2add57 100644
--- a/2004/i/nono/src/logger/log.h
+++ b/2004/i/nono/src/logger/log.h
@@ -41,6 +41,7 @@ class Log : public std::ostream, protected std::streambuf
warning,
info,
debug,
+ verydebug,
nbLevel
};
private:
diff --git a/2004/i/nono/src/motor/Makefile.defs b/2004/i/nono/src/motor/Makefile.defs
index 7e9055a..f709a54 100644
--- a/2004/i/nono/src/motor/Makefile.defs
+++ b/2004/i/nono/src/motor/Makefile.defs
@@ -1,13 +1,13 @@
TARGETS += test_motor test_asserv test_tracker
LIBS += motor.a
test_motor_SOURCES = test_motor.cc motor.a serial.a erreur.a config.a date.a \
- utils.a
+ utils.a logger.a
test_asserv_SOURCES = test_asserv.cc motor.a serial.a erreur.a config.a \
- date.a utils.a
+ date.a utils.a logger.a
test_tracker_SOURCES = test_tracker.cc motor.a serial.a erreur.a config.a \
- date.a utils.a
+ date.a utils.a logger.a
motor_a_SOURCES = asserv.cc tracker.cc motor.cc movement_basic.cc \
- movement_goto.cc
+ movement_goto.cc movement_rotation.cc
test_motor: $(test_motor_SOURCES:%.cc=%.o)
diff --git a/2004/i/nono/src/motor/asserv.cc b/2004/i/nono/src/motor/asserv.cc
index 3c1a9f7..2107908 100644
--- a/2004/i/nono/src/motor/asserv.cc
+++ b/2004/i/nono/src/motor/asserv.cc
@@ -27,8 +27,6 @@
#include "date/date.h"
#include "utils/hexa.h"
-#include <iostream>
-
/// Constructeur.
Asserv::Asserv (AsservTracker &asservTracker)
: ttyspeed_ (0), accel_ (-1), kp_ (-1), ki_ (-1), kd_ (-1),
@@ -36,7 +34,8 @@ Asserv::Asserv (AsservTracker &asservTracker)
inBufSize_ (64), inBufPos_ (0), inBuf_ (0),
firstCounter_ (true),
countLeft_ (0), countRight_ (0),
- asservTracker_ (asservTracker)
+ asservTracker_ (asservTracker),
+ log_ ("asserv")
{
// Lit la conf.
Config rc ("rc/asserv");
@@ -58,7 +57,7 @@ Asserv::Asserv (AsservTracker &asservTracker)
// Ouvre le port série.
serial_.open (ttyname_.c_str ());
// Alloue la mémoire du tampon d'entrée.
- inBuf_ = new char[inBufSize_];
+ inBuf_ = new char[inBufSize_ + 1];
}
/// Destructeur.
@@ -259,7 +258,7 @@ Asserv::sendLast (void)
{
if (sendQueue_.empty ()) return;
std::string &s = sendQueue_.front ();
-std::cout << "send " << s << std::endl;
+ log_ (Log::debug) << "send " << s << std::endl;
serial_.write (s.data (), s.size ());
}
@@ -267,8 +266,8 @@ std::cout << "send " << s << std::endl;
void
Asserv::handleMessage (void)
{
-inBuf_[inBufPos_] = 0;
-//std::cout << "recv " << inBuf_ << std::endl;
+ inBuf_[inBufPos_] = 0;
+ log_ (Log::debug) << "recv " << inBuf_ << std::endl;
if (inBufPos_ > 1 && inBuf_[0] == '!')
{
switch (inBuf_[1])
@@ -304,8 +303,8 @@ Asserv::handleStatMotor (void)
{
if (inBufPos_ != 2 + 1 + 2 + 1 + 4 + 1 + 4)
{
-std::cout << "stat motor error" << std::endl;
// Mauvaise transmission.
+ log_ (Log::warning) << "stat motor error" << std::endl;
return;
}
char side = inBuf_[2];
@@ -320,8 +319,8 @@ Asserv::handleCounter (void)
{
if (inBufPos_ != 2 + 4 + 1 + 4)
{
-std::cout << "counter error" << std::endl;
// Mauvaise transmission.
+ log_ (Log::warning) << "counter error" << std::endl;
return;
}
int l = getSignedShort (inBuf_ + 2);
@@ -334,7 +333,8 @@ std::cout << "counter error" << std::endl;
firstCounter_ = false;
}
// Attention à l'overflow.
-//std::cout << "counter before " << countLeft_ << ' ' << countRight_ << ' ' << l << ' ' << r << std::endl;
+ log_ (Log::verydebug) << "counter before " << countLeft_ << ' ' <<
+ countRight_ << ' ' << l << ' ' << r << std::endl;
if (l > 0x4000 && countLeft_ < -0x4000)
countLeft_ += 0x10000;
if (l < -0x4000 && countLeft_ > 0x4000)
@@ -343,10 +343,12 @@ std::cout << "counter error" << std::endl;
countRight_ += 0x10000;
if (r < -0x4000 && countRight_ > 0x4000)
countRight_ -= 0x10000;
-//std::cout << "counter after " << countLeft_ << ' ' << countRight_ << ' ' << l << ' ' << r << std::endl;
+ log_ (Log::verydebug) << "counter after " << countLeft_ << ' ' <<
+ countRight_ << ' ' << l << ' ' << r << std::endl;
// Met à jour le tracker.
asservTracker_.updateCounter (l - countLeft_, r - countRight_);
-//std::cout << "tracker update " << l - countLeft_ << ' ' << r - countRight_ << std::endl;
+ log_ (Log::verydebug) << "tracker update " << l - countLeft_ << ' ' << r -
+ countRight_ << std::endl;
// Retiens les anciennes valeurs.
countLeft_ = l;
countRight_ = r;
diff --git a/2004/i/nono/src/motor/asserv.h b/2004/i/nono/src/motor/asserv.h
index 2736c78..cfda523 100644
--- a/2004/i/nono/src/motor/asserv.h
+++ b/2004/i/nono/src/motor/asserv.h
@@ -25,6 +25,7 @@
//
// }}}
#include "serial/serial.h"
+#include "logger/log.h"
#include <string>
#include <queue>
@@ -58,6 +59,8 @@ class Asserv
int countLeft_, countRight_;
// Objet interessé par les stats.
AsservTracker &asservTracker_;
+ // Système de log.
+ Log log_;
public:
/// Constructeur.
Asserv (AsservTracker &asservTracker);
diff --git a/2004/i/nono/src/motor/movement_types.h b/2004/i/nono/src/motor/movement_types.h
index 4872d89..4a5e2d4 100644
--- a/2004/i/nono/src/motor/movement_types.h
+++ b/2004/i/nono/src/motor/movement_types.h
@@ -26,5 +26,6 @@
// }}}
#include "movement_basic.h"
#include "movement_goto.h"
+#include "movement_rotation.h"
#endif // movement_types_h
diff --git a/2004/i/nono/src/motor/test_motor.cc b/2004/i/nono/src/motor/test_motor.cc
index 40ddb99..2f5f893 100644
--- a/2004/i/nono/src/motor/test_motor.cc
+++ b/2004/i/nono/src/motor/test_motor.cc
@@ -87,6 +87,17 @@ main (int argc, char **argv)
m.setMovement (mov);
}
break;
+ case 'r':
+ {
+ i++;
+ double dA;
+ if (i >= argc) break;
+ dA = atof (argv[i++]);
+ cout << "rotation " << dA << endl;
+ Movement *mov = new MovementRotation (dA);
+ m.setMovement (mov);
+ }
+ break;
default:
int s;
s = atoi (argv[i++]);
diff --git a/2004/i/nono/src/motor/tracker.cc b/2004/i/nono/src/motor/tracker.cc
index ba90b95..25f6f22 100644
--- a/2004/i/nono/src/motor/tracker.cc
+++ b/2004/i/nono/src/motor/tracker.cc
@@ -76,12 +76,9 @@ bool
Tracker::computeError (double x, double y, double &el, double &ea, double eps,
double dist) const
{
- // Calcule le point cible courant.
- double aX = posX_;
- double aY = posY_;
// Calcule la diférence avec la cible voulue.
- double eX = x - aX;
- double eY = y - aY;
+ double eX = x - posX_;
+ double eY = y - posY_;
// Calcule la distance au carré.
double d = eX * eX + eY * eY;
// Vérifie l'eps.
@@ -106,6 +103,20 @@ Tracker::computeError (double x, double y, double &el, double &ea, double eps,
return true;
}
+// Calcule l'erreur angulaire pour atteindre un angle, retourne faux si
+// atteind.
+bool
+Tracker::computeAngleError (double a, double &ea, double eps) const
+{
+ ea = a - angle_;
+ if (ea < eps)
+ {
+ ea = 0.0;
+ return false;
+ }
+ return true;
+}
+
// Calcule la longueur de l'arc gauche et droite pour atteindre un point.
// EPS précise la distance minimale. Renvois faux si atteind.
bool
diff --git a/2004/i/nono/src/motor/tracker.h b/2004/i/nono/src/motor/tracker.h
index 5271c08..2674782 100644
--- a/2004/i/nono/src/motor/tracker.h
+++ b/2004/i/nono/src/motor/tracker.h
@@ -52,6 +52,9 @@ class Tracker
// retourne faux si atteind.
bool computeError (double x, double y, double &el, double &ea, double eps,
double dist) const;
+ // Calcule l'erreur angulaire pour atteindre un angle, retourne faux si
+ // atteind.
+ bool computeAngleError (double a, double &ea, double eps) const;
// Calcule la longueur de l'arc gauche et droite pour atteindre un point.
// EPS précise la distance minimale. Renvois faux si atteind.
bool computeArcs (double x, double y, double &l, double &r, double eps)
diff --git a/2004/i/nono/src/serial/serial_dev.cc b/2004/i/nono/src/serial/serial_dev.cc
index ca5b07d..47d7461 100644
--- a/2004/i/nono/src/serial/serial_dev.cc
+++ b/2004/i/nono/src/serial/serial_dev.cc
@@ -68,10 +68,10 @@ SerialDev::open (const char *ttyname, int speed/*0*/)
case 1200:
cfsetspeed (&tios, B1200);
break;
+ case 0:
case 9660:
cfsetspeed (&tios, B9600);
break;
- case 0:
case 19200:
cfsetspeed (&tios, B19200);
break;