Go to the documentation of this file.00001
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
00030
00031
00032
00033 #include "ReferenceForceUpdaterService_impl.h"
00034
00035
00036
00037
00038
00039
00040
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
00062
00063 virtual RTC::ReturnCode_t onInitialize();
00064
00065
00066
00067 virtual RTC::ReturnCode_t onFinalize();
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
00080
00081
00082
00083 virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00084
00085
00086
00087 virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
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
00126
00127
00128
00129
00130
00131
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
00148
00149
00150
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
00159
00160
00161
00162
00163
00164
00165
00166
00167 RTC::CorbaPort m_ReferenceForceUpdaterServicePort;
00168
00169
00170
00171
00172
00173 ReferenceForceUpdaterService_impl m_ReferenceForceUpdaterService;
00174
00175
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
00185 double update_freq;
00186
00187 double update_time_ratio;
00188
00189 double p_gain;
00190
00191 double d_gain;
00192
00193 double i_gain;
00194
00195 double transition_time;
00196
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
00211 motion_dir = hrp::Vector3::UnitZ();
00212 frame="local";
00213 update_freq = 50;
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
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;
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