12 #include <hrpModel/ModelLoaderUtil.h> 14 #include <hrpModel/Sensor.h> 22 "implementation_id",
"RemoveForceSensorLinkOffset",
23 "type_name",
"RemoveForceSensorLinkOffset",
24 "description",
"null component",
25 "version", HRPSYS_PACKAGE_VERSION,
27 "category",
"example",
28 "activity_type",
"DataFlowComponent",
31 "lang_type",
"compile",
33 "conf.default.debugLevel",
"0",
41 m_qCurrentIn(
"qCurrent", m_qCurrent),
42 m_rpyIn(
"rpy", m_rpy),
43 m_RemoveForceSensorLinkOffsetServicePort(
"RemoveForceSensorLinkOffsetService"),
46 max_sensor_offset_calib_counter(0)
59 std::cerr <<
"[" <<
m_profile.instance_name <<
"] onInitialize()" << std::endl;
90 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
91 int comPos = nameServer.find(
",");
93 comPos = nameServer.length();
95 nameServer = nameServer.substr(0, comPos);
98 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
100 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" << std::endl;
101 return RTC::RTC_ERROR;
108 for (
unsigned int i = 0;
i < nforce;
i++) {
144 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onActivated(" << ec_id <<
")" << std::endl;
150 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onDeactivated(" << ec_id <<
")" << std::endl;
154 #define DEBUGP ((m_debugLevel==1 && loop%200==0) || m_debugLevel > 1 ) 170 rpy = hrp::Vector3::Zero();
174 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++ ){
179 m_robot->calcForwardKinematics();
183 std::string sensor_name =
m_forceIn[
i]->name();
188 std::cerr <<
"[" <<
m_profile.instance_name <<
"] wrench [" <<
m_forceIn[
i]->name() <<
"]" << std::endl;;
189 std::cerr <<
"[" <<
m_profile.instance_name <<
"] raw force = " << data_p.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) << std::endl;
190 std::cerr <<
"[" <<
m_profile.instance_name <<
"] raw moment = " << data_r.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) << std::endl;
215 for (
size_t j = 0;
j < 3;
j++) {
220 std::cerr <<
"[" <<
m_profile.instance_name <<
"] off force = " << fmp.
off_force.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) << std::endl;
221 std::cerr <<
"[" <<
m_profile.instance_name <<
"] off moment = " << fmp.
off_moment.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) << std::endl;
224 std::cerr <<
"[" <<
m_profile.instance_name <<
"] unknwon force param " << sensor_name << std::endl;
247 std::cerr <<
"[" <<
m_profile.instance_name <<
"] force_offset = " <<
m_forcemoment_offset_param[i_name_].force_offset.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[N]" << std::endl;
248 std::cerr <<
"[" <<
m_profile.instance_name <<
"] moment_offset = " <<
m_forcemoment_offset_param[i_name_].moment_offset.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[Nm]" << std::endl;
249 std::cerr <<
"[" <<
m_profile.instance_name <<
"] link_offset_centroid = " <<
m_forcemoment_offset_param[i_name_].link_offset_centroid.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"]")) <<
"[m]" << std::endl;
255 std::cerr <<
"[" <<
m_profile.instance_name <<
"] setForceMomentOffsetParam [" << i_name_ <<
"]" << std::endl;
259 memcpy(
m_forcemoment_offset_param[i_name_].link_offset_centroid.data(), i_param_.link_offset_centroid.get_buffer(),
sizeof(double) * 3);
264 std::cerr <<
"[" <<
m_profile.instance_name <<
"] No such limb"<< std::endl;
275 memcpy(i_param_.link_offset_centroid.get_buffer(),
m_forcemoment_offset_param[i_name_].link_offset_centroid.data(),
sizeof(double) * 3);
279 std::cerr <<
"[" <<
m_profile.instance_name <<
"] No such limb " << i_name_ <<
" in getForceMomentOffsetParam" << std::endl;
286 std::cerr <<
"[" <<
m_profile.instance_name <<
"] loadForceMomentOffsetParams" << std::endl;
287 std::ifstream
ifs(filename.c_str());
299 std::cerr <<
"[" <<
m_profile.instance_name <<
"] " << tmps <<
"" << std::endl;
302 std::cerr <<
"[" <<
m_profile.instance_name <<
"] no such (" << tmps <<
")" << std::endl;
308 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to open(" << filename <<
")" << std::endl;
316 std::cerr <<
"[" <<
m_profile.instance_name <<
"] dumpForceMomentOffsetParams" << std::endl;
317 std::ofstream ofs(filename.c_str());
320 ofs << it->first <<
" ";
321 ofs << it->second.force_offset[0] <<
" " << it->second.force_offset[1] <<
" " << it->second.force_offset[2] <<
" ";
322 ofs << it->second.moment_offset[0] <<
" " << it->second.moment_offset[1] <<
" " << it->second.moment_offset[2] <<
" ";
323 ofs << it->second.link_offset_centroid[0] <<
" " << it->second.link_offset_centroid[1] <<
" " << it->second.link_offset_centroid[2] <<
" ";
324 ofs << it->second.link_offset_mass << std::endl;
327 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to open(" << filename <<
")" << std::endl;
335 std::cerr <<
"[" <<
m_profile.instance_name <<
"] removeForceSensorOffset..." << std::endl;
338 std::vector<std::string> valid_names, invalid_names, calibrating_names;
339 bool is_valid_argument =
true;
342 if ( names.length() == 0 ) {
343 std::cerr <<
"[" <<
m_profile.instance_name <<
"] No sensor names are specified, calibrate all sensors = [";
345 valid_names.push_back(it->first);
346 std::cerr << it->first <<
" ";
348 std::cerr <<
"]" << std::endl;
350 for (
size_t i = 0;
i < names.length();
i++) {
351 std::string
name(names[
i]);
354 valid_names.push_back(name);
356 calibrating_names.push_back(name);
357 is_valid_argument =
false;
360 invalid_names.push_back(name);
361 is_valid_argument =
false;
367 if ( !is_valid_argument ) {
368 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Cannot start removeForceSensorOffset, invalid = [";
369 for (
size_t i = 0;
i < invalid_names.size();
i++) std::cerr << invalid_names[
i] <<
" ";
370 std::cerr <<
"], calibrating = [";
371 for (
size_t i = 0;
i < calibrating_names.size();
i++) std::cerr << calibrating_names[
i] <<
" ";
372 std::cerr <<
"]" << std::endl;
378 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Calibrate sensor names = [";
379 for (
size_t i = 0;
i < valid_names.size();
i++) std::cerr << valid_names[
i] <<
" ";
380 std::cerr <<
"]" << std::endl;
383 for (
size_t i = 0;
i < valid_names.size();
i++) {
384 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Offset-removed force before calib [" << valid_names[
i] <<
"], ";
385 std::cerr <<
"force = " <<
m_forcemoment_offset_param[valid_names[
i]].off_force.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"][N]")) <<
", ";
386 std::cerr <<
"moment = " <<
m_forcemoment_offset_param[valid_names[
i]].off_moment.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"][Nm]"));
387 std::cerr << std::endl;
390 for (
size_t i = 0;
i < valid_names.size();
i++) {
397 for (
size_t i = 0;
i < valid_names.size();
i++) {
403 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Calibrate done (calib time = " << tm <<
"[s])" << std::endl;
404 for (
size_t i = 0;
i < valid_names.size();
i++) {
405 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Calibrated offset [" << valid_names[
i] <<
"], ";
406 std::cerr <<
"force_offset = " <<
m_forcemoment_offset_param[valid_names[
i]].force_offset.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"][N]")) <<
", ";
407 std::cerr <<
"moment_offset = " <<
m_forcemoment_offset_param[valid_names[
i]].moment_offset.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"][Nm]")) << std::endl;
408 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Offset-removed force after calib [" << valid_names[
i] <<
"], ";
409 std::cerr <<
"force = " <<
m_forcemoment_offset_param[valid_names[
i]].off_force.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"][N]")) <<
", ";
410 std::cerr <<
"moment = " <<
m_forcemoment_offset_param[valid_names[
i]].off_moment.format(Eigen::IOFormat(Eigen::StreamPrecision, 0,
", ",
", ",
"",
"",
"[",
"][Nm]"));
411 std::cerr << std::endl;
414 std::cerr <<
"[" <<
m_profile.instance_name <<
"] removeForceSensorOffset...done" << std::endl;
460 RTC::Create<RemoveForceSensorLinkOffset>,
461 RTC::Delete<RemoveForceSensorLinkOffset>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
TimedDoubleSeq m_qCurrent
hrp::Vector3 force_offset
bool loadForceMomentOffsetParams(const std::string &filename)
bool dumpForceMomentOffsetParams(const std::string &filename)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
bool stringTo(To &val, const char *str)
InPort< TimedOrientation3D > m_rpyIn
static std::vector< std::vector< double > > force_offset
png_infop png_charpp name
InPort< TimedDoubleSeq > m_qCurrentIn
RemoveForceSensorLinkOffset(RTC::Manager *manager)
Constructor.
unsigned int m_debugLevel
hrp::Vector3 moment_offset_sum
int max_sensor_offset_calib_counter
coil::Properties & getProperties()
static Manager & instance()
bool removeForceSensorOffset(const ::OpenHRP::RemoveForceSensorLinkOffsetService::StrSequence &names, const double tm)
boost::shared_ptr< Body > BodyPtr
hrp::Vector3 force_offset_sum
RTC::CorbaPort m_RemoveForceSensorLinkOffsetServicePort
Matrix33 rotFromRpy(const Vector3 &rpy)
coil::Properties & getConfig()
void rotm3times(hrp::Matrix33 &m12, const hrp::Matrix33 &m1, const hrp::Matrix33 &m2)
ExecutionContextHandle_t UniqueId
std::vector< OutPort< TimedDoubleSeq > * > m_forceOut
virtual RTC::ReturnCode_t onInitialize()
std::vector< InPort< TimedDoubleSeq > * > m_forceIn
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
RemoveForceSensorLinkOffsetService_impl m_service0
def j(str, encoding="cp932")
std::map< std::string, ForceMomentOffsetParam > m_forcemoment_offset_param
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
void printForceMomentOffsetParam(const std::string &i_name_)
static const char * removeforcesensorlinkoffset_spec[]
bool setForceMomentOffsetParam(const std::string &i_name_, const OpenHRP::RemoveForceSensorLinkOffsetService::forcemomentOffsetParam &i_param_)
coil::Guard< coil::Mutex > Guard
bool getForceMomentOffsetParam(const std::string &i_name_, OpenHRP::RemoveForceSensorLinkOffsetService::forcemomentOffsetParam &i_param_)
hrp::Vector3 link_offset_centroid
void registerInPort(const char *name, InPortBase &inport)
std::vector< TimedDoubleSeq > m_force
bool addPort(PortBase &port)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
hrp::Vector3 moment_offset
bool addInPort(const char *name, InPortBase &inport)
int sensor_offset_calib_counter
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
void registerOutPort(const char *name, OutPortBase &outport)
void rmfsoff(RemoveForceSensorLinkOffset *i_rmfsoff)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void updateRootLinkPosRot(const hrp::Vector3 &rpy)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
virtual ~RemoveForceSensorLinkOffset()
Destructor.
void RemoveForceSensorLinkOffsetInit(RTC::Manager *manager)