runCtrl.h

Go to the documentation of this file.
00001 #ifndef RUN_CTRL_H
00002 #define RUN_CTRL_H
00003 
00013 #include "runInterface.h"
00014 #include "ticksCtrlInterface.h"
00015 #include "connectionDevice.h"
00016 #include "structTables.h"
00017 #include "nodeAccess.h"
00018 #include "timeUtils.h"
00019 #include <list>
00020 
00021 
00025 class RunCtrl : public ObjCoordinateCtrl, public RunInterface,
00026                 public TicksCtrlInterface {
00027   friend class PacketHandleHostTest;
00028   friend class tRunCtrl_Simulator;
00029   friend class MonitorTask;
00030 
00031 protected:
00032   enum {
00033     SimulatorPort = 49754,
00034   };
00035 
00039   enum Default {
00040     Baudrate = 115200,          
00041     StraightVel = 300,          
00042     StraightAcc = 600,          
00043     RotateVel = 0x10000 >> 1,   
00044     RotateAcc = 0x10000 >> 1,   
00045     FollowRadius = 500,         
00046   };
00047 
00048 private:
00049   ConnectionDevice* con;
00050   nodeInfo_t* node;
00051   long unique_id;
00052   bool crd_auto;
00053   nodeInfo_t nodeResource;
00054 
00055 protected:
00056   VXV::Position local_offset;   
00058 private:
00059   std::string error_message;
00060 
00061   typedef struct {
00062     int straight_ref_vel;
00063     int straight_ref_acc;
00064     long rotate_ref_vel;
00065     long rotate_ref_acc;
00066     int follow_r;
00067   } runParams_t;
00068 
00069   enum { SEND_COMMAND_SIZE = 256 };
00070   typedef struct {
00071     VXV::Position position;
00072     const CoordinateCtrl* crd;
00073     int send_command_size;
00074     char send_command[SEND_COMMAND_SIZE];
00075   } runCommand_t;
00076 
00077   typedef struct {
00078     runParams_t params;
00079     runCommand_t command;
00080   } runState_t;
00081 
00082   std::list<runState_t> state_stack;
00083 
00084   unsigned long pre_module_msec;
00085   unsigned long total_msec;
00086   ticksInfo_t ticksInfoObj;
00087   ticksInfo_t& getTicksInfo(void) {
00088     return ticksInfoObj;
00089   }
00090   void beginTimeAdjust(void);
00091   void endTimeAdjust(void);
00092   unsigned long getModuleRawTicks(void);
00093 
00094   void initRunParams(void);
00095   void printHelp(void);
00096   void printVersion(void);
00097   bool parseArgs(int* ret_value, int argc, char *argv[]);
00098   int checkVersion(void);
00099   void crdNortify(int state, const CoordinateCtrl* crd);
00100   const VXV::Position getRunCmdPos(const CoordinateCtrl* crd,
00101                                    const VXV::Position& position);
00102   void sendUpdatedPosition(const CoordinateCtrl* crd,
00103                            const VXV::Position& position);
00104   unsigned long updateTicksDiff(unsigned long ticks);
00105   RunCtrl(const RunCtrl& rhs);
00106 
00107 #include "commandCtrl.h"
00108 
00109 protected:
00110   runCtrl_t* tbl;               
00111   runCtrl_t tblResource;
00112 
00122   int to_div16(const VXV::Direction& t);
00123 
00136   virtual int raw_connect(ConnectionDevice* conObj,
00137                           const char* device, long baudrate);
00138 
00142   virtual unsigned long getHostTicks(void);
00143 
00147   virtual void initTicksInfo(void);
00148 
00149 public:
00150   enum {
00151     LineOver = +1, LineNotOver = -1,
00152     DefaultTimeout = -1,
00153   };
00154   CoordinateCtrl& FS;           
00160   RunCtrl(void);
00161   virtual ~RunCtrl(void);
00162 
00163   const char* what(void);
00164 
00165   virtual int connect(int argc, char *argv[]);
00166 
00167   virtual int connect(const char* device, long baudrate = Baudrate);
00168 
00203   virtual int connect(void);
00204 
00216   int connectSocket(const char* host, long port = SimulatorPort);
00217 
00218   virtual void disconnect(void);
00219 
00239   virtual bool isConnected(void);
00240 
00241   void push_runState(void);
00242   void pop_runState(void);
00243 
00244 
00252   void set_sendRetryTimes(int times);
00253 
00261   void set_recvTimeout(int timeout = DefaultTimeout);
00262 
00270   void set_watchDogTimer(unsigned long msec);
00271 
00280   virtual VXV::Position3D getLocalPosition(void);
00281   VXV::Position getRunPosition(const CoordinateCtrl* crd = VXV::GL);
00282   void adjustRunPosition(const VXV::Position& position,
00283                          const CoordinateCtrl* crd = VXV::GL);
00284   void coordinateUpdateDetect(bool on);
00285 
00293   virtual void stop(void);
00294   virtual void followLine(const VXV::Position& position,
00295                           const CoordinateCtrl* crd = VXV::GL);
00296   virtual void followCircle(const VXV::Grid& center, int radius,
00297                             const CoordinateCtrl* crd = VXV::GL);
00298   void followCircleOnTangent(const VXV::Position& position, int radius,
00299                              const CoordinateCtrl* crd = VXV::GL);
00300   virtual void stopToLine(const VXV::Position& position,
00301                           const CoordinateCtrl* crd = VXV::GL);
00302   virtual void rotateToDirection(const VXV::Direction& direction,
00303                                  const CoordinateCtrl* crd = VXV::GL);
00304 
00305   virtual void rotateAngle(const VXV::Direction& direction);
00306   virtual void spin(const VXV::Direction& velocity);
00307   virtual void lastMoveCommand(const CoordinateCtrl* crd = VXV::GL);
00308 
00317   virtual bool isStable(void);
00318   int getLengthToGrid(const VXV::Grid& grid,
00319                       const CoordinateCtrl* crd = VXV::GL);
00320   int getLengthToBody(const VXV::Grid& grid,
00321                       const CoordinateCtrl* crd = VXV::GL);
00322   int getLengthToLine(const VXV::Position& line,
00323                       const CoordinateCtrl* crd = VXV::GL);
00324   VXV::Direction getAngleToDirection(const VXV::Direction& t,
00325                                      const CoordinateCtrl* crd = VXV::GL);
00326   int getStraightVelDiff(int mm_vel = 0);
00327   VXV::Direction getRotateVelDiff(const VXV::Direction& t = VXV::Direction());
00328 
00337   void setStraightRefVel(int mm_sec);
00338   void setStraightRefAcc(int mm_acc);
00339   void setRotateRefVel(const VXV::Direction& rotate_vel);
00340   void setRotateRefAcc(const VXV::Direction& rotate_acc);
00341   void setCurveRadius(int mm);
00342   int getStraightVel(void);
00343   VXV::Direction getRotateVel(void);
00344   int getCurveRadius(void);
00345 
00354   virtual void servoCtrl(bool on);
00355 
00364   void setMotorPwm(int id, unsigned char duty);
00365 
00373   void setMotorPwm(int id, unsigned char duty[], int num);
00374 
00385   void setMotorMode(int id, unsigned char mode);
00386 
00394   void setMotorMode(int id, unsigned char mode[], int num);
00395 
00404   void getEncoderVel(int id, int *cnt);
00405 
00413   void getEncoderVel(int id, int cnt[], int num);
00414 
00425   void getEncoderValue(int id, unsigned short *cnt);
00426 
00434   void getEncoderValue(int id, unsigned short cnt[], int num);
00435 
00444   void setWheelVel(int id, int mm_vel);
00445 
00453   void setWheelVel(int id, int mm_vel[], int num);
00454 
00463   VXV::Position getNoResetRunPosition(void);
00464   int getBodyRotateCount(void);
00465   void getEncoderRotateCount(int id, int count[], int num = 1);
00466 
00468 };
00469 
00470 
00474 class RunCtrl_Exception : public std::exception {
00475   std::string error_message;
00476 
00477 public:
00478 
00487   RunCtrl_Exception(const char* message) throw () : error_message(message){}
00488   virtual ~RunCtrl_Exception(void) throw () {}
00489 
00511   virtual const char* what(void) const throw() {
00512     return error_message.c_str();
00513   }
00515 };
00516 
00517 #endif /* !RUN_CTRL_H */
00518 

Generated on Mon Apr 13 22:52:04 2009 by  doxygen 1.5.7.1