45 typedef map<int, const char*> IdToLabelMap;
47 IdToLabelMap commandLabelMap;
49 IdLabel commandLabels[] = {
51 { DynamicsSimulator::POSITION_GIVEN,
"Position Given (High Gain Mode)" },
62 void initializeCommandLabelMaps()
64 if(commandLabelMap.empty()){
67 IdLabel& idLabel = commandLabels[i++];
71 commandLabelMap[idLabel.id] = idLabel.label;
76 const char* getLabelOfLinkDataType(DynamicsSimulator::LinkDataType
type)
78 IdToLabelMap::iterator p = commandLabelMap.find(type);
79 return (p != commandLabelMap.end()) ? p->second :
"Requesting Unknown Data Type";
84 template<
typename X,
typename X_ptr>
87 CosNaming::Name ncName;
89 ncName[0].id = CORBA::string_dup(n.c_str());
90 ncName[0].kind = CORBA::string_dup(
"");
93 srv = X::_narrow(cxt->resolve(ncName));
95 std::cerr << n <<
" not found: ";
97 case CosNaming::NamingContext::missing_node:
98 std::cerr <<
"Missing Node" << std::endl;
99 case CosNaming::NamingContext::not_context:
100 std::cerr <<
"Not Context" << std::endl;
102 case CosNaming::NamingContext::not_object:
103 std::cerr <<
"Not Object" << std::endl;
107 }
catch(CosNaming::NamingContext::CannotProceed &exc) {
108 std::cerr <<
"Resolve " << n <<
" CannotProceed" << std::endl;
109 }
catch(CosNaming::NamingContext::AlreadyBound &exc) {
110 std::cerr <<
"Resolve " << n <<
" InvalidName" << std::endl;
117 : orb_(CORBA::ORB::_duplicate(orb))
120 cout <<
"DynamicsSimulator_impl::DynamicsSimulator_impl()" << endl;
128 CollisionDetectorFactory_var collisionDetectorFactory;
130 CORBA::Object_var nS = orb->resolve_initial_references(
"NameService");
131 CosNaming::NamingContext_var cxT;
132 cxT = CosNaming::NamingContext::_narrow(nS);
133 collisionDetectorFactory =
135 CollisionDetectorFactory_var>(
"CollisionDetectorFactory", cxT);
136 if (CORBA::is_nil(collisionDetectorFactory)) {
137 std::cerr <<
"CollisionDetectorFactory not found" << std::endl;
143 std::cerr <<
"failed to create CollisionDetector" << std::endl;
160 cout <<
"DynamicsSimulator_impl::~DynamicsSimulator_impl()" << endl;
170 cout <<
"DynamicsSimulator_impl::destroy()" << endl;
173 PortableServer::POA_var poa_ = _default_POA();
174 PortableServer::ObjectId_var
id = poa_->servant_to_id(
this);
175 poa_->deactivate_object(
id);
182 BodyInfo_ptr bodyInfo
186 cout <<
"DynamicsSimulator_impl::registerCharacter(" 187 << name <<
", " << bodyInfo <<
" )" << std::endl;
195 std::cout <<
"Loaded Model:\n" << *body << std::endl;
207 CORBA::Double timeStep,
208 OpenHRP::DynamicsSimulator::IntegrateMethod integrateOpt,
209 OpenHRP::DynamicsSimulator::SensorOption sensorOpt
213 cout <<
"DynamicsSimulator_impl::init(" << timeStep <<
", ";
214 cout << (integrateOpt == OpenHRP::DynamicsSimulator::EULER ?
"EULER, " :
"RUNGE_KUTTA, ");
215 cout << (sensorOpt == OpenHRP::DynamicsSimulator::DISABLE_SENSOR ?
"DISABLE_SENSOR" :
"ENABLE_SENSOR");
216 std::cout <<
")" << std::endl;
222 if(integrateOpt == OpenHRP::DynamicsSimulator::EULER){
231 for(
int i=0;
i <
n; ++
i){
245 const char *charName1,
246 const char *linkName1,
247 const char *charName2,
248 const char *linkName2,
249 const CORBA::Double staticFriction,
250 const CORBA::Double slipFriction,
251 const DblSequence6 & K,
252 const DblSequence6 &
C,
253 const double culling_thresh,
254 const double restitution
257 const double epsilon = 0.0;
260 cout <<
"DynamicsSimulator_impl::registerCollisionCheckPair(" 261 << charName1 <<
", " << linkName1 <<
", " 262 << charName2 <<
", " << linkName2 <<
", " 263 << staticFriction <<
", " << slipFriction <<
", " << restitution;
264 if((K.length() == 6) && (C.length() == 6)){
267 << K[CORBA::ULong(0)] <<
", " 268 << K[CORBA::ULong(1)] <<
", " 269 << K[CORBA::ULong(2)] <<
" }\n" 271 << K[CORBA::ULong(3)] <<
", " 272 << K[CORBA::ULong(4)] <<
", " 273 << K[CORBA::ULong(5)] <<
" }\n" 276 << C[CORBA::ULong(0)] <<
", " 277 << C[CORBA::ULong(1)] <<
", " 278 << C[CORBA::ULong(2)] <<
" }\n" 280 << C[CORBA::ULong(3)] <<
", " 281 << C[CORBA::ULong(4)] <<
", " 282 << C[CORBA::ULong(5)] <<
" }\n" 285 cout <<
", NULL, NULL)" << endl;
292 if(bodyIndex1 >= 0 && bodyIndex2 >= 0){
297 std::string emptyString =
"";
298 vector<Link*> links1;
299 if(emptyString == linkName1){
302 std::copy(traverse.
begin(), traverse.
end(), links1.begin());
304 links1.push_back(body1->link(linkName1));
307 vector<Link*> links2;
308 if(emptyString == linkName2){
311 std::copy(traverse.
begin(), traverse.
end(), links2.begin());
313 links2.push_back(body2->link(linkName2));
316 for(
size_t i=0;
i < links1.size(); ++
i){
317 for(
size_t j=0;
j < links2.size(); ++
j){
318 Link* link1 = links1[
i];
319 Link* link2 = links2[
j];
321 if(link1 && link2 && link1 != link2){
323 (bodyIndex1, link1, bodyIndex2, link2, staticFriction, slipFriction, culling_thresh, restitution, epsilon);
326 LinkPair_var linkPair =
new LinkPair();
327 linkPair->charName1 = CORBA::string_dup(charName1);
328 linkPair->linkName1 = CORBA::string_dup(link1->
name.c_str());
329 linkPair->charName2 = CORBA::string_dup(charName2);
330 linkPair->linkName2 = CORBA::string_dup(link2->
name.c_str());
331 linkPair->tolerance = 0;
343 const char *charName1,
344 const char *linkName1,
345 const char *charName2,
346 const char *linkName2,
347 const double tolerance
351 cout <<
"DynamicsSimulator_impl::registerIntersectionCheckPair(" 352 << charName1 <<
", " << linkName1 <<
", " 353 << charName2 <<
", " << linkName2 <<
", " 354 << tolerance <<
")" << endl;
360 if(bodyIndex1 >= 0 && bodyIndex2 >= 0){
365 std::string emptyString =
"";
366 vector<Link*> links1;
367 if(emptyString == linkName1){
370 std::copy(traverse.
begin(), traverse.
end(), links1.begin());
372 links1.push_back(body1->link(linkName1));
375 vector<Link*> links2;
376 if(emptyString == linkName2){
379 std::copy(traverse.
begin(), traverse.
end(), links2.begin());
381 links2.push_back(body2->link(linkName2));
384 for(
size_t i=0;
i < links1.size(); ++
i){
385 for(
size_t j=0;
j < links2.size(); ++
j){
386 Link* link1 = links1[
i];
387 Link* link2 = links2[
j];
389 if(link1 && link2 && link1 != link2){
391 LinkPair_var linkPair =
new LinkPair();
392 linkPair->charName1 = CORBA::string_dup(charName1);
393 linkPair->linkName1 = CORBA::string_dup(link1->
name.c_str());
394 linkPair->charName2 = CORBA::string_dup(charName2);
395 linkPair->linkName2 = CORBA::string_dup(link2->
name.c_str());
396 linkPair->tolerance = tolerance;
407 const char* charName1,
408 const char* linkName1,
409 const char* charName2,
410 const char* linkName2,
411 const DblSequence3& link1LocalPos,
412 const DblSequence3& link2LocalPos,
413 const ExtraJointType jointType,
414 const DblSequence3& jointAxis,
415 const char* extraJointName
419 cout <<
"DynamicsSimulator_impl::registerExtraJoint(" 420 << charName1 <<
", " << linkName1 <<
", " 421 << charName2 <<
", " << linkName2 <<
"\n" 424 << link1LocalPos[CORBA::ULong(0)] <<
", " 425 << link1LocalPos[CORBA::ULong(1)] <<
", " 426 << link1LocalPos[CORBA::ULong(2)] <<
"}\n{" 427 << link2LocalPos[CORBA::ULong(0)] <<
", " 428 << link2LocalPos[CORBA::ULong(1)] <<
", " 429 << link2LocalPos[CORBA::ULong(2)] <<
"}\n{" 430 << jointAxis[CORBA::ULong(0)] <<
", " 431 << jointAxis[CORBA::ULong(1)] <<
", " 432 << jointAxis[CORBA::ULong(2)] <<
"}\n" 433 << extraJointName <<
")\n";
439 if(bodyIndex1 >= 0 && bodyIndex2 >= 0){
442 Link* link1 = body1->link(linkName1);
443 Link* link2 = body2->link(linkName2);
446 (bodyIndex1, link1, bodyIndex2, link2, link1LocalPos.get_buffer(), link2LocalPos.get_buffer(), jointType, jointAxis.get_buffer() );
453 const char * characterName,
454 const char * extraJointName,
455 DblSequence6_out contactForce
459 cout <<
"DynamicsSimulator_impl::getConnectionConstraintForce(" 460 << characterName <<
", " << extraJointName <<
")" << endl;
467 const char *characterName,
468 const char *sensorName,
469 DblSequence_out sensorOutput
473 cout <<
"DynamicsSimulator_impl::getCharacterSensorData(" 474 << characterName <<
", " << sensorName <<
")";
479 std::cerr <<
"not found! :" << characterName << std::endl;
483 sensorOutput =
new DblSequence;
487 switch(sensor->
type){
492 sensorOutput->length(6);
497 sensorOutput[CORBA::ULong(0)] = forceSensor->
f(0); sensorOutput[CORBA::ULong(1)] = forceSensor->
f(1); sensorOutput[CORBA::ULong(2)] = forceSensor->
f(2);
498 sensorOutput[CORBA::ULong(3)] = forceSensor->
tau(0); sensorOutput[CORBA::ULong(4)] = forceSensor->
tau(1); sensorOutput[CORBA::ULong(5)] = forceSensor->
tau(2);
504 case Sensor::RATE_GYRO:
507 sensorOutput->length(3);
511 sensorOutput[CORBA::ULong(0)] = gyro->
w(0); sensorOutput[CORBA::ULong(1)] = gyro->
w(1); sensorOutput[CORBA::ULong(2)] = gyro->
w(2);
516 case Sensor::ACCELERATION:
519 sensorOutput->length(3);
523 sensorOutput[CORBA::ULong(0)] = accelSensor->
dv(0); sensorOutput[CORBA::ULong(1)] = accelSensor->
dv(1); sensorOutput[CORBA::ULong(2)] = accelSensor->
dv(2);
531 sensorOutput->length(rangeSensor->
distances.size());
532 for (
unsigned int i=0;
i<rangeSensor->
distances.size();
i++){
544 cout <<
"DynamicsSimulator_impl::getCharacterSensorData - output\n" 545 <<
"( " << sensorOutput[CORBA::ULong(0)];
549 cout << sensorOutput[i++];
550 if(i == sensorOutput->length())
break;
562 cout <<
"DynamicsSimulator_impl::initSimulation()" << endl;
593 cout <<
"DynamicsSimulator_impl::stepSimulation()" << endl;
627 const char* characterName,
628 const char* linkName,
629 OpenHRP::DynamicsSimulator::LinkDataType
type,
630 const DblSequence& wdata
634 cout <<
"DynamicsSimulator_impl::setCharacterLinkData(" 635 << characterName <<
", " << linkName <<
", " 636 << getLabelOfLinkDataType(type) <<
", ";
639 case OpenHRP::DynamicsSimulator::POSITION_GIVEN:
644 cout << wdata[CORBA::ULong(0)] <<
")\n";
648 cout << wdata[CORBA::ULong(0)] <<
", " 649 << wdata[CORBA::ULong(1)] <<
", " 650 << wdata[CORBA::ULong(2)] <<
",\n" 651 << wdata[CORBA::ULong(3)] <<
", " 652 << wdata[CORBA::ULong(4)] <<
", " 653 << wdata[CORBA::ULong(5)] <<
",\n" 654 << wdata[CORBA::ULong(6)] <<
"," 655 << wdata[CORBA::ULong(7)] <<
", " 656 << wdata[CORBA::ULong(8)] <<
",\n " 657 << wdata[CORBA::ULong(9)] <<
"," 658 << wdata[CORBA::ULong(10)] <<
", " 659 << wdata[CORBA::ULong(11)] <<
")" << endl;
663 cout << wdata[CORBA::ULong(0)] <<
", " 664 << wdata[CORBA::ULong(1)] <<
", " 665 << wdata[CORBA::ULong(2)] <<
")" << endl;
671 std::cerr <<
"not found! :" << characterName << std::endl;
674 Link* link = body->link(linkName);
676 std::cerr <<
"not found! :" << linkName << std::endl;
682 case OpenHRP::DynamicsSimulator::POSITION_GIVEN:
698 link->
ddq = wdata[0];
708 link->
p(0) = wdata[0];
709 link->
p(1) = wdata[1];
710 link->
p(2) = wdata[2];
719 link->
v(0) = wdata[0];
720 link->
v(1) = wdata[1];
721 link->
v(2) = wdata[2];
722 link->
w(0) = wdata[3];
723 link->
w(1) = wdata[4];
724 link->
w(2) = wdata[5];
726 link->
vo = link->
v - link->
w.cross(link->
p);
732 link->
dv(0) = wdata[0];
733 link->
dv(1) = wdata[1];
734 link->
dv(2) = wdata[2];
735 link->
dw(0) = wdata[3];
736 link->
dw(1) = wdata[4];
737 link->
dw(2) = wdata[5];
743 link->
fext(0) = wdata[0];
744 link->
fext(1) = wdata[1];
745 link->
fext(2) = wdata[2];
746 link->
tauext(0) = wdata[3];
747 link->
tauext(1) = wdata[4];
748 link->
tauext(2) = wdata[5];
763 const char * characterName,
764 const char * linkName,
765 OpenHRP::DynamicsSimulator::LinkDataType type,
766 DblSequence_out out_rdata
770 cout <<
"DynamicsSimulator_impl::getCharacterLinkData(" 771 << characterName <<
", " << linkName <<
", " 772 << getLabelOfLinkDataType(type) <<
")" << endl;
777 std::cerr <<
"not found! :" << characterName << std::endl;
780 Link* link = body->link(linkName);
782 std::cerr <<
"not found! :" << linkName << std::endl;
786 DblSequence_var rdata =
new DblSequence;
802 rdata[0] = link->
ddq;
813 rdata[0] = link->
p(0);
814 rdata[1] = link->
p(1);
815 rdata[2] = link->
p(2);
816 double*
buf = rdata->get_buffer();
823 rdata[0] = link->
v(0);
824 rdata[1] = link->
v(1);
825 rdata[2] = link->
v(2);
826 rdata[3] = link->
w(0);
827 rdata[4] = link->
w(1);
828 rdata[5] = link->
w(2);
833 rdata[0] = link->
fext(0);
834 rdata[1] = link->
fext(1);
835 rdata[2] = link->
fext(2);
836 rdata[3] = link->
tauext(0);
837 rdata[4] = link->
tauext(1);
838 rdata[5] = link->
tauext(2);
843 int n = constraintForces.size();
845 for(
int i=0;
i<
n;
i++){
846 rdata[
i*6 ] = constraintForces[
i].point(0);
847 rdata[
i*6+1] = constraintForces[
i].point(1);
848 rdata[
i*6+2] = constraintForces[
i].point(2);
849 rdata[
i*6+3] = constraintForces[
i].force(0);
850 rdata[
i*6+4] = constraintForces[
i].force(1);
851 rdata[
i*6+5] = constraintForces[
i].force(2);
860 out_rdata = rdata._retn();
866 const char * characterName,
867 OpenHRP::DynamicsSimulator::LinkDataType type,
868 DblSequence_out rdata
872 cout <<
"DynamicsSimulator_impl::getCharacterAllLinkData(" 873 << characterName <<
", " 874 << getLabelOfLinkDataType(type) <<
")" << endl;
879 std::cerr <<
"not found! :" << characterName << std::endl;
882 int n = body->numJoints();
883 rdata =
new DblSequence();
889 for(
int i=0;
i <
n; ++
i){
890 (*rdata)[
i] = body->joint(
i)->q;
895 for(
int i=0;
i <
n; ++
i){
896 (*rdata)[
i] = body->joint(
i)->dq;
901 for(
int i=0;
i <
n; ++
i){
902 (*rdata)[
i] = body->joint(
i)->ddq;
907 for(
int i=0;
i <
n; ++
i){
908 (*rdata)[
i] = body->joint(
i)->u;
913 cerr <<
"ERROR - Invalid type: " << getLabelOfLinkDataType(type) << endl;
921 const char * characterName,
922 OpenHRP::DynamicsSimulator::LinkDataType type,
923 const DblSequence & wdata
927 cout <<
"DynamicsSimulator_impl::setCharacterAllLinkData(" 928 << characterName <<
", " 929 << getLabelOfLinkDataType(type) <<
",\n(";
930 if(wdata.length()) cout << wdata[0];
931 for(CORBA::ULong
i=0;
i<wdata.length(); ++
i){
932 cout <<
", " << wdata[
i];
934 cout <<
"))" << endl;
939 std::cerr <<
"not found! :" << characterName << std::endl;
943 unsigned int n = wdata.length();
944 if(n > body->numJoints()){
945 n = body->numJoints();
951 for(
unsigned int i=0;
i <
n; ++
i){
952 if(body->joint(
i)->jointType != Link::FIXED_JOINT)
953 body->joint(
i)->q = wdata[
i];
958 for(
unsigned int i=0;
i <
n; ++
i){
959 if(body->joint(
i)->jointType != Link::FIXED_JOINT)
960 body->joint(
i)->dq = wdata[
i];
965 for(
unsigned int i=0;
i <
n; ++
i){
966 if(body->joint(
i)->jointType != Link::FIXED_JOINT)
967 body->joint(
i)->ddq = wdata[
i];
972 for(
unsigned int i=0;
i <
n; ++
i){
973 if(body->joint(
i)->jointType != Link::FIXED_JOINT
974 || body->joint(
i)->isCrawler)
975 body->joint(
i)->u = wdata[
i];
980 std::cerr <<
"ERROR - Invalid type: " << getLabelOfLinkDataType(type) << endl;
990 const DblSequence3& wdata
993 if(wdata.length() != 3){
994 std::cerr <<
"setGVector : The data length is not three. " << std::endl;
1003 cout <<
"DynamicsSimulator_impl::setGVector(" 1004 << wdata[CORBA::ULong(0)] <<
", " 1005 << wdata[CORBA::ULong(1)] <<
", " 1006 << wdata[CORBA::ULong(2)] <<
")" << endl;
1013 DblSequence3_out wdata
1023 cout <<
"DynamicsSimulator_impl::getGVector(";
1024 cout << wdata[CORBA::ULong(0)] <<
", " 1025 << wdata[CORBA::ULong(1)] <<
", " 1026 << wdata[CORBA::ULong(2)] <<
")" << endl;
1033 const char * characterName,
1034 OpenHRP::DynamicsSimulator::JointDriveMode jointMode
1037 bool isHighGainMode = (jointMode == OpenHRP::DynamicsSimulator::HIGH_GAIN_MODE);
1041 std::cerr <<
"not found! :" << characterName << std::endl;
1045 for(
unsigned int i=1;
i < body->numLinks(); ++
i){
1046 body->link(
i)->isHighGainMode = isHighGainMode;
1050 cout <<
"DynamicsSimulator_impl::setCharacterAllJointModes(";
1051 cout << characterName <<
", ";
1052 cout << (isHighGainMode ?
"HIGH_GAIN_MODE" :
"TORQUE_MODE");
1053 cout <<
")" << endl;
1060 const char * characterName,
1061 const char * fromLink,
const char * toLink,
1062 const LinkPosition& target
1066 cout <<
"DynamicsSimulator_impl::calcCharacterInverseKinematics(" 1067 << characterName <<
", " << fromLink <<
", " << toLink <<
",\n" 1069 << target.p[0] <<
", " << target.p[1] <<
", " << target.p[2] <<
",\n\n" 1070 << target.R[0] <<
", " << target.R[1] <<
", " << target.R[2] <<
",\n" 1071 << target.R[3] <<
", " << target.R[4] <<
", " << target.R[5] <<
",\n" 1072 << target.R[6] <<
", " << target.R[7] <<
", " << target.R[8] << endl;
1075 bool solved =
false;
1079 std::cerr <<
"not found! :" << characterName << std::endl;
1086 Vector3 p(target.p[0], target.p[1], target.p[2]);
1088 for (
int i=0;
i<3;
i++) {
1089 for (
int j=0;
j<3;
j++){
1090 R(
i,
j) = target.R[3*
i+
j];
1094 solved =
path.calcInverseKinematics(p, R);
1108 const char * characterName
1112 cout <<
"DynamicsSimulator_impl::calcCharacterForwardKinematics( " 1113 << characterName << endl;
1118 std::cerr <<
"not found! :" << characterName << std::endl;
1121 body->calcForwardKinematics(
true,
true);
1131 world.
body(
i)->calcForwardKinematics(
true,
true);
1158 DistanceSequence_var distances =
new DistanceSequence;
1160 return distances._retn();
1171 LinkPairSequence_var pairs =
new LinkPairSequence;
1173 return pairs._retn();
1181 cout <<
"DynamicsSimulator_impl::getWorldState()\n";
1186 wstate =
new WorldState;
1193 cout <<
"getWorldState - exit" << endl;
1208 sstate =
new SensorState;
1216 cout <<
"DynamicsSimulator_impl::_setupCharacterData()\n";
1223 for(
int i=0;
i <
n; ++
i){
1226 int numLinks = body->numLinks();
1228 characterPosition.characterName = CORBA::string_dup(body->name().c_str());
1229 LinkPositionSequence& linkPositions = characterPosition.linkPositions;
1230 linkPositions.length(numLinks);
1232 int numJoints = body->numJoints();
1234 sensorState.q.length(numJoints);
1235 sensorState.dq.length(numJoints);
1236 sensorState.u.length(numJoints);
1237 sensorState.force.length(body->numSensors(Sensor::FORCE));
1238 sensorState.rateGyro.length(body->numSensors(Sensor::RATE_GYRO));
1239 sensorState.accel.length(body->numSensors(Sensor::ACCELERATION));
1240 sensorState.range.length(body->numSensors(Sensor::RANGE));
1243 std::cout <<
"character[" <<
i <<
"], nlinks = " << numLinks <<
"\n";
1248 cout <<
"_setupCharacterData() - exit" << endl;;
1256 cout <<
"DynamicsSimulator_impl::_updateCharacterPositions()\n";
1262 #pragma omp parallel for num_threads(3) 1263 for(
int i=0;
i <
n; ++
i){
1265 int numLinks = body->numLinks();
1270 cout <<
"character[" <<
i <<
"], nlinks = " << numLinks <<
"\n";
1273 for(
int j=0;
j < numLinks; ++
j) {
1274 Link* link = body->link(
j);
1275 LinkPosition& linkPosition = characterPosition.linkPositions[
j];
1284 cout <<
"_updateCharacterData() - exit" << endl;
1292 cout <<
"DynamicsSimulator_impl::_updateSensorStates()\n";
1296 for(
int i=0;
i < numBodies; ++
i){
1301 int numJoints = body->numJoints();
1303 for(
int j=0;
j < numJoints;
j++){
1304 Link* joint = body->joint(
j);
1305 state.
q [
j] = joint->
q;
1306 state.dq[
j] = joint->
dq;
1307 state.u [
j] = joint->
u;
1310 int n = body->numSensors(Sensor::FORCE);
1311 for(
int id = 0;
id <
n; ++
id){
1316 std::cout <<
"Force Sensor: f:" << sensor->
f <<
"tau:" << sensor->
tau <<
"\n";
1320 n = body->numSensors(Sensor::RATE_GYRO);
1321 for(
int id=0;
id <
n; ++
id){
1325 std::cout <<
"Rate Gyro:" << sensor->
w <<
"\n";
1329 n = body->numSensors(Sensor::ACCELERATION);
1330 for(
int id=0;
id <
n; ++
id){
1334 std::cout <<
"Accel:" << sensor->
dv << std::endl;
1338 n = body->numSensors(Sensor::RANGE);
1339 for (
int id=0;
id <
n; ++
id){
1350 rangeSensor->
distances.resize(data->length());
1351 for (
unsigned int i=0;
i<data->length();
i++){
1362 cout <<
"_updateCharacterData() - exit" << endl;
1374 const char *characterName,
1375 LinkPairSequence_out pairs
1379 cout <<
"DynamicsSimulator_impl::getCharacterCollidingPairs(" 1380 << characterName <<
")" << endl;
1384 std::cerr <<
"not found! :" << characterName << std::endl;
1388 std::vector<unsigned int> locations;
1392 if( (strcmp(characterName,
collisions[
i].pair.charName1) == 0) ||
1393 (strcmp(characterName,
collisions[i].pair.charName2) == 0))
1394 locations.push_back(i);
1397 pairs->length(locations.size());
1400 for(std::vector<unsigned int>::iterator iter = locations.begin();
1401 iter != locations.end(); ++iter) {
1403 strcpy(pairs[n].charName1,
collisions[*iter].pair.charName1);
1404 strcpy(pairs[n].charName2,
collisions[*iter].pair.charName2);
1405 strcpy(pairs[n].linkName1,
collisions[*iter].pair.linkName1);
1406 strcpy(pairs[n].linkName2,
collisions[*iter].pair.linkName2);
1415 const char *characterName,
1416 const char *baseLink,
1417 const char *targetLink,
1418 DblSequence_out jacobian
1422 cout <<
"DynamicsSimulator_impl::calcCharacterJacobian(" 1423 << characterName <<
", " 1425 << targetLink <<
")" << endl;
1430 std::cerr <<
"not found! :" << characterName << std::endl;
1434 JointPath path(body->link(baseLink), body->link(targetLink));
1438 path.calcJacobian(J);
1440 jacobian->length(height * width);
1442 for(
int r=0; r <
height; ++r){
1444 (*jacobian)[i++] = J(r,
c);
1455 orb_(CORBA::ORB::_duplicate(orb))
1457 initializeCommandLabelMaps();
1460 cout <<
"DynamicsSimulatorFactory_impl::DynamicsSimulatorFactory_impl()" << endl;
1468 cout <<
"DynamicsSimulatorFactory_impl::~DynamicsSimulatorFactory_impl()" << endl;
1471 PortableServer::POA_var poa = _default_POA();
1472 PortableServer::ObjectId_var
id = poa -> servant_to_id(
this);
1473 poa -> deactivate_object(
id);
1480 cout <<
"DynamicsSimulatorFactory_impl::create()" << endl;
1485 PortableServer::ServantBase_var integratorrServant = integratorImpl;
1486 PortableServer::POA_var poa_ = _default_POA();
1487 PortableServer::ObjectId_var
id =
1488 poa_ -> activate_object(integratorImpl);
1490 return integratorImpl -> _this();
1496 orb_->shutdown(
false);
virtual void registerCollisionCheckPair(const char *char1, const char *name1, const char *char2, const char *name2, CORBA::Double staticFriction, CORBA::Double slipFriction, const DblSequence6 &K, const DblSequence6 &C, const double culling_thresh, const double restitution)
std::vector< double > distances
The header file of the LinkTraverse class.
DynamicsSimulator_impl(CORBA::ORB_ptr orb)
void setGravityAcceleration(const Vector3 &g)
set gravity acceleration
ConstraintForceArray constraintForces
Vector3 fext
external force
Vector3 vo
translation elements of spacial velocity
X_ptr checkCorbaServer(std::string n, CosNaming::NamingContext_var &cxt)
png_infop png_charp png_int_32 png_int_32 int * type
bool addExtraJoint(int bodyIndex1, Link *link1, int bodyIndex2, Link *link2, const double *link1LocalPos, const double *link2LocalPos, const short jointType, const double *jointAxis)
double ddq
joint acceleration
int bodyIndex(const std::string &name)
get index of body by name
bool needToUpdateSensorStates
virtual void getCharacterSensorState(const char *characterName, SensorState_out sstate)
~DynamicsSimulatorFactory_impl()
void setEulerMethod()
choose euler method for integration
std::vector< Link * >::const_iterator end() const
int addBody(BodyPtr body)
add body to this world
~DynamicsSimulator_impl()
virtual void initialize()
initialize this world. This must be called after all bodies are registered.
const Vector3 & getGravityAcceleration()
get gravity acceleration
void _updateCharacterPositions()
void _updateSensorStates()
png_infop png_charpp name
void setCurrentTime(double tm)
set current time
CollisionDetector_var collisionDetector
virtual void getGVector(DblSequence3_out wdata)
CharacterPositionSequence_var allCharacterPositions
virtual void registerExtraJoint(const char *charName1, const char *linkName1, const char *charName2, const char *linkName2, const DblSequence3 &link1LocalPos, const DblSequence3 &link2LocalPos, const ExtraJointType jointType, const DblSequence3 &jointAxis, const char *extraJointName)
HRPMODEL_API bool loadBodyFromBodyInfo(BodyPtr body, OpenHRP::BodyInfo_ptr bodyInfo, bool loadGeometryForCollisionDetection=false, Link *(*f)()=NULL)
virtual DistanceSequence * checkDistance()
hrp::World< hrp::ConstraintForceSolver > world
virtual bool checkCollision(bool checkAll)
void setVector3(const Vector3 &v3, V &v, size_t top=0)
void getMatrix33FromRowMajorArray(Matrix33 &m33, const Array &a, size_t top=0)
bool needToUpdatePositions
Vector3 w
angular velocity, omega
SensorStateSequence_var allCharacterSensorStates
std::vector< Link * >::const_iterator begin() const
void setRungeKuttaMethod()
choose runge-kutta method for integration
virtual void getCharacterLinkData(const char *characterName, const char *link, OpenHRP::DynamicsSimulator::LinkDataType type, DblSequence_out rdata)
boost::shared_ptr< Body > BodyPtr
png_infop png_uint_32 * width
std::vector< ConstraintForce > ConstraintForceArray
void _setupCharacterData()
void setSegmentAttitude(const Matrix33 &R)
void enableConstraintForceOutput(bool on)
virtual void calcWorldForwardKinematics()
BodyPtr body(int index)
get body by index
virtual void getExtraJointConstraintForce(const char *characterName, const char *extraJointName, DblSequence6_out contactForce)
void setMatrix33ToRowMajorArray(const Matrix33 &m33, Array &a, size_t top=0)
virtual void init(CORBA::Double timeStep, OpenHRP::DynamicsSimulator::IntegrateMethod integrateOpt, OpenHRP::DynamicsSimulator::SensorOption sensorOpt)
virtual void calcCharacterForwardKinematics(const char *characterName)
unsigned int numLinks() const
LinkPairSequence_var collidingLinkPairs
virtual CORBA::Boolean calcCharacterInverseKinematics(const char *characterName, const char *baseLink, const char *targetLink, const LinkPosition &target)
virtual void setGVector(const DblSequence3 &wdata)
DynamicsSimulatorFactory_impl(CORBA::ORB_ptr orb)
png_infop png_uint_32 png_uint_32 * height
Vector3 tauext
external torque (around the world origin)
Vector3 dv
linear acceleration
def j(str, encoding="cp932")
The header file of the LinkPath and JointPath classes.
virtual LinkPairSequence * checkIntersection(CORBA::Boolean checkAll)
virtual void initSimulation()
double averageTime() const
static const bool USE_INTERNAL_COLLISION_DETECTOR
Vector3 dw
derivative of omega
bool addCollisionCheckLinkPair(int bodyIndex1, Link *link1, int bodyIndex2, Link *link2, double muStatic, double muDynamic, double culling_thresh, double restitution, double epsilon)
static const int debugMode
virtual void getWorldState(WorldState_out wstate)
virtual void calcNextState(OpenHRP::CollisionSequence &corbaCollisionSequence)
virtual void setCharacterLinkData(const char *characterName, const char *link, OpenHRP::DynamicsSimulator::LinkDataType type, const DblSequence &data)
TConstraintForceSolver constraintForceSolver
void clearExternalForces()
virtual void stepSimulation()
static const bool enableTimeMeasure
DynamicsSimulator_ptr create()
virtual void getCharacterAllLinkData(const char *characterName, OpenHRP::DynamicsSimulator::LinkDataType type, DblSequence_out wdata)
void setTimeStep(double dt)
set time step
virtual void registerIntersectionCheckPair(const char *char1, const char *name1, const char *char2, const char *name2, const double tolerance)
void getVector3(Vector3 &v3, const V &v, size_t top=0)
CollisionSequence_var collisions
virtual void setCharacterAllJointModes(const char *characterName, OpenHRP::DynamicsSimulator::JointDriveMode jointMode)
virtual void setCharacterAllLinkData(const char *characterName, OpenHRP::DynamicsSimulator::LinkDataType type, const DblSequence &wdata)
double currentTime(void) const
get current time
virtual CORBA::Boolean getCharacterCollidingPairs(const char *characterName, LinkPairSequence_out pairs)
unsigned int numBodies()
get the number of bodies in this world
void enableSensors(bool on)
enable/disable sensor simulation
virtual void registerCharacter(const char *name, BodyInfo_ptr binfo)
virtual void calcCharacterJacobian(const char *characterName, const char *baseLink, const char *targetLink, DblSequence_out jacobian)
Matrix33 segmentAttitude()
virtual void getCharacterSensorValues(const char *characterName, const char *sensorName, DblSequence_out values)