00001 // -*- C++ -*- 00007 #ifndef ACCELERATIONFILTER_H 00008 #define ACCELERATIONFILTER_H 00009 00010 #include <rtm/idl/BasicDataType.hh> 00011 #include <rtm/idl/ExtendedDataTypes.hh> 00012 #include "hrpsys/idl/HRPDataTypes.hh" 00013 #include "hrpsys/idl/AccelerationFilterService.hh" 00014 #include <rtm/Manager.h> 00015 #include <rtm/DataFlowComponentBase.h> 00016 #include <rtm/CorbaPort.h> 00017 #include <rtm/DataInPort.h> 00018 #include <rtm/DataOutPort.h> 00019 #include <rtm/idl/BasicDataTypeSkel.h> 00020 #include <rtm/idl/ExtendedDataTypesSkel.h> 00021 // 00022 #include <hrpModel/Body.h> 00023 // 00024 #include <../TorqueFilter/IIRFilter.h> 00025 00026 // Service implementation headers 00027 // <rtc-template block="service_impl_h"> 00028 #include "AccelerationFilterService_impl.h" 00029 00030 // </rtc-template> 00031 00032 // Service Consumer stub headers 00033 // <rtc-template block="consumer_stub_h"> 00034 00035 // </rtc-template> 00036 00037 using namespace RTC; 00038 00039 class AccelerationFilter : public RTC::DataFlowComponentBase 00040 { 00041 public: 00042 AccelerationFilter(RTC::Manager* manager); 00043 ~AccelerationFilter(); 00044 00045 // The initialize action (on CREATED->ALIVE transition) 00046 // formaer rtc_init_entry() 00047 virtual RTC::ReturnCode_t onInitialize(); 00048 00049 // The finalize action (on ALIVE->END transition) 00050 // formaer rtc_exiting_entry() 00051 // virtual RTC::ReturnCode_t onFinalize(); 00052 00053 // The startup action when ExecutionContext startup 00054 // former rtc_starting_entry() 00055 // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id); 00056 00057 // The shutdown action when ExecutionContext stop 00058 // former rtc_stopping_entry() 00059 // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id); 00060 00061 // The activated action (Active state entry action) 00062 // former rtc_active_entry() 00063 virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id); 00064 00065 // The deactivated action (Active state exit action) 00066 // former rtc_active_exit() 00067 virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id); 00068 00069 // The execution action that is invoked periodically 00070 // former rtc_active_do() 00071 virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id); 00072 00073 // The aborting action when main logic error occurred. 00074 // former rtc_aborting_entry() 00075 // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id); 00076 00077 // The error action in ERROR state 00078 // former rtc_error_do() 00079 // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id); 00080 00081 // The reset action that is invoked resetting 00082 // This is same but different the former rtc_init_entry() 00083 // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id); 00084 00085 // The state update action that is invoked after onExecute() action 00086 // no corresponding operation exists in OpenRTm-aist-0.2.0 00087 // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id); 00088 00089 // The action that is invoked when execution context's rate is changed 00090 // no corresponding operation exists in OpenRTm-aist-0.2.0 00091 // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id); 00092 bool resetFilter(const OpenHRP::AccelerationFilterService::ControlMode &mode, 00093 const double *vel); 00094 bool setParam(const ::OpenHRP::AccelerationFilterService::AccelerationFilterParam& i_param); 00095 bool getParam(::OpenHRP::AccelerationFilterService::AccelerationFilterParam &i_param); 00096 00097 protected: 00098 // Configuration variable declaration 00099 // <rtc-template block="config_declare"> 00100 // </rtc-template> 00101 00102 // DataInPort declaration 00103 // <rtc-template block="inport_declare"> 00104 TimedAcceleration3D m_accIn; 00105 InPort<TimedAcceleration3D> m_accInIn; 00106 TimedAngularVelocity3D m_rateIn; 00107 InPort<TimedAngularVelocity3D> m_rateInIn; 00108 TimedOrientation3D m_rpyIn; 00109 InPort<TimedOrientation3D> m_rpyInIn; 00110 TimedPoint3D m_posIn; 00111 InPort<TimedPoint3D> m_posInIn; 00112 // </rtc-template> 00113 00114 // DataOutPort declaration 00115 // <rtc-template block="outport_declare"> 00116 TimedVector3D m_velOut; 00117 OutPort<TimedVector3D> m_velOutOut; 00118 //TimedPoint3D m_posOut; 00119 //OutPort<TimedPoint3D> m_posOutOut; 00120 00121 // </rtc-template> 00122 00123 // CORBA Port declaration 00124 // <rtc-template block="corbaport_declare"> 00125 RTC::CorbaPort m_AccelerationFilterServicePort; 00126 00127 // </rtc-template> 00128 00129 // Service declaration 00130 // <rtc-template block="service_declare"> 00131 AccelerationFilterService_impl m_service0; 00132 00133 // </rtc-template> 00134 00135 // Consumer declaration 00136 // <rtc-template block="consumer_declare"> 00137 00138 // </rtc-template> 00139 00140 private: 00141 typedef boost::shared_ptr< IIRFilter> IIRFilterPtr; 00142 double m_dt; 00143 double m_gravity; 00144 bool m_use_filter_bool; 00145 hrp::Vector3 m_global_vel; 00146 std::vector<IIRFilterPtr > m_filters; 00147 hrp::Vector3 m_previous_pos; 00148 00149 coil::Mutex m_mutex; 00150 }; 00151 00152 00153 extern "C" 00154 { 00155 DLL_EXPORT void AccelerationFilterInit(RTC::Manager* manager); 00156 }; 00157 00158 #endif // ACCELERATIONFILTER_H 00159