From a0a5169f762f760d7d50597625d47ea557c0d7a4 Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 19 Mar 2006 23:52:41 +0000 Subject: Ajout d'un outils de mesure. --- n/asserv/src/asserv/main.c | 2 + n/asserv/utils/graph/Makefile | 6 ++ n/asserv/utils/graph/Makefile.defs | 4 + n/asserv/utils/graph/asserv_graph.cc | 138 +++++++++++++++++++++++++++++++++++ n/asserv/utils/graph/rc/config | 12 +++ 5 files changed, 162 insertions(+) create mode 100644 n/asserv/utils/graph/Makefile create mode 100644 n/asserv/utils/graph/Makefile.defs create mode 100644 n/asserv/utils/graph/asserv_graph.cc create mode 100644 n/asserv/utils/graph/rc/config diff --git a/n/asserv/src/asserv/main.c b/n/asserv/src/asserv/main.c index b32f2b1..866d784 100644 --- a/n/asserv/src/asserv/main.c +++ b/n/asserv/src/asserv/main.c @@ -180,7 +180,9 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) pos_reset (); main_mode = 0; pwm_left = v8_to_v16 (args[0], args[1]); + UTILS_BOUND (pwm_left, -PWM_MAX, PWM_MAX); pwm_right = v8_to_v16 (args[2], args[3]); + UTILS_BOUND (pwm_right, -PWM_MAX, PWM_MAX); break; case c ('c', 4): /* Add to position consign. diff --git a/n/asserv/utils/graph/Makefile b/n/asserv/utils/graph/Makefile new file mode 100644 index 0000000..b4feaed --- /dev/null +++ b/n/asserv/utils/graph/Makefile @@ -0,0 +1,6 @@ +SRCDIR = ../../../../i/marvin/src +EXTRA_SUBDIRS = . + +local-all: asserv_graph + +include $(SRCDIR)/Makefile.defs diff --git a/n/asserv/utils/graph/Makefile.defs b/n/asserv/utils/graph/Makefile.defs new file mode 100644 index 0000000..a159e7b --- /dev/null +++ b/n/asserv/utils/graph/Makefile.defs @@ -0,0 +1,4 @@ +PROGRAMS += asserv_graph + +asserv_graph_OBJECTS = asserv_graph.o $(proto_OBJECTS) $(log_OBJECTS) \ + $(serial_OBJECTS) $(utils_OBJECTS) $(timer_OBJECTS) diff --git a/n/asserv/utils/graph/asserv_graph.cc b/n/asserv/utils/graph/asserv_graph.cc new file mode 100644 index 0000000..a3760e6 --- /dev/null +++ b/n/asserv/utils/graph/asserv_graph.cc @@ -0,0 +1,138 @@ +// asserv_graph.cc +// {{{ +// +// Copyright (C) 2006 Nicolas Schodet +// +// Robot APB Team/Efrei 2006. +// 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 "proto/proto.hh" +#include "timer/timer.hh" +#include "config/config.hh" + +#include +#include + +/// Classe de connexion à Proto. +class AsservGraph : public Proto::Receiver +{ + Proto proto_; + int tkp, tki, tkd; + int akp, aki, akd; + int es, is; + int te, ti, ae, ai; + int pl, pr; + int n; + public: + AsservGraph (void) + : proto_ (*this), + te (0), ti (0), ae (0), ai (0), + n (0) + { + Config &config = Config::getInstance (); + tkp = config.get ("asserv.tkp"); + tki = config.get ("asserv.tkd"); + tkd = config.get ("asserv.tki"); + akp = config.get ("asserv.akp"); + aki = config.get ("asserv.akd"); + akd = config.get ("asserv.aki"); + es = config.get ("asserv.esat"); + is = config.get ("asserv.isat"); + proto_.open (config.get ("asserv.tty")); + init (); + } + ~AsservGraph (void) + { + proto_.send ('z'); + } + void init (void) + { + proto_.send ('z'); + proto_.send ('p', "bww", 'p', tkp, akp); + proto_.send ('p', "bww", 'i', tki, aki); + proto_.send ('p', "bww", 'd', tkd, akd); + proto_.send ('p', "bw", 'E', es); + proto_.send ('p', "bw", 'I', is); + proto_.send ('P', "b", 1); + proto_.send ('W', "b", 1); + } + void receive (char command, const Proto::Frame &frame) + { + switch (command) + { + case 'P': + proto_.decode (frame, "WWWW", te, ti, ae, ai); + break; + case 'W': + if (proto_.decode (frame, "WW", pl, pr)) + { + std::cout << te << ' ' << ti << ' ' << ae << ' ' << ai << ' ' + << pl << ' ' << pr << std::endl; + te = ti = ae = ai = 0; + n++; + } + break; + } + } + void main (void) + { + proto_.send ('w', "ww", 0x3ff, 0x3ff); + for (n = 0; n < 100;) + proto_.wait (-1); + proto_.send ('w'); + for (n = 0; n < 100;) + proto_.wait (-1); + proto_.send ('c', "ww", 16, 0); + for (n = 0; n < 100;) + proto_.wait (-1); + proto_.send ('w'); + } +}; + +/// Affiche un memo de syntaxe. +void +syntax (void) +{ + std::cout << "asserv_graph - graphe des variables de l'asservissement.\n" + "Syntaxe : asserv_graph\n" + " ? affiche cet écran d'aide\n" + << std::endl; +} + +int +main (int argc, char **argv) +{ + try + { + if (argc != 1) + { + syntax (); + return 1; + } + Config config (argc, argv); + AsservGraph asservGraph; + asservGraph.main (); + } + catch (const std::exception &e) + { + std::cerr << e.what () << std::endl; + return 1; + } + return 0; +} diff --git a/n/asserv/utils/graph/rc/config b/n/asserv/utils/graph/rc/config new file mode 100644 index 0000000..e110c54 --- /dev/null +++ b/n/asserv/utils/graph/rc/config @@ -0,0 +1,12 @@ +asserv.tty = "../../src/asserv/uart0.pts" + +asserv.tkp = 700 +asserv.tki = 20 +asserv.tkd = 0 + +asserv.akp = 0 +asserv.aki = 0 +asserv.akd = 0 + +asserv.esat = 4095 +asserv.isat = 400 -- cgit v1.2.3