ReferenceForceUpdater.h
Go to the documentation of this file.
1 // -*- C++ -*-
10 #ifndef REFERENCEFORCEUPDATOR_COMPONENT_H
11 #define REFERENCEFORCEUPDATOR_COMPONENT_H
12 
13 #include <rtm/idl/BasicDataType.hh>
14 #include <rtm/idl/ExtendedDataTypes.hh>
15 #include <rtm/Manager.h>
16 #include <rtm/DataFlowComponentBase.h>
17 #include <rtm/CorbaPort.h>
18 #include <rtm/DataInPort.h>
19 #include <rtm/DataOutPort.h>
20 #include <rtm/idl/BasicDataTypeSkel.h>
21 #include <rtm/idl/ExtendedDataTypesSkel.h>
22 #include <hrpModel/Body.h>
23 #include "../ImpedanceController/JointPathEx.h"
24 #include "../ImpedanceController/RatsMatrix.h"
25 #include "../SequencePlayer/interpolator.h"
26 #include "../TorqueFilter/IIRFilter.h"
27 #include <boost/shared_ptr.hpp>
28 
29 // #include "ImpedanceOutputGenerator.h"
30 // #include "ObjectTurnaroundDetector.h"
31 // Service implementation headers
32 // <rtc-template block="service_impl_h">
34 
35 // </rtc-template>
36 
37 // Service Consumer stub headers
38 // <rtc-template block="consumer_stub_h">
39 
40 // </rtc-template>
41 
42 using namespace RTC;
43 
49 {
50  public:
59  virtual ~ReferenceForceUpdater();
60 
61  // The initialize action (on CREATED->ALIVE transition)
62  // formaer rtc_init_entry()
63  virtual RTC::ReturnCode_t onInitialize();
64 
65  // The finalize action (on ALIVE->END transition)
66  // formaer rtc_exiting_entry()
67  virtual RTC::ReturnCode_t onFinalize();
68 
69  // The startup action when ExecutionContext startup
70  // former rtc_starting_entry()
71  // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id);
72 
73  // The shutdown action when ExecutionContext stop
74  // former rtc_stopping_entry()
75  // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id);
76 
77  // The activated action (Active state entry action)
78  // former rtc_active_entry()
79  virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
80 
81  // The deactivated action (Active state exit action)
82  // former rtc_active_exit()
83  virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
84 
85  // The execution action that is invoked periodically
86  // former rtc_active_do()
87  virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
88 
89  // The aborting action when main logic error occurred.
90  // former rtc_aborting_entry()
91  // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id);
92 
93  // The error action in ERROR state
94  // former rtc_error_do()
95  // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id);
96 
97  // The reset action that is invoked resetting
98  // This is same but different the former rtc_init_entry()
99  // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id);
100 
101  // The state update action that is invoked after onExecute() action
102  // no corresponding operation exists in OpenRTm-aist-0.2.0
103  // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id);
104 
105  // The action that is invoked when execution context's rate is changed
106  // no corresponding operation exists in OpenRTm-aist-0.2.0
107  // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id);
108 
109  bool setReferenceForceUpdaterParam(const std::string& i_name_, const OpenHRP::ReferenceForceUpdaterService::ReferenceForceUpdaterParam& i_param);
110  bool getReferenceForceUpdaterParam(const std::string& i_name_, OpenHRP::ReferenceForceUpdaterService::ReferenceForceUpdaterParam_out i_param);
111  bool startReferenceForceUpdater(const std::string& i_name_);
112  bool stopReferenceForceUpdater(const std::string& i_name_);
113  bool startReferenceForceUpdaterNoWait(const std::string& i_name_);
114  bool stopReferenceForceUpdaterNoWait(const std::string& i_name_);
115  void waitReferenceForceUpdaterTransition(const std::string& i_name_);
116  bool getSupportedReferenceForceUpdaterNameSequence(OpenHRP::ReferenceForceUpdaterService::StrSequence_out o_names);
117  void getTargetParameters ();
118  void calcFootOriginCoords (hrp::Vector3& foot_origin_pos, hrp::Matrix33& foot_origin_rot);
119  void updateRefFootOriginExtMoment (const std::string& arm);
120  void updateRefObjExtMoment0 (const std::string& arm);
121  void updateRefForces (const std::string& arm);
122  inline bool eps_eq(const double a, const double b, const double eps = 1e-3) { return std::fabs((a)-(b)) <= eps; };
123 
124  protected:
125  // Configuration variable declaration
126  // <rtc-template block="config_declare">
127 
128  // </rtc-template>
129 
130  // DataInPort declaration
131  // <rtc-template block="inport_declare">
132  TimedDoubleSeq m_qRef;
134  TimedPoint3D m_basePos;
136  TimedOrientation3D m_baseRpy;
138  std::vector<TimedDoubleSeq> m_force;
139  std::vector<InPort<TimedDoubleSeq> *> m_forceIn;
140  std::vector<TimedDoubleSeq> m_ref_force_in;
141  std::vector<InPort<TimedDoubleSeq> *> m_ref_forceIn;
142  TimedOrientation3D m_rpy;
146 
147  // </rtc-template>
148 
149  // DataOutPort declaration
150  // <rtc-template block="outport_declare">
151  std::vector<TimedDoubleSeq> m_ref_force_out;
152  std::vector<OutPort<TimedDoubleSeq> *> m_ref_forceOut;
157 
158  // </rtc-template>
159 
160  // CORBA Port declaration
161  // <rtc-template block="corbaport_declare">
162 
163  // </rtc-template>
164 
165  // Service declaration
166  // <rtc-template block="service_declare">
168 
169  // </rtc-template>
170 
171  // Consumer declaration
172  // <rtc-template block="consumer_declare">
174 
175  // </rtc-template>
176 
177  private:
178  struct ee_trans {
179  std::string target_name, sensor_name;
182  };
184  // Update frequency [Hz]
185  double update_freq;
186  // Update time ratio \in [0,1]
188  // P gain
189  double p_gain;
190  // D gain
191  double d_gain;
192  // I gain
193  double i_gain;
194  // Transition time[s]
196  // Motion direction to update reference force
198  std::string frame;
200  bool is_active, is_stopping, is_hold_value;
202  void printParam (const std::string print_str)
203  {
204  std::cerr << "[" << print_str << "] p_gain = " << p_gain << ", d_gain = " << d_gain << ", i_gain = " << i_gain << std::endl;
205  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;
206  std::cerr << "[" << print_str << "] motion_dir = " << motion_dir.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", " [", "]")) << std::endl;
207  std::cerr << "[" << print_str << "] frame = " << frame << ", is_hold_value = " << (is_hold_value?"true":"false") << std::endl;
208  }
209  void initializeParam () {
210  //params defined in idl
211  motion_dir = hrp::Vector3::UnitZ();
212  frame="local";
213  update_freq = 50; // Hz
214  update_time_ratio = 0.5;
215  p_gain = 0.02;
216  d_gain = 0;
217  i_gain = 0;
218  transition_time = 1.0;
219  //additional params (not defined in idl)
220  is_active = false;
221  is_stopping = false;
222  is_hold_value = false;
223  };
225  initializeParam();
226  };
227  ReferenceForceUpdaterParam (const double _dt) {
228  initializeParam();
229  update_count = round((1/update_freq)/_dt);
230  double default_cutoff_freq = 1e8;
231  act_force_filter = boost::shared_ptr<FirstOrderLowPassFilter<hrp::Vector3> >(new FirstOrderLowPassFilter<hrp::Vector3>(default_cutoff_freq, _dt, hrp::Vector3::Zero()));
232  };
233  };
234  std::map<std::string, hrp::VirtualForceSensorParam> m_vfs;
236  double m_dt;
237  unsigned int m_debugLevel;
239  std::map<std::string, ee_trans> ee_map;
240  std::map<std::string, size_t> ee_index_map;
241  std::map<std::string, ReferenceForceUpdaterParam> m_RFUParam;
242  std::vector<hrp::Vector3> ref_force;
243  std::map<std::string, interpolator*> ref_force_interpolator;
244  std::map<std::string, interpolator*> transition_interpolator;
245  std::vector<double> transition_interpolator_ratio;
248  int loop;//counter in onExecute
249  const std::string footoriginextmoment_name, objextmoment0_name;
250 };
251 
252 
253 extern "C"
254 {
256 };
257 
258 #endif // REFERENCEFORCEUPDATOR_COMPONENT_H
ec_id
std::map< std::string, hrp::VirtualForceSensorParam > m_vfs
InPort< TimedOrientation3D > m_baseRpyIn
OutPort< TimedPoint3D > m_refFootOriginExtMomentOut
const std::string objextmoment0_name
InPort< TimedOrientation3D > m_rpyIn
sample RT component which has one data input port and one data output port
InPort< TimedPoint3D > m_diffFootOriginExtMomentIn
TimedOrientation3D m_baseRpy
std::map< std::string, ee_trans > ee_map
manager
InPort< TimedPoint3D > m_basePosIn
std::vector< TimedDoubleSeq > m_ref_force_out
ReferenceForceUpdaterService_impl m_ReferenceForceUpdaterService
TimedBoolean m_refFootOriginExtMomentIsHoldValue
std::vector< InPort< TimedDoubleSeq > * > m_ref_forceIn
Eigen::Vector3d Vector3
Eigen::Matrix3d Matrix33
ExecutionContextHandle_t UniqueId
std::map< std::string, size_t > ee_index_map
std::map< std::string, interpolator * > ref_force_interpolator
std::vector< TimedDoubleSeq > m_force
std::vector< TimedDoubleSeq > m_ref_force_in
std::vector< InPort< TimedDoubleSeq > * > m_forceIn
RTC::CorbaPort m_ReferenceForceUpdaterServicePort
InPort< TimedDoubleSeq > m_qRefIn
TimedPoint3D m_diffFootOriginExtMoment
OutPort< TimedBoolean > m_refFootOriginExtMomentIsHoldValueOut
std::vector< OutPort< TimedDoubleSeq > * > m_ref_forceOut
std::vector< double > transition_interpolator_ratio
#define eps
std::vector< hrp::Vector3 > ref_force
boost::shared_ptr< FirstOrderLowPassFilter< hrp::Vector3 > > act_force_filter
std::map< std::string, ReferenceForceUpdaterParam > m_RFUParam
std::map< std::string, interpolator * > transition_interpolator
void ReferenceForceUpdaterInit(RTC::Manager *manager)
#define eps_eq(a, b, epsilon)


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51