summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/asserv/test_asserv.cc
diff options
context:
space:
mode:
authorhaller2005-04-17 02:32:07 +0000
committerhaller2005-04-17 02:32:07 +0000
commitdcb901c549f81eb8124458448ce40e305a98fd4d (patch)
tree4f313b99dcf91073f0c178a6dd48957c397b93a1 /2005/i/robert/src/asserv/test_asserv.cc
parentf0d97a476182f9f6fbe91cac516cf045d84f051e (diff)
Corrections de quelques erreurs de syntaxe
classe à tester avec un port série
Diffstat (limited to '2005/i/robert/src/asserv/test_asserv.cc')
-rw-r--r--2005/i/robert/src/asserv/test_asserv.cc433
1 files changed, 220 insertions, 213 deletions
diff --git a/2005/i/robert/src/asserv/test_asserv.cc b/2005/i/robert/src/asserv/test_asserv.cc
index d7c8964..54e5716 100644
--- a/2005/i/robert/src/asserv/test_asserv.cc
+++ b/2005/i/robert/src/asserv/test_asserv.cc
@@ -25,252 +25,259 @@
//
// }}}
+#include "asserv.hh"
+#include "config/config.hh"
+#include "timer/timer.hh"
+
+#include<stdexcept>
+#include<cstdlib>
+
/// Classe de test pour asserv.
class TestAsserv : public Asserv::Receiver
{
- void receiveCounter (double lMotor, double rMotor)
- {
- std::cout << "C:" << "lMotor:" << lMotor << " rMotor:" << rMotor << std::endl;
- }
- void receivePosX (double xPos)
- {
- std::cout << "X:" << "XPos:" << xPos << std::endl;
- }
- void receivePosY (double yPos)
- {
- std::cout << "Y:" << "yPos:" << yPos << std::endl;
- }
- void receivePosA (double aPos)
- {
- std::cout << "A:" << "aPos:" << aPos << std::endl;
- }
- void receiveMotor (int oldLSpeed_e, int LSpeed_int, int oldRSpeed_e, int RSpeed_int)
- {
- std::cout << "S:" << "oldLSpeed_e:" << oldLSpeed_e << "LSpeed_int:" <<
- LSpeed_int << "oldRSpeed_e:" << oldRSpeed_e <<
- "RSpeed_int:" << RSpeed_int << std::endl;
- }
- void receivePwm (double leftPwm, double rightPwm)
- {
- std::cout << "W:" << "leftPwm" << leftPwm << " rightPwm:" << rightPwm << std::endl;
- }
- void receiveTiming (double motorTimer5, double motorTimer4,
- double motorTimer3, double motorTimer2,
- double motorTimer1,
- double motorTimer0 )
- {
- std::cout << "T:" << "motorTimer5:" << motorTimer5 <<
- " motorTimer4:" << motorTimer4 << "motorTimer3:" <<
- motorTimer3 << "motorTimer2:" << motorTimer2 <<
- "motorTimer1:" << motorTimer1 << "motorTimer0:" <<
- motorTimer0 << std::endl;
- }
- void receiveInPort (double state)
- {
- std::cout << "P:" << "state:" << state << std::endl;
- }
- void jaifini (void)
- {
- std::cout << "F:" << "J'ai fini!!" << std::endl;
- }
+ void receiveCounter (double lMotor, double rMotor)
+ {
+ std::cout << "C:" << "lMotor:" << lMotor << " rMotor:" << rMotor << std::endl;
+ }
+ void receivePosX (double xPos)
+ {
+ std::cout << "X:" << "XPos:" << xPos << std::endl;
+ }
+ void receivePosY (double yPos)
+ {
+ std::cout << "Y:" << "yPos:" << yPos << std::endl;
+ }
+ void receivePosA (double aPos)
+ {
+ std::cout << "A:" << "aPos:" << aPos << std::endl;
+ }
+ void receiveMotor (int oldLSpeed_e, int LSpeed_int, int oldRSpeed_e, int RSpeed_int)
+ {
+ std::cout << "S:" << "oldLSpeed_e:" << oldLSpeed_e << "LSpeed_int:" <<
+ LSpeed_int << "oldRSpeed_e:" << oldRSpeed_e <<
+ "RSpeed_int:" << RSpeed_int << std::endl;
+ }
+ void receivePwm (double leftPwm, double rightPwm)
+ {
+ std::cout << "W:" << "leftPwm" << leftPwm << " rightPwm:" << rightPwm << std::endl;
+ }
+ void receiveTiming (double motorTimer5, double motorTimer4,
+ double motorTimer3, double motorTimer2,
+ double motorTimer1,
+ double motorTimer0 )
+ {
+ std::cout << "T:" << "motorTimer5:" << motorTimer5 <<
+ " motorTimer4:" << motorTimer4 << "motorTimer3:" <<
+ motorTimer3 << "motorTimer2:" << motorTimer2 <<
+ "motorTimer1:" << motorTimer1 << "motorTimer0:" <<
+ motorTimer0 << std::endl;
+ }
+ void receiveInPort (double state)
+ {
+ std::cout << "P:" << "state:" << state << std::endl;
+ }
+ void jaifini (void)
+ {
+ std::cout << "F:" << "J'ai fini!!" << std::endl;
+ }
};
/// Affiche un memo de suntaxe.
-void
+ void
syntax (void)
{
std::cout << "test_asserv - test la classe de protocol asserv.\n"
- "Syntaxe : test_asserv <config File> <...>\n"
+ "Syntaxe : test_asserv <...>\n"
" s <cmd> <args...> envois une commande\n"
" w <ms> attend pendant un nombre de millisecondes\n"
" ? affiche cet cran d'aide\n"
<< std::endl;
}
-int
+ int
main (int argc, char **argv)
{
try
- {
+ {
int i;
if (argc < 2)
- {
+ {
syntax ();
return 1;
- }
+ }
+ Config config(argc, argv);
TestAsserv testAsserv;
Asserv asserv(config, testAsserv);
- //proto.open (argv[1]);
- // XXX Charger la conf
- i = 2;
+ i = 1;
while (i < argc)
- {
+ {
switch (argv[i][0])
- {
- case 's':
- {
- switch(arg[++i][0])
- {
- case 'z':
- asserv.reset();
- break;
- case 'l':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.linearMove(strtod(argv[i], 0));
- break;
- case 'a':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.angularMove(strtod(argv[i], 0));
- break;
- case 'g':
- if(++i + 1 > argc)
- throw std::runtime_error("syntax error");
- asserv.goToPosition(strtod(argv[i], 0), strtod(argv[++i], 0));
- break;
- case 'f':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.fuckTheWall(strtod(argv[i], 0));
- break;
- case 's':
- if(++i + 1 > argc)
- throw std::runtime_error("syntax error");
- asserv.setSpeed(strtod(argv[i], 0), strtod(argv[++i], 0));
- break;
- case 'w':
- if(++i + 1 > argc)
- throw std::runtime_error("syntax error");
- asserv.setPwm(strtod(argv[i], 0), strtod(argv[++i], 0));
- break;
- case 'F':
- asserv.finishAck();
- break;
- case 'C':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.statCounter(strtod(argv[i], 0));
- break;
- case 'X':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.statPosition(strtod(argv[i], 0));
- break;
- case 'S':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.statMotor(strtod(argv[i], 0));
- break;
- case 'W':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.statPwm(strtod(argv[i], 0));
- break;
- case 'T':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.statTiming(strtod(argv[i], 0));
- break;
- case 'P':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.fuckTheWall(strtod(argv[i], 0));
- break;
- case 'p':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- switch(argv[i][0])
- {
- case 'x':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setXPos(strtod(argv[i], 0));
- break;
- case 'y':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setYPos(strtod(argv[i], 0));
- break;
- case 'a':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setAngle(strtod(argv[i], 0));
- break;
- case 'f':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setFooting(strtod(argv[i], 0));
- break;
- case 'e':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setEpsilon(strtod(argv[i], 0));
- break;
- case 'p':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setKp(strtod(argv[i], 0));
- break;
- case 'i':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setKi(strtod(argv[i], 0));
- break;
- case 'd':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setKd(strtod(argv[i], 0));
- break;
- case 'I':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setSpeedIntMax(strtoi(argv[i], 0));
- break;
- case 'a':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setAccel(strtod(argv[i], 0));
- break;
- case 'm':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- asserv.setMaxSpeed(strtod(argv[i], 0));
- break;
+ {
+ case 's':
+ {
+ switch(argv[++i][0])
+ {
+ case 'z':
+ asserv.reset();
+ break;
+ case 'l':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.linearMove(strtod(argv[i], 0));
+ break;
+ case 'a':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.angularMove(strtod(argv[i], 0));
+ break;
+ case 'g':
+ if(++i + 1 > argc)
+ throw std::runtime_error("syntax error");
+ asserv.goToPosition(strtod(argv[i], 0), strtod(argv[++i], 0));
+ break;
+ case 'f':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.fuckTheWall(strtod(argv[i], 0));
+ break;
+ case 's':
+ if(++i + 1 > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setSpeed(strtod(argv[i], 0), strtod(argv[++i], 0));
+ break;
+ case 'w':
+ if(++i + 1 > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setPwm(strtod(argv[i], 0), strtod(argv[++i], 0));
+ break;
+ case 'F':
+ asserv.finishAck();
+ break;
+ case 'C':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.statCounter(strtod(argv[i], 0));
+ break;
+ case 'X':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.statPosition(strtod(argv[i], 0));
+ break;
+ case 'S':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.statMotor(strtod(argv[i], 0));
+ break;
+ case 'W':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.statPwm(strtod(argv[i], 0));
+ break;
+ case 'T':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.statTiming(strtod(argv[i], 0));
+ break;
+ case 'P':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.fuckTheWall(strtod(argv[i], 0));
+ break;
+ case 'p':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ switch(argv[i][0])
+ {
+ case 'x':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setXPos(strtod(argv[i], 0));
+ break;
+ case 'y':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setYPos(strtod(argv[i], 0));
+ break;
+ case 'a':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setAngle(strtod(argv[i], 0));
+ break;
+ case 'f':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setFooting(strtol(argv[i], 0, 10));
+ break;
+ case 'e':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setEpsilon(strtod(argv[i], 0));
+ break;
+ case 'p':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setKp(strtod(argv[i], 0));
+ break;
+ case 'i':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setKi(strtod(argv[i], 0));
+ break;
+ case 'd':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setKd(strtod(argv[i], 0));
+ break;
+ case 'I':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setSpeedIntMax(strtol(argv[i], 0, 10));
+ break;
+ case 'A':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setAccel(strtod(argv[i], 0));
+ break;
+ case 'm':
+ if(++i > argc)
+ throw std::runtime_error("syntax error");
+ asserv.setMaxSpeed(strtod(argv[i], 0));
+ break;
+ }
+ }
- while (!asserv.wait (-1))
- ;
- }
- break;
- case 'w':
- {
- int stop, t;
- if (i + 1 >= argc)
- throw std::runtime_error ("syntax error");
- stop = atoi (argv[++i]) + Timer::getProgramTime ();
- t = Timer::getProgramTime ();
- while (t < stop)
- {
- asserv.wait (stop - t);
+ while (!asserv.wait (-1));
+ break;
+ }
+ case 'w':
+ {
+ int stop, t;
+ if (i + 1 >= argc)
+ throw std::runtime_error ("syntax error");
+ stop = atoi (argv[++i]) + Timer::getProgramTime ();
t = Timer::getProgramTime ();
- }
- break;
- }
- case '?':
- syntax ();
- return 0;
- default:
- throw std::runtime_error ("syntax error");
- }
+ while (t < stop)
+ {
+ asserv.wait (stop - t);
+ t = Timer::getProgramTime ();
+ }
+ break;
+ }
+ case '?':
+ syntax ();
+ return 0;
+ default:
+ throw std::runtime_error ("syntax error");
+ }
i++;
- }
- }
+ }
+ }
catch (const std::exception &e)
- {
+ {
std::cerr << e.what () << std::endl;
syntax ();
return 1;
- }
+ }
return 0;
}