00001 // -*- C++ -*- 00010 #ifndef ROBOT_HARDWARE_H 00011 #define ROBOT_HARDWARE_H 00012 00013 #include <rtm/idl/BasicDataType.hh> 00014 #include <rtm/idl/ExtendedDataTypes.hh> 00015 #include "hrpsys/idl/HRPDataTypes.hh" 00016 #include "hrpsys/idl/RobotHardwareService.hh" 00017 #include <rtm/Manager.h> 00018 #include <rtm/DataFlowComponentBase.h> 00019 #include <rtm/CorbaPort.h> 00020 #include <rtm/DataInPort.h> 00021 #include <rtm/DataOutPort.h> 00022 #include <rtm/idl/BasicDataTypeSkel.h> 00023 #include <rtm/idl/ExtendedDataTypesSkel.h> 00024 00025 #include <hrpModel/Body.h> 00026 00027 // Service implementation headers 00028 // <rtc-template block="service_impl_h"> 00029 #include "RobotHardwareService_impl.h" 00030 00031 // </rtc-template> 00032 00033 // Service Consumer stub headers 00034 // <rtc-template block="consumer_stub_h"> 00035 00036 // </rtc-template> 00037 00038 using namespace RTC; 00039 00040 class robot; 00041 00045 class RobotHardware 00046 : public RTC::DataFlowComponentBase 00047 { 00048 public: 00053 RobotHardware(RTC::Manager* manager); 00057 virtual ~RobotHardware(); 00058 00059 // The initialize action (on CREATED->ALIVE transition) 00060 // formaer rtc_init_entry() 00061 virtual RTC::ReturnCode_t onInitialize(); 00062 00063 // The finalize action (on ALIVE->END transition) 00064 // formaer rtc_exiting_entry() 00065 // virtual RTC::ReturnCode_t onFinalize(); 00066 00067 // The startup action when ExecutionContext startup 00068 // former rtc_starting_entry() 00069 // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id); 00070 00071 // The shutdown action when ExecutionContext stop 00072 // former rtc_stopping_entry() 00073 // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id); 00074 00075 // The activated action (Active state entry action) 00076 // former rtc_active_entry() 00077 // virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id); 00078 00079 // The deactivated action (Active state exit action) 00080 // former rtc_active_exit() 00081 // virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id); 00082 00083 // The execution action that is invoked periodically 00084 // former rtc_active_do() 00085 virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id); 00086 00087 // The aborting action when main logic error occurred. 00088 // former rtc_aborting_entry() 00089 // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id); 00090 00091 // The error action in ERROR state 00092 // former rtc_error_do() 00093 // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id); 00094 00095 // The reset action that is invoked resetting 00096 // This is same but different the former rtc_init_entry() 00097 // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id); 00098 00099 // The state update action that is invoked after onExecute() action 00100 // no corresponding operation exists in OpenRTm-aist-0.2.0 00101 // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id); 00102 00103 // The action that is invoked when execution context's rate is changed 00104 // no corresponding operation exists in OpenRTm-aist-0.2.0 00105 // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id); 00106 00107 virtual inline void getTimeNow(Time &tm) { 00108 coil::TimeValue coiltm(coil::gettimeofday()); 00109 tm.sec = coiltm.sec(); 00110 tm.nsec = coiltm.usec() * 1000; 00111 }; 00112 00113 protected: 00114 // Configuration variable declaration 00115 // <rtc-template block="config_declare"> 00116 int m_isDemoMode; 00117 00118 // </rtc-template> 00119 00120 // DataInPort declaration 00121 // <rtc-template block="inport_declare"> 00122 00126 TimedDoubleSeq m_qRef; 00127 InPort<TimedDoubleSeq> m_qRefIn; 00131 TimedDoubleSeq m_dqRef; 00132 InPort<TimedDoubleSeq> m_dqRefIn; 00136 TimedDoubleSeq m_ddqRef; 00137 InPort<TimedDoubleSeq> m_ddqRefIn; 00141 TimedDoubleSeq m_tauRef; 00142 InPort<TimedDoubleSeq> m_tauRefIn; 00143 00144 // </rtc-template> 00145 00149 TimedDoubleSeq m_q; 00153 TimedDoubleSeq m_dq; 00157 TimedDoubleSeq m_tau; 00161 TimedDoubleSeq m_ctau; 00165 TimedDoubleSeq m_pdtau; 00169 std::vector<TimedAcceleration3D> m_acc; 00173 std::vector<TimedAngularVelocity3D> m_rate; 00178 std::vector<TimedDoubleSeq> m_force; 00179 OpenHRP::TimedLongSeqSeq m_servoState; 00180 TimedLong m_emergencySignal; 00181 OpenHRP::RobotHardwareService::TimedRobotState2 m_rstate2; 00182 00183 // DataOutPort declaration 00184 // <rtc-template block="outport_declare"> 00185 OutPort<TimedDoubleSeq> m_qOut; 00186 OutPort<TimedDoubleSeq> m_dqOut; 00187 OutPort<TimedDoubleSeq> m_tauOut; 00188 OutPort<TimedDoubleSeq> m_ctauOut; 00189 OutPort<TimedDoubleSeq> m_pdtauOut; 00190 std::vector<OutPort<TimedAcceleration3D> *> m_accOut; 00191 std::vector<OutPort<TimedAngularVelocity3D> *> m_rateOut; 00192 std::vector<OutPort<TimedDoubleSeq> *> m_forceOut; 00193 OutPort<OpenHRP::TimedLongSeqSeq> m_servoStateOut; 00194 OutPort<TimedLong> m_emergencySignalOut; 00195 OutPort<OpenHRP::RobotHardwareService::TimedRobotState2> m_rstate2Out; 00196 00197 // </rtc-template> 00198 00199 // CORBA Port declaration 00200 // <rtc-template block="corbaport_declare"> 00201 RTC::CorbaPort m_RobotHardwareServicePort; 00202 00203 // </rtc-template> 00204 00205 // Service declaration 00206 // <rtc-template block="service_declare"> 00207 RobotHardwareService_impl m_service0; 00208 00209 // </rtc-template> 00210 00211 // Consumer declaration 00212 // <rtc-template block="consumer_declare"> 00213 00214 // </rtc-template> 00215 00216 robot *robot_ptr(void) { return m_robot.get(); }; 00217 private: 00218 void getStatus2(OpenHRP::RobotHardwareService::RobotState2 &rstate2); 00219 00220 int dummy; 00221 boost::shared_ptr<robot> m_robot; 00222 }; 00223 00224 00225 extern "C" 00226 { 00227 void RobotHardwareInit(RTC::Manager* manager); 00228 }; 00229 00230 #endif // ROBOT_HARDWARE_H