summaryrefslogtreecommitdiff
path: root/n/asserv/utils/graph/asserv_graph.cc
diff options
context:
space:
mode:
authorschodet2006-03-19 23:52:41 +0000
committerschodet2006-03-19 23:52:41 +0000
commita0a5169f762f760d7d50597625d47ea557c0d7a4 (patch)
tree4e96f5b1ad4586b6cdea2d9809782bcf184dad94 /n/asserv/utils/graph/asserv_graph.cc
parent98550a89a352a1656c01ab9e72d3406856bcddd0 (diff)
Ajout d'un outils de mesure.
Diffstat (limited to 'n/asserv/utils/graph/asserv_graph.cc')
-rw-r--r--n/asserv/utils/graph/asserv_graph.cc138
1 files changed, 138 insertions, 0 deletions
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 <iostream>
+#include <stdexcept>
+
+/// 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<int> ("asserv.tkp");
+ tki = config.get<int> ("asserv.tkd");
+ tkd = config.get<int> ("asserv.tki");
+ akp = config.get<int> ("asserv.akp");
+ aki = config.get<int> ("asserv.akd");
+ akd = config.get<int> ("asserv.aki");
+ es = config.get<int> ("asserv.esat");
+ is = config.get<int> ("asserv.isat");
+ proto_.open (config.get<std::string> ("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;
+}