00001 // -*- C++ -*- 00010 #ifndef SOFT_ERROR_LIMITER_H 00011 #define SOFT_ERROR_LIMITER_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 "JointLimitTable.h" 00022 00023 // Service implementation headers 00024 // <rtc-template block="service_impl_h"> 00025 #include "SoftErrorLimiterService_impl.h" 00026 #include "beep.h" 00027 00028 // </rtc-template> 00029 00030 // Service Consumer stub headers 00031 // <rtc-template block="consumer_stub_h"> 00032 00033 // </rtc-template> 00034 00035 using namespace RTC; 00036 00040 class SoftErrorLimiter 00041 : public RTC::DataFlowComponentBase 00042 { 00043 public: 00048 SoftErrorLimiter(RTC::Manager* manager); 00052 virtual ~SoftErrorLimiter(); 00053 00054 // The initialize action (on CREATED->ALIVE transition) 00055 // formaer rtc_init_entry() 00056 virtual RTC::ReturnCode_t onInitialize(); 00057 00058 // The finalize action (on ALIVE->END transition) 00059 // formaer rtc_exiting_entry() 00060 //virtual RTC::ReturnCode_t onFinalize(); 00061 00062 // The startup action when ExecutionContext startup 00063 // former rtc_starting_entry() 00064 // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id); 00065 00066 // The shutdown action when ExecutionContext stop 00067 // former rtc_stopping_entry() 00068 // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id); 00069 00070 // The activated action (Active state entry action) 00071 // former rtc_active_entry() 00072 virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id); 00073 00074 // The deactivated action (Active state exit action) 00075 // former rtc_active_exit() 00076 virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id); 00077 00078 // The execution action that is invoked periodically 00079 // former rtc_active_do() 00080 virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id); 00081 00082 // The aborting action when main logic error occurred. 00083 // former rtc_aborting_entry() 00084 // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id); 00085 00086 // The error action in ERROR state 00087 // former rtc_error_do() 00088 // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id); 00089 00090 // The reset action that is invoked resetting 00091 // This is same but different the former rtc_init_entry() 00092 // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id); 00093 00094 // The state update action that is invoked after onExecute() action 00095 // no corresponding operation exists in OpenRTm-aist-0.2.0 00096 // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id); 00097 00098 // The action that is invoked when execution context's rate is changed 00099 // no corresponding operation exists in OpenRTm-aist-0.2.0 00100 // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id); 00101 00102 00103 protected: 00104 // Configuration variable declaration 00105 // <rtc-template block="config_declare"> 00106 00107 // </rtc-template> 00108 00109 TimedDoubleSeq m_qRef; 00110 TimedDoubleSeq m_qCurrent; 00111 OpenHRP::TimedLongSeqSeq m_servoState; 00112 TimedLongSeq m_beepCommand; 00113 00114 // DataInPort declaration 00115 // <rtc-template block="inport_declare"> 00116 InPort<TimedDoubleSeq> m_qRefIn; 00117 InPort<TimedDoubleSeq> m_qCurrentIn; 00118 InPort<OpenHRP::TimedLongSeqSeq> m_servoStateIn; 00119 00120 // </rtc-template> 00121 00122 // DataOutPort declaration 00123 // <rtc-template block="outport_declare"> 00124 OutPort<TimedDoubleSeq> m_qOut; 00125 OutPort<OpenHRP::TimedLongSeqSeq> m_servoStateOut; 00126 OutPort<TimedLongSeq> m_beepCommandOut; 00127 00128 // </rtc-template> 00129 00130 // CORBA Port declaration 00131 // <rtc-template block="corbaport_declare"> 00132 RTC::CorbaPort m_SoftErrorLimiterServicePort; 00133 00134 // </rtc-template> 00135 00136 // Service declaration 00137 // <rtc-template block="service_declare"> 00138 SoftErrorLimiterService_impl m_service0; 00139 00140 // </rtc-template> 00141 00142 // Consumer declaration 00143 // <rtc-template block="consumer_declare"> 00144 00145 // </rtc-template> 00146 00147 private: 00148 boost::shared_ptr<robot> m_robot; 00149 std::map<std::string, hrp::JointLimitTable> joint_limit_tables; 00150 std::vector<bool> m_joint_mask; 00151 unsigned int m_debugLevel; 00152 int dummy, position_limit_error_beep_freq, soft_limit_error_beep_freq, debug_print_freq; 00153 double dt; 00154 BeepClient bc; 00155 // Since this RTC is stable RTC, we support both direct beeping from this RTC and beepring through BeeperRTC. 00156 // If m_beepCommand is connected to BeeperRTC, is_beep_port_connected is true. 00157 bool is_beep_port_connected; 00158 }; 00159 00160 00161 extern "C" 00162 { 00163 void SoftErrorLimiterInit(RTC::Manager* manager); 00164 }; 00165 00166 #endif // SOFT_ERROR_LIMITER_H