sip.h

00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2000
00004  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
00005  *
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 /*
00024  * $Id: sip.h,v 1.7.2.1 2007/04/24 22:20:20 gerkey Exp $
00025  *
00026  * part of the P2OS parser.  methods for filling and parsing server
00027  * information packets (SIPs)
00028  */
00029 #ifndef _SIP_H
00030 #define _SIP_H
00031 
00032 #include <limits.h>
00033 
00034 #include <p2os.h>
00035 
00036 typedef struct ArmJoint
00037 {
00038         char speed;
00039         unsigned char home;
00040         unsigned char min;
00041         unsigned char centre;
00042         unsigned char max;
00043         unsigned char ticksPer90;
00044 } ArmJoint;
00045 
00046 class SIP
00047 {
00048  private:
00049   int PositionChange( unsigned short, unsigned short );
00050   int param_idx; // index of our robot's data in the parameter table
00051 
00052  public:
00053   // these values are returned in every standard SIP
00054   bool lwstall, rwstall;
00055   unsigned char status, battery, sonarreadings, analog, digin, digout;
00056   unsigned short ptu, compass, timer, rawxpos;
00057   unsigned short rawypos, frontbumpers, rearbumpers;
00058   short angle, lvel, rvel, control;
00059   unsigned short sonars[PLAYER_SONAR_MAX_SAMPLES];
00060   int xpos, ypos;
00061   int x_offset,y_offset,angle_offset;
00062 
00063   // these values are returned in a CMUcam serial string extended SIP
00064   // (in host byte-order)
00065   unsigned short blobmx, blobmy;        // Centroid
00066   unsigned short blobx1, blobx2, bloby1, bloby2;        // Bounding box
00067   unsigned short blobarea, blobconf;    // Area and confidence
00068   unsigned int   blobcolor;
00069 
00070   // This value is filled by ParseGyro()
00071   int32_t gyro_rate;
00072 
00073   // This information comes from the ARMpac and ARMINFOpac packets
00074   bool armPowerOn, armConnected;
00075   bool armJointMoving[6];
00076   unsigned char armJointPos[6];
00077   double armJointPosRads[6];
00078   unsigned char armJointTargetPos[6];
00079   char *armVersionString;
00080   unsigned char armNumJoints;
00081   ArmJoint *armJoints;
00082 
00083   // Need this value to calculate approx position of lift when in between up and down
00084   double lastLiftPos;
00085 
00086   /* returns 0 if Parsed correctly otherwise 1 */
00087   void Parse( unsigned char *buffer );
00088   void ParseSERAUX( unsigned char *buffer );
00089   void ParseGyro(unsigned char* buffer);
00090   void ParseArm (unsigned char *buffer);
00091   void ParseArmInfo (unsigned char *buffer);
00092   void Print();
00093   void PrintSonars();
00094   void PrintArm ();
00095   void PrintArmInfo ();
00096   void Fill(player_p2os_data_t* data);
00097 
00098   SIP(int idx)
00099   {
00100     param_idx = idx;
00101     for(int i=0;i<ARRAYSIZE(sonars);i++)
00102       sonars[i] = 0;
00103 
00104     xpos = INT_MAX;
00105     ypos = INT_MAX;
00106 
00107     // intialise some of the internal values
00108     blobmx = blobmy = blobx1 = blobx2 = bloby1 = bloby2 = blobarea = blobconf = blobcolor = 0;
00109     armPowerOn = armConnected = false;
00110     armVersionString = NULL;
00111     armJoints = NULL;
00112     armNumJoints = 0;
00113     for (int i = 0; i < 6; ++i)
00114     {
00115       armJointMoving[i] = false;
00116       armJointPos[i] = 0;
00117       armJointPosRads[i] = 0;
00118       armJointTargetPos[i] = 0;
00119     }
00120   }
00121 };
00122 
00123 #endif

Last updated 12 September 2005 21:38:45