00001 // -*- mode: c++; indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*- 00002 /* 00003 * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc. 00004 * All rights reserved. This program is made available under the terms of the 00005 * Eclipse Public License v1.0 which accompanies this distribution, and is 00006 * available at http://www.eclipse.org/legal/epl-v10.html 00007 * Contributors: 00008 * National Institute of Advanced Industrial Science and Technology (AIST) 00009 * General Robotix Inc. 00010 */ 00019 #ifndef SamplePD_HG_H 00020 #define SamplePD_HG_H 00021 00022 #define DOF (29) 00023 00024 #include <rtm/idl/BasicDataType.hh> 00025 #include <rtm/Manager.h> 00026 #include <rtm/DataFlowComponentBase.h> 00027 #include <rtm/CorbaPort.h> 00028 #include <rtm/DataInPort.h> 00029 #include <rtm/DataOutPort.h> 00030 #include <rtm/idl/BasicDataTypeSkel.h> 00031 00032 #include <vector> 00033 00034 // Service implementation headers 00035 // <rtc-template block="service_impl_h"> 00036 00037 // </rtc-template> 00038 00039 // Service Consumer stub headers 00040 // <rtc-template block="consumer_stub_h"> 00041 00042 // </rtc-template> 00043 00044 using namespace RTC; 00045 00046 class SamplePD_HG 00047 : public RTC::DataFlowComponentBase 00048 { 00049 public: 00050 SamplePD_HG(RTC::Manager* manager); 00051 ~SamplePD_HG(); 00052 00053 // The initialize action (on CREATED->ALIVE transition) 00054 // formaer rtc_init_entry() 00055 virtual RTC::ReturnCode_t onInitialize(); 00056 00057 // The finalize action (on ALIVE->END transition) 00058 // formaer rtc_exiting_entry() 00059 // virtual RTC::ReturnCode_t onFinalize(); 00060 00061 // The startup action when ExecutionContext startup 00062 // former rtc_starting_entry() 00063 // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id); 00064 00065 // The shutdown action when ExecutionContext stop 00066 // former rtc_stopping_entry() 00067 // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id); 00068 00069 // The activated action (Active state entry action) 00070 // former rtc_active_entry() 00071 virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id); 00072 00073 // The deactivated action (Active state exit action) 00074 // former rtc_active_exit() 00075 virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id); 00076 00077 // The execution action that is invoked periodically 00078 // former rtc_active_do() 00079 virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id); 00080 00081 // The aborting action when main logic error occurred. 00082 // former rtc_aborting_entry() 00083 // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id); 00084 00085 // The error action in ERROR state 00086 // former rtc_error_do() 00087 // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id); 00088 00089 // The reset action that is invoked resetting 00090 // This is same but different the former rtc_init_entry() 00091 // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id); 00092 00093 // The state update action that is invoked after onExecute() action 00094 // no corresponding operation exists in OpenRTm-aist-0.2.0 00095 // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id); 00096 00097 // The action that is invoked when execution context's rate is changed 00098 // no corresponding operation exists in OpenRTm-aist-0.2.0 00099 // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id); 00100 00101 00102 protected: 00103 // Configuration variable declaration 00104 // <rtc-template block="config_declare"> 00105 00106 // </rtc-template> 00107 00108 // DataInPort declaration 00109 // <rtc-template block="inport_declare"> 00110 TimedDoubleSeq m_angle_in; 00111 InPort<TimedDoubleSeq> m_angle_inIn; 00112 00113 // </rtc-template> 00114 00115 // DataOutPort declaration 00116 // <rtc-template block="outport_declare"> 00117 TimedDoubleSeq m_angle_out; 00118 OutPort<TimedDoubleSeq> m_angle_outOut; 00119 TimedDoubleSeq m_vel; 00120 OutPort<TimedDoubleSeq> m_velOut; 00121 TimedDoubleSeq m_acc; 00122 OutPort<TimedDoubleSeq> m_accOut; 00123 TimedDoubleSeq m_torque; 00124 OutPort<TimedDoubleSeq> m_torqueOut; 00125 00126 // </rtc-template> 00127 00128 // CORBA Port declaration 00129 // <rtc-template block="corbaport_declare"> 00130 00131 // </rtc-template> 00132 00133 // Service declaration 00134 // <rtc-template block="service_declare"> 00135 00136 // </rtc-template> 00137 00138 // Consumer declaration 00139 // <rtc-template block="consumer_declare"> 00140 00141 // </rtc-template> 00142 00143 private: 00144 int dummy; 00145 std::ifstream angle, vel, acc, gain; 00146 double *Pgain; 00147 double *Dgain; 00148 std::vector<double> qold; 00149 double q_ref[DOF], dq_ref[DOF], ddq_ref[DOF]; 00150 00151 void openFiles(); 00152 void closeFiles(); 00153 }; 00154 00155 00156 extern "C" 00157 { 00158 DLL_EXPORT void SamplePD_HGInit(RTC::Manager* manager); 00159 }; 00160 00161 #endif // SamplePD_HG_H