// 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; }