Fawkes API  Fawkes Development Version
evid100p_thread.h
00001 
00002 /***************************************************************************
00003  *  evid100p_thread.h - Sony EviD100P pan/tilt unit act thread
00004  *
00005  *  Created: Sun Jun 21 12:30:59 2009
00006  *  Copyright  2006-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.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #ifndef __PLUGINS_PANTILT_SONY_EVID100P_THREAD_H_
00024 #define __PLUGINS_PANTILT_SONY_EVID100P_THREAD_H_
00025 
00026 #include "../act_thread.h"
00027 
00028 #include <blackboard/interface_listener.h>
00029 
00030 #ifdef USE_TIMETRACKER
00031 #  include <utils/time/tracker.h>
00032 #endif
00033 #include <string>
00034 #include <memory>
00035 
00036 namespace fawkes {
00037   class PanTiltInterface;
00038 }
00039 
00040 class SonyEviD100PVisca;
00041 
00042 class PanTiltSonyEviD100PThread
00043 : public PanTiltActThread,
00044   public fawkes::BlackBoardInterfaceListener
00045 {
00046  public:
00047   PanTiltSonyEviD100PThread(std::string &pantilt_cfg_prefix,
00048                             std::string &ptu_cfg_prefix,
00049                             std::string &ptu_name);
00050 
00051   virtual void init();
00052   virtual void finalize();
00053   virtual void loop();
00054 
00055   // For BlackBoardInterfaceListener
00056   virtual bool bb_interface_message_received(fawkes::Interface *interface,
00057                                              fawkes::Message *message) throw();
00058 
00059   void update_sensor_values();
00060 
00061  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00062  protected: virtual void run() { Thread::run(); }
00063 
00064  private:
00065   fawkes::PanTiltInterface *__pantilt_if;
00066 
00067   fawkes::RefPtr<SonyEviD100PVisca> __cam;
00068 
00069   std::string  __pantilt_cfg_prefix;
00070   std::string  __ptu_cfg_prefix;
00071   std::string  __ptu_name;
00072   std::string  __cfg_device;
00073   unsigned int __cfg_read_timeout_ms;
00074 
00075 
00076   class WorkerThread : public fawkes::Thread
00077   {
00078   public:
00079     WorkerThread(std::string ptu_name, fawkes::Logger *logger,
00080                  fawkes::RefPtr<SonyEviD100PVisca> cam,
00081                  const float &pan_min, const float &pan_max,
00082                  const float &tilt_min, const float &tilt_max);
00083 
00084     ~WorkerThread();
00085     void goto_pantilt(float pan, float tilt);
00086     void get_pantilt(float &pan, float &tilt);
00087     void set_velocities(float pan_vel, float tilt_vel);
00088     bool is_final();
00089     void stop_motion();
00090     bool has_fresh_data();
00091 
00092     virtual void once();
00093     virtual void loop();
00094 
00095   private:
00096     void exec_goto_pantilt(float pan, float tilt);
00097 
00098   private:
00099     fawkes::RefPtr<SonyEviD100PVisca>  __cam;
00100     fawkes::Logger        *__logger;
00101 
00102     float         __pan_min;
00103     float         __pan_max;
00104     float         __tilt_min;
00105     float         __tilt_max;
00106 
00107     fawkes::Mutex *__move_mutex;
00108     bool  __move_pending;
00109     float __target_pan;
00110     float __target_tilt;
00111     bool  __velo_pending;
00112     float __pan_vel;
00113     float __tilt_vel;
00114 
00115     float __cur_pan;
00116     float __cur_tilt;
00117 
00118     bool __fresh_data;
00119   };
00120 
00121   WorkerThread *__wt;
00122 };
00123 
00124 #endif