ObjectContactTurnaroundDetector.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #include <rtm/CorbaNaming.h>
00011 #include <hrpModel/Link.h>
00012 #include <hrpModel/Sensor.h>
00013 #include <hrpModel/ModelLoaderUtil.h>
00014 #include "ObjectContactTurnaroundDetector.h"
00015 #include "../ImpedanceController/RatsMatrix.h"
00016 #include "hrpsys/util/Hrpsys.h"
00017 #include <boost/assign.hpp>
00018 
00019 typedef coil::Guard<coil::Mutex> Guard;
00020 
00021 // Module specification
00022 // <rtc-template block="module_spec">
00023 static const char* objectcontactturnarounddetector_spec[] =
00024     {
00025         "implementation_id", "ObjectContactTurnaroundDetector",
00026         "type_name",         "ObjectContactTurnaroundDetector",
00027         "description",       "object contact turnaround detector component",
00028         "version",           HRPSYS_PACKAGE_VERSION,
00029         "vendor",            "AIST",
00030         "category",          "example",
00031         "activity_type",     "DataFlowComponent",
00032         "max_instance",      "10",
00033         "language",          "C++",
00034         "lang_type",         "compile",
00035         // Configuration variables
00036         "conf.default.debugLevel", "0",
00037         ""
00038     };
00039 // </rtc-template>
00040 
00041 ObjectContactTurnaroundDetector::ObjectContactTurnaroundDetector(RTC::Manager* manager)
00042     : RTC::DataFlowComponentBase(manager),
00043       // <rtc-template block="initializer">
00044       m_qCurrentIn("qCurrent", m_qCurrent),
00045       m_rpyIn("rpy", m_rpy),
00046       m_contactStatesIn("contactStates", m_contactStates),
00047       m_otdDataOut("otdData", m_otdData),
00048       m_ObjectContactTurnaroundDetectorServicePort("ObjectContactTurnaroundDetectorService"),
00049       // </rtc-template>
00050       m_robot(hrp::BodyPtr()),
00051       m_debugLevel(0),
00052       dummy(0)
00053 {
00054     m_service0.otd(this);
00055 }
00056 
00057 ObjectContactTurnaroundDetector::~ObjectContactTurnaroundDetector()
00058 {
00059 }
00060 
00061 
00062 RTC::ReturnCode_t ObjectContactTurnaroundDetector::onInitialize()
00063 {
00064     std::cerr << "[" << m_profile.instance_name << "] onInitialize()" << std::endl;
00065     bindParameter("debugLevel", m_debugLevel, "0");
00066 
00067     // Registration: InPort/OutPort/Service
00068     // <rtc-template block="registration">
00069     // Set InPort buffers
00070     addInPort("qCurrent", m_qCurrentIn);
00071     addInPort("rpy", m_rpyIn);
00072     addInPort("contactStates", m_contactStatesIn);
00073 
00074     // Set OutPort buffer
00075     addOutPort("otdData", m_otdDataOut);
00076   
00077     // Set service provider to Ports
00078     m_ObjectContactTurnaroundDetectorServicePort.registerProvider("service0", "ObjectContactTurnaroundDetectorService", m_service0);
00079   
00080     // Set service consumers to Ports
00081   
00082     // Set CORBA Service Ports
00083     addPort(m_ObjectContactTurnaroundDetectorServicePort);
00084   
00085     // </rtc-template>
00086     // <rtc-template block="bind_config">
00087     // Bind variables and configuration variable
00088   
00089     // </rtc-template>
00090 
00091     RTC::Properties& prop = getProperties();
00092     coil::stringTo(m_dt, prop["dt"].c_str());
00093 
00094     m_robot = hrp::BodyPtr(new hrp::Body());
00095 
00096     RTC::Manager& rtcManager = RTC::Manager::instance();
00097     std::string nameServer = rtcManager.getConfig()["corba.nameservers"];
00098     int comPos = nameServer.find(",");
00099     if (comPos < 0){
00100         comPos = nameServer.length();
00101     }
00102     nameServer = nameServer.substr(0, comPos);
00103     RTC::CorbaNaming naming(rtcManager.getORB(), nameServer.c_str());
00104     if (!loadBodyFromModelLoader(m_robot, prop["model"].c_str(), 
00105                                  CosNaming::NamingContext::_duplicate(naming.getRootContext())
00106                                  )){
00107       std::cerr << "[" << m_profile.instance_name << "] failed to load model[" << prop["model"] << "]" << std::endl;
00108       return RTC::RTC_ERROR;
00109     }
00110 
00111 
00112     // Setting for wrench data ports (real)
00113     std::vector<std::string> fsensor_names;
00114     //   find names for real force sensors
00115     unsigned int npforce = m_robot->numSensors(hrp::Sensor::FORCE);
00116     for (unsigned int i=0; i<npforce; i++){
00117         fsensor_names.push_back(m_robot->sensor(hrp::Sensor::FORCE, i)->name);
00118     }
00119     //   add ports for all force sensors
00120     unsigned int nforce  = npforce;
00121     m_force.resize(nforce);
00122     m_forceIn.resize(nforce);
00123     std::cerr << "[" << m_profile.instance_name << "] force sensor ports" << std::endl;
00124     for (unsigned int i=0; i<nforce; i++){
00125         m_forceIn[i] = new InPort<TimedDoubleSeq>(fsensor_names[i].c_str(), m_force[i]);
00126         m_force[i].data.length(6);
00127         registerInPort(fsensor_names[i].c_str(), *m_forceIn[i]);
00128         std::cerr << "[" << m_profile.instance_name << "]   name = " << fsensor_names[i] << std::endl;
00129     }
00130 
00131     unsigned int dof = m_robot->numJoints();
00132     for ( unsigned int i = 0 ; i < dof; i++ ){
00133       if ( (int)i != m_robot->joint(i)->jointId ) {
00134         std::cerr << "[" << m_profile.instance_name << "] jointId is not equal to the index number" << std::endl;
00135         return RTC::RTC_ERROR;
00136       }
00137     }
00138 
00139     // setting from conf file
00140     // rleg,TARGET_LINK,BASE_LINK,x,y,z,rx,ry,rz,rth #<=pos + rot (axis+angle)
00141     coil::vstring end_effectors_str = coil::split(prop["end_effectors"], ",");
00142     std::map<std::string, std::string> base_name_map;
00143     if (end_effectors_str.size() > 0) {
00144         size_t prop_num = 10;
00145         size_t num = end_effectors_str.size()/prop_num;
00146         for (size_t i = 0; i < num; i++) {
00147             std::string ee_name, ee_target, ee_base;
00148             coil::stringTo(ee_name, end_effectors_str[i*prop_num].c_str());
00149             coil::stringTo(ee_target, end_effectors_str[i*prop_num+1].c_str());
00150             coil::stringTo(ee_base, end_effectors_str[i*prop_num+2].c_str());
00151             ee_trans eet;
00152             for (size_t j = 0; j < 3; j++) {
00153                 coil::stringTo(eet.localPos(j), end_effectors_str[i*prop_num+3+j].c_str());
00154             }
00155             double tmpv[4];
00156             for (int j = 0; j < 4; j++ ) {
00157                 coil::stringTo(tmpv[j], end_effectors_str[i*prop_num+6+j].c_str());
00158             }
00159             eet.localR = Eigen::AngleAxis<double>(tmpv[3], hrp::Vector3(tmpv[0], tmpv[1], tmpv[2])).toRotationMatrix(); // rotation in VRML is represented by axis + angle
00160             eet.target_name = ee_target;
00161             eet.index = i;
00162             ee_map.insert(std::pair<std::string, ee_trans>(ee_name , eet));
00163             base_name_map.insert(std::pair<std::string, std::string>(ee_name, ee_base));
00164             std::cerr << "[" << m_profile.instance_name << "] End Effector [" << ee_name << "]" << ee_target << " " << ee_base << std::endl;
00165             std::cerr << "[" << m_profile.instance_name << "]   target = " << ee_target << ", base = " << ee_base << std::endl;
00166             std::cerr << "[" << m_profile.instance_name << "]   localPos = " << eet.localPos.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", ", ", "", "", "    [", "]")) << "[m]" << std::endl;
00167             std::cerr << "[" << m_profile.instance_name << "]   localR = " << eet.localR.format(Eigen::IOFormat(Eigen::StreamPrecision, 0, ", ", "\n", "    [", "]")) << std::endl;
00168         }
00169         m_contactStates.data.length(num);
00170     }
00171 
00172     // initialize sensor_names
00173     std::cerr << "[" << m_profile.instance_name << "] Add sensor_names" << std::endl;
00174     for (unsigned int i=0; i<m_forceIn.size(); i++){
00175         std::string sensor_name = m_forceIn[i]->name();
00176         hrp::ForceSensor* sensor = m_robot->sensor<hrp::ForceSensor>(sensor_name);
00177         std::string sensor_link_name;
00178         if ( sensor ) {
00179             // real force sensor
00180             sensor_link_name = sensor->link->name;
00181         } else {
00182             std::cerr << "[" << m_profile.instance_name << "]   unknown force param" << std::endl;
00183             continue;
00184         }
00185         // 1. Check whether adequate ee_map exists for the sensor.
00186         std::string ee_name;
00187         bool is_ee_exists = false;
00188         for ( std::map<std::string, ee_trans>::iterator it = ee_map.begin(); it != ee_map.end(); it++ ) {
00189             hrp::Link* alink = m_robot->link(it->second.target_name);
00190             std::string tmp_base_name = base_name_map[it->first];
00191             while (alink != NULL && alink->name != tmp_base_name && !is_ee_exists) {
00192                 if ( alink->name == sensor_link_name ) {
00193                     is_ee_exists = true;
00194                     ee_name = it->first;
00195                 }
00196                 alink = alink->parent;
00197             }
00198         }
00199         if (!is_ee_exists) {
00200             std::cerr << "[" << m_profile.instance_name << "]   No such ee setting for " << sensor_name << " and " << sensor_link_name << "!!. sensor_name for " << sensor_name << " cannot be added!!" << std::endl;
00201             continue;
00202         }
00203         // 4. Set impedance param
00204         ee_map[ee_name].sensor_name = sensor_name;
00205         std::cerr << "[" << m_profile.instance_name << "]   sensor = " << sensor_name << ", sensor-link = " << sensor_link_name << ", ee_name = " << ee_name << ", ee-link = " << ee_map[ee_name].target_name << std::endl;
00206     }
00207 
00208     otd = boost::shared_ptr<ObjectContactTurnaroundDetectorBase>(new ObjectContactTurnaroundDetectorBase(m_dt));
00209     otd->setPrintStr(std::string(m_profile.instance_name));
00210 
00211     // allocate memory for outPorts
00212     loop = 0;
00213     m_otdData.data.length(4); // mode, raw, filtered, dfiltered
00214 
00215     return RTC::RTC_OK;
00216 }
00217 
00218 
00219 
00220 RTC::ReturnCode_t ObjectContactTurnaroundDetector::onFinalize()
00221 {
00222     return RTC::RTC_OK;
00223 }
00224 
00225 /*
00226   RTC::ReturnCode_t ObjectContactTurnaroundDetector::onStartup(RTC::UniqueId ec_id)
00227   {
00228   return RTC::RTC_OK;
00229   }
00230 */
00231 
00232 /*
00233   RTC::ReturnCode_t ObjectContactTurnaroundDetector::onShutdown(RTC::UniqueId ec_id)
00234   {
00235   return RTC::RTC_OK;
00236   }
00237 */
00238 
00239 RTC::ReturnCode_t ObjectContactTurnaroundDetector::onActivated(RTC::UniqueId ec_id)
00240 {
00241     std::cerr << "[" << m_profile.instance_name<< "] onActivated(" << ec_id << ")" << std::endl;
00242     return RTC::RTC_OK;
00243 }
00244 
00245 RTC::ReturnCode_t ObjectContactTurnaroundDetector::onDeactivated(RTC::UniqueId ec_id)
00246 {
00247   std::cerr << "[" << m_profile.instance_name<< "] onDeactivated(" << ec_id << ")" << std::endl;
00248   return RTC::RTC_OK;
00249 }
00250 
00251 #define DEBUGP ((m_debugLevel==1 && loop%200==0) || m_debugLevel > 1 )
00252 RTC::ReturnCode_t ObjectContactTurnaroundDetector::onExecute(RTC::UniqueId ec_id)
00253 {
00254     //std::cout << "ObjectContactTurnaroundDetector::onExecute(" << ec_id << ")" << std::endl;
00255     loop ++;
00256 
00257     // check dataport input
00258     for (unsigned int i=0; i<m_forceIn.size(); i++){
00259         if ( m_forceIn[i]->isNew() ) {
00260             m_forceIn[i]->read();
00261         }
00262     }
00263     if (m_rpyIn.isNew()) {
00264       m_rpyIn.read();
00265     }
00266     if (m_qCurrentIn.isNew()) {
00267       m_qCurrentIn.read();
00268       m_otdData.tm = m_qCurrent.tm;
00269     }
00270     if (m_contactStatesIn.isNew()) {
00271       m_contactStatesIn.read();
00272     }
00273     if ( m_qCurrent.data.length() ==  m_robot->numJoints() &&
00274          ee_map.find("rleg") != ee_map.end() && ee_map.find("lleg") != ee_map.end() ) { // if legged robot
00275         Guard guard(m_mutex);
00276         calcObjectContactTurnaroundDetectorState();
00277         m_otdDataOut.write();
00278     }
00279     return RTC::RTC_OK;
00280 }
00281 
00282 /*
00283   RTC::ReturnCode_t ObjectContactTurnaroundDetector::onAborting(RTC::UniqueId ec_id)
00284   {
00285   return RTC::RTC_OK;
00286   }
00287 */
00288 
00289 /*
00290   RTC::ReturnCode_t ObjectContactTurnaroundDetector::onError(RTC::UniqueId ec_id)
00291   {
00292   return RTC::RTC_OK;
00293   }
00294 */
00295 
00296 /*
00297   RTC::ReturnCode_t ObjectContactTurnaroundDetector::onReset(RTC::UniqueId ec_id)
00298   {
00299   return RTC::RTC_OK;
00300   }
00301 */
00302 
00303 /*
00304   RTC::ReturnCode_t ObjectContactTurnaroundDetector::onStateUpdate(RTC::UniqueId ec_id)
00305   {
00306   return RTC::RTC_OK;
00307   }
00308 */
00309 
00310 /*
00311   RTC::ReturnCode_t ObjectContactTurnaroundDetector::onRateChanged(RTC::UniqueId ec_id)
00312   {
00313   return RTC::RTC_OK;
00314   }
00315 */
00316 
00317 void ObjectContactTurnaroundDetector::calcFootMidCoords (hrp::Vector3& new_foot_mid_pos, hrp::Matrix33& new_foot_mid_rot)
00318 {
00319   std::vector<hrp::Vector3> foot_pos;
00320   std::vector<hrp::Matrix33> foot_rot;
00321   std::vector<std::string> leg_names = boost::assign::list_of("rleg")("lleg");
00322   for (size_t i = 0; i < leg_names.size(); i++) {
00323     hrp::Link* target_link = m_robot->link(ee_map[leg_names[i]].target_name);
00324     foot_pos.push_back(target_link->p + target_link->R * ee_map[leg_names[i]].localPos);
00325     foot_rot.push_back(target_link->R * ee_map[leg_names[i]].localR);
00326   }
00327   new_foot_mid_pos = (foot_pos[0]+foot_pos[1])/2.0;
00328   rats::mid_rot(new_foot_mid_rot, 0.5, foot_rot[0], foot_rot[1]);
00329 }
00330 
00331 void ObjectContactTurnaroundDetector::calcFootOriginCoords (hrp::Vector3& foot_origin_pos, hrp::Matrix33& foot_origin_rot)
00332 {
00333   std::vector<rats::coordinates> leg_c_v;
00334   hrp::Vector3 ez = hrp::Vector3::UnitZ();
00335   hrp::Vector3 ex = hrp::Vector3::UnitX();
00336   std::vector<std::string> leg_names;
00337   for ( std::map<std::string, ee_trans>::iterator it = ee_map.begin(); it != ee_map.end(); it++ ) {
00338       // If rleg or lleg, and if reference contact states is true
00339       if (it->first.find("leg") != std::string::npos && m_contactStates.data[it->second.index]) leg_names.push_back(it->first);
00340   }
00341   for (size_t i = 0; i < leg_names.size(); i++) {
00342     hrp::Link* target_link = m_robot->link(ee_map[leg_names[i]].target_name);
00343     rats::coordinates leg_c(hrp::Vector3(target_link->p + target_link->R * ee_map[leg_names[i]].localPos), hrp::Matrix33(target_link->R * ee_map[leg_names[i]].localR));
00344     hrp::Vector3 xv1(leg_c.rot * ex);
00345     xv1(2)=0.0;
00346     xv1.normalize();
00347     hrp::Vector3 yv1(ez.cross(xv1));
00348     leg_c.rot(0,0) = xv1(0); leg_c.rot(1,0) = xv1(1); leg_c.rot(2,0) = xv1(2);
00349     leg_c.rot(0,1) = yv1(0); leg_c.rot(1,1) = yv1(1); leg_c.rot(2,1) = yv1(2);
00350     leg_c.rot(0,2) = ez(0); leg_c.rot(1,2) = ez(1); leg_c.rot(2,2) = ez(2);
00351     leg_c_v.push_back(leg_c);
00352   }
00353   if (leg_names.size() == 2) {
00354     rats::coordinates tmpc;
00355     rats::mid_coords(tmpc, 0.5, leg_c_v[0], leg_c_v[1]);
00356     foot_origin_pos = tmpc.pos;
00357     foot_origin_rot = tmpc.rot;
00358   } else { // size = 1
00359     foot_origin_pos = leg_c_v[0].pos;
00360     foot_origin_rot = leg_c_v[0].rot;
00361   }
00362 }
00363 
00364 void ObjectContactTurnaroundDetector::calcObjectContactTurnaroundDetectorState()
00365 {
00366     // TODO
00367     // Currently only for legged robots
00368     // Set actual state
00369     for ( unsigned int i = 0; i < m_robot->numJoints(); i++ ) {
00370         m_robot->joint(i)->q = m_qCurrent.data[i];
00371     }
00372     updateRootLinkPosRot(m_rpy);
00373     m_robot->calcForwardKinematics();
00374     // Calc
00375     std::vector<hrp::Vector3> otd_forces, otd_moments, otd_hposv;
00376     hrp::Vector3 fmpos;
00377     hrp::Matrix33 fmrot, fmrotT;
00378     //calcFootMidCoords(fmpos, fmrot);
00379     calcFootOriginCoords(fmpos, fmrot);
00380     fmrotT = fmrot.transpose();
00381     for (unsigned int i=0; i<m_forceIn.size(); i++) {
00382         std::string sensor_name = m_forceIn[i]->name();
00383         if ( find(otd_sensor_names.begin(), otd_sensor_names.end(), sensor_name) != otd_sensor_names.end() ) {
00384             hrp::ForceSensor* sensor = m_robot->sensor<hrp::ForceSensor>(sensor_name);
00385             hrp::Vector3 data_p(m_force[i].data[0], m_force[i].data[1], m_force[i].data[2]);
00386             hrp::Vector3 data_r(m_force[i].data[3], m_force[i].data[4], m_force[i].data[5]);
00387             hrp::Matrix33 sensorR = sensor->link->R * sensor->localR;
00388             otd_forces.push_back(fmrotT*(sensorR*data_p));
00389             otd_moments.push_back(fmrotT*(sensorR*data_r));
00390             hrp::Vector3 eePos;
00391             for ( std::map<std::string, ee_trans>::iterator it = ee_map.begin(); it != ee_map.end(); it++ ) {
00392                 if ( it->second.sensor_name == sensor_name ) {
00393                     ee_trans& eet = it->second;
00394                     hrp::Link* target_link = m_robot->link(eet.target_name);
00395                     eePos = fmrotT * (target_link->p + target_link->R * eet.localPos - fmpos);
00396                 }
00397             }
00398             otd_hposv.push_back(eePos);
00399         }
00400     }
00401     otd->checkDetection(otd_forces, otd_moments, otd_hposv);
00402     // otdData
00403     m_otdData.data[0] = static_cast<double>(otd->getMode());
00404     m_otdData.data[1] = otd->getRawWrench();
00405     m_otdData.data[2] = otd->getFilteredWrench();
00406     m_otdData.data[3] = otd->getFilteredDwrench();
00407 };
00408 
00409 //
00410 
00411 void ObjectContactTurnaroundDetector::updateRootLinkPosRot (TimedOrientation3D tmprpy)
00412 {
00413   if ( m_robot->numSensors(hrp::Sensor::ACCELERATION) > 0) {
00414       hrp::Sensor *sensor = m_robot->sensor(hrp::Sensor::ACCELERATION, 0);
00415       hrp::Matrix33 tmpr;
00416       rats::rotm3times(tmpr, hrp::Matrix33(sensor->link->R*sensor->localR).transpose(), m_robot->rootLink()->R);
00417       rats::rotm3times(m_robot->rootLink()->R, hrp::rotFromRpy(tmprpy.data.r, tmprpy.data.p, tmprpy.data.y), tmpr);
00418       m_robot->rootLink()->p = hrp::Vector3::Zero();
00419   }
00420 }
00421 
00422 //
00423 // ObjectContactTurnaroundDetector
00424 //
00425 
00426 void ObjectContactTurnaroundDetector::startObjectContactTurnaroundDetection(const double i_ref_diff_wrench, const double i_max_time, const OpenHRP::ObjectContactTurnaroundDetectorService::StrSequence& i_ee_names)
00427 {
00428     Guard guard(m_mutex);
00429     otd->startDetection(i_ref_diff_wrench, i_max_time);
00430     otd_sensor_names.clear();
00431     for (size_t i = 0; i < i_ee_names.length(); i++) {
00432         otd_sensor_names.push_back(ee_map[std::string(i_ee_names[i])].sensor_name);
00433     }
00434 }
00435 
00436 OpenHRP::ObjectContactTurnaroundDetectorService::DetectorMode ObjectContactTurnaroundDetector::checkObjectContactTurnaroundDetection()
00437 {
00438     OpenHRP::ObjectContactTurnaroundDetectorService::DetectorMode tmpmode;
00439     switch (otd->getMode()) {
00440     case ObjectContactTurnaroundDetectorBase::MODE_IDLE:
00441         tmpmode = ObjectContactTurnaroundDetectorService::MODE_DETECTOR_IDLE;
00442         break;
00443     case ObjectContactTurnaroundDetectorBase::MODE_STARTED:
00444         tmpmode = ObjectContactTurnaroundDetectorService::MODE_STARTED;
00445         break;
00446     case ObjectContactTurnaroundDetectorBase::MODE_DETECTED:
00447         tmpmode = ObjectContactTurnaroundDetectorService::MODE_DETECTED;
00448         break;
00449     case ObjectContactTurnaroundDetectorBase::MODE_MAX_TIME:
00450         tmpmode = ObjectContactTurnaroundDetectorService::MODE_MAX_TIME;
00451         break;
00452     default:
00453         tmpmode = ObjectContactTurnaroundDetectorService::MODE_DETECTOR_IDLE;
00454         break;
00455     }
00456     return tmpmode;
00457 }
00458 
00459 bool ObjectContactTurnaroundDetector::setObjectContactTurnaroundDetectorParam(const OpenHRP::ObjectContactTurnaroundDetectorService::objectContactTurnaroundDetectorParam &i_param_)
00460 {
00461     Guard guard(m_mutex);
00462     std::cerr << "[" << m_profile.instance_name << "] setObjectContactTurnaroundDetectorParam" << std::endl;
00463     otd->setWrenchCutoffFreq(i_param_.wrench_cutoff_freq);
00464     otd->setDwrenchCutoffFreq(i_param_.dwrench_cutoff_freq);
00465     otd->setDetectRatioThre(i_param_.detect_ratio_thre);
00466     otd->setStartRatioThre(i_param_.start_ratio_thre);
00467     otd->setDetectTimeThre(i_param_.detect_time_thre);
00468     otd->setStartTimeThre(i_param_.start_time_thre);
00469     hrp::Vector3 tmp;
00470     for (size_t i = 0; i < 3; i++) tmp(i) = i_param_.axis[i];
00471     otd->setAxis(tmp);
00472     for (size_t i = 0; i < 3; i++) tmp(i) = i_param_.moment_center[i];
00473     otd->setMomentCenter(tmp);
00474     ObjectContactTurnaroundDetectorBase::detector_total_wrench dtw;
00475     switch (i_param_.detector_total_wrench) {
00476     case OpenHRP::ObjectContactTurnaroundDetectorService::TOTAL_FORCE:
00477         dtw = ObjectContactTurnaroundDetectorBase::TOTAL_FORCE;
00478         break;
00479     case OpenHRP::ObjectContactTurnaroundDetectorService::TOTAL_MOMENT:
00480         dtw = ObjectContactTurnaroundDetectorBase::TOTAL_MOMENT;
00481         break;
00482     case OpenHRP::ObjectContactTurnaroundDetectorService::TOTAL_MOMENT2:
00483         dtw = ObjectContactTurnaroundDetectorBase::TOTAL_MOMENT2;
00484         break;
00485     default:
00486         break;
00487     }
00488     otd->setDetectorTotalWrench(dtw);
00489     otd->printParams();
00490     return true;
00491 };
00492 
00493 bool ObjectContactTurnaroundDetector::getObjectContactTurnaroundDetectorParam(OpenHRP::ObjectContactTurnaroundDetectorService::objectContactTurnaroundDetectorParam& i_param_)
00494 {
00495     std::cerr << "[" << m_profile.instance_name << "] getObjectContactTurnaroundDetectorParam" << std::endl;
00496     i_param_.wrench_cutoff_freq = otd->getWrenchCutoffFreq();
00497     i_param_.dwrench_cutoff_freq = otd->getDwrenchCutoffFreq();
00498     i_param_.detect_ratio_thre = otd->getDetectRatioThre();
00499     i_param_.start_ratio_thre = otd->getStartRatioThre();
00500     i_param_.detect_time_thre = otd->getDetectTimeThre();
00501     i_param_.start_time_thre = otd->getStartTimeThre();
00502     hrp::Vector3 tmp = otd->getAxis();
00503     for (size_t i = 0; i < 3; i++) i_param_.axis[i] = tmp(i);
00504     tmp = otd->getMomentCenter();
00505     for (size_t i = 0; i < 3; i++) i_param_.moment_center[i] = tmp(i);
00506     OpenHRP::ObjectContactTurnaroundDetectorService::DetectorTotalWrench dtw;
00507     switch (otd->getDetectorTotalWrench()) {
00508     case ObjectContactTurnaroundDetectorBase::TOTAL_FORCE:
00509         dtw = OpenHRP::ObjectContactTurnaroundDetectorService::TOTAL_FORCE;
00510         break;
00511     case ObjectContactTurnaroundDetectorBase::TOTAL_MOMENT:
00512         dtw = OpenHRP::ObjectContactTurnaroundDetectorService::TOTAL_MOMENT;
00513         break;
00514     case ObjectContactTurnaroundDetectorBase::TOTAL_MOMENT2:
00515         dtw = OpenHRP::ObjectContactTurnaroundDetectorService::TOTAL_MOMENT2;
00516         break;
00517     default:
00518         break;
00519     }
00520     i_param_.detector_total_wrench = dtw;
00521     return true;
00522 }
00523 
00524 bool ObjectContactTurnaroundDetector::getObjectForcesMoments(OpenHRP::ObjectContactTurnaroundDetectorService::Dbl3Sequence_out o_forces, OpenHRP::ObjectContactTurnaroundDetectorService::Dbl3Sequence_out o_moments, OpenHRP::ObjectContactTurnaroundDetectorService::DblSequence3_out o_3dofwrench, double& o_fric_coeff_wrench)
00525 {
00526     std::cerr << "[" << m_profile.instance_name << "] getObjectForcesMoments" << std::endl;
00527     if (otd_sensor_names.size() == 0) return false;
00528     hrp::Vector3 tmpv = otd->getAxis() * otd->getFilteredWrench();
00529     o_forces = new OpenHRP::ObjectContactTurnaroundDetectorService::Dbl3Sequence ();
00530     o_moments = new OpenHRP::ObjectContactTurnaroundDetectorService::Dbl3Sequence ();
00531     o_forces->length(otd_sensor_names.size());
00532     o_moments->length(otd_sensor_names.size());
00533     for (size_t i = 0; i < o_forces->length(); i++) o_forces[i].length(3);
00534     for (size_t i = 0; i < o_moments->length(); i++) o_moments[i].length(3);
00535     // Temp
00536     for (size_t i = 0; i < otd_sensor_names.size(); i++) {
00537         o_forces[i][0] = tmpv(0)/otd_sensor_names.size();
00538         o_forces[i][1] = tmpv(1)/otd_sensor_names.size();
00539         o_forces[i][2] = tmpv(2)/otd_sensor_names.size();
00540         o_moments[i][0] = o_moments[i][1] = o_moments[i][2] = 0.0;
00541     }
00542     o_3dofwrench = new OpenHRP::ObjectContactTurnaroundDetectorService::DblSequence3 ();
00543     o_3dofwrench->length(3);
00544     for (size_t i = 0; i < 3; i++) (*o_3dofwrench)[i] = tmpv(i);
00545     o_fric_coeff_wrench = otd->getFilteredFrictionCoeffWrench();
00546     return true;
00547 }
00548 
00549 extern "C"
00550 {
00551 
00552     void ObjectContactTurnaroundDetectorInit(RTC::Manager* manager)
00553     {
00554         RTC::Properties profile(objectcontactturnarounddetector_spec);
00555         manager->registerFactory(profile,
00556                                  RTC::Create<ObjectContactTurnaroundDetector>,
00557                                  RTC::Delete<ObjectContactTurnaroundDetector>);
00558     }
00559 
00560 };


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:55