ReferenceForceUpdater.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #ifndef REFERENCEFORCEUPDATOR_COMPONENT_H
00011 #define REFERENCEFORCEUPDATOR_COMPONENT_H
00012 
00013 #include <rtm/idl/BasicDataType.hh>
00014 #include <rtm/idl/ExtendedDataTypes.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 <rtm/idl/ExtendedDataTypesSkel.h>
00022 #include <hrpModel/Body.h>
00023 #include "../ImpedanceController/JointPathEx.h"
00024 #include "../ImpedanceController/RatsMatrix.h"
00025 #include "../SequencePlayer/interpolator.h"
00026 #include "../TorqueFilter/IIRFilter.h"
00027 #include <boost/shared_ptr.hpp>
00028 
00029 // #include "ImpedanceOutputGenerator.h"
00030 // #include "ObjectTurnaroundDetector.h"
00031 // Service implementation headers
00032 // <rtc-template block="service_impl_h">
00033 #include "ReferenceForceUpdaterService_impl.h"
00034 
00035 // </rtc-template>
00036 
00037 // Service Consumer stub headers
00038 // <rtc-template block="consumer_stub_h">
00039 
00040 // </rtc-template>
00041 
00042 using namespace RTC;
00043 
00047 class ReferenceForceUpdater
00048   : public RTC::DataFlowComponentBase
00049 {
00050  public:
00055   ReferenceForceUpdater(RTC::Manager* manager);
00059   virtual ~ReferenceForceUpdater();
00060 
00061   // The initialize action (on CREATED->ALIVE transition)
00062   // formaer rtc_init_entry()
00063   virtual RTC::ReturnCode_t onInitialize();
00064 
00065   // The finalize action (on ALIVE->END transition)
00066   // formaer rtc_exiting_entry()
00067   virtual RTC::ReturnCode_t onFinalize();
00068 
00069   // The startup action when ExecutionContext startup
00070   // former rtc_starting_entry()
00071   // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id);
00072 
00073   // The shutdown action when ExecutionContext stop
00074   // former rtc_stopping_entry()
00075   // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id);
00076 
00077   // The activated action (Active state entry action)
00078   // former rtc_active_entry()
00079   virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
00080 
00081   // The deactivated action (Active state exit action)
00082   // former rtc_active_exit()
00083   virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00084 
00085   // The execution action that is invoked periodically
00086   // former rtc_active_do()
00087   virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
00088 
00089   // The aborting action when main logic error occurred.
00090   // former rtc_aborting_entry()
00091   // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id);
00092 
00093   // The error action in ERROR state
00094   // former rtc_error_do()
00095   // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id);
00096 
00097   // The reset action that is invoked resetting
00098   // This is same but different the former rtc_init_entry()
00099   // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id);
00100 
00101   // The state update action that is invoked after onExecute() action
00102   // no corresponding operation exists in OpenRTm-aist-0.2.0
00103   // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id);
00104 
00105   // The action that is invoked when execution context's rate is changed
00106   // no corresponding operation exists in OpenRTm-aist-0.2.0
00107   // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id);
00108 
00109   bool setReferenceForceUpdaterParam(const std::string& i_name_, const OpenHRP::ReferenceForceUpdaterService::ReferenceForceUpdaterParam& i_param);
00110   bool getReferenceForceUpdaterParam(const std::string& i_name_, OpenHRP::ReferenceForceUpdaterService::ReferenceForceUpdaterParam_out i_param);
00111   bool startReferenceForceUpdater(const std::string& i_name_);
00112   bool stopReferenceForceUpdater(const std::string& i_name_);
00113   bool startReferenceForceUpdaterNoWait(const std::string& i_name_);
00114   bool stopReferenceForceUpdaterNoWait(const std::string& i_name_);
00115   void waitReferenceForceUpdaterTransition(const std::string& i_name_);
00116   bool getSupportedReferenceForceUpdaterNameSequence(OpenHRP::ReferenceForceUpdaterService::StrSequence_out o_names);
00117   void getTargetParameters ();
00118   void calcFootOriginCoords (hrp::Vector3& foot_origin_pos, hrp::Matrix33& foot_origin_rot);
00119   void updateRefFootOriginExtMoment (const std::string& arm);
00120   void updateRefObjExtMoment0 (const std::string& arm);
00121   void updateRefForces (const std::string& arm);
00122   inline bool eps_eq(const double a, const double b, const double eps = 1e-3) { return std::fabs((a)-(b)) <= eps; };
00123 
00124  protected:
00125   // Configuration variable declaration
00126   // <rtc-template block="config_declare">
00127   
00128   // </rtc-template>
00129 
00130   // DataInPort declaration
00131   // <rtc-template block="inport_declare">
00132   TimedDoubleSeq m_qRef;
00133   InPort<TimedDoubleSeq> m_qRefIn;
00134   TimedPoint3D m_basePos;
00135   InPort<TimedPoint3D> m_basePosIn;
00136   TimedOrientation3D m_baseRpy;
00137   InPort<TimedOrientation3D> m_baseRpyIn;
00138   std::vector<TimedDoubleSeq> m_force;
00139   std::vector<InPort<TimedDoubleSeq> *> m_forceIn;
00140   std::vector<TimedDoubleSeq> m_ref_force_in;
00141   std::vector<InPort<TimedDoubleSeq> *> m_ref_forceIn;
00142   TimedOrientation3D m_rpy;
00143   InPort<TimedOrientation3D> m_rpyIn;
00144   TimedPoint3D m_diffFootOriginExtMoment;
00145   InPort<TimedPoint3D> m_diffFootOriginExtMomentIn;
00146 
00147   // </rtc-template>
00148 
00149   // DataOutPort declaration
00150   // <rtc-template block="outport_declare">
00151   std::vector<TimedDoubleSeq> m_ref_force_out;
00152   std::vector<OutPort<TimedDoubleSeq> *> m_ref_forceOut;
00153   TimedPoint3D m_refFootOriginExtMoment;
00154   OutPort<TimedPoint3D> m_refFootOriginExtMomentOut;
00155   TimedBoolean m_refFootOriginExtMomentIsHoldValue;
00156   OutPort<TimedBoolean> m_refFootOriginExtMomentIsHoldValueOut;
00157 
00158   // </rtc-template>
00159 
00160   // CORBA Port declaration
00161   // <rtc-template block="corbaport_declare">
00162   
00163   // </rtc-template>
00164 
00165   // Service declaration
00166   // <rtc-template block="service_declare">
00167   RTC::CorbaPort m_ReferenceForceUpdaterServicePort;
00168   
00169   // </rtc-template>
00170 
00171   // Consumer declaration
00172   // <rtc-template block="consumer_declare">
00173   ReferenceForceUpdaterService_impl m_ReferenceForceUpdaterService;
00174   
00175   // </rtc-template>
00176 
00177  private:
00178   struct ee_trans {
00179     std::string target_name, sensor_name;
00180     hrp::Vector3 localPos;
00181     hrp::Matrix33 localR;
00182   };
00183   struct ReferenceForceUpdaterParam {
00184     // Update frequency [Hz]
00185     double update_freq;
00186     // Update time ratio \in [0,1]
00187     double update_time_ratio;
00188     // P gain
00189     double p_gain;
00190     // D gain
00191     double d_gain;
00192     // I gain
00193     double i_gain;
00194     // Transition time[s]
00195     double transition_time;
00196     // Motion direction to update reference force
00197     hrp::Vector3 motion_dir;
00198     std::string frame;
00199     int update_count;
00200     bool is_active, is_stopping, is_hold_value;
00201     boost::shared_ptr<FirstOrderLowPassFilter<hrp::Vector3> > act_force_filter;
00202     void printParam (const std::string print_str)
00203     {
00204         std::cerr << "[" << print_str << "]   p_gain = " << p_gain << ", d_gain = " << d_gain << ", i_gain = " << i_gain << std::endl;
00205         std::cerr << "[" << print_str << "]   update_freq = " << update_freq << "[Hz], update_count = " << update_count << ", update_time_ratio = " << update_time_ratio << ", transition_time = " << transition_time << "[s], cutoff_freq = " << act_force_filter->getCutOffFreq() << "[Hz]" << std::endl;
00206         std::cerr << "[" << print_str << "]   motion_dir = " << motion_dir.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", "    [", "]")) << std::endl;
00207         std::cerr << "[" << print_str << "]   frame = " << frame << ", is_hold_value = " << (is_hold_value?"true":"false") << std::endl;
00208     }
00209     void initializeParam () {
00210       //params defined in idl
00211       motion_dir = hrp::Vector3::UnitZ();
00212       frame="local";
00213       update_freq = 50; // Hz
00214       update_time_ratio = 0.5;
00215       p_gain = 0.02;
00216       d_gain = 0;
00217       i_gain = 0;
00218       transition_time = 1.0;
00219       //additional params (not defined in idl)
00220       is_active = false;
00221       is_stopping = false;
00222       is_hold_value = false;
00223     };
00224     ReferenceForceUpdaterParam () {
00225       initializeParam();
00226     };
00227     ReferenceForceUpdaterParam (const double _dt) {
00228       initializeParam();
00229       update_count = round((1/update_freq)/_dt);
00230       double default_cutoff_freq = 1e8;
00231       act_force_filter = boost::shared_ptr<FirstOrderLowPassFilter<hrp::Vector3> >(new FirstOrderLowPassFilter<hrp::Vector3>(default_cutoff_freq, _dt, hrp::Vector3::Zero()));
00232     };
00233   };
00234   std::map<std::string, hrp::VirtualForceSensorParam> m_vfs;
00235   hrp::BodyPtr m_robot;
00236   double m_dt;
00237   unsigned int m_debugLevel;
00238   coil::Mutex m_mutex;
00239   std::map<std::string, ee_trans> ee_map;
00240   std::map<std::string, size_t> ee_index_map;
00241   std::map<std::string, ReferenceForceUpdaterParam> m_RFUParam;
00242   std::vector<hrp::Vector3> ref_force;
00243   std::map<std::string, interpolator*> ref_force_interpolator;
00244   std::map<std::string, interpolator*> transition_interpolator;
00245   std::vector<double> transition_interpolator_ratio;
00246   hrp::Matrix33 foot_origin_rot;
00247   bool use_sh_base_pos_rpy;
00248   int loop;//counter in onExecute
00249   const std::string footoriginextmoment_name, objextmoment0_name;
00250 };
00251 
00252 
00253 extern "C"
00254 {
00255   void ReferenceForceUpdaterInit(RTC::Manager* manager);
00256 };
00257 
00258 #endif // REFERENCEFORCEUPDATOR_COMPONENT_H


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:18