act_thread.h

00001 
00002 /***************************************************************************
00003  *  act_thread.h - Katana plugin act thread
00004  *
00005  *  Created: Mon Jun 08 17:59:57 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_KATANA_ACT_THREAD_H_
00024 #define __PLUGINS_KATANA_ACT_THREAD_H_
00025 
00026 #include "motion_thread.h"
00027 #include "calib_thread.h"
00028 #include "goto_thread.h"
00029 #include "gripper_thread.h"
00030 #include "sensacq_thread.h"
00031 
00032 #include <core/threading/thread.h>
00033 #include <aspect/blocked_timing.h>
00034 #include <aspect/logging.h>
00035 #include <aspect/configurable.h>
00036 #include <aspect/blackboard.h>
00037 #include <blackboard/interface_listener.h>
00038 #include <core/utils/refptr.h>
00039 #ifdef USE_TIMETRACKER
00040 #  include <utils/time/tracker.h>
00041 #endif
00042 #include <string>
00043 #include <memory>
00044 
00045 namespace fawkes {
00046   class KatanaInterface;
00047 }
00048 
00049 // Classes from libkni (KNI)
00050 class CCdlCOM;
00051 class CCplSerialCRC;
00052 class CLMBase;
00053 class CKatBase;
00054 class CSctBase;
00055 
00056 class KatanaActThread
00057 : public fawkes::Thread,
00058   public fawkes::BlockedTimingAspect,
00059   public fawkes::LoggingAspect,
00060   public fawkes::ConfigurableAspect,
00061   public fawkes::BlackBoardAspect,
00062   public fawkes::BlackBoardInterfaceListener
00063 {
00064  public:
00065   KatanaActThread();
00066 
00067   virtual void init();
00068   virtual void finalize();
00069   virtual void once();
00070   virtual void loop();
00071 
00072   // For BlackBoardInterfaceListener
00073   virtual bool bb_interface_message_received(fawkes::Interface *interface,
00074                                              fawkes::Message *message) throw();
00075 
00076   void update_sensor_values();
00077 
00078  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
00079  protected: virtual void run() { Thread::run(); }
00080 
00081  private:
00082   void stop_motion();
00083   void update_position(bool refresh);
00084   void update_sensors(bool refresh);
00085   void start_motion(fawkes::RefPtr<KatanaMotionThread> motion_thread,
00086                     unsigned int msgid, const char *logmsg, ...);
00087 
00088  private:
00089   fawkes::KatanaInterface *__katana_if;
00090 
00091   std::string    __cfg_device;
00092   std::string    __cfg_kni_conffile;
00093   bool           __cfg_auto_calibrate;
00094   unsigned int   __cfg_defmax_speed;
00095   unsigned int   __cfg_read_timeout;
00096   unsigned int   __cfg_write_timeout;
00097   unsigned int   __cfg_gripper_pollint;
00098   unsigned int   __cfg_goto_pollint;
00099   float          __cfg_park_x;
00100   float          __cfg_park_y;
00101   float          __cfg_park_z;
00102   float          __cfg_park_phi;
00103   float          __cfg_park_theta;
00104   float          __cfg_park_psi;
00105 
00106   std::auto_ptr<KatanaSensorAcquisitionThread> __sensacq_thread;
00107   fawkes::RefPtr<KatanaMotionThread>           __actmot_thread;
00108   fawkes::RefPtr<KatanaCalibrationThread>      __calib_thread;
00109   fawkes::RefPtr<KatanaGotoThread>             __goto_thread;
00110   fawkes::RefPtr<KatanaGripperThread>          __gripper_thread;
00111 
00112   fawkes::RefPtr<CLMBase>        __katana;
00113   std::auto_ptr<CCdlCOM>         __device;
00114   std::auto_ptr<CCplSerialCRC>   __protocol;
00115   CKatBase                      *__katbase;
00116   CSctBase                      *__sensor_ctrl;
00117 #ifdef USE_TIMETRACKER
00118   std::auto_ptr<fawkes::TimeTracker> __tt;
00119   unsigned int __tt_count;
00120   unsigned int __ttc_read_sensor;
00121 #endif
00122 };
00123 
00124 
00125 #endif