RemKhepServerROS.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00029
00030 #ifndef __REM_KHEP_SERVER_ROS_H_
00031 #define __REM_KHEP_SERVER_ROS_H_
00032
00033
00034 #include <IPCommModule.h>
00035 #include <CommonOptions.h>
00036 #include <remKhepComm.h>
00037 #include <MotionModule.h>
00038 #include <KorebotROS.h>
00039
00040
00041 #include <ROSNode.h>
00042 #include <sensor_msgs/LaserScan.h>
00043 #ifdef ROS_ELECTRIC
00044 #include <gazebo/Joint.hh>
00045 #endif
00046
00047 #ifdef ROS_FUERTE
00048 #include <physics/Joint.hh>
00049 #endif
00050
00051 #include <ros/ros.h>
00052
00053
00054 #include <boost/bind.hpp>
00055
00056
00057
00058
00059 #define SAMPLE_TIME_USEC 30000
00060 #define WAIT_TIME_USEC 1000
00061
00062
00063 #define KHS_COMM_DEBUG 0
00064 #define KHS_DEBUG 0
00065 #define KHS_EXECUTE_DEBUG 0
00066
00067 using namespace std;
00068
00069
00070 #define KH3_DEBUG(debLevel,_staticLevel,message) \
00071 { \
00072 if(debLevel <= _staticLevel) { \
00073 stringstream KH3_DEBUG_ss; \
00074 KH3_DEBUG_ss << "\033[01;31m" << "[KH3DEBUG] " << "\033[0m" << message; \
00075 std::cout << KH3_DEBUG_ss.str() << std::endl; \
00076 } \
00077 }
00078
00079 namespace MipResources{
00080 enum{
00081 RIGHT,
00082 LEFT,
00083 NUM_WHEELS
00084 };
00085
00086 enum CommRateTypes {
00087 FIXED,
00088 VARIABLE,
00089 NUM_COMM_RATE_TYPES
00090 };
00091
00092 struct laserScanStr{
00093 MipBaselib::Time _time;
00094 vector<Decimal> _ranges;
00095 };
00096
00100 class KheperaServerROSOptions : public Options{
00101 public:
00102 IntOption* urg04lxActive;
00103 IntOption* korebotActive;
00104 StringOption* commRateType;
00105
00106
00107 StringOption* laserTopicName;
00108
00109 StringOption* kh3TopicName;
00110
00111 StringOption* kh3NodeName;
00112
00113 string getObjectName() const{
00114 return "KheperaServerROSOptions";
00115 }
00116
00117 KheperaServerROSOptions();
00118 };
00119
00123 class KheperaServerROSPars{
00124 private:
00125
00126 string _robotName;
00127
00128 int _debugLevel;
00129
00130 int _urg04lxActive;
00131
00132 string _laserTopicName;
00133
00134 string _topicName;
00135
00136 string _nodeName;
00137
00138 GAZEBO_JOINT_PTR _joints[2];
00139
00140 Decimal _wheelSep;
00141
00142 Decimal _wheelDiam;
00143
00144 string _intMethodOdo;
00145
00146 string _commType;
00147
00148 Decimal _torqueMax;
00149
00150 Decimal _encRes;
00151
00152 public:
00154 KheperaServerROSPars();
00155
00157 KheperaServerROSPars(const string &robotName, const int &debugLevel, const int &urgAct, const string <n, const string &tn, const string& nn, const string &imo, GAZEBO_JOINT_PTR jtr, GAZEBO_JOINT_PTR jtl, const Decimal &ws, const Decimal &wd, const string &ct, const Decimal &tm, const Decimal &er);
00158
00160 KheperaServerROSPars(const KheperaServerROSPars &A);
00161
00163 KheperaServerROSPars operator= (KheperaServerROSPars A);
00164
00167 string getRobotName() const;
00168
00171 int getDebugLevel() const;
00172
00175 int getUrg04lxActive() const;
00176
00179 string getLaserTopicName() const;
00180
00183 string getTopicName() const;
00184
00187 string getNodeName() const;
00188
00191 GAZEBO_JOINT_PTR getLeftWheel();
00192
00195 GAZEBO_JOINT_PTR getRightWheel();
00196
00199 Decimal getWheelSeparation() const;
00200
00203 Decimal getWheelDiameter() const;
00204
00207 string getIntMethodOdo() const;
00208
00211 string getCommunicationType() const;
00212
00215 Decimal getMaxTorque() const;
00216
00219 Decimal getEncoderResolution() const;
00220 };
00221
00222
00226 class KheperaServerROS : public MIPObject{
00227
00228 private:
00229
00230
00231 static const int ticksToErase = 44;
00232
00233
00234 KorebotROS* _korebot;
00235
00236 KheperaServerROSOptions* _options;
00237
00238 bool _newTState;
00239 bool _newVelocity;
00240 Decimal _driveToBeSet;
00241 Decimal _turnrateToBeSet;
00242 MotionModuleTState _motionModuleTStateToBeSet;
00243 MotionModuleTState _lastMotionModuleTState;
00244
00245
00246 string _robotName;
00247 int _debugLevel;
00248 int _urg04lxActive;
00249 GAZEBO_JOINT_PTR _leftJoint;
00250 GAZEBO_JOINT_PTR _rightJoint;
00251
00252
00253 ros::Subscriber _subscriberURG04LXmm;
00254
00255 laserScanStr _laserScan;
00256
00257
00258 ROSNode* _rosNode;
00259
00260 int topicSpecifier;
00261
00262
00263 deque<string> _incomingPackets;
00264 vector<string> _outcomingPackets;
00265
00266 char _stateBuffer[70];
00267 int _stateBufferCounter;
00268 int _numSentState;
00269 SimTimer _execCmdsTimer;
00270
00271
00272 char _laserBuffer[5048];
00273 int _laserBufferCounter;
00274 int _numSentScan;
00275
00276 CommRateTypes _commRateType;
00277
00278 pthread_mutex_t _laserMutex;
00279
00280 string getObjectName() const {
00281 return "KheperaServerROS";
00282 }
00283
00284
00285 void laserCallback(const sensor_msgs::LaserScan::ConstPtr& msg);
00286
00287 public:
00288
00292 KheperaServerROS(int argc, const char* argv[]);
00293
00295 KheperaServerROS(KheperaServerROSPars * khPars);
00296
00298 ~KheperaServerROS();
00299
00301 bool searchConnection();
00302
00304 void receiveCommands();
00305
00308 int parseCommands();
00309
00311 void executeCommands();
00312
00315 ROSNode* getRosNode();
00316
00319 KorebotROS* getKorebot();
00320
00324 void getVelocityCommand(Decimal &xVel, Decimal &omega);
00325
00328 void getTStateCommand(MotionModuleTState &state);
00329
00331 void lockLaserMutex();
00332
00334 void unlockLaserMutex();
00335 };
00336
00337 }
00338
00339 #endif