player/worlds/my_code/xswarming.h

00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 #include <libplayerc++/playerc++.h>
00005 
00006 using namespace PlayerCc;
00007 
00011 class Robot
00012 {
00013 public:
00014 
00015         
00016         int m_ID;
00017         char m_name[16];
00018         
00019         Robot(int mID);
00020         ~Robot(void){}; //declared as empty function.
00024         void            ReadSensors(void);   
00025         void            LogPosition(FILE *fp);
00026         
00027 protected:
00030         
00031         /*
00032         have to declare as pointers because it doesn't like constructing the objects
00033         without input arguements.
00034         */
00035         PlayerClient    *m_robot;
00036         Position2dProxy *m_posProx;
00037         SimulationProxy *m_simProx;
00040 };
00041 
00042 
00047 Robot::Robot(int ID)
00048 {
00049         //initialises some member variables
00050         m_ID = ID-1;    
00051         sprintf(m_name, "robot%d", ID);
00053         
00062         //initialise player related member variables
00063         m_robot = new PlayerClient("localhost", 6665);
00064         
00065         m_posProx = new Position2dProxy(m_robot, m_ID);
00066         m_simProx = new SimulationProxy(m_robot, 0);
00067                 
00068         //do some initialising player stuff.
00069         //it's a pointer so we can't access its functions with the . operator
00070         m_posProx->SetMotorEnable(1);
00071         m_posProx->RequestGeom();
00072         m_robot->Read();
00073         return;
00074 }


00112 
00116 void Robot::ReadSensors(void)
00117 {
00119         m_robot->Read();
00120         return;
00121 }
00122 
00123 
00130 void Robot::LogPosition(FILE *fp)
00131 {
00132         double x, y, yaw;
00133         
00137         m_simProx->GetPose2d(m_name, x, y, yaw);
00138         fprintf(fp, "'%s', %f, %f, %f\n", m_name, x, y, yaw);
00139         fflush(fp);
00145 }
00146 


Generated on Fri May 29 12:51:25 2009 for xswarm by  doxygen 1.5.5