sip.hpp
Go to the documentation of this file.
00001 /*
00002  *  P2OS for ROS
00003  *  Copyright (C) 2009  David Feil-Seifer, Brian Gerkey, Kasper Stoy,
00004  *      Richard Vaughan, & Andrew Howard
00005  *  Copyright (C) 2018  Hunter L. Allen
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 #ifndef P2OS_DRIVER__SIP_HPP_
00023 #define P2OS_DRIVER__SIP_HPP_
00024 #include <p2os_driver/p2os.hpp>
00025 
00026 #include <climits>
00027 #include <cstdint>
00028 #include <string>
00029 
00030 typedef struct ArmJoint
00031 {
00032   char speed;
00033   unsigned char home;
00034   unsigned char min;
00035   unsigned char centre;
00036   unsigned char max;
00037   unsigned char ticksPer90;
00038 } ArmJoint;
00039 
00040 enum PlayerGripperStates
00041 {
00042   PLAYER_GRIPPER_STATE_OPEN = 1,
00043   PLAYER_GRIPPER_STATE_CLOSED,
00044   PLAYER_GRIPPER_STATE_MOVING,
00045   PLAYER_GRIPPER_STATE_ERROR
00046 };
00047 
00048 enum PlayerActArrayStates
00049 {
00050   PLAYER_ACTARRAY_ACTSTATE_IDLE = 1,
00051   PLAYER_ACTARRAY_ACTSTATE_MOVING,
00052   PLAYER_ACTARRAY_ACTSTATE_STALLED
00053 };
00054 
00055 class SIP
00056 {
00057 private:
00058   int PositionChange(uint16_t, uint16_t);
00059   int param_idx;   // index of our robot's data in the parameter table
00060 
00061 public:
00062   // these values are returned in every standard SIP
00063   bool lwstall, rwstall;
00064   unsigned char motors_enabled, sonar_flag;
00065   unsigned char status, battery, sonarreadings, analog, digin, digout;
00066   uint16_t ptu, compass, timer, rawxpos;
00067   uint16_t rawypos, frontbumpers, rearbumpers;
00068   int16_t angle, lvel, rvel, control;
00069   uint16_t * sonars;
00070   int xpos, ypos;
00071   int x_offset, y_offset, angle_offset;
00072   std::string odom_frame_id;
00073   std::string base_link_frame_id;
00074 
00075   // these values are returned in a CMUcam serial string extended SIP
00076   // (in host byte-order)
00077   uint16_t blobmx, blobmy;  // Centroid
00078   uint16_t blobx1, blobx2, bloby1, bloby2;  // Bounding box
00079   uint16_t blobarea, blobconf;  // Area and confidence
00080   unsigned int blobcolor;
00081 
00082   // This value is filled by ParseGyro()
00083   int32_t gyro_rate;
00084 
00085   // This information comes from the ARMpac and ARMINFOpac packets
00086   bool armPowerOn, armConnected;
00087   bool armJointMoving[6];
00088   unsigned char armJointPos[6];
00089   double armJointPosRads[6];
00090   unsigned char armJointTargetPos[6];
00091   char * armVersionString;
00092   unsigned char armNumJoints;
00093   ArmJoint * armJoints;
00094 
00095   // Need this value to calculate approx position of lift when in between up
00096   // and down
00097   double lastLiftPos;
00098 
00099   // Timestamping SIP packets
00100   // double timeStandardSIP, timeGyro, timeSERAUX, timeArm;
00101 
00102   /* returns 0 if Parsed correctly otherwise 1 */
00103   void ParseStandard(unsigned char * buffer);
00104   void ParseSERAUX(unsigned char * buffer);
00105   void ParseGyro(unsigned char * buffer);
00106   void ParseArm(unsigned char * buffer);
00107   void ParseArmInfo(unsigned char * buffer);
00108   void Print();
00109   void PrintSonars();
00110   void PrintArm();
00111   void PrintArmInfo();
00112   void FillStandard(ros_p2os_data_t * data);
00113   // void FillSERAUX(player_p2os_data_t* data);
00114   // void FillGyro(player_p2os_data_t* data);
00115   // void FillArm(player_p2os_data_t* data);
00116 
00117   explicit SIP(int idx)
00118   : param_idx(idx), sonarreadings(0), sonars(NULL),
00119     xpos(0), ypos(0), x_offset(0), y_offset(0), angle_offset(0),
00120     blobmx(0), blobmy(0), blobx1(0), blobx2(0), bloby1(0), bloby2(0),
00121     blobarea(0), blobconf(0), blobcolor(0),
00122     armPowerOn(false), armConnected(false), armVersionString(NULL),
00123     armNumJoints(0), armJoints(NULL),
00124     lastLiftPos(0.0f)
00125   {
00126     for (int i = 0; i < 6; ++i) {
00127       armJointMoving[i] = false;
00128       armJointPos[i] = 0;
00129       armJointPosRads[i] = 0;
00130       armJointTargetPos[i] = 0;
00131     }
00132   }
00133 
00134   ~SIP()
00135   {
00136     delete[] sonars;
00137   }
00138 };
00139 
00140 #endif  // P2OS_DRIVER__SIP_HPP_


p2os_driver
Author(s): Hunter L. Allen , David Feil-Seifer , Aris Synodinos , Brian Gerkey, Kasper Stoy, Richard Vaughan, Andrew Howard, Tucker Hermans, ActivMedia Robotics LLC, MobileRobots Inc.
autogenerated on Wed Mar 27 2019 02:34:57