12 #include <hrpModel/ModelLoaderUtil.h> 19 "implementation_id",
"VirtualForceSensor",
20 "type_name",
"VirtualForceSensor",
21 "description",
"null component",
22 "version", HRPSYS_PACKAGE_VERSION,
24 "category",
"example",
25 "activity_type",
"DataFlowComponent",
28 "lang_type",
"compile",
30 "conf.default.debugLevel",
"0",
38 m_qCurrentIn(
"qCurrent", m_qCurrent),
39 m_tauInIn(
"tauIn", m_tauIn),
40 m_VirtualForceSensorServicePort(
"VirtualForceSensorService"),
55 std::cerr <<
"[" <<
m_profile.instance_name <<
"] onInitialize()" << std::endl;
86 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
87 int comPos = nameServer.find(
",");
89 comPos = nameServer.length();
91 nameServer = nameServer.substr(0, comPos);
94 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
96 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"] in " 98 return RTC::RTC_ERROR;
103 for(
unsigned int i = 0;
i < virtual_force_sensor.size()/10;
i++ ){
104 std::string
name = virtual_force_sensor[
i*10+0];
109 for (
int j = 0; j < 7; j++ ) {
113 p.
R = Eigen::AngleAxis<double>(tr[6],
hrp::Vector3(tr[3],tr[4],tr[5])).toRotationMatrix();
116 std::cerr <<
"[" <<
m_profile.instance_name <<
"] virtual force sensor : " << name << std::endl;
117 std::cerr <<
"[" <<
m_profile.instance_name <<
"] base : " << p.
base_name << std::endl;
119 std::cerr <<
"[" <<
m_profile.instance_name <<
"] T, R : " << p.
p[0] <<
" " << p.
p[1] <<
" " << p.
p[2] << std::endl << p.
R << std::endl;
123 std::cerr <<
"[" <<
m_profile.instance_name <<
"] ERROR : Unknown link path " <<
m_sensors[name].base_name <<
" " <<
m_sensors[name].target_name << std::endl;
124 return RTC::RTC_ERROR;
131 std::map<std::string, VirtualForceSensorParam>::iterator it =
m_sensors.begin();
167 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onActivated(" << ec_id <<
")" << std::endl;
173 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onDeactivated(" << ec_id <<
")" << std::endl;
177 #define DEBUGP ((m_debugLevel==1 && loop%200==0) || m_debugLevel > 1 ) 186 tm.sec = coiltm.
sec();
187 tm.nsec = coiltm.
usec()*1000;
199 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++ ){
202 m_robot->calcForwardKinematics();
204 m_robot->rootLink()->calcSubMassCM();
206 std::map<std::string, VirtualForceSensorParam>::iterator it =
m_sensors.begin();
211 int n = path->numJoints();
214 std::cerr <<
" sensor name : " << (*it).first << std::endl;
215 std::cerr <<
"sensor torque : ";
216 for (
int j = 0; j < n; j++) {
217 std::cerr <<
" " <<
m_tauIn.data[path->joint(j)->jointId] ;
219 std::cerr << std::endl;
226 std::cerr <<
" raw force : ";
227 for (
int j = 0; j < 6; j ++ ) {
228 std::cerr <<
" " << force[j] ;
230 std::cerr << std::endl;
234 for (
int j = 0; j < 3; j ++ ) {
235 force_p[j] = force[j];
236 force_r[j] = force[j+3];
238 force_p = force_p - (*it).second.forceOffset;
239 force_r = force_r - (*it).second.momentOffset;
240 for (
int j = 0; j < 3; j ++ ) {
241 m_force[i].data[j+0] = force_p[j];
242 m_force[i].data[j+3] = force_r[j];
246 std::cerr <<
" output force : ";
247 for (
int j = 0; j < 6; j++) {
248 std::cerr <<
" " <<
m_force[i].data[j];
250 std::cerr << std::endl;
260 (:calc-force-from-joint-torque
261 (limb all-torque &key (move-target (send
self limb :end-coords)) (use-torso))
263 (send
self :link-list
264 (send move-target :parent)
265 (unless use-torso (car (send
self limb :links)))))
267 (send
self :calc-jacobian-from-link-list
269 :move-target move-target
270 :rotation-axis (list
t)
271 :translation-axis (list t)))
272 (torque (instantiate
float-vector (
length link-list))))
273 (dotimes (i (
length link-list))
275 (elt all-torque (
position (send (elt link-list i) :joint) (send
self :joint-list)))))
276 (transform (send
self :calc-
inverse-jacobian (transpose jacobian))
321 std::map<std::string, VirtualForceSensorParam>::iterator it;
323 if ((*it).first != sensorName){
332 for (
int i = 0;
i < 3;
i ++ ) {
333 force_p[
i] = force[
i];
334 force_r[
i] = force[
i+3];
336 (*it).second.forceOffset = force_p;
337 (*it).second.momentOffset = force_r;
341 std::cerr <<
"removeVirtualForceSensorOffset: No sensor " << sensorName << std::endl;
347 std::map<std::string, VirtualForceSensorParam>::iterator it;
349 if ((*it).first != sensorName){
353 int n = path->numJoints();
356 path->calcJacobian(J);
366 for (
int i = 0;
i < n;
i++) {
367 torque[
i] = -
m_tauIn.data[path->joint(
i)->jointId];
371 force = Jtinv * torque;
376 for (
int i = 0;
i < 3;
i++) {
377 force_p[
i] = force[
i];
378 force_r[
i] = force[
i + 3];
380 force_p = (*it).second.R.transpose() * path->endLink()->R.transpose() * force_p;
381 force_r = (*it).second.R.transpose() * path->endLink()->R.transpose() * force_r;
383 outputForce.resize(6);
384 for(
int i = 0;
i < 3;
i++) {
385 outputForce[
i] = force_p[
i];
386 outputForce[
i + 3] = force_r[
i];
392 std::cerr <<
"calcVirtualForce: No sensor " << sensorName << std::endl;
404 RTC::Create<VirtualForceSensor>,
405 RTC::Delete<VirtualForceSensor>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
InPort< TimedDoubleSeq > m_tauInIn
bool calcRawVirtualForce(std::string sensorName, hrp::dvector &outputForce)
bool stringTo(To &val, const char *str)
png_infop png_charpp name
virtual ~VirtualForceSensor()
Destructor.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
png_bytep png_bytep png_size_t length
dmatrix inverse(const dmatrix &M)
coil::Properties & getProperties()
static Manager & instance()
unsigned int m_debugLevel
static const char * virtualforcesensor_spec[]
boost::shared_ptr< Body > BodyPtr
std::vector< std::string > vstring
int gettimeofday(struct timeval *tv, struct timezone *tz)
coil::Properties & getConfig()
std::vector< TimedDoubleSeq > m_force
ExecutionContextHandle_t UniqueId
bool removeVirtualForceSensorOffset(std::string sensorName)
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
std::vector< OutPort< TimedDoubleSeq > * > m_forceOut
int calcPseudoInverse(const dmatrix &_a, dmatrix &_a_pseu, double _sv_ratio)
InPort< TimedDoubleSeq > m_qCurrentIn
virtual RTC::ReturnCode_t onInitialize()
bool addPort(PortBase &port)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
void vfsensor(VirtualForceSensor *i_vfsensor)
VirtualForceSensorService_impl m_service0
boost::shared_ptr< JointPath > JointPathPtr
RTC::CorbaPort m_VirtualForceSensorServicePort
VirtualForceSensor(RTC::Manager *manager)
Constructor.
bool addInPort(const char *name, InPortBase &inport)
void registerOutPort(const char *name, OutPortBase &outport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void VirtualForceSensorInit(RTC::Manager *manager)
TimedDoubleSeq m_qCurrent
std::map< std::string, VirtualForceSensorParam > m_sensors
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
hrp::Vector3 momentOffset