Fawkes API  Fawkes Development Version
dp_ptu.h
00001 
00002 /***************************************************************************
00003  *  dp_ptu.h - Controller for Directed Perception, Inc. Pan-Tilt Unit on B21
00004  *
00005  *  Created: Wed Nov 29 23:02:42 2006 (FireVision)
00006  *  Copyright  2005-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __PLUGINS_PANTILT_DIRPERC_DP_PTU_H_
00025 #define __PLUGINS_PANTILT_DIRPERC_DP_PTU_H_
00026 
00027 #define DPPTU_MAX_OBUFFER_SIZE  20
00028 #define DPPTU_MAX_IBUFFER_SIZE 255
00029 
00030 class DirectedPerceptionPTU
00031 {
00032 
00033  public:
00034   DirectedPerceptionPTU(const char *device_file, unsigned int timeout_ms = 10);
00035   virtual ~DirectedPerceptionPTU();
00036 
00037   // pan/tilt, radians
00038   virtual void set_pan_tilt_rad(float pan, float tilt);
00039   virtual void get_pan_tilt_rad(float &pan, float &tilt);
00040   virtual void get_limits(float &pan_min, float &pan_max,
00041                           float &tilt_min, float &tilt_max);
00042 
00043   virtual void reset();
00044   virtual void stop_motion();
00045 
00046   // ticks
00047   virtual void set_pan(int pan);
00048   virtual void set_tilt(int tilt);
00049   virtual void set_pan_tilt(int pan, int tilt);
00050   virtual int  get_pan();
00051   virtual int  get_tilt();
00052   virtual void get_pan_tilt(int &pan, int &tilt);
00053   virtual int  min_pan();
00054   virtual int  max_pan();
00055   virtual int  min_tilt();
00056   virtual int  max_tilt();
00057 
00058  private:
00059   void  open();
00060   void  close();
00061   void  send(const char *command, int value);
00062   void  send(const char *command);
00063   void  write(const char *buffer);
00064   bool  read(char *buffer, unsigned int buffer_size);
00065   bool  result_ok();
00066   bool  data_available();
00067   int   query_int(const char *query_command);
00068   int   pan_rad2ticks(float r);
00069   int   tilt_rad2ticks(float r);
00070   float pan_ticks2rad(int ticks);
00071   float tilt_ticks2rad(int ticks);
00072 
00073 
00074  private:
00075   // commands
00076   static const char * DPPTU_PAN_ABSPOS;
00077   static const char * DPPTU_TILT_ABSPOS;
00078   static const char * DPPTU_PAN_RELPOS;
00079   static const char * DPPTU_TILT_RELPOS;
00080   static const char * DPPTU_PAN_RESOLUTION;
00081   static const char * DPPTU_TILT_RESOLUTION;
00082   static const char * DPPTU_PAN_MIN;
00083   static const char * DPPTU_PAN_MAX;
00084   static const char * DPPTU_TILT_MIN;
00085   static const char * DPPTU_TILT_MAX;
00086   static const char * DPPTU_LIMITENFORCE_QUERY;
00087   static const char * DPPTU_LIMITENFORCE_ENABLE;
00088   static const char * DPPTU_LIMITENFORCE_DISABLE;
00089   static const char * DPPTU_IMMEDIATE_EXECUTION;
00090   static const char * DPPTU_SLAVED_EXECUTION;
00091   static const char * DPPTU_AWAIT_COMPLETION;
00092   static const char * DPPTU_HALT_ALL;
00093   static const char * DPPTU_HALT_PAN;
00094   static const char * DPPTU_HALT_TILT;
00095   static const char * DPPTU_PAN_SPEED;
00096   static const char * DPPTU_TILT_SPEED;
00097   static const char * DPPTU_PAN_ACCEL;
00098   static const char * DPPTU_TILT_ACCEL;
00099   static const char * DPPTU_PAN_BASESPEED;
00100   static const char * DPPTU_TILT_BASESPEED;
00101   static const char * DPPTU_PAN_UPPER_SPEED_LIMIT;
00102   static const char * DPPTU_PAN_LOWER_SPEED_LIMIT;
00103   static const char * DPPTU_TILT_UPPER_SPEED_LIMIT;
00104   static const char * DPPTU_TILT_LOWER_SPEED_LIMIT;
00105   static const char * DPPTU_RESET;
00106   static const char * DPPTU_STORE;
00107   static const char * DPPTU_RESTORE;
00108   static const char * DPPTU_FACTORY_RESET;
00109   static const char * DPPTU_ECHO_QUERY;
00110   static const char * DPPTU_ECHO_ENABLE;
00111   static const char * DPPTU_ECHO_DISABLE;
00112   static const char * DPPTU_ASCII_VERBOSE;
00113   static const char * DPPTU_ASCII_TERSE;
00114   static const char * DPPTU_ASCII_QUERY;
00115   static const char * DPPTU_VERSION;
00116 
00117   char         *__device_file;
00118   int           __fd;
00119   bool          __opened;
00120   unsigned int  __timeout_ms;
00121 
00122   char          __obuffer[DPPTU_MAX_OBUFFER_SIZE];
00123   char          __ibuffer[DPPTU_MAX_IBUFFER_SIZE];
00124 
00125   int           __pan_resolution;
00126   int           __tilt_resolution;
00127   int           __pan_upper_limit;
00128   int           __pan_lower_limit;
00129   int           __tilt_lower_limit;
00130   int           __tilt_upper_limit;
00131 
00132 };
00133 
00134 #endif