CollisionDetector.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #ifndef COLLISION_DETECTOR_H
00011 #define COLLISION_DETECTOR_H
00012 
00013 #include <rtm/idl/BasicDataType.hh>
00014 #include "hrpsys/idl/HRPDataTypes.hh"
00015 #include <rtm/Manager.h>
00016 #include <rtm/DataFlowComponentBase.h>
00017 #include <rtm/CorbaPort.h>
00018 #include <rtm/DataInPort.h>
00019 #include <rtm/DataOutPort.h>
00020 #include <rtm/idl/BasicDataTypeSkel.h>
00021 #include <hrpModel/Body.h>
00022 #include <hrpModel/ColdetLinkPair.h>
00023 #include <hrpModel/ModelLoaderUtil.h>
00024 #ifdef USE_HRPSYSUTIL
00025 #include "GLscene.h"
00026 #include "hrpsys/util/SDLUtil.h"
00027 #include "hrpsys/util/LogManager.h"
00028 #endif // USE_HRPSYSUTIL
00029 #include "TimedPosture.h"
00030 #include "interpolator.h"
00031 
00032 #include "VclipLinkPair.h"
00033 #include "CollisionDetectorService_impl.h"
00034 #include "../SoftErrorLimiter/beep.h"
00035 
00036 // Service implementation headers
00037 // <rtc-template block="service_impl_h">
00038 
00039 // </rtc-template>
00040 
00041 // Service Consumer stub headers
00042 // <rtc-template block="consumer_stub_h">
00043 
00044 // </rtc-template>
00045 
00046 using namespace RTC;
00047 
00051 class CollisionDetector
00052   : public RTC::DataFlowComponentBase
00053 {
00054  public:
00059   CollisionDetector(RTC::Manager* manager);
00063   virtual ~CollisionDetector();
00064 
00065   // The initialize action (on CREATED->ALIVE transition)
00066   // formaer rtc_init_entry()
00067   virtual RTC::ReturnCode_t onInitialize();
00068 
00069   // The finalize action (on ALIVE->END transition)
00070   // formaer rtc_exiting_entry()
00071   virtual RTC::ReturnCode_t onFinalize();
00072 
00073   // The startup action when ExecutionContext startup
00074   // former rtc_starting_entry()
00075   // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id);
00076 
00077   // The shutdown action when ExecutionContext stop
00078   // former rtc_stopping_entry()
00079   // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id);
00080 
00081   // The activated action (Active state entry action)
00082   // former rtc_active_entry()
00083   virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
00084 
00085   // The deactivated action (Active state exit action)
00086   // former rtc_active_exit()
00087   virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00088 
00089   // The execution action that is invoked periodically
00090   // former rtc_active_do()
00091   virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
00092 
00093   // The aborting action when main logic error occurred.
00094   // former rtc_aborting_entry()
00095   // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id);
00096 
00097   // The error action in ERROR state
00098   // former rtc_error_do()
00099   // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id);
00100 
00101   // The reset action that is invoked resetting
00102   // This is same but different the former rtc_init_entry()
00103   // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id);
00104 
00105   // The state update action that is invoked after onExecute() action
00106   // no corresponding operation exists in OpenRTm-aist-0.2.0
00107   // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id);
00108 
00109   // The action that is invoked when execution context's rate is changed
00110   // no corresponding operation exists in OpenRTm-aist-0.2.0
00111   // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id);
00112 
00113   bool setTolerance(const char *i_link_pair_name, double i_tolerance);
00114   bool setCollisionLoop(int input_loop);
00115   bool getCollisionStatus(OpenHRP::CollisionDetectorService::CollisionState &state);
00116 
00117   bool checkIsSafeTransition(void);
00118   bool enable(void);
00119   bool disable(void);
00120 
00121  protected:
00122   // Configuration variable declaration
00123   // <rtc-template block="config_declare">
00124   
00125   // </rtc-template>
00126 
00127   // DataInPort declaration
00128   // <rtc-template block="inport_declare">
00129   TimedDoubleSeq m_qRef;
00130   InPort<TimedDoubleSeq> m_qRefIn;
00131   TimedDoubleSeq m_qCurrent;
00132   InPort<TimedDoubleSeq> m_qCurrentIn;
00133   OpenHRP::TimedLongSeqSeq m_servoState;
00134   InPort<OpenHRP::TimedLongSeqSeq> m_servoStateIn;
00135   
00136   // </rtc-template>
00137 
00138   // DataOutPort declaration
00139   // <rtc-template block="outport_declare">
00140   TimedDoubleSeq m_q;
00141   OutPort<TimedDoubleSeq> m_qOut;
00142   TimedLongSeq m_beepCommand;
00143   OutPort<TimedLongSeq> m_beepCommandOut;
00144   
00145   // </rtc-template>
00146 
00147   // CORBA Port declaration
00148   // <rtc-template block="corbaport_declare">
00149   RTC::CorbaPort m_CollisionDetectorServicePort;
00150   
00151   // </rtc-template>
00152 
00153   // Service declaration
00154   // <rtc-template block="service_declare">
00155   CollisionDetectorService_impl m_service0;
00156   
00157   // </rtc-template>
00158 
00159   // Consumer declaration
00160   // <rtc-template block="consumer_declare">
00161 
00162   
00163   // </rtc-template>
00164   void setupVClipModel(hrp::BodyPtr i_body);
00165   void setupVClipModel(hrp::Link *i_link);
00166 
00167  private:
00168   class CollisionLinkPair {
00169   public:
00170       CollisionLinkPair(VclipLinkPairPtr i_pair) : point0(hrp::Vector3(0,0,0)), point1(hrp::Vector3(0,0,0)), distance(0) {
00171           pair = i_pair;
00172       }
00173       VclipLinkPairPtr pair;
00174       hrp::Vector3 point0, point1;
00175       double distance;
00176   };
00177 #ifdef USE_HRPSYSUTIL
00178   CollisionDetectorComponent::GLscene m_scene;
00179   LogManager<TimedPosture> m_log; 
00180   SDLwindow m_window;
00181   GLbody *m_glbody;
00182 #endif // USE_HRPSYSUTIL
00183   std::vector<Vclip::Polyhedron *> m_VclipLinks;
00184   std::vector<int> m_curr_collision_mask, m_init_collision_mask;
00185   bool m_use_limb_collision;
00186   bool m_use_viewer;
00187   hrp::BodyPtr m_robot;
00188   std::map<std::string, CollisionLinkPair *> m_pair;
00189   int m_loop_for_check, m_collision_loop;
00190   bool m_safe_posture;
00191   int m_recover_time;
00192   double m_dt;
00193   //
00194   double *m_recover_jointdata, *m_lastsafe_jointdata;
00195   bool *m_link_collision;
00196   interpolator* m_interpolator;
00197   double i_dt;
00198   int default_recover_time;
00199   unsigned int m_debugLevel;
00200   bool m_enable;
00201   int collision_beep_freq, collision_beep_count;
00202   bool m_have_safe_posture;
00203   OpenHRP::CollisionDetectorService::CollisionState m_state;
00204   BeepClient bc;
00205   // Since this RTC is stable RTC, we support both direct beeping from this RTC and beepring through BeeperRTC.
00206   // If m_beepCommand is connected to BeeperRTC, is_beep_port_connected is true.
00207   bool is_beep_port_connected;
00208   int dummy;
00209 };
00210 
00211 #ifndef USE_HRPSYSUTIL
00212 hrp::Link *hrplinkFactory();
00213 #endif // USE_HRPSYSUTIL
00214 
00215 extern "C"
00216 {
00217   void CollisionDetectorInit(RTC::Manager* manager);
00218 };
00219 
00220 #endif // COLLISION_DETECTOR_H


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:54