7 #include <hrpCorba/DynamicsSimulator.hh> 14 #define deg2rad(x) ( 3.14159265358979 / 180*(x) ) 15 #define DOF 29 // 初期姿勢配列の長さ 18 template <
typename X,
typename X_ptr>
21 CosNaming::Name ncName;
23 ncName[0].id = CORBA::string_dup(n.c_str());
24 ncName[0].kind = CORBA::string_dup(
"");
28 srv = X::_narrow(cxt->resolve(ncName));
32 std::cerr << n <<
" not found: ";
35 case CosNaming::NamingContext::missing_node:
36 std::cerr <<
"Missing Node" << std::endl;
38 case CosNaming::NamingContext::not_context:
39 std::cerr <<
"Not Context" << std::endl;
41 case CosNaming::NamingContext::not_object:
42 std::cerr <<
"Not Object" << std::endl;
47 catch(CosNaming::NamingContext::CannotProceed &exc)
49 std::cerr <<
"Resolve " << n <<
" CannotProceed" << std::endl;
51 catch(CosNaming::NamingContext::AlreadyBound &exc)
53 std::cerr <<
"Resolve " << n <<
" InvalidName" << std::endl;
59 int main(
int argc,
char* argv[])
62 string url =
"file://";
67 for(i=0; i < argc - 1; i++)
69 if( strcmp(argv[i],
"-url") == 0)
72 }
else if( strcmp(argv[i],
"-ddp") == 0)
74 ddp = strtod( argv[++i], NULL);
75 }
else if( strcmp(argv[i],
"-timeK") == 0)
77 timeK = strtod( argv[++i], NULL);
81 string robot_url = url+
"sample.wrl";
82 string floor_url = url+
"floor.wrl";
84 const char *ROBOT_URL = robot_url.c_str();
85 const char *FLOOR_URL = floor_url.c_str();
91 orb = CORBA::ORB_init(argc, argv);
94 CORBA::Object_var poaObj = orb -> resolve_initial_references(
"RootPOA");
95 PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj);
98 PortableServer::POAManager_var
manager = rootPOA -> the_POAManager();
101 CosNaming::NamingContext_var cxT;
103 CORBA::Object_var nS = orb->resolve_initial_references(
"NameService");
104 cxT = CosNaming::NamingContext::_narrow(nS);
110 DynamicsSimulatorFactory_var dynamicsSimulatorFactory;
111 dynamicsSimulatorFactory =
113 DynamicsSimulatorFactory_var> (
"DynamicsSimulatorFactory", cxT);
115 if (CORBA::is_nil(dynamicsSimulatorFactory))
117 std::cerr <<
"DynamicsSimulatorFactory not found" << std::endl;
120 DynamicsSimulator_var dynamicsSimulator
121 = dynamicsSimulatorFactory->create();
124 BodyInfo_var robotInfo =
loadBodyInfo(ROBOT_URL, argc, argv);
125 dynamicsSimulator->registerCharacter(
"robot", robotInfo);
128 BodyInfo_var floorInfo =
loadBodyInfo(FLOOR_URL, argc, argv);
129 dynamicsSimulator->registerCharacter(
"floor", floorInfo);
135 dynamicsSimulator->init(0.002,
136 DynamicsSimulator::RUNGE_KUTTA,
137 DynamicsSimulator::ENABLE_SENSOR);
140 DblSequence3 gVector;
142 gVector[0] = gVector[1] = 0;
144 dynamicsSimulator->setGVector(gVector);
147 dynamicsSimulator->setCharacterAllJointModes(
148 "robot", DynamicsSimulator::TORQUE_MODE);
151 double init_pos[] = {0.00E+00, -3.60E-02, 0, 7.85E-02, -4.25E-02, 0.00E+00,
152 1.75E-01, -3.49E-03, 0, -1.57E+00, 0.00E+00, 0.00E+00,
153 0.00E+00, 0.00E+00, -3.60E-02, 0, 7.85E-02, -4.25E-02,
154 0.00E+00, 1.75E-01, 3.49E-03, 0, -1.57E+00, 0.00E+00,
155 0.00E+00, 0.00E+00, 0, 0, 0};
160 for (
int i=0; i<
DOF; i++)
164 dynamicsSimulator->setCharacterAllLinkData(
168 dynamicsSimulator->calcWorldForwardKinematics();
175 dynamicsSimulator->registerCollisionCheckPair(
187 dynamicsSimulator->initSimulation();
196 onlineViewer->load(
"robot", ROBOT_URL);
197 onlineViewer->load(
"floor", FLOOR_URL);
198 onlineViewer->setLogName(
"clap");
199 onlineViewer->clearLog();
201 catch (CORBA::SystemException& ex)
203 std::cerr <<
"Failed to connect GrxUI." << endl;
209 double RARM_p[] = {0.197403, -0.210919, 0.93732};
210 double RARM_R[] = {0.174891, -0.000607636, -0.984588,
211 0.00348999, 0.999994, 2.77917e-06,
212 0.984582, -0.00343669, 0.174892};
214 double LARM_p[] = {0.197403, 0.210919, 0.93732};
215 double LARM_R[] = {0.174891, 0.000607636, -0.984588,
216 -0.00348999, 0.999994, -2.77917e-06,
217 0.984582, 0.00343669, 0.174892};
222 WorldState_var
state;
227 link.p[0] = RARM_p[0];
228 link.p[1] = RARM_p[1] + dp;
229 link.p[2] = RARM_p[2];
230 for (
int i=0; i<9; i++)
231 link.R[i] = RARM_R[i];
232 dynamicsSimulator->calcCharacterInverseKinematics(CORBA::string_dup(
"robot"),
233 CORBA::string_dup(
"CHEST"),
234 CORBA::string_dup(
"RARM_WRIST_R"),
237 link.p[0] = LARM_p[0];
238 link.p[1] = LARM_p[1] - dp;
239 link.p[2] = LARM_p[2];
240 for (
int i=0; i<9; i++)
241 link.R[i] = LARM_R[i];
242 dynamicsSimulator->calcCharacterInverseKinematics(CORBA::string_dup(
"robot"),
243 CORBA::string_dup(
"CHEST"),
244 CORBA::string_dup(
"LARM_WRIST_R"),
247 dynamicsSimulator->calcWorldForwardKinematics();
252 dynamicsSimulator->getWorldState(state);
253 state->time = dp*timeK;
254 onlineViewer->update(state);
256 catch (CORBA::SystemException& ex)
258 std::cerr <<
"OnlineViewer could not be updated." << endl;
259 std::cerr <<
"ex._rep_id() = " << ex._rep_id() << endl;
263 if(state->time >= 200.0){
264 std::cout << state->time << endl;
268 dynamicsSimulator->checkCollision(
true);
270 if (state->collisions.length() > 0)
272 if (state->collisions[0].points.length() > 0)
HRPMODEL_API OpenHRP::BodyInfo_var loadBodyInfo(const char *url, int &argc, char *argv[])
int main(int argc, char *argv[])
HRP_UTIL_EXPORT OpenHRP::OnlineViewer_var getOnlineViewer(int argc, char **argv)
X_ptr checkCorbaServer(std::string n, CosNaming::NamingContext_var &cxt)