urbiwalk.cc

00001 #include "urbi/usyncclient.hh"
00002 #include "move.hh"
00003 
00004 
00005 int
00006 main (int argc, char * argv[])
00007 {
00008   if (argc<2)
00009     {
00010       printf("usage: %s robotname [initialize] [configfile]\n"
00011              "\tSet initialize to 0 to skip upload of command files.(needed the first time, and each time changes are made to the configuration\n"
00012              "\tThen send commands to stdin with the syntax 'w[alk] value_in_meters relativePrecision' or 't[urn] value_in_degrees relativePrecision'\n",argv[0]);
00013       exit(1);
00014     }
00015 
00016   urbi::USyncClient cl(argv[1]);
00017   cl.start();
00018   if (cl.error())
00019     exit(2);
00020   urbi::Move mv;
00021   char * config;
00022   bool init=true;
00023   if (argc>2 && argv[2][0]=='0')
00024     init=false;
00025   if (argc>3)
00026     config=argv[3];
00027   else
00028     config="moveset/moveconfig";
00029   cl.send("motoron;");
00030   if (init)
00031     printf("Uploading elementary movement commands, this may take a few seconds...\n");
00032   if (mv.initialize(&cl,init,config))
00033     exit(1);
00034   double useless;
00035   cl.syncGetDevice("neck",useless);
00036   if (init)
00037     printf("Done.\n");
00038   printf("Ready to accept commands\n");
00039 
00040   while (1)
00041     {
00042       char line[1024];
00043       fgets(line,1024,stdin);
00044       char cmd[64];
00045       float val,prec;
00046       int arg=sscanf(line,"%s%f%f",cmd,&val,&prec);
00047       if (arg<2)
00048         continue;
00049       if (arg<3)
00050         prec=0.2;
00051       if (cmd[0]=='w')
00052         mv.walk(val,prec);
00053       else
00054         mv.turn(val,prec);
00055       printf(cmd[0]=='w'?"walked %f meters(%f)\n":"turned %f degrees (%f)\n",
00056              val,prec);
00057     }
00058 }

Generated on Tue Apr 10 17:45:45 2007 for URBISDK by  doxygen 1.5.1