2018-05-24 05:48:45 +00:00
|
|
|
|
|
|
|
#include "b3RobotSimulatorClientAPI_NoGUI.h"
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
b3RobotSimulatorClientAPI_NoGUI* sim = new b3RobotSimulatorClientAPI_NoGUI();
|
|
|
|
|
|
|
|
bool isConnected = sim->connect(eCONNECT_SHARED_MEMORY);
|
2018-06-10 02:40:12 +00:00
|
|
|
|
2018-05-24 05:48:45 +00:00
|
|
|
if (!isConnected)
|
|
|
|
{
|
|
|
|
printf("Using Direct mode\n");
|
|
|
|
isConnected = sim->connect(eCONNECT_DIRECT);
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2018-05-24 05:48:45 +00:00
|
|
|
{
|
|
|
|
printf("Using shared memory\n");
|
|
|
|
}
|
2018-06-10 02:40:12 +00:00
|
|
|
|
2018-05-24 05:48:45 +00:00
|
|
|
//remove all existing objects (if any)
|
|
|
|
sim->resetSimulation();
|
2018-09-23 21:17:31 +00:00
|
|
|
sim->setGravity(btVector3(0, 0, -9.8));
|
2018-06-10 02:40:12 +00:00
|
|
|
sim->setNumSolverIterations(100);
|
|
|
|
b3RobotSimulatorSetPhysicsEngineParameters args;
|
|
|
|
sim->getPhysicsEngineParameters(args);
|
|
|
|
|
2018-05-24 05:48:45 +00:00
|
|
|
int planeUid = sim->loadURDF("plane.urdf");
|
|
|
|
printf("planeUid = %d\n", planeUid);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-05-24 05:48:45 +00:00
|
|
|
int r2d2Uid = sim->loadURDF("r2d2.urdf");
|
|
|
|
printf("r2d2 #joints = %d\n", sim->getNumJoints(r2d2Uid));
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
btVector3 basePosition = btVector3(0, 0, 0.5);
|
|
|
|
btQuaternion baseOrientation = btQuaternion(0, 0, 0, 1);
|
2018-05-24 05:48:45 +00:00
|
|
|
|
2018-06-10 02:40:12 +00:00
|
|
|
sim->resetBasePositionAndOrientation(r2d2Uid, basePosition, baseOrientation);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-05-24 05:48:45 +00:00
|
|
|
while (sim->isConnected())
|
|
|
|
{
|
2018-06-10 02:40:12 +00:00
|
|
|
btVector3 basePos;
|
|
|
|
btQuaternion baseOrn;
|
2018-09-23 21:17:31 +00:00
|
|
|
sim->getBasePositionAndOrientation(r2d2Uid, basePos, baseOrn);
|
|
|
|
printf("r2d2 basePosition = [%f,%f,%f]\n", basePos[0], basePos[1], basePos[2]);
|
|
|
|
|
2018-05-24 05:48:45 +00:00
|
|
|
sim->stepSimulation();
|
|
|
|
}
|
|
|
|
delete sim;
|
|
|
|
}
|