16 #include <hrpCorba/OpenHRPCommon.hh> 33 const double sth = sin(a[3]);
34 const double vth = 1.0 - cos(a[3]);
40 const double axx = ax*ax*vth;
41 const double ayy = ay*ay*vth;
42 const double azz = az*az*vth;
43 const double axy = ax*ay*vth;
44 const double ayz = ay*az*vth;
45 const double azx = az*ax*vth;
51 mat(0,0) = 1.0 - azz - ayy;
55 mat(1,1) = 1.0 - azz - axx;
59 mat(2,2) = 1.0 - ayy - axx;
84 int numSensors = iSensors.length();
86 for(
int i=0;
i < numSensors; ++
i)
88 SensorInfo iSensor = iSensors[
i];
94 std::cerr <<
"Warning: sensor ID is not given to sensor " << iSensor.name
95 <<
"of character " << jnt->
CharName() <<
"." << std::endl;
98 int sensorType = Sensor::COMMON;
110 CORBA::String_var type0 = iSensor.type;
113 if( type ==
"Force" ) { sensorType = Sensor::FORCE; }
114 else if( type ==
"RateGyro" ) { sensorType = Sensor::RATE_GYRO; }
115 else if( type ==
"Acceleration" ) { sensorType = Sensor::ACCELERATION; }
116 else if( type ==
"Vision" ) { sensorType = Sensor::VISION; }
119 CORBA::String_var name0 = iSensor.name;
121 const DblArray3& p = iSensor.translation;
122 static fVec3 localPos;
125 const DblArray4& rot = iSensor.rotation;
127 world->
addSensor(jnt, sensorType,
id, name, localPos, localR);
132 static inline double getLimitValue(DblSequence_var limitseq,
double defaultValue)
134 return (limitseq->length() == 0) ? defaultValue : limitseq[0];
141 LinkInfo iLink = iLinks[index];
144 CORBA::String_var
name = iLink.name;
149 myname = std::string(name) + std::string(sep) + std::string(charname);
154 int jointId = iLink.jointId;
157 CORBA::String_var jointType = iLink.jointType;
158 const std::string jt(jointType);
164 else if(jt ==
"free")
168 else if(jt ==
"rotate")
172 else if(jt ==
"slide")
185 std::cerr <<
"Warning: Joint ID is not given to joint " << jnt->
name 186 <<
" of character " << charname <<
"." << std::endl;
190 const DblArray3&
t =iLink.translation;
191 static fVec3 rel_pos;
194 const DblArray4& r = iLink.rotation;
202 const DblArray3&
a = iLink.jointAxis;
203 static fVec3 loc_axis;
211 p_axis.
mul(rel_att, loc_axis);
213 x.
set(1.0, 0.0, 0.0);
214 y.
set(0.0, 1.0, 0.0);
215 double zx = p_axis*
x;
225 double yz = y*p_axis;
231 init_att(0,0) =
x(0); init_att(1,0) =
x(1); init_att(2,0) =
x(2);
232 init_att(0,1) =
y(0); init_att(1,1) =
y(1); init_att(2,1) =
y(2);
233 init_att(0,2) = p_axis(0); init_att(1,2) = p_axis(1); init_att(2,2) = p_axis(2);
241 if(loc_axis(0) > 0.95) axis =
AXIS_X;
242 else if(loc_axis(1) > 0.95) axis =
AXIS_Y;
243 else if(loc_axis(2) > 0.95) axis =
AXIS_Z;
245 std::cerr <<
"unsupported joint axis for " << myname
246 <<
", only X, Y and Z axes are supported" << std::endl;
271 jnt->
mass = iLink.mass;
302 const DblArray3& rc = iLink.centerOfMass;
307 const DblArray9& I = iLink.inertia;
315 for(
unsigned int i = 0 ;
i < iLinks[index].childIndices.length() ;
i++ )
317 if( 0 <= iLinks[index].childIndices[
i] )
319 createLink(world, charname, iLinks[index].childIndices[i], iLinks, jnt);
340 CORBA::String_var
name = _name;
342 int n = bodyInfo->links()->length();
343 LinkInfoSequence_var iLinks = bodyInfo->links();
346 for(
int i=0;
i <
n; ++
i)
348 if(iLinks[
i].parentIndex < 0)
361 matrix33 Rs(tvmet::identity<matrix33>());
362 Link* rootLink =
createLink(body, rootIndex, iLinks, Rs, importLinkShape);
363 body->setRootLink(rootLink);
365 DblArray3_var p = iLinks[rootIndex]->translation();
366 vector3 pos(p[0u], p[1u], p[2u]);
367 const DblArray4 &R = iLinks[rootIndex]->rotation();
370 body->setDefaultRootPosition(pos, att);
372 body->installCustomizer();
374 body->initializeConfiguration();
386 CosNaming::Name ncName;
388 ncName[0].id = CORBA::string_dup(
"ModelLoader");
389 ncName[0].kind = CORBA::string_dup(
"");
390 ModelLoader_var modelLoader = NULL;
392 modelLoader = ModelLoader::_narrow(cxt->resolve(ncName));
394 std::cerr <<
"ModelLoader not found: ";
396 case CosNaming::NamingContext::missing_node:
397 std::cerr <<
"Missing Node" << std::endl;
398 case CosNaming::NamingContext::not_context:
399 std::cerr <<
"Not Context" << std::endl;
401 case CosNaming::NamingContext::not_object:
402 std::cerr <<
"Not Object" << std::endl;
406 }
catch(CosNaming::NamingContext::CannotProceed &exc) {
407 std::cerr <<
"Resolve ModelLoader CannotProceed" << std::endl;
408 }
catch(CosNaming::NamingContext::AlreadyBound &exc) {
409 std::cerr <<
"Resolve ModelLoader InvalidName" << std::endl;
412 BodyInfo_var bodyInfo;
414 bodyInfo = modelLoader->getBodyInfo(url);
415 }
catch(CORBA::SystemException& ex) {
416 std::cerr <<
"CORBA::SystemException raised by ModelLoader: " << ex._rep_id() << std::endl;
418 }
catch(ModelLoader::ModelLoaderException& ex){
419 std::cerr <<
"ModelLoaderException ( " << ex.description <<
") : " << ex.description << std::endl;
422 if(CORBA::is_nil(bodyInfo)){
432 CosNaming::NamingContext_var cxt;
434 CORBA::Object_var nS = orb->resolve_initial_references(
"NameService");
435 cxt = CosNaming::NamingContext::_narrow(nS);
436 }
catch(CORBA::SystemException& ex) {
437 std::cerr <<
"NameService doesn't exist" << std::endl;
447 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
454 vector<string> argvec;
458 argvec.push_back(arg);
460 int argc = argvec.size();
461 char **argv =
new char *[argc];
462 for (
int i=0;
i<argc;
i++){
463 argv[
i] = (
char *)argvec[
i].c_str();
png_infop png_charp png_int_32 png_int_32 int * type
Joint * AddRoot(const char *name=0, const fVec3 &grav=fVec3(0.0, 0.0, 9.8))
Add the (unique) root joint.
static void array_to_mat33(const DblArray4 &a, fMat33 &mat)
void set(const fMat33 &mat)
Copies a matrix.
void cross(const fVec3 &vec1, const fVec3 &vec2)
Cross product.
Forward dynamics computation based on Assembly-Disassembly Algorithm.
void addCharacter(Joint *rjoint, const std::string &_name, OpenHRP::LinkInfoSequence_var links)
png_infop png_charpp name
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void SetFixedJointType(const fVec3 &rpos, const fMat33 &ratt)
Set joint type to fixed.
void identity()
Identity matrix.
int BeginCreateChain(int append=false)
Indicates begining of creating a kinematic chain.
void getMatrix33FromRowMajorArray(Matrix33 &m33, const Array &a, size_t top=0)
void set(double *v)
Set element values from array or three values.
static char charname_separator
static double getLimitValue(DblSequence_var limitseq, double defaultValue)
JointType j_type
joint type
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
char * name
joint name (including the character name)
void SetSlideJointType(const fVec3 &rpos, const fMat33 &ratt, AxisIndex ai)
Set joint type to prismatic.
int EndCreateChain(SceneGraph *sg=NULL)
End editing a chain.
void SetSphereJointType(const fVec3 &rpos, const fMat33 &ratt)
Set joint type to spherical.
static void array_to_vec3(const DblArray3 &a, fVec3 &vec)
int addSensor(Joint *jnt, int sensorType, int id, const std::string name, const fVec3 &_localPos, const fMat33 &_localR)
fVec3 loc_com
center of mass in local frame
int AddJoint(Joint *target, Joint *p)
Add a new joint target as a child of joint p.
void SetRotateJointType(const fVec3 &rpos, const fMat33 &ratt, AxisIndex ai)
Set joint type to rotational.
The class representing the whole mechanism. May contain multiple characters.
char * CharName() const
Returns the character name.
friend double length(const fVec3 &v)
Returns the length of a vector.
static Joint * createLink(::World *world, const char *charname, int index, LinkInfoSequence_var iLinks, Joint *pjoint)
AxisIndex
Direction of a 1-DOF joint.
int loadBodyFromBodyInfo(::World *world, const char *_name, BodyInfo_ptr bodyInfo)
void mul(const fVec3 &vec, double d)
Main class for forward dynamics computation.
The class for representing a joint.
int i_joint
index of the joint
static void createSensors(::World *world, Joint *jnt, SensorInfoSequence iSensors)
void SetFreeJointType(const fVec3 &rpos, const fMat33 &ratt)
Set joint type to free.