urbimirror.cc

00001 #include "urbi/uclient.hh"
00002 #include <signal.h>
00003 
00004 urbi::UClient *d;
00005 
00006 const char * devices[]=
00007 {
00008   "legLF1",
00009   "legLF2",
00010   "legLF3",
00011   "legLH1",
00012   "legLH2",
00013   "legLH3",
00014   "legRH1",
00015   "legRH2",
00016   "legRH3",
00017   "legRF1",
00018   "legRF2",
00019   "legRF3",
00020   "neck",
00021   "headPan",
00022   "headTilt",
00023   "tailTilt",
00024   "tailPan",
00025   "mouth"
00026 };
00027 
00028 int devCount = sizeof (devices) / sizeof (*devices);
00029 
00030 urbi::UCallbackAction
00031 command(const urbi::UMessage &msg)
00032 {
00033   //get command id
00034   if (msg.type != urbi::MESSAGE_DATA
00035       || msg.value->type != urbi::DATA_DOUBLE)
00036     return urbi::URBI_CONTINUE;
00037   d->send("%s.val = %lf,", msg.tag.c_str (), (double) *msg.value);
00038   return urbi::URBI_CONTINUE;
00039 }
00040 
00041 void endRecord(int)
00042 {
00043   urbi::exit(0);
00044 }
00045 
00046 int main(int argc, char * argv[])
00047 {
00048   if (argc != 3)
00049     {
00050       printf("usage: %s sourcerobot destinationrobot [motorstate]\n"
00051              "\t Mirror the movements of one robot to the other.\n",
00052              argv[0]);
00053       urbi::exit(1);
00054     }
00055 
00056   signal(SIGINT,endRecord);
00057 
00058   urbi::UClient c(argv[1]);
00059   if (c.error())
00060     urbi::exit(2);
00061 
00062   d = new urbi::UClient(argv[2]);
00063   if (d->error())
00064     urbi::exit(2);
00065 
00066   int motorstate=0;
00067 
00068   // FIXME: impossible.
00069   if (argc>=4)
00070     motorstate=strtol(argv[3],NULL,0);
00071 
00072   if (!motorstate)
00073     c.send("motoroff;");
00074 
00075   d->send("motoron;");
00076 
00077   c.send("looptag: loop {");
00078   for (int i=0;i<devCount-1; ++i)
00079     {
00080       c.setCallback(command,devices[i]);
00081       c.send("%s: %s.val&",devices[i], devices[i]);
00082     }
00083 
00084   c.setCallback(command,devices[devCount-1]);
00085   c.send("%s: %s.val},",devices[devCount-1], devices[devCount-1]);
00086 
00087   urbi::execute();
00088 }

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