summaryrefslogtreecommitdiff
path: root/2004
diff options
context:
space:
mode:
authorschodet2004-05-19 13:15:12 +0000
committerschodet2004-05-19 13:15:12 +0000
commit43cbee25345ca2a8c6e4a950ad8d5e91375d0527 (patch)
treed192ae91d040d4f441bd593787faf7701d97acae /2004
parenta489a86584e82b33821aa2b7287af145e36f4f83 (diff)
Plein de trucs.
Diffstat (limited to '2004')
-rw-r--r--2004/i/nono/src/io/Makefile.defs10
-rw-r--r--2004/i/nono/src/io/analog.cc51
-rw-r--r--2004/i/nono/src/io/analog.h46
-rw-r--r--2004/i/nono/src/io/analog_cmd.cc52
-rw-r--r--2004/i/nono/src/io/analog_cmd.h35
-rw-r--r--2004/i/nono/src/io/analog_servo_pp.cc74
-rw-r--r--2004/i/nono/src/io/analog_servo_pp.h52
-rw-r--r--2004/i/nono/src/io/gpio.cc9
-rw-r--r--2004/i/nono/src/io/gpio.h6
-rw-r--r--2004/i/nono/src/io/gpio_asserv.cc28
-rw-r--r--2004/i/nono/src/io/gpio_asserv.h11
-rw-r--r--2004/i/nono/src/io/gpio_cmd.cc (renamed from 2004/i/nono/src/io/io_cmd.cc)75
-rw-r--r--2004/i/nono/src/io/gpio_cmd.h (renamed from 2004/i/nono/src/io/io_cmd.h)12
-rw-r--r--2004/i/nono/src/io/gpio_concat.cc8
-rw-r--r--2004/i/nono/src/io/gpio_concat.h2
-rw-r--r--2004/i/nono/src/io/gpio_param.cc126
-rw-r--r--2004/i/nono/src/io/gpio_param.h60
-rw-r--r--2004/i/nono/src/io/gpio_servo_pp.cc83
-rw-r--r--2004/i/nono/src/io/gpio_servo_pp.h15
-rw-r--r--2004/i/nono/src/io/test_gpio_concat.cc8
-rw-r--r--2004/i/nono/src/io/test_io.cc43
21 files changed, 751 insertions, 55 deletions
diff --git a/2004/i/nono/src/io/Makefile.defs b/2004/i/nono/src/io/Makefile.defs
index efc1ad0..e6cf1fa 100644
--- a/2004/i/nono/src/io/Makefile.defs
+++ b/2004/i/nono/src/io/Makefile.defs
@@ -1,9 +1,11 @@
TARGETS += test_io test_gpio_concat
LIBS += io.a
-test_io_SOURCES = test_io.cc io_cmd.cc servo_cmd.cc io.a date.a serial.a \
- motor.a logger.a utils.a config.a
-test_gpio_concat_SOURCES = test_gpio_concat.cc io_cmd.cc io.a date.a serial.a
-io_a_SOURCES = gpio.cc gpio_servo_pp.cc gpio_concat.cc gpio_asserv.cc
+test_io_SOURCES = test_io.cc gpio_cmd.cc servo_cmd.cc analog_cmd.cc io.a \
+ date.a serial.a motor.a logger.a utils.a config.a
+test_gpio_concat_SOURCES = test_gpio_concat.cc gpio_cmd.cc io.a date.a \
+ serial.a
+io_a_SOURCES = gpio.cc gpio_servo_pp.cc gpio_concat.cc gpio_asserv.cc \
+ gpio_param.cc analog.cc analog_servo_pp.cc
test_io: $(test_io_SOURCES:%.cc=%.o)
diff --git a/2004/i/nono/src/io/analog.cc b/2004/i/nono/src/io/analog.cc
new file mode 100644
index 0000000..1d7d9bd
--- /dev/null
+++ b/2004/i/nono/src/io/analog.cc
@@ -0,0 +1,51 @@
+// analog.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "analog.h"
+
+/// Destructeur.
+Analog::~Analog (void)
+{
+}
+
+/// Met à jour.
+void
+Analog::update (void)
+{
+}
+
+/// Récupère le nombre d'entrées analogiques.
+int
+Analog::getNb (void) const
+{
+ return 0;
+}
+
+/// Récupère une entrée par son nom.
+int
+Analog::getByName (const std::string &name) const
+{
+ return -1;
+}
+
diff --git a/2004/i/nono/src/io/analog.h b/2004/i/nono/src/io/analog.h
new file mode 100644
index 0000000..5537239
--- /dev/null
+++ b/2004/i/nono/src/io/analog.h
@@ -0,0 +1,46 @@
+#ifndef analog_h
+#define analog_h
+// analog.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 <string>
+
+/// Classe d'un capteur analogique.
+class Analog
+{
+ public:
+ /// Destructeur.
+ virtual ~Analog (void);
+ /// Récupère la valeur linéarisée du capteur n.
+ virtual double get (int n) = 0;
+ /// Met à jour.
+ virtual void update (void);
+ /// Récupère le nombre d'entrées analogiques.
+ virtual int getNb (void) const;
+ /// Récupère une entrée par son nom.
+ virtual int getByName (const std::string &name) const;
+};
+
+#endif // analog_h
diff --git a/2004/i/nono/src/io/analog_cmd.cc b/2004/i/nono/src/io/analog_cmd.cc
new file mode 100644
index 0000000..6dd5ba9
--- /dev/null
+++ b/2004/i/nono/src/io/analog_cmd.cc
@@ -0,0 +1,52 @@
+// analog_cmd.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "analog_cmd.h"
+#include "analog.h"
+
+#include <iostream>
+#include <cstdlib>
+
+const char analogHelp[] =
+ " a <name/n> lit l'entrée analogique n\n";
+
+bool
+analogCmd (int argc, char **argv, int &i, Analog &analog)
+{
+ switch (argv[i][0])
+ {
+ case 'a':
+ i++;
+ int n;
+ n = analog.getByName (argv[i]);
+ if (n == -1)
+ n = atoi (argv[i]);
+ std::cout << "test: ana " << analog.get (n) << std::endl;
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
diff --git a/2004/i/nono/src/io/analog_cmd.h b/2004/i/nono/src/io/analog_cmd.h
new file mode 100644
index 0000000..267fda7
--- /dev/null
+++ b/2004/i/nono/src/io/analog_cmd.h
@@ -0,0 +1,35 @@
+#ifndef analog_cmd_h
+#define analog_cmd_h
+// analog_cmd.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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.
+//
+// }}}
+
+class Analog;
+
+extern const char analogHelp[];
+
+bool
+analogCmd (int argc, char **argv, int &i, Analog &analog);
+
+#endif // analog_cmd_h
diff --git a/2004/i/nono/src/io/analog_servo_pp.cc b/2004/i/nono/src/io/analog_servo_pp.cc
new file mode 100644
index 0000000..804830c
--- /dev/null
+++ b/2004/i/nono/src/io/analog_servo_pp.cc
@@ -0,0 +1,74 @@
+// analog_servo_pp.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "analog_servo_pp.h"
+#include "config/config.h"
+
+/// Constructeur.
+AnalogServoPp::AnalogServoPp (GpioServoPp &gspp)
+ : gspp_ (gspp)
+{
+ Config rc ("rc/analog_servo_pp");
+ while (!rc.eof ())
+ {
+ double d;
+ rc >> d;
+ linear_.push_back (d);
+ }
+ // Construit la table des noms.
+ names_["ana0"] = 0;
+ names_["ana1"] = 1;
+ names_["ana2"] = 2;
+ names_["ana3"] = 3;
+}
+
+/// Récupère la valeur linéarisée du capteur n.
+double
+AnalogServoPp::get (int n)
+{
+ int i = gspp_.getAna (n);
+ if (i >= 0 && i < static_cast<int> (linear_.size ()))
+ return linear_[i];
+ else
+ return 0.0;
+}
+
+/// Récupère le nombre d'entrées analogiques.
+int
+AnalogServoPp::getNb (void) const
+{
+ return gspp_.getNbAna ();
+}
+
+/// Récupère une entrée par son nom.
+int
+AnalogServoPp::getByName (const std::string &name) const
+{
+ Names::const_iterator i = names_.find (name);
+ if (i != names_.end ())
+ return i->second;
+ else
+ return -1;
+}
+
diff --git a/2004/i/nono/src/io/analog_servo_pp.h b/2004/i/nono/src/io/analog_servo_pp.h
new file mode 100644
index 0000000..94d357c
--- /dev/null
+++ b/2004/i/nono/src/io/analog_servo_pp.h
@@ -0,0 +1,52 @@
+#ifndef analog_servo_pp_h
+#define analog_servo_pp_h
+// analog_servo_pp.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "analog.h"
+#include "gpio_servo_pp.h"
+
+#include <map>
+#include <vector>
+
+/// Capteurs analogiques
+class AnalogServoPp : public Analog
+{
+ GpioServoPp &gspp_;
+ std::vector<int> linear_;
+ // Nom des E/S.
+ typedef std::map<std::string, int> Names;
+ Names names_;
+ public:
+ /// Constructeur.
+ AnalogServoPp (GpioServoPp &gspp);
+ /// Récupère la valeur linéarisée du capteur n.
+ double get (int n);
+ /// Récupère le nombre d'entrées analogiques.
+ int getNb (void) const;
+ /// Récupère une entrée par son nom.
+ int getByName (const std::string &name) const;
+};
+
+#endif // analog_servo_pp_h
diff --git a/2004/i/nono/src/io/gpio.cc b/2004/i/nono/src/io/gpio.cc
index 4b23450..dd97fa8 100644
--- a/2004/i/nono/src/io/gpio.cc
+++ b/2004/i/nono/src/io/gpio.cc
@@ -77,8 +77,15 @@ Gpio::update (void)
/// Récupère le nombre d'entrées/sorties.
int
-Gpio::getNbIo (void)
+Gpio::getNbIo (void) const
{
return 0;
}
+/// Récupère une entrée/sortie par son nom.
+int
+Gpio::getByName (const std::string &name) const
+{
+ return -1;
+}
+
diff --git a/2004/i/nono/src/io/gpio.h b/2004/i/nono/src/io/gpio.h
index 65a5a64..aaf32e4 100644
--- a/2004/i/nono/src/io/gpio.h
+++ b/2004/i/nono/src/io/gpio.h
@@ -25,6 +25,8 @@
//
// }}}
+#include <string>
+
/// General Purpose Input/Output.
class Gpio
{
@@ -52,7 +54,9 @@ class Gpio
/// Met à jour.
virtual void update (void);
/// Récupère le nombre d'entrées/sorties.
- virtual int getNbIo (void);
+ virtual int getNbIo (void) const;
+ /// Récupère une entrée/sortie par son nom.
+ virtual int getByName (const std::string &name) const;
};
#endif // gpio_h
diff --git a/2004/i/nono/src/io/gpio_asserv.cc b/2004/i/nono/src/io/gpio_asserv.cc
index de2256d..0438001 100644
--- a/2004/i/nono/src/io/gpio_asserv.cc
+++ b/2004/i/nono/src/io/gpio_asserv.cc
@@ -32,6 +32,17 @@ GpioAsserv::GpioAsserv (Asserv &asserv)
: outputs_ (0), asserv_ (asserv)
{
asserv_.setGpiDelay (3);
+ names_["b1"] = 1;
+ names_["b2"] = 2;
+ names_["b3"] = 3;
+ names_["b5"] = 5;
+ names_["b6"] = 6;
+ names_["d2"] = 2 + nbOutputs_;
+ names_["d3"] = 3 + nbOutputs_;
+ names_["d4"] = 4 + nbOutputs_;
+ names_["d5"] = 5 + nbOutputs_;
+ names_["d6"] = 6 + nbOutputs_;
+ names_["d7"] = 7 + nbOutputs_;
}
/// Destructeur.
@@ -50,8 +61,7 @@ GpioAsserv::set (int n, unsigned int bits, int nb)
mask <<= n;
bits <<= n;
outputs_ = (outputs_ & ~mask) | (bits & mask);
- unsigned int toSend = (outputs_ & 0x07) << 1 | (outputs_ & 0x18) << 2;
- asserv_.sendGpo (toSend);
+ asserv_.sendGpo (outputs_);
}
/// Lit plusieurs entrées.
@@ -60,9 +70,8 @@ GpioAsserv::get (int n, int nb)
{
if (n < nbOutputs_ || n + nb > nbOutputs_ + nbInputs_)
throw std::out_of_range ("GpioServoPp::get: Out of range.");
- unsigned int mask = 1 << (nb) - 1;
+ unsigned int mask = (1 << nb) - 1;
unsigned int recv = asserv_.getGpi ();
- recv = recv >> 2;
unsigned int bits = (recv >> (n - nbOutputs_)) & mask;
return bits;
}
@@ -74,3 +83,14 @@ GpioAsserv::getNbIo (void)
return nbOutputs_ + nbInputs_;
}
+/// Récupère une entrée/sortie par son nom.
+int
+GpioAsserv::getByName (const std::string &name) const
+{
+ Names::const_iterator i = names_.find (name);
+ if (i != names_.end ())
+ return i->second;
+ else
+ return -1;
+}
+
diff --git a/2004/i/nono/src/io/gpio_asserv.h b/2004/i/nono/src/io/gpio_asserv.h
index 557b77e..b2967a6 100644
--- a/2004/i/nono/src/io/gpio_asserv.h
+++ b/2004/i/nono/src/io/gpio_asserv.h
@@ -26,17 +26,22 @@
// }}}
#include "gpio.h"
+#include <map>
+
class Asserv;
-/// Classe pour la gestion de la carte servo à Pierre Prot.
+/// Classe pour la gestion des gpio de la carte d'asservissement.
class GpioAsserv : public Gpio
{
/// Nombre d'entrées/sorties.
- static const int nbInputs_ = 6, nbOutputs_ = 5;
+ static const int nbInputs_ = 8, nbOutputs_ = 8;
/// Sorties courantes.
unsigned int outputs_;
/// Référence vers l'asserv.
Asserv &asserv_;
+ /// Nom des E/S.
+ typedef std::map<std::string, int> Names;
+ Names names_;
public:
/// Constructeur.
explicit GpioAsserv (Asserv &asserv);
@@ -48,6 +53,8 @@ class GpioAsserv : public Gpio
unsigned int get (int n, int nb);
/// Récupère le nombre d'entrées/sorties.
int getNbIo (void);
+ /// Récupère une entrée/sortie par son nom.
+ int getByName (const std::string &name) const;
};
#endif // gpio_asserv_h
diff --git a/2004/i/nono/src/io/io_cmd.cc b/2004/i/nono/src/io/gpio_cmd.cc
index d64928f..56ae7a2 100644
--- a/2004/i/nono/src/io/io_cmd.cc
+++ b/2004/i/nono/src/io/gpio_cmd.cc
@@ -1,4 +1,4 @@
-// io_cmd.cc
+// gpio_cmd.cc
// nono - programme du robot 2004. {{{
//
// Copyright (C) 2004 Nicolas Schodet
@@ -22,44 +22,95 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// }}}
-#include "io_cmd.h"
+#include "gpio_cmd.h"
#include "gpio.h"
+#include "date/date.h"
#include <iostream>
#include <cstdlib>
-const char ioHelp[] =
- " o <n> <bits> <nb> set des sorties.\n"
- " i <n> <nb> get des entrées.\n"
+const char gpioHelp[] =
+ " o <n/name> <bit> set une sortie.\n"
+ " i <n/name> get une entrée.\n"
+ " j <n/name> <bit> attend que l'entrée passe à bit.\n"
+ " O <n> <bits> <nb> set des sorties.\n"
+ " I <n> <nb> get des entrées.\n"
" d <n> <bits> <nb> dir des entrées/sorties.\n";
bool
-ioCmd (int argc, char **argv, int &i, Gpio &io)
+gpioCmd (int argc, char **argv, int &i, Gpio &gpio)
{
- int n, bits, nb;
+ static bool inJack = false;
+ int n, nb;
+ unsigned bits, bit;
switch (argv[i][0])
{
case 'o':
i++;
if (i >= argc) break;
+ n = gpio.getByName (argv[i]);
+ if (n == -1)
+ n = atoi (argv[i]);
+ i++;
+ if (i >= argc) break;
+ bit = atoi (argv[i++]);
+ std::cout << "test: set " << n << ' ' << bit << std::endl;
+ gpio.set (n, bit);
+ break;
+ case 'O':
+ i++;
+ if (i >= argc) break;
n = atoi (argv[i++]);
if (i >= argc) break;
bits = atoi (argv[i++]);
if (i >= argc) break;
nb = atoi (argv[i++]);
- std::cout << "test: set " << n << ' ' << std::hex << bits <<
+ std::cout << "test: set " << n << " 0x" << std::hex << bits <<
std::dec << ' ' << nb << std::endl;
- io.set (n, bits, nb);
+ gpio.set (n, bits, nb);
break;
case 'i':
i++;
if (i >= argc) break;
+ n = gpio.getByName (argv[i]);
+ if (n == -1)
+ n = atoi (argv[i]);
+ i++;
+ std::cout << "test: get " << n << std::endl;
+ bit = gpio.get (n);
+ std::cout << "test: get result " << bit << std::endl;
+ break;
+ case 'j':
+ i++;
+ if (i >= argc) break;
+ n = gpio.getByName (argv[i]);
+ if (n == -1)
+ n = atoi (argv[i]);
+ i++;
+ if (i >= argc) break;
+ bit = atoi (argv[i++]);
+ if (!inJack)
+ std::cout << "test: jack " << n << ' ' << bit << std::endl;
+ if (gpio.get (n) != bit)
+ {
+ i -= 3;
+ inJack = true;
+ Date::wait (50);
+ }
+ else
+ {
+ inJack = false;
+ }
+ break;
+ case 'I':
+ i++;
+ if (i >= argc) break;
n = atoi (argv[i++]);
if (i >= argc) break;
nb = atoi (argv[i++]);
std::cout << "test: get " << n << ' ' << nb << std::endl;
- bits = io.get (n, nb);
- std::cout << "test: get result " << std::hex << bits <<
+ bits = gpio.get (n, nb);
+ std::cout << "test: get result 0x" << std::hex << bits <<
std::dec << std::endl;
break;
case 'd':
@@ -72,7 +123,7 @@ ioCmd (int argc, char **argv, int &i, Gpio &io)
nb = atoi (argv[i++]);
std::cout << "test: dir " << n << ' ' << std::hex << bits <<
std::dec << ' ' << nb << std::endl;
- io.dir (n, bits, nb);
+ gpio.dir (n, bits, nb);
break;
default:
return false;
diff --git a/2004/i/nono/src/io/io_cmd.h b/2004/i/nono/src/io/gpio_cmd.h
index a7d6e8a..e992f0c 100644
--- a/2004/i/nono/src/io/io_cmd.h
+++ b/2004/i/nono/src/io/gpio_cmd.h
@@ -1,6 +1,6 @@
-#ifndef io_cmd_h
-#define io_cmd_h
-// io_cmd.h
+#ifndef gpio_cmd_h
+#define gpio_cmd_h
+// gpio_cmd.h
// nono - programme du robot 2004. {{{
//
// Copyright (C) 2004 Nicolas Schodet
@@ -27,9 +27,9 @@
class Gpio;
-extern const char ioHelp[];
+extern const char gpioHelp[];
bool
-ioCmd (int argc, char **argv, int &i, Gpio &io);
+gpioCmd (int argc, char **argv, int &i, Gpio &gpio);
-#endif // io_cmd_h
+#endif // gpio_cmd_h
diff --git a/2004/i/nono/src/io/gpio_concat.cc b/2004/i/nono/src/io/gpio_concat.cc
index 646a524..7a35b50 100644
--- a/2004/i/nono/src/io/gpio_concat.cc
+++ b/2004/i/nono/src/io/gpio_concat.cc
@@ -115,3 +115,11 @@ GpioConcat::getNbIo (void)
return io0_.getNbIo () + io1_.getNbIo ();
}
+/// Récupère une entrée/sortie par son nom.
+int
+GpioConcat::getByName (const std::string &name) const
+{
+ int n = io0_.getByName (name);
+ return n == -1 ? io1_.getByName (name) : n;
+}
+
diff --git a/2004/i/nono/src/io/gpio_concat.h b/2004/i/nono/src/io/gpio_concat.h
index 73bab01..9b72628 100644
--- a/2004/i/nono/src/io/gpio_concat.h
+++ b/2004/i/nono/src/io/gpio_concat.h
@@ -44,6 +44,8 @@ class GpioConcat : public Gpio
void update (void);
/// Récupère le nombre d'entrées/sorties.
int getNbIo (void);
+ /// Récupère une entrée/sortie par son nom.
+ int getByName (const std::string &name) const;
};
#endif // gpio_concat_h
diff --git a/2004/i/nono/src/io/gpio_param.cc b/2004/i/nono/src/io/gpio_param.cc
new file mode 100644
index 0000000..0b6b024
--- /dev/null
+++ b/2004/i/nono/src/io/gpio_param.cc
@@ -0,0 +1,126 @@
+// gpio_param.cc
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "gpio_param.h"
+#include "config/config.h"
+
+/// Constructeur.
+GpioParam::GpioParam (Gpio &gpio)
+ : gpio_ (gpio)
+{
+ Config rc ("rc/gpio");
+ std::string name, io;
+ int n;
+ while (!rc.eof ())
+ {
+ if (rc.isId ("io"))
+ {
+ rc.getId ();
+ rc.getId (name);
+ if (rc.isId ())
+ {
+ rc.getId (io);
+ n = gpio.getByName (io);
+ if (n == -1)
+ throw std::runtime_error
+ (std::string ("gpio param: no io named ") + io);
+ }
+ else
+ {
+ rc >> n;
+ }
+ names_[name] = n;
+ }
+ else
+ rc.noId ();
+ }
+}
+
+/// Change plusieurs sorties.
+void
+GpioParam::set (int n, unsigned int bits, int nb)
+{
+ gpio_.set (n, bits, nb);
+}
+
+/// Change une sortie.
+void
+GpioParam::set (int n, unsigned int bit)
+{
+ gpio_.set (n, bit);
+}
+
+/// Lit plusieurs entrées.
+unsigned int
+GpioParam::get (int n, int nb)
+{
+ return gpio_.get (n, nb);
+}
+
+/// Lit une entrée.
+unsigned int
+GpioParam::get (int n)
+{
+ return gpio_.get (n);
+}
+
+/// Change la direction de plusieurs I/O.
+void
+GpioParam::dir (int n, unsigned int bits, int nb)
+{
+ gpio_.dir (n, bits, nb);
+}
+
+/// Change la direction d'un I/O (1 pour I, 0 pour O).
+void
+GpioParam::dir (int n, unsigned int bit)
+{
+ gpio_.dir (n, bit);
+}
+
+/// Met à jour.
+void
+GpioParam::update (void)
+{
+ gpio_.update ();
+}
+
+/// Récupère le nombre d'entrées/sorties.
+int
+GpioParam::getNbIo (void) const
+{
+ return gpio_.getNbIo ();
+}
+
+/// Récupère une entrée/sortie par son nom.
+int
+GpioParam::getByName (const std::string &name) const
+{
+ Names::const_iterator i = names_.find (name);
+ if (i != names_.end ())
+ return i->second;
+ else
+ return gpio_.getByName (name);
+}
+
diff --git a/2004/i/nono/src/io/gpio_param.h b/2004/i/nono/src/io/gpio_param.h
new file mode 100644
index 0000000..3a85cca
--- /dev/null
+++ b/2004/i/nono/src/io/gpio_param.h
@@ -0,0 +1,60 @@
+#ifndef gpio_param_h
+#define gpio_param_h
+// gpio_param.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// 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 "gpio.h"
+
+#include <map>
+
+/// Classe de paramétrage E/S.
+class GpioParam : public Gpio
+{
+ typedef std::map<std::string, int> Names;
+ Names names_;
+ Gpio &gpio_;
+ public:
+ /// Constructeur.
+ GpioParam (Gpio &gpio);
+ /// Change plusieurs sorties.
+ virtual void set (int n, unsigned int bits, int nb);
+ /// Change une sortie.
+ virtual void set (int n, unsigned int bit);
+ /// Lit plusieurs entrées.
+ virtual unsigned int get (int n, int nb);
+ /// Lit une entrée.
+ virtual unsigned int get (int n);
+ /// Change la direction de plusieurs I/O.
+ virtual void dir (int n, unsigned int bits, int nb);
+ /// Change la direction d'un I/O (1 pour I, 0 pour O).
+ virtual void dir (int n, unsigned int bit);
+ /// Met à jour.
+ virtual void update (void);
+ /// Récupère le nombre d'entrées/sorties.
+ virtual int getNbIo (void) const;
+ /// Récupère une entrée/sortie par son nom.
+ virtual int getByName (const std::string &name) const;
+};
+
+#endif // gpio_param_h
diff --git a/2004/i/nono/src/io/gpio_servo_pp.cc b/2004/i/nono/src/io/gpio_servo_pp.cc
index 5edab20..c249c7b 100644
--- a/2004/i/nono/src/io/gpio_servo_pp.cc
+++ b/2004/i/nono/src/io/gpio_servo_pp.cc
@@ -31,7 +31,7 @@
/// Constructeur.
GpioServoPp::GpioServoPp (void)
: outputs_ (0), inputs_ (0),
- serial_ (true), ttyspeed_ (0),
+ ttyspeed_ (0),
log_ ("io", "pp")
{
Config rc ("rc/gpio_servo_pp");
@@ -43,9 +43,25 @@ GpioServoPp::GpioServoPp (void)
))
rc.noId ();
}
+ // Ouvre le port série.
serial_.open (ttyname_, ttyspeed_);
for (int i = 0; i < nbServo_; ++i)
servoPos_[i] = 0;
+ // Construit la table des noms.
+ names_["o0"] = 0;
+ names_["o1"] = 1;
+ names_["o2"] = 2;
+ names_["o3"] = 3;
+ names_["o4"] = 4;
+ names_["o5"] = 5;
+ names_["i0"] = 6;
+ names_["i1"] = 7;
+ names_["i2"] = 8;
+ names_["i3"] = 9;
+ names_["i4"] = 10;
+ names_["i5"] = 11;
+ names_["i6"] = 12;
+ names_["i7"] = 13;
}
/// Destructeur.
@@ -63,7 +79,7 @@ GpioServoPp::set (int n, unsigned int bits, int nb)
bits <<= n;
outputs_ = (outputs_ & ~mask) | (bits & mask) | 0x80;
serial_.putchar (outputs_);
- log_ (Log::debug) << "send " << std::hex << outputs_ << std::dec <<
+ log_ (Log::debug) << "send 0x" << std::hex << outputs_ << std::dec <<
std::endl;
}
@@ -73,7 +89,7 @@ GpioServoPp::get (int n, int nb)
{
if (n < nbOutputs_ || n + nb > nbOutputs_ + nbInputs_)
throw std::out_of_range ("GpioServoPp::get: Out of range.");
- unsigned int mask = 1 << (nb) - 1;
+ unsigned int mask = (1 << nb) - 1;
unsigned int bits = (inputs_ >> (n - nbOutputs_)) & mask;
return bits;
}
@@ -84,9 +100,9 @@ GpioServoPp::move (int n, int diff)
{
n %= nbServo_;
servoPos_[n] += diff;
- int v = n << 7 | servoPos_[n];
+ int v = n << 6 | servoPos_[n];
serial_.putchar (v);
- log_ (Log::debug) << "send " << std::hex << v << std::dec << std::endl;
+ log_ (Log::debug) << "send 0x" << std::hex << v << std::dec << std::endl;
}
/// Bouge un servo en position POS.
@@ -95,9 +111,9 @@ GpioServoPp::moveTo (int n, int pos)
{
n %= nbServo_;
servoPos_[n] = pos;
- int v = n << 7 | servoPos_[n];
+ int v = n << 6 | servoPos_[n];
serial_.putchar (v);
- log_ (Log::debug) << "send " << std::hex << v << std::dec << std::endl;
+ log_ (Log::debug) << "send 0x" << std::hex << v << std::dec << std::endl;
}
/// Met à jour.
@@ -107,15 +123,35 @@ GpioServoPp::update (void)
int c;
while ((c = serial_.getchar ()) != -1)
{
- log_ (Log::debug) << "recv " << std::hex << c << std::dec <<
+ log_ (Log::verydebug) << "recv 0x" << std::hex << c << std::dec <<
std::endl;
- switch (inputs_ & 0x0f)
+ switch (c & 0x0f)
{
case 0x0:
- inputs_ |= c >> 4;
+ inputs_ = (inputs_ & 0x0f) | (c & 0xf0);
+ log_ (Log::debug) << "comp " << (c >> 4) << std::endl;
break;
case 0x7:
- inputs_ |= c & 0xf0;
+ inputs_ = (inputs_ & 0xf0) | (c >> 4);
+ log_ (Log::debug) << "digi " << (c >> 4) << std::endl;
+ break;
+ case 0x1:
+ case 0x2:
+ case 0x3:
+ case 0x4:
+ case 0x9:
+ case 0xa:
+ case 0xb:
+ case 0xc:
+ {
+ int n = (c & 0x07) - 1;
+ anaInput_[n] = c >> 3;
+ log_ (Log::debug) << "ana " << n << ' ' << (c >> 3) <<
+ std::endl;
+ break;
+ }
+ default:
+ log_ (Log::debug) << "other";
break;
}
}
@@ -128,3 +164,28 @@ GpioServoPp::getNbIo (void)
return nbOutputs_ + nbInputs_;
}
+/// Récupère une entrée/sortie par son nom.
+int
+GpioServoPp::getByName (const std::string &name) const
+{
+ Names::const_iterator i = names_.find (name);
+ if (i != names_.end ())
+ return i->second;
+ else
+ return -1;
+}
+
+/// Récupère la valeure d'une entrée analogique.
+unsigned int
+GpioServoPp::getAna (int n)
+{
+ return anaInput_[n];
+}
+
+/// Récupère le nombre d'entrées analogiques.
+int
+GpioServoPp::getNbAna (void) const
+{
+ return nbAnaInputs_;
+}
+
diff --git a/2004/i/nono/src/io/gpio_servo_pp.h b/2004/i/nono/src/io/gpio_servo_pp.h
index f5ee63a..5e4a601 100644
--- a/2004/i/nono/src/io/gpio_servo_pp.h
+++ b/2004/i/nono/src/io/gpio_servo_pp.h
@@ -29,17 +29,19 @@
#include "serial/serial.h"
#include "logger/log.h"
-#include <string>
+#include <map>
/// Classe pour la gestion de la carte servo à Pierre Prot.
class GpioServoPp : public Gpio, public Servo
{
/// Nombre d'entrées/sorties.
- static const int nbInputs_ = 6, nbOutputs_ = 6, nbServo_ = 2;
+ static const int nbInputs_ = 8, nbOutputs_ = 6,
+ nbServo_ = 2, nbAnaInputs_ = 4;
/// Sorties courantes.
unsigned int outputs_;
/// Dernière valeurs d'entrées.
unsigned int inputs_;
+ unsigned int anaInput_[4];
/// Position des servos.
int servoPos_[nbServo_];
// Ligne série.
@@ -48,6 +50,9 @@ class GpioServoPp : public Gpio, public Servo
int ttyspeed_;
// Logger.
Log log_;
+ // Nom des E/S.
+ typedef std::map<std::string, int> Names;
+ Names names_;
public:
/// Constructeur.
GpioServoPp (void);
@@ -65,6 +70,12 @@ class GpioServoPp : public Gpio, public Servo
void update (void);
/// Récupère le nombre d'entrées/sorties.
int getNbIo (void);
+ /// Récupère une entrée/sortie par son nom.
+ int getByName (const std::string &name) const;
+ /// Récupère la valeure d'une entrée analogique.
+ unsigned int getAna (int n);
+ /// Récupère le nombre d'entrées analogiques.
+ int getNbAna (void) const;
};
#endif // gpio_servo_pp_h
diff --git a/2004/i/nono/src/io/test_gpio_concat.cc b/2004/i/nono/src/io/test_gpio_concat.cc
index a6ec722..7afb151 100644
--- a/2004/i/nono/src/io/test_gpio_concat.cc
+++ b/2004/i/nono/src/io/test_gpio_concat.cc
@@ -23,7 +23,7 @@
//
// }}}
#include "gpio_concat.h"
-#include "io_cmd.h"
+#include "gpio_cmd.h"
#include <string>
#include <iostream>
@@ -65,8 +65,8 @@ void
syntax (void)
{
std::cout <<
- "test_io - teste les entrées/sorties.\n"
- << ioHelp <<
+ "test_gpio_concat - teste l'aglomérateur d'E/S.\n"
+ << gpioHelp <<
" ? cet ecran d'aide" << std::endl;
}
@@ -80,7 +80,7 @@ main (int argc, char **argv)
int i = 1;
while (i < argc)
{
- if (!ioCmd (argc, argv, i, cc))
+ if (!gpioCmd (argc, argv, i, cc))
{
switch (argv[i][0])
{
diff --git a/2004/i/nono/src/io/test_io.cc b/2004/i/nono/src/io/test_io.cc
index 999549e..dd13c94 100644
--- a/2004/i/nono/src/io/test_io.cc
+++ b/2004/i/nono/src/io/test_io.cc
@@ -22,14 +22,17 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// }}}
-#include "gpio_servo_pp.h"
+#include "analog_servo_pp.h"
+#include "analog_cmd.h"
+#include "date/date.h"
#include "gpio_asserv.h"
+#include "gpio_cmd.h"
#include "gpio_concat.h"
-#include "servo.h"
-#include "date/date.h"
+#include "gpio_servo_pp.h"
+#include "gpio_param.h"
#include "motor/asserv.h"
-#include "io_cmd.h"
#include "servo_cmd.h"
+#include "servo.h"
#include <exception>
#include <iostream>
@@ -39,7 +42,8 @@ syntax (void)
{
std::cout <<
"test_io - teste les entrées/sorties.\n"
- << ioHelp << servoHelp <<
+ << gpioHelp << servoHelp << analogHelp <<
+ " f lit les entrées et affiche\n"
" <timeout> attend\n"
" ? cet ecran d'aide" << std::endl;
}
@@ -53,19 +57,35 @@ main (int argc, char **argv)
Asserv a (at);
a.reset ();
GpioServoPp gspp;
+ AnalogServoPp ana (gspp);
GpioAsserv ga (a);
GpioConcat gc (ga, gspp, ga.getNbIo ());
+ GpioParam gp (gc);
int i = 1;
while (i < argc)
{
- if (!ioCmd (argc, argv, i, gc)
- && !servoCmd (argc, argv, i, gspp))
+ if (!gpioCmd (argc, argv, i, gp)
+ && !servoCmd (argc, argv, i, gspp)
+ && !analogCmd (argc, argv, i, ana))
{
switch (argv[i][0])
{
case '?':
syntax ();
return 0;
+ case 'f':
+ i++;
+ while (1)
+ {
+ a.ok ();
+ gspp.update ();
+ Date::wait (50);
+ std::cout << "test: flood " << gspp.get (6, 8)
+ << ' ' << ana.get (0) << ' '
+ << ana.get (1) << ' ' << ana.get (2)
+ << ' ' << ana.get (3) << std::endl;
+ }
+ break;
default:
int s;
s = atoi (argv[i++]);
@@ -75,7 +95,14 @@ main (int argc, char **argv)
return 1;
}
std::cout << "test: sleep " << s << std::endl;
- Date::wait (s * 1000);
+ int start;
+ start = Date::getInstance ().start ();
+ while (Date::getInstance ().start () < start + s)
+ {
+ a.ok ();
+ gspp.update ();
+ Date::wait (50);
+ }
break;
}
}