2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
#include "PhysicsClientExample.h"
|
|
|
|
|
|
|
|
#include "../CommonInterfaces/CommonMultiBodyBase.h"
|
2016-05-31 17:23:04 +00:00
|
|
|
#include "../CommonInterfaces/Common2dCanvasInterface.h"
|
2015-07-14 22:30:17 +00:00
|
|
|
#include "SharedMemoryCommon.h"
|
|
|
|
#include "../CommonInterfaces/CommonParameterInterface.h"
|
2016-10-14 22:06:09 +00:00
|
|
|
|
2015-09-25 05:42:22 +00:00
|
|
|
#include "PhysicsClientC_API.h"
|
2015-07-14 22:30:17 +00:00
|
|
|
#include "PhysicsClient.h"
|
2015-09-17 06:09:10 +00:00
|
|
|
//#include "SharedMemoryCommands.h"
|
2015-11-23 04:50:32 +00:00
|
|
|
#include "PhysicsLoopBackC_API.h"
|
|
|
|
#include "PhysicsDirectC_API.h"
|
2015-09-17 06:09:10 +00:00
|
|
|
#include "PhysicsClientC_API.h"
|
2016-05-18 16:34:42 +00:00
|
|
|
#include "PhysicsServerSharedMemory.h"
|
2015-08-06 18:59:31 +00:00
|
|
|
struct MyMotorInfo2
|
|
|
|
{
|
|
|
|
btScalar m_velTarget;
|
|
|
|
btScalar m_maxForce;
|
2016-04-19 21:19:18 +00:00
|
|
|
btScalar m_posTarget;
|
2015-08-06 18:59:31 +00:00
|
|
|
int m_uIndex;
|
2016-04-19 21:19:18 +00:00
|
|
|
int m_qIndex;
|
2015-08-06 18:59:31 +00:00
|
|
|
};
|
|
|
|
|
2016-06-07 23:11:58 +00:00
|
|
|
int camVisualizerWidth = 320;//1024/3;
|
|
|
|
int camVisualizerHeight = 240;//768/3;
|
2016-05-31 17:23:04 +00:00
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
enum CustomCommands
|
|
|
|
{
|
|
|
|
CMD_CUSTOM_SET_REALTIME_SIMULATION = CMD_MAX_CLIENT_COMMANDS+1,
|
|
|
|
CMD_CUSTOM_SET_GRAVITY
|
|
|
|
};
|
2015-09-17 06:09:10 +00:00
|
|
|
|
2015-08-06 18:59:31 +00:00
|
|
|
#define MAX_NUM_MOTORS 128
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
class PhysicsClientExample : public SharedMemoryCommon
|
|
|
|
{
|
|
|
|
protected:
|
2015-09-17 06:09:10 +00:00
|
|
|
b3PhysicsClientHandle m_physicsClientHandle;
|
2016-05-18 16:34:42 +00:00
|
|
|
|
|
|
|
//this m_physicsServer is only used when option eCLIENTEXAMPLE_SERVER is enabled
|
|
|
|
PhysicsServerSharedMemory m_physicsServer;
|
2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
bool m_wantsTermination;
|
2015-09-17 06:09:10 +00:00
|
|
|
btAlignedObjectArray<int> m_userCommandRequests;
|
2016-06-17 01:46:34 +00:00
|
|
|
btAlignedObjectArray<int> m_bodyUniqueIds;
|
|
|
|
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
int m_sharedMemoryKey;
|
2015-10-13 18:32:25 +00:00
|
|
|
int m_selectedBody;
|
|
|
|
int m_prevSelectedBody;
|
2016-05-31 17:23:04 +00:00
|
|
|
struct Common2dCanvasInterface* m_canvas;
|
2016-08-11 21:55:30 +00:00
|
|
|
int m_canvasRGBIndex;
|
|
|
|
int m_canvasDepthIndex;
|
|
|
|
int m_canvasSegMaskIndex;
|
2017-05-08 04:09:08 +00:00
|
|
|
|
2017-05-08 05:21:38 +00:00
|
|
|
btScalar m_lightPos[3];
|
|
|
|
btScalar m_specularCoeff;
|
2016-05-31 17:23:04 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
void createButton(const char* name, int id, bool isTrigger );
|
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
void createButtons();
|
|
|
|
|
2016-05-18 16:34:42 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-08-06 18:59:31 +00:00
|
|
|
//@todo, add accessor methods
|
2016-04-19 23:52:47 +00:00
|
|
|
// MyMotorInfo2 m_motorTargetVelocities[MAX_NUM_MOTORS];
|
2016-04-19 21:19:18 +00:00
|
|
|
MyMotorInfo2 m_motorTargetPositions[MAX_NUM_MOTORS];
|
2015-08-06 18:59:31 +00:00
|
|
|
int m_numMotors;
|
2016-05-18 16:34:42 +00:00
|
|
|
int m_options;
|
|
|
|
bool m_isOptionalServerConnected;
|
2015-08-06 18:59:31 +00:00
|
|
|
|
2016-05-18 16:34:42 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
PhysicsClientExample(GUIHelperInterface* helper, int options);
|
2015-07-14 22:30:17 +00:00
|
|
|
virtual ~PhysicsClientExample();
|
|
|
|
|
|
|
|
virtual void initPhysics();
|
2015-10-13 18:32:25 +00:00
|
|
|
void selectComboBox(int comboIndex, const char* name)
|
|
|
|
{
|
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
2016-06-17 01:46:34 +00:00
|
|
|
int itemIndex = int(atoi(name));
|
|
|
|
int bodyIndex = m_bodyUniqueIds[itemIndex];
|
2015-10-13 18:32:25 +00:00
|
|
|
if (m_selectedBody != bodyIndex)
|
|
|
|
{
|
|
|
|
m_selectedBody = bodyIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
virtual void stepSimulation(float deltaTime);
|
|
|
|
|
|
|
|
virtual void resetCamera()
|
|
|
|
{
|
2017-04-07 04:13:23 +00:00
|
|
|
float dist = 3.45;
|
|
|
|
float pitch = 287;
|
|
|
|
float yaw = 16.2;
|
|
|
|
float targetPos[3]={2.05,0.02,0.53};//-3,2.8,-2.5};
|
2015-07-14 22:30:17 +00:00
|
|
|
m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]);
|
2015-08-20 05:51:16 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool wantsTermination()
|
|
|
|
{
|
|
|
|
return m_wantsTermination;
|
|
|
|
}
|
2015-08-06 18:59:31 +00:00
|
|
|
|
|
|
|
virtual bool isConnected()
|
|
|
|
{
|
2015-09-17 06:09:10 +00:00
|
|
|
return (m_physicsClientHandle!=0);
|
2015-08-06 18:59:31 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
void enqueueCommand(int commandId);
|
|
|
|
|
|
|
|
void prepareAndSubmitCommand(int commandId);
|
|
|
|
|
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
virtual void exitPhysics(){};
|
2015-08-20 05:51:16 +00:00
|
|
|
virtual void renderScene()
|
|
|
|
{
|
2016-05-18 16:34:42 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
m_physicsServer.renderScene();
|
|
|
|
}
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
b3DebugLines debugLines;
|
|
|
|
b3GetDebugLines(m_physicsClientHandle,&debugLines);
|
|
|
|
int numLines = debugLines.m_numDebugLines;
|
2015-09-03 21:18:22 +00:00
|
|
|
|
|
|
|
int lineWidth = 1;
|
|
|
|
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
btAlignedObjectArray<btVector3FloatData> points;
|
|
|
|
points.resize(numLines*2);
|
|
|
|
btAlignedObjectArray<unsigned int> indices;
|
|
|
|
indices.resize(numLines*2);
|
|
|
|
|
|
|
|
for (int i=0;i<numLines;i++)
|
|
|
|
{
|
2015-09-17 06:09:10 +00:00
|
|
|
points[i*2].m_floats[0] = debugLines.m_linesFrom[i*3+0];
|
|
|
|
points[i*2].m_floats[1] = debugLines.m_linesFrom[i*3+1];
|
|
|
|
points[i*2].m_floats[2] = debugLines.m_linesFrom[i*3+2];
|
|
|
|
points[i*2+1].m_floats[0] = debugLines.m_linesTo[i*3+0];
|
|
|
|
points[i*2+1].m_floats[1] = debugLines.m_linesTo[i*3+1];
|
|
|
|
points[i*2+1].m_floats[2] = debugLines.m_linesTo[i*3+2];
|
2015-09-03 21:18:22 +00:00
|
|
|
indices[i*2] = i*2;
|
|
|
|
indices[i*2+1] = i*2+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-14 05:23:28 +00:00
|
|
|
float color[4] = {0.2,0.2,1,1};
|
2015-09-03 21:18:22 +00:00
|
|
|
|
|
|
|
if (points.size() && indices.size())
|
|
|
|
{
|
|
|
|
m_guiHelper->getRenderInterface()->drawLines(&points[0].m_floats[0],color,points.size(),sizeof(btVector3FloatData),&indices[0],indices.size(),lineWidth);
|
|
|
|
}
|
|
|
|
} else
|
2015-08-20 05:51:16 +00:00
|
|
|
{
|
2015-09-03 21:18:22 +00:00
|
|
|
for (int i=0;i<numLines;i++)
|
|
|
|
{
|
2015-09-17 06:09:10 +00:00
|
|
|
m_guiHelper->getRenderInterface()->drawLine(debugLines.m_linesFrom,debugLines.m_linesTo,debugLines.m_linesColor,lineWidth);
|
2015-09-03 21:18:22 +00:00
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
}
|
2015-09-04 18:28:08 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
void prepareControlCommand(b3SharedMemoryCommandHandle commandHandle)
|
2015-09-04 18:28:08 +00:00
|
|
|
{
|
2016-06-17 01:46:34 +00:00
|
|
|
|
2015-09-04 18:28:08 +00:00
|
|
|
for (int i=0;i<m_numMotors;i++)
|
|
|
|
{
|
2016-04-19 21:19:18 +00:00
|
|
|
|
|
|
|
btScalar targetPos = m_motorTargetPositions[i].m_posTarget;
|
|
|
|
int qIndex = m_motorTargetPositions[i].m_qIndex;
|
2016-04-19 23:52:47 +00:00
|
|
|
int uIndex = m_motorTargetPositions[i].m_uIndex;
|
2016-06-17 01:46:34 +00:00
|
|
|
static int serial=0;
|
|
|
|
serial++;
|
|
|
|
// b3Printf("# motors = %d, cmd[%d] qIndex = %d, uIndex = %d, targetPos = %f", m_numMotors, serial, qIndex,uIndex,targetPos);
|
|
|
|
|
2016-04-19 21:19:18 +00:00
|
|
|
b3JointControlSetDesiredPosition(commandHandle, qIndex, targetPos);
|
2016-07-13 01:16:13 +00:00
|
|
|
b3JointControlSetDesiredVelocity(commandHandle,uIndex,0);
|
2016-07-25 05:22:42 +00:00
|
|
|
b3JointControlSetKp(commandHandle, qIndex, 0.2);
|
|
|
|
b3JointControlSetKd(commandHandle, uIndex, 1.);
|
2016-04-19 21:19:18 +00:00
|
|
|
|
2016-07-25 05:22:42 +00:00
|
|
|
b3JointControlSetMaximumForce(commandHandle,uIndex,5000);
|
2015-09-04 18:28:08 +00:00
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
}
|
2016-05-18 16:34:42 +00:00
|
|
|
virtual void physicsDebugDraw(int debugFlags)
|
|
|
|
{
|
|
|
|
if (m_options==eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
m_physicsServer.physicsDebugDraw(debugFlags);
|
|
|
|
}
|
|
|
|
}
|
2015-08-07 07:13:26 +00:00
|
|
|
virtual bool mouseMoveCallback(float x,float y){return false;};
|
|
|
|
virtual bool mouseButtonCallback(int button, int state, float x, float y){return false;}
|
|
|
|
virtual bool keyboardCallback(int key, int state){return false;}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void setSharedMemoryKey(int key)
|
|
|
|
{
|
2015-09-17 06:09:10 +00:00
|
|
|
m_sharedMemoryKey = key;
|
2015-08-07 07:13:26 +00:00
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
void MyComboBoxCallback (int combobox, const char* item, void* userPointer)
|
|
|
|
{
|
2016-06-17 01:46:34 +00:00
|
|
|
//b3Printf("Item selected %s", item);
|
2015-10-13 18:32:25 +00:00
|
|
|
|
|
|
|
PhysicsClientExample* cl = (PhysicsClientExample*) userPointer;
|
|
|
|
b3Assert(cl);
|
|
|
|
if (cl)
|
|
|
|
{
|
|
|
|
cl->selectComboBox(combobox,item);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-08-06 18:59:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
void MyCallback(int buttonId, bool buttonState, void* userPtr)
|
|
|
|
{
|
|
|
|
PhysicsClientExample* cl = (PhysicsClientExample*) userPtr;
|
2015-10-13 18:32:25 +00:00
|
|
|
b3Assert(cl);
|
|
|
|
|
|
|
|
if (cl && buttonState)
|
2015-09-17 06:09:10 +00:00
|
|
|
{
|
|
|
|
cl->enqueueCommand(buttonId);
|
|
|
|
}
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
void PhysicsClientExample::enqueueCommand(int commandId)
|
|
|
|
{
|
|
|
|
m_userCommandRequests.push_back(commandId);
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
void PhysicsClientExample::prepareAndSubmitCommand(int commandId)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (commandId)
|
|
|
|
{
|
|
|
|
case CMD_LOAD_URDF:
|
|
|
|
{
|
2016-11-29 21:19:35 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3LoadUrdfCommandInit(m_physicsClientHandle, "kuka_iiwa/model.urdf");
|
2015-09-17 06:09:10 +00:00
|
|
|
//setting the initial position, orientation and other arguments are optional
|
|
|
|
double startPosX = 0;
|
2016-08-18 16:44:33 +00:00
|
|
|
static double startPosY = 0;
|
2015-09-17 06:09:10 +00:00
|
|
|
double startPosZ = 0;
|
2015-09-25 05:42:22 +00:00
|
|
|
b3LoadUrdfCommandSetStartPosition(commandHandle, startPosX,startPosY,startPosZ);
|
2015-10-13 18:32:25 +00:00
|
|
|
startPosY += 2.f;
|
2015-09-17 06:09:10 +00:00
|
|
|
// ret = b3LoadUrdfCommandSetUseFixedBase(commandHandle, 1);
|
2015-09-25 05:42:22 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
2016-06-13 17:11:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CMD_LOAD_SDF:
|
|
|
|
{
|
2017-04-07 04:13:23 +00:00
|
|
|
#ifdef BT_DEBUG
|
2017-05-09 17:31:28 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3LoadSdfCommandInit(m_physicsClientHandle, "two_cubes.sdf");
|
2017-04-07 04:13:23 +00:00
|
|
|
#else
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3LoadSdfCommandInit(m_physicsClientHandle, "kitchens/1.sdf");//two_cubes.sdf");//kitchens/1.sdf");//kuka_iiwa/model.sdf");
|
|
|
|
#endif
|
2016-06-13 17:11:28 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
2015-09-17 06:09:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-20 01:37:15 +00:00
|
|
|
case CMD_REQUEST_CAMERA_IMAGE_DATA:
|
|
|
|
{
|
|
|
|
///request an image from a simulated camera, using a software renderer.
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitRequestCameraImage(m_physicsClientHandle);
|
2016-07-13 01:16:13 +00:00
|
|
|
//b3RequestCameraImageSelectRenderer(commandHandle,ER_BULLET_HARDWARE_OPENGL);
|
2016-06-01 18:04:10 +00:00
|
|
|
|
2016-08-08 21:23:44 +00:00
|
|
|
float viewMatrix[16];
|
|
|
|
float projectionMatrix[16];
|
|
|
|
m_guiHelper->getRenderInterface()->getActiveCamera()->getCameraProjectionMatrix(projectionMatrix);
|
2016-07-13 01:16:13 +00:00
|
|
|
m_guiHelper->getRenderInterface()->getActiveCamera()->getCameraViewMatrix(viewMatrix);
|
|
|
|
|
2016-06-01 18:04:10 +00:00
|
|
|
b3RequestCameraImageSetCameraMatrices(commandHandle, viewMatrix,projectionMatrix);
|
2016-08-08 21:23:44 +00:00
|
|
|
b3RequestCameraImageSetPixelResolution(commandHandle, camVisualizerWidth,camVisualizerHeight);
|
2017-05-08 05:21:38 +00:00
|
|
|
float lightPos[3];
|
|
|
|
lightPos[0] = m_lightPos[0];
|
|
|
|
lightPos[1] = m_lightPos[1];
|
|
|
|
lightPos[2] = m_lightPos[2];
|
|
|
|
b3RequestCameraImageSetLightDirection(commandHandle, lightPos);
|
2017-05-08 04:09:08 +00:00
|
|
|
b3RequestCameraImageSetLightSpecularCoeff(commandHandle, m_specularCoeff);
|
2016-08-08 21:23:44 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
2016-05-20 01:37:15 +00:00
|
|
|
}
|
2015-09-17 06:09:10 +00:00
|
|
|
case CMD_CREATE_BOX_COLLISION_SHAPE:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CreateBoxShapeCommandInit(m_physicsClientHandle);
|
2016-09-01 20:30:07 +00:00
|
|
|
b3CreateBoxCommandSetStartPosition(commandHandle,0,0,-1.5);
|
2015-11-07 01:11:15 +00:00
|
|
|
b3CreateBoxCommandSetColorRGBA(commandHandle,0,0,1,1);
|
2015-09-17 06:09:10 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
2015-10-27 21:55:46 +00:00
|
|
|
case CMD_CREATE_RIGID_BODY:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CreateBoxShapeCommandInit(m_physicsClientHandle);
|
|
|
|
b3CreateBoxCommandSetStartPosition(commandHandle,0,0,0);
|
|
|
|
b3CreateBoxCommandSetMass(commandHandle,1);
|
|
|
|
b3CreateBoxCommandSetCollisionShapeType(commandHandle,COLLISION_SHAPE_TYPE_CYLINDER_Y);
|
2015-11-07 01:11:15 +00:00
|
|
|
b3CreateBoxCommandSetColorRGBA(commandHandle,1,1,0,1);
|
2015-10-27 21:55:46 +00:00
|
|
|
double radius = 0.2;
|
|
|
|
double halfHeight = 0.5;
|
|
|
|
b3CreateBoxCommandSetHalfExtents(commandHandle,radius,halfHeight,radius);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
case CMD_REQUEST_ACTUAL_STATE:
|
|
|
|
{
|
2015-10-27 22:46:13 +00:00
|
|
|
if (m_selectedBody>=0)
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3RequestActualStateCommandInit(m_physicsClientHandle,m_selectedBody);
|
2016-04-19 23:52:47 +00:00
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_physicsClientHandle, commandHandle);
|
2015-10-27 22:46:13 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
2016-04-19 23:52:47 +00:00
|
|
|
|
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle, m_selectedBody);
|
|
|
|
for (int i = 0; i < numJoints; ++i) {
|
|
|
|
struct b3JointSensorState sensorState;
|
|
|
|
b3GetJointState(m_physicsClientHandle, statusHandle, i, &sensorState);
|
2016-10-19 05:05:28 +00:00
|
|
|
//b3Printf("Joint %d: %f", i, sensorState.m_jointMotorTorque);
|
2016-04-19 23:52:47 +00:00
|
|
|
}
|
2015-10-27 22:46:13 +00:00
|
|
|
}
|
2015-09-17 06:09:10 +00:00
|
|
|
break;
|
|
|
|
};
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-10-14 05:23:28 +00:00
|
|
|
case CMD_INIT_POSE:
|
|
|
|
{
|
|
|
|
|
|
|
|
if (m_selectedBody>=0)
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CreatePoseCommandInit(m_physicsClientHandle,m_selectedBody);
|
|
|
|
static int toggle = 0;
|
|
|
|
double pos[3] = {0,0,0};
|
|
|
|
pos[toggle] = 2;
|
|
|
|
toggle++;
|
|
|
|
if (toggle>2)
|
|
|
|
toggle=0;
|
|
|
|
|
|
|
|
btQuaternion orn;
|
|
|
|
orn.setValue(0,0,0,1);
|
|
|
|
|
|
|
|
switch (toggle)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
orn = btQuaternion(btVector3(1,0,0),SIMD_HALF_PI);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
orn = btQuaternion(btVector3(0,1,0),SIMD_HALF_PI);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
orn = btQuaternion(btVector3(0,0,1),SIMD_HALF_PI);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
orn.setValue(0,0,0,1);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
b3CreatePoseCommandSetBaseOrientation(commandHandle,orn[0],orn[1],orn[2],orn[3]);
|
|
|
|
b3CreatePoseCommandSetBasePosition(commandHandle, pos[0],pos[1],pos[2]);
|
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle,m_selectedBody);
|
|
|
|
static double jointPos = SIMD_PI/2.f;
|
|
|
|
|
|
|
|
for (int i=0;i<numJoints;i++)
|
|
|
|
{
|
|
|
|
b3JointInfo info;
|
|
|
|
b3GetJointInfo(m_physicsClientHandle, m_selectedBody,i, &info);
|
|
|
|
if ((info.m_jointType == 0) || (info.m_jointType == 1)) //revolute or prismatic
|
|
|
|
{
|
|
|
|
b3CreatePoseCommandSetJointPosition(m_physicsClientHandle,commandHandle,i,jointPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jointPos += SIMD_PI/8.0;
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-09-17 06:09:10 +00:00
|
|
|
case CMD_STEP_FORWARD_SIMULATION:
|
|
|
|
{
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitStepSimulationCommand(m_physicsClientHandle);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CMD_REQUEST_DEBUG_LINES:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitRequestDebugLinesCommand(m_physicsClientHandle, btIDebugDraw::DBG_DrawWireframe);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SEND_DESIRED_STATE:
|
|
|
|
{
|
2016-06-17 01:46:34 +00:00
|
|
|
if (m_selectedBody>=0)
|
|
|
|
{
|
|
|
|
// b3SharedMemoryCommandHandle command = b3JointControlCommandInit( m_physicsClientHandle, m_selectedBody, CONTROL_MODE_VELOCITY);
|
2016-06-23 15:40:36 +00:00
|
|
|
b3SharedMemoryCommandHandle command = b3JointControlCommandInit2( m_physicsClientHandle, m_selectedBody, CONTROL_MODE_POSITION_VELOCITY_PD);
|
2016-06-17 01:46:34 +00:00
|
|
|
// b3Printf("prepare control command for body %d", m_selectedBody);
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
prepareControlCommand(command);
|
2016-06-17 01:46:34 +00:00
|
|
|
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, command);
|
2016-06-17 01:46:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-09-17 06:09:10 +00:00
|
|
|
}
|
|
|
|
case CMD_RESET_SIMULATION:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitResetSimulationCommand(m_physicsClientHandle);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SEND_BULLET_DATA_STREAM:
|
|
|
|
{
|
|
|
|
#if 0
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
//this worked, but needs C-API and a streaming options, similar to debug lines
|
|
|
|
command.m_type = buttonId;
|
|
|
|
cl->enqueueCommand(command);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
case CMD_CUSTOM_SET_GRAVITY: {
|
2016-04-19 23:52:47 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitPhysicsParamCommand(m_physicsClientHandle);
|
|
|
|
b3PhysicsParamSetGravity(commandHandle, 0.0, 0.0, -9.8);
|
2016-05-18 16:34:42 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
2016-04-19 23:52:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
|
|
|
|
case CMD_CUSTOM_SET_REALTIME_SIMULATION:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitPhysicsParamCommand(m_physicsClientHandle);
|
|
|
|
b3PhysicsParamSetRealTimeSimulation(commandHandle,1);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
|
2016-08-10 01:40:12 +00:00
|
|
|
case CMD_CALCULATE_INVERSE_DYNAMICS:
|
|
|
|
{
|
|
|
|
if (m_selectedBody >= 0)
|
|
|
|
{
|
|
|
|
btAlignedObjectArray<double> jointPositionsQ;
|
|
|
|
btAlignedObjectArray<double> jointVelocitiesQdot;
|
|
|
|
btAlignedObjectArray<double> jointAccelerations;
|
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle, m_selectedBody);
|
|
|
|
if (numJoints)
|
|
|
|
{
|
|
|
|
b3Printf("Compute inverse dynamics for joint accelerations:");
|
|
|
|
jointPositionsQ.resize(numJoints);
|
|
|
|
jointVelocitiesQdot.resize(numJoints);
|
|
|
|
jointAccelerations.resize(numJoints);
|
|
|
|
for (int i = 0; i < numJoints; i++)
|
|
|
|
{
|
|
|
|
jointAccelerations[i] = 100;
|
|
|
|
b3Printf("Desired joint acceleration[%d]=%f", i, jointAccelerations[i]);
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CalculateInverseDynamicsCommandInit(m_physicsClientHandle,
|
|
|
|
m_selectedBody, &jointPositionsQ[0], &jointVelocitiesQdot[0], &jointAccelerations[0]);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
case CMD_REQUEST_CONTACT_POINT_INFORMATION:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitRequestContactPointInformation(m_physicsClientHandle);
|
|
|
|
b3SetContactFilterBodyA(commandHandle,0);
|
|
|
|
b3SetContactFilterBodyB(commandHandle,1);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-13 06:03:36 +00:00
|
|
|
case CMD_SAVE_WORLD:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3SaveWorldCommandInit(m_physicsClientHandle, "saveWorld.py");
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
case CMD_REQUEST_VISUAL_SHAPE_INFO:
|
|
|
|
{
|
|
|
|
if (m_selectedBody >= 0)
|
|
|
|
{
|
|
|
|
//request visual shape information
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitRequestVisualShapeInformation(m_physicsClientHandle, m_selectedBody);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-11-29 21:19:35 +00:00
|
|
|
case CMD_SET_SHADOW:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitRequestCameraImage(m_physicsClientHandle);
|
|
|
|
float viewMatrix[16];
|
|
|
|
float projectionMatrix[16];
|
|
|
|
m_guiHelper->getRenderInterface()->getActiveCamera()->getCameraProjectionMatrix(projectionMatrix);
|
|
|
|
m_guiHelper->getRenderInterface()->getActiveCamera()->getCameraViewMatrix(viewMatrix);
|
|
|
|
|
|
|
|
b3RequestCameraImageSetCameraMatrices(commandHandle, viewMatrix,projectionMatrix);
|
|
|
|
b3RequestCameraImageSetPixelResolution(commandHandle, camVisualizerWidth,camVisualizerHeight);
|
|
|
|
bool hasShadow = true;
|
|
|
|
b3RequestCameraImageSetShadow(commandHandle, hasShadow);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
b3Error("Unknown buttonId");
|
|
|
|
btAssert(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-11-11 20:44:26 +00:00
|
|
|
|
|
|
|
|
2016-05-18 16:34:42 +00:00
|
|
|
PhysicsClientExample::PhysicsClientExample(GUIHelperInterface* helper, int options)
|
2015-07-14 22:30:17 +00:00
|
|
|
:SharedMemoryCommon(helper),
|
2015-10-30 20:24:02 +00:00
|
|
|
m_physicsClientHandle(0),
|
2015-08-07 07:13:26 +00:00
|
|
|
m_wantsTermination(false),
|
2015-09-17 06:09:10 +00:00
|
|
|
m_sharedMemoryKey(SHARED_MEMORY_KEY),
|
2015-11-11 20:44:26 +00:00
|
|
|
m_selectedBody(-1),
|
|
|
|
m_prevSelectedBody(-1),
|
2016-08-11 21:55:30 +00:00
|
|
|
m_canvas(0),
|
|
|
|
m_canvasRGBIndex(-1),
|
|
|
|
m_canvasDepthIndex(-1),
|
2017-01-16 06:26:11 +00:00
|
|
|
m_canvasSegMaskIndex(-1),
|
2017-05-08 04:09:08 +00:00
|
|
|
m_specularCoeff(1.0),
|
2017-01-16 06:26:11 +00:00
|
|
|
m_numMotors(0),
|
|
|
|
m_options(options),
|
|
|
|
m_isOptionalServerConnected(false)
|
2016-08-11 21:55:30 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
{
|
|
|
|
b3Printf("Started PhysicsClientExample\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsClientExample::~PhysicsClientExample()
|
|
|
|
{
|
2015-10-13 18:32:25 +00:00
|
|
|
if (m_physicsClientHandle)
|
|
|
|
{
|
|
|
|
b3ProcessServerStatus(m_physicsClientHandle);
|
|
|
|
b3DisconnectSharedMemory(m_physicsClientHandle);
|
|
|
|
}
|
2016-05-18 16:34:42 +00:00
|
|
|
|
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
bool deInitializeSharedMemory = true;
|
|
|
|
m_physicsServer.disconnectSharedMemory(deInitializeSharedMemory);
|
|
|
|
}
|
2016-06-04 02:03:56 +00:00
|
|
|
|
2016-08-11 21:55:30 +00:00
|
|
|
if (m_canvas)
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
2016-08-11 21:55:30 +00:00
|
|
|
if (m_canvasRGBIndex>=0)
|
|
|
|
m_canvas->destroyCanvas(m_canvasRGBIndex);
|
|
|
|
if (m_canvasDepthIndex>=0)
|
|
|
|
m_canvas->destroyCanvas(m_canvasDepthIndex);
|
|
|
|
if (m_canvasSegMaskIndex>=0)
|
|
|
|
m_canvas->destroyCanvas(m_canvasSegMaskIndex);
|
|
|
|
|
2016-06-04 02:03:56 +00:00
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
b3Printf("~PhysicsClientExample\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsClientExample::createButton(const char* name, int buttonId, bool isTrigger )
|
|
|
|
{
|
|
|
|
ButtonParams button(name,buttonId, isTrigger);
|
|
|
|
button.m_callback = MyCallback;
|
|
|
|
button.m_userPointer = this;
|
|
|
|
m_guiHelper->getParameterInterface()->registerButtonParameter(button);
|
|
|
|
}
|
2015-08-07 07:13:26 +00:00
|
|
|
|
|
|
|
void PhysicsClientExample::createButtons()
|
|
|
|
{
|
|
|
|
bool isTrigger = false;
|
|
|
|
|
2015-09-09 22:14:47 +00:00
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
2015-10-13 18:32:25 +00:00
|
|
|
m_guiHelper->getParameterInterface()->removeAllParameters();
|
|
|
|
|
2015-09-09 22:14:47 +00:00
|
|
|
createButton("Load URDF",CMD_LOAD_URDF, isTrigger);
|
2016-06-13 17:11:28 +00:00
|
|
|
createButton("Load SDF",CMD_LOAD_SDF, isTrigger);
|
2016-10-13 06:03:36 +00:00
|
|
|
createButton("Save World",CMD_SAVE_WORLD, isTrigger);
|
2016-11-29 21:19:35 +00:00
|
|
|
createButton("Set Shadow",CMD_SET_SHADOW, isTrigger);
|
2016-05-20 01:37:15 +00:00
|
|
|
createButton("Get Camera Image",CMD_REQUEST_CAMERA_IMAGE_DATA,isTrigger);
|
2015-09-09 22:14:47 +00:00
|
|
|
createButton("Step Sim",CMD_STEP_FORWARD_SIMULATION, isTrigger);
|
2016-10-19 05:05:28 +00:00
|
|
|
createButton("Realtime Sim",CMD_CUSTOM_SET_REALTIME_SIMULATION, isTrigger);
|
|
|
|
createButton("Get Visual Shape Info",CMD_REQUEST_VISUAL_SHAPE_INFO, isTrigger);
|
2015-09-09 22:14:47 +00:00
|
|
|
createButton("Send Bullet Stream",CMD_SEND_BULLET_DATA_STREAM, isTrigger);
|
2016-05-18 16:34:42 +00:00
|
|
|
if (m_options!=eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
createButton("Get State",CMD_REQUEST_ACTUAL_STATE, isTrigger);
|
|
|
|
}
|
2015-09-09 22:14:47 +00:00
|
|
|
createButton("Send Desired State",CMD_SEND_DESIRED_STATE, isTrigger);
|
|
|
|
createButton("Create Box Collider",CMD_CREATE_BOX_COLLISION_SHAPE,isTrigger);
|
2016-07-13 01:16:13 +00:00
|
|
|
createButton("Create Cylinder Body",CMD_CREATE_RIGID_BODY,isTrigger);
|
2015-09-09 22:14:47 +00:00
|
|
|
createButton("Reset Simulation",CMD_RESET_SIMULATION,isTrigger);
|
2016-07-13 01:16:13 +00:00
|
|
|
createButton("Initialize Pose",CMD_INIT_POSE, isTrigger);
|
2016-10-19 05:05:28 +00:00
|
|
|
createButton("Set gravity", CMD_CUSTOM_SET_GRAVITY, isTrigger);
|
2016-08-10 01:40:12 +00:00
|
|
|
createButton("Compute Inverse Dynamics", CMD_CALCULATE_INVERSE_DYNAMICS, isTrigger);
|
2016-09-01 20:30:07 +00:00
|
|
|
createButton("Get Contact Point Info", CMD_REQUEST_CONTACT_POINT_INFORMATION, isTrigger);
|
2015-10-13 18:32:25 +00:00
|
|
|
|
2016-06-17 01:46:34 +00:00
|
|
|
if (m_bodyUniqueIds.size())
|
|
|
|
{
|
|
|
|
if (m_selectedBody<0)
|
|
|
|
m_selectedBody = 0;
|
|
|
|
|
|
|
|
ComboBoxParams comboParams;
|
|
|
|
comboParams.m_comboboxId = 0;
|
|
|
|
comboParams.m_numItems = m_bodyUniqueIds.size();
|
|
|
|
comboParams.m_startItem = m_selectedBody;
|
|
|
|
comboParams.m_callback = MyComboBoxCallback;
|
|
|
|
comboParams.m_userPointer = this;
|
|
|
|
//todo: get the real object name
|
|
|
|
|
|
|
|
const char** blarray = new const char*[m_bodyUniqueIds.size()];
|
|
|
|
|
|
|
|
for (int i=0;i<m_bodyUniqueIds.size();i++)
|
|
|
|
{
|
|
|
|
char* bla = new char[16];
|
|
|
|
sprintf(bla,"%d", i);
|
|
|
|
blarray[i] = bla;
|
|
|
|
comboParams.m_items=blarray;//{&bla};
|
|
|
|
}
|
|
|
|
m_guiHelper->getParameterInterface()->registerComboBox(comboParams);
|
|
|
|
}
|
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
|
2015-10-30 20:24:02 +00:00
|
|
|
if (m_physicsClientHandle && m_selectedBody>=0)
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
2016-06-17 01:46:34 +00:00
|
|
|
m_numMotors = 0;
|
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle,m_selectedBody);
|
|
|
|
for (int i=0;i<numJoints;i++)
|
|
|
|
{
|
|
|
|
b3JointInfo info;
|
|
|
|
b3GetJointInfo(m_physicsClientHandle,m_selectedBody,i,&info);
|
2016-10-19 05:05:28 +00:00
|
|
|
//b3Printf("Joint %s at q-index %d and u-index %d\n",info.m_jointName,info.m_qIndex,info.m_uIndex);
|
2015-10-13 18:32:25 +00:00
|
|
|
|
|
|
|
if (info.m_flags & JOINT_HAS_MOTORIZED_POWER)
|
|
|
|
{
|
|
|
|
if (m_numMotors<MAX_NUM_MOTORS)
|
|
|
|
{
|
|
|
|
char motorName[1024];
|
2016-04-19 23:52:47 +00:00
|
|
|
sprintf(motorName,"%s q", info.m_jointName);
|
|
|
|
// MyMotorInfo2* motorInfo = &m_motorTargetVelocities[m_numMotors];
|
|
|
|
MyMotorInfo2* motorInfo = &m_motorTargetPositions[m_numMotors];
|
2015-10-13 18:32:25 +00:00
|
|
|
motorInfo->m_velTarget = 0.f;
|
2016-04-19 23:52:47 +00:00
|
|
|
motorInfo->m_posTarget = 0.f;
|
2015-10-13 18:32:25 +00:00
|
|
|
motorInfo->m_uIndex = info.m_uIndex;
|
2016-04-19 21:19:18 +00:00
|
|
|
motorInfo->m_qIndex = info.m_qIndex;
|
2015-10-13 18:32:25 +00:00
|
|
|
|
2016-04-19 23:52:47 +00:00
|
|
|
// SliderParams slider(motorName,&motorInfo->m_velTarget);
|
|
|
|
// slider.m_minVal=-4;
|
|
|
|
// slider.m_maxVal=4;
|
|
|
|
SliderParams slider(motorName,&motorInfo->m_posTarget);
|
|
|
|
slider.m_minVal=-4;
|
|
|
|
slider.m_maxVal=4;
|
2015-10-13 18:32:25 +00:00
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
|
|
|
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
|
|
|
|
}
|
|
|
|
m_numMotors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-08 04:09:08 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SliderParams sliderLightPosX("light source position x",&m_lightPos[0]);
|
|
|
|
SliderParams sliderLightPosY("light source position y",&m_lightPos[1]);
|
|
|
|
SliderParams sliderLightPosZ("light source position z",&m_lightPos[2]);
|
|
|
|
SliderParams sliderSpecularCoeff("specular coefficient",&m_specularCoeff);
|
|
|
|
sliderLightPosX.m_minVal=-1.5;
|
|
|
|
sliderLightPosX.m_maxVal=1.5;
|
|
|
|
sliderLightPosY.m_minVal=-1.5;
|
|
|
|
sliderLightPosY.m_maxVal=1.5;
|
|
|
|
sliderLightPosZ.m_minVal=-1.5;
|
|
|
|
sliderLightPosZ.m_maxVal=1.5;
|
|
|
|
sliderSpecularCoeff.m_minVal=0;
|
|
|
|
sliderSpecularCoeff.m_maxVal=5.0;
|
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
|
|
|
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(sliderLightPosX);
|
|
|
|
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(sliderLightPosY);
|
|
|
|
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(sliderLightPosZ);
|
|
|
|
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(sliderSpecularCoeff);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-09-09 22:14:47 +00:00
|
|
|
}
|
2015-08-07 07:13:26 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
void PhysicsClientExample::initPhysics()
|
|
|
|
{
|
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
int upAxis = 2;
|
|
|
|
m_guiHelper->setUpAxis(upAxis);
|
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
createButtons();
|
2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
2015-09-09 22:14:47 +00:00
|
|
|
MyCallback(CMD_LOAD_URDF, true, this);
|
|
|
|
MyCallback(CMD_STEP_FORWARD_SIMULATION,true,this);
|
2016-09-27 19:13:45 +00:00
|
|
|
|
2015-09-09 22:14:47 +00:00
|
|
|
MyCallback(CMD_RESET_SIMULATION,true,this);
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
m_selectedBody = -1;
|
|
|
|
m_prevSelectedBody = -1;
|
2017-05-08 04:09:08 +00:00
|
|
|
|
|
|
|
m_lightPos[0] = 1.0;
|
|
|
|
m_lightPos[1] = 1.0;
|
|
|
|
m_lightPos[2] = 1.0;
|
2015-10-13 18:32:25 +00:00
|
|
|
|
2016-05-18 16:34:42 +00:00
|
|
|
{
|
2016-05-31 17:23:04 +00:00
|
|
|
m_canvas = m_guiHelper->get2dCanvasInterface();
|
|
|
|
if (m_canvas)
|
|
|
|
{
|
2016-08-11 21:55:30 +00:00
|
|
|
|
|
|
|
m_canvasRGBIndex = m_canvas->createCanvas("Synthetic Camera RGB data",camVisualizerWidth, camVisualizerHeight);
|
|
|
|
m_canvasDepthIndex = m_canvas->createCanvas("Synthetic Camera Depth data",camVisualizerWidth, camVisualizerHeight);
|
|
|
|
m_canvasSegMaskIndex = m_canvas->createCanvas("Synthetic Camera Segmentation Mask",camVisualizerWidth, camVisualizerHeight);
|
2016-05-31 17:23:04 +00:00
|
|
|
|
|
|
|
for (int i=0;i<camVisualizerWidth;i++)
|
|
|
|
{
|
|
|
|
for (int j=0;j<camVisualizerHeight;j++)
|
|
|
|
{
|
|
|
|
unsigned char red=255;
|
|
|
|
unsigned char green=255;
|
|
|
|
unsigned char blue=255;
|
|
|
|
unsigned char alpha=255;
|
|
|
|
if (i==j)
|
|
|
|
{
|
|
|
|
red = 0;
|
|
|
|
green=0;
|
|
|
|
blue=0;
|
|
|
|
}
|
2016-08-11 21:55:30 +00:00
|
|
|
m_canvas->setPixel(m_canvasRGBIndex,i,j,red,green,blue,alpha);
|
|
|
|
m_canvas->setPixel(m_canvasDepthIndex,i,j,red,green,blue,alpha);
|
|
|
|
m_canvas->setPixel(m_canvasSegMaskIndex,i,j,red,green,blue,alpha);
|
|
|
|
|
2016-05-31 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 21:55:30 +00:00
|
|
|
m_canvas->refreshImageData(m_canvasRGBIndex);
|
|
|
|
m_canvas->refreshImageData(m_canvasDepthIndex);
|
|
|
|
m_canvas->refreshImageData(m_canvasSegMaskIndex);
|
|
|
|
|
2016-05-31 17:23:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-18 16:34:42 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 20:54:52 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
m_isOptionalServerConnected = m_physicsServer.connectSharedMemory( m_guiHelper);
|
|
|
|
}
|
|
|
|
|
2016-06-04 02:03:56 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_DIRECT)
|
|
|
|
{
|
|
|
|
m_physicsClientHandle = b3ConnectPhysicsDirect();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_physicsClientHandle = b3ConnectSharedMemory(m_sharedMemoryKey);
|
|
|
|
//m_physicsClientHandle = b3ConnectPhysicsLoopback(SHARED_MEMORY_KEY);
|
|
|
|
}
|
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
if (!b3CanSubmitCommand(m_physicsClientHandle))
|
|
|
|
{
|
2015-08-06 18:59:31 +00:00
|
|
|
b3Warning("Cannot connect to physics client");
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PhysicsClientExample::stepSimulation(float deltaTime)
|
|
|
|
{
|
2016-05-18 16:34:42 +00:00
|
|
|
|
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
for (int i=0;i<100;i++)
|
|
|
|
{
|
|
|
|
m_physicsServer.processClientCommands();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
if (m_prevSelectedBody != m_selectedBody)
|
|
|
|
{
|
|
|
|
createButtons();
|
|
|
|
m_prevSelectedBody = m_selectedBody;
|
|
|
|
}
|
2015-10-14 05:23:28 +00:00
|
|
|
|
|
|
|
//while (!b3CanSubmitCommand(m_physicsClientHandle))
|
|
|
|
{
|
|
|
|
b3SharedMemoryStatusHandle status = b3ProcessServerStatus(m_physicsClientHandle);
|
|
|
|
bool hasStatus = (status != 0);
|
|
|
|
if (hasStatus)
|
2015-07-21 06:35:29 +00:00
|
|
|
{
|
2015-10-14 05:23:28 +00:00
|
|
|
|
|
|
|
int statusType = b3GetStatusType(status);
|
|
|
|
if (statusType == CMD_ACTUAL_STATE_UPDATE_COMPLETED)
|
2015-07-21 06:35:29 +00:00
|
|
|
{
|
2015-10-14 05:23:28 +00:00
|
|
|
//b3Printf("bla\n");
|
|
|
|
}
|
2016-05-20 01:37:15 +00:00
|
|
|
if (statusType ==CMD_CAMERA_IMAGE_COMPLETED)
|
|
|
|
{
|
2016-06-07 01:54:05 +00:00
|
|
|
// static int counter=0;
|
|
|
|
// char msg[1024];
|
|
|
|
// sprintf(msg,"Camera image %d OK\n",counter++);
|
2016-05-31 17:23:04 +00:00
|
|
|
b3CameraImageData imageData;
|
|
|
|
b3GetCameraImageData(m_physicsClientHandle,&imageData);
|
2016-08-11 21:55:30 +00:00
|
|
|
if (m_canvas)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2016-08-11 21:55:30 +00:00
|
|
|
|
|
|
|
//compute depth image range
|
|
|
|
float minDepthValue = 1e20f;
|
|
|
|
float maxDepthValue = -1e20f;
|
|
|
|
|
|
|
|
for (int i=0;i<camVisualizerWidth;i++)
|
|
|
|
{
|
|
|
|
for (int j=0;j<camVisualizerHeight;j++)
|
|
|
|
{
|
|
|
|
int xIndex = int(float(i)*(float(imageData.m_pixelWidth)/float(camVisualizerWidth)));
|
|
|
|
int yIndex = int(float(j)*(float(imageData.m_pixelHeight)/float(camVisualizerHeight)));
|
|
|
|
btClamp(yIndex,0,imageData.m_pixelHeight);
|
|
|
|
btClamp(xIndex,0,imageData.m_pixelWidth);
|
|
|
|
|
|
|
|
if (m_canvasDepthIndex >=0)
|
|
|
|
{
|
|
|
|
int depthPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth);
|
2016-08-12 20:55:37 +00:00
|
|
|
float depthValue = imageData.m_depthValues[depthPixelIndex];
|
2016-08-11 21:55:30 +00:00
|
|
|
//todo: rescale the depthValue to [0..255]
|
|
|
|
if (depthValue>-1e20)
|
|
|
|
{
|
|
|
|
maxDepthValue = btMax(maxDepthValue,depthValue);
|
|
|
|
minDepthValue = btMin(minDepthValue,depthValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 23:11:58 +00:00
|
|
|
for (int i=0;i<camVisualizerWidth;i++)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2016-06-07 23:11:58 +00:00
|
|
|
for (int j=0;j<camVisualizerHeight;j++)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2016-06-07 23:11:58 +00:00
|
|
|
int xIndex = int(float(i)*(float(imageData.m_pixelWidth)/float(camVisualizerWidth)));
|
|
|
|
int yIndex = int(float(j)*(float(imageData.m_pixelHeight)/float(camVisualizerHeight)));
|
2016-05-31 17:23:04 +00:00
|
|
|
btClamp(yIndex,0,imageData.m_pixelHeight);
|
|
|
|
btClamp(xIndex,0,imageData.m_pixelWidth);
|
2016-06-10 22:07:52 +00:00
|
|
|
int bytesPerPixel = 4; //RGBA
|
2016-05-31 17:23:04 +00:00
|
|
|
|
2016-08-11 21:55:30 +00:00
|
|
|
if (m_canvasRGBIndex >=0)
|
|
|
|
{
|
|
|
|
int rgbPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth)*bytesPerPixel;
|
|
|
|
m_canvas->setPixel(m_canvasRGBIndex,i,j,
|
|
|
|
imageData.m_rgbColorData[rgbPixelIndex],
|
|
|
|
imageData.m_rgbColorData[rgbPixelIndex+1],
|
|
|
|
imageData.m_rgbColorData[rgbPixelIndex+2],
|
|
|
|
255); //alpha set to 255
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_canvasDepthIndex >=0)
|
|
|
|
{
|
|
|
|
int depthPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth);
|
2016-08-12 20:55:37 +00:00
|
|
|
float depthValue = imageData.m_depthValues[depthPixelIndex];
|
2016-08-11 21:55:30 +00:00
|
|
|
//todo: rescale the depthValue to [0..255]
|
|
|
|
if (depthValue>-1e20)
|
|
|
|
{
|
2017-04-06 21:31:34 +00:00
|
|
|
int rgb = 0;
|
|
|
|
|
|
|
|
if (maxDepthValue!=minDepthValue)
|
|
|
|
{
|
|
|
|
rgb = (depthValue-minDepthValue)*(255. / (btFabs(maxDepthValue-minDepthValue)));
|
|
|
|
if (rgb<0 || rgb>255)
|
|
|
|
{
|
|
|
|
//printf("rgb=%d\n",rgb);
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 21:55:30 +00:00
|
|
|
m_canvas->setPixel(m_canvasDepthIndex,i,j,
|
|
|
|
rgb,
|
|
|
|
rgb,
|
|
|
|
255, 255); //alpha set to 255
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_canvas->setPixel(m_canvasDepthIndex,i,j,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, 255); //alpha set to 255
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_canvasSegMaskIndex>=0 && (0!=imageData.m_segmentationMaskValues))
|
|
|
|
{
|
|
|
|
int segmentationMaskPixelIndex = (xIndex+yIndex*imageData.m_pixelWidth);
|
|
|
|
int segmentationMask = imageData.m_segmentationMaskValues[segmentationMaskPixelIndex];
|
|
|
|
btVector4 palette[4] = {btVector4(32,255,32,255),
|
|
|
|
btVector4(32,32,255,255),
|
|
|
|
btVector4(255,255,32,255),
|
|
|
|
btVector4(32,255,255,255)};
|
|
|
|
if (segmentationMask>=0)
|
|
|
|
{
|
|
|
|
btVector4 rgb = palette[segmentationMask&3];
|
|
|
|
m_canvas->setPixel(m_canvasSegMaskIndex,i,j,
|
|
|
|
rgb.x(),
|
|
|
|
rgb.y(),
|
|
|
|
rgb.z(), 255); //alpha set to 255
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_canvas->setPixel(m_canvasSegMaskIndex,i,j,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, 255); //alpha set to 255
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 17:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 21:55:30 +00:00
|
|
|
if (m_canvasRGBIndex >=0)
|
|
|
|
m_canvas->refreshImageData(m_canvasRGBIndex);
|
|
|
|
if (m_canvasDepthIndex >=0)
|
|
|
|
m_canvas->refreshImageData(m_canvasDepthIndex);
|
|
|
|
if (m_canvasSegMaskIndex >=0)
|
|
|
|
m_canvas->refreshImageData(m_canvasSegMaskIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-31 17:23:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 01:54:05 +00:00
|
|
|
// b3Printf(msg);
|
2016-05-20 01:37:15 +00:00
|
|
|
}
|
2016-08-10 01:40:12 +00:00
|
|
|
if (statusType == CMD_CALCULATED_INVERSE_DYNAMICS_COMPLETED)
|
|
|
|
{
|
|
|
|
int bodyUniqueId;
|
|
|
|
int dofCount;
|
|
|
|
|
|
|
|
b3GetStatusInverseDynamicsJointForces(status,
|
|
|
|
&bodyUniqueId,
|
|
|
|
&dofCount,
|
|
|
|
0);
|
|
|
|
|
|
|
|
btAlignedObjectArray<double> jointForces;
|
|
|
|
if (dofCount)
|
|
|
|
{
|
|
|
|
jointForces.resize(dofCount);
|
|
|
|
b3GetStatusInverseDynamicsJointForces(status,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&jointForces[0]);
|
|
|
|
for (int i = 0; i < dofCount; i++)
|
|
|
|
{
|
|
|
|
b3Printf("jointForces[%d]=%f", i, jointForces[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (statusType == CMD_CALCULATED_INVERSE_DYNAMICS_FAILED)
|
|
|
|
{
|
|
|
|
b3Warning("Inverse Dynamics computations failed");
|
|
|
|
}
|
|
|
|
|
2016-05-20 01:37:15 +00:00
|
|
|
if (statusType == CMD_CAMERA_IMAGE_FAILED)
|
|
|
|
{
|
2016-06-07 01:54:05 +00:00
|
|
|
b3Warning("Camera image FAILED\n");
|
2016-05-20 01:37:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-13 17:11:28 +00:00
|
|
|
if (statusType == CMD_SDF_LOADING_COMPLETED)
|
|
|
|
{
|
2016-06-15 01:41:19 +00:00
|
|
|
int bodyIndicesOut[1024];
|
|
|
|
int bodyCapacity = 1024;
|
|
|
|
int numBodies = b3GetStatusBodyIndices(status, bodyIndicesOut, bodyCapacity);
|
|
|
|
if (numBodies > bodyCapacity)
|
|
|
|
{
|
|
|
|
b3Warning("loadSDF number of bodies (%d) exceeds the internal body capacity (%d)",numBodies, bodyCapacity);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
for (int i=0;i<numBodies;i++)
|
|
|
|
{
|
|
|
|
int bodyUniqueId = bodyIndicesOut[i];
|
2016-06-17 01:46:34 +00:00
|
|
|
m_bodyUniqueIds.push_back(bodyUniqueId);
|
2016-06-15 01:41:19 +00:00
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle,bodyUniqueId);
|
2016-06-17 01:46:34 +00:00
|
|
|
if (numJoints>0)
|
|
|
|
{
|
|
|
|
m_selectedBody = bodyUniqueId;
|
|
|
|
}
|
|
|
|
/* int numJoints = b3GetNumJoints(m_physicsClientHandle,bodyUniqueId);
|
2016-06-15 01:41:19 +00:00
|
|
|
b3Printf("numJoints = %d", numJoints);
|
|
|
|
for (int i=0;i<numJoints;i++)
|
|
|
|
{
|
|
|
|
b3JointInfo info;
|
|
|
|
b3GetJointInfo(m_physicsClientHandle,bodyUniqueId,i,&info);
|
|
|
|
b3Printf("Joint %s at q-index %d and u-index %d\n",info.m_jointName,info.m_qIndex,info.m_uIndex);
|
|
|
|
}
|
2016-06-17 01:46:34 +00:00
|
|
|
|
|
|
|
*/
|
2016-06-15 01:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//int numJoints = b3GetNumJoints(m_physicsClientHandle,bodyIndex);
|
|
|
|
|
2016-06-13 17:11:28 +00:00
|
|
|
//int bodyIndex = b3GetStatusBodyIndex(status);
|
|
|
|
/*if (bodyIndex>=0)
|
|
|
|
{
|
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle,bodyIndex);
|
|
|
|
|
|
|
|
for (int i=0;i<numJoints;i++)
|
|
|
|
{
|
|
|
|
b3JointInfo info;
|
|
|
|
b3GetJointInfo(m_physicsClientHandle,bodyIndex,i,&info);
|
|
|
|
b3Printf("Joint %s at q-index %d and u-index %d\n",info.m_jointName,info.m_qIndex,info.m_uIndex);
|
|
|
|
}
|
|
|
|
ComboBoxParams comboParams;
|
|
|
|
comboParams.m_comboboxId = bodyIndex;
|
|
|
|
comboParams.m_numItems = 1;
|
|
|
|
comboParams.m_startItem = 0;
|
|
|
|
comboParams.m_callback = MyComboBoxCallback;
|
|
|
|
comboParams.m_userPointer = this;
|
|
|
|
const char* bla = "bla";
|
|
|
|
const char* blarray[1];
|
|
|
|
blarray[0] = bla;
|
|
|
|
|
|
|
|
comboParams.m_items=blarray;//{&bla};
|
|
|
|
m_guiHelper->getParameterInterface()->registerComboBox(comboParams);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2016-05-20 01:37:15 +00:00
|
|
|
|
2015-10-14 05:23:28 +00:00
|
|
|
if (statusType == CMD_URDF_LOADING_COMPLETED)
|
|
|
|
{
|
|
|
|
int bodyIndex = b3GetStatusBodyIndex(status);
|
|
|
|
if (bodyIndex>=0)
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
2016-06-17 01:46:34 +00:00
|
|
|
m_bodyUniqueIds.push_back(bodyIndex);
|
|
|
|
m_selectedBody = bodyIndex;
|
2015-10-14 05:23:28 +00:00
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle,bodyIndex);
|
|
|
|
|
|
|
|
for (int i=0;i<numJoints;i++)
|
|
|
|
{
|
|
|
|
b3JointInfo info;
|
|
|
|
b3GetJointInfo(m_physicsClientHandle,bodyIndex,i,&info);
|
2016-10-19 05:05:28 +00:00
|
|
|
//b3Printf("Joint %s at q-index %d and u-index %d\n",info.m_jointName,info.m_qIndex,info.m_uIndex);
|
2015-10-14 05:23:28 +00:00
|
|
|
}
|
2016-06-17 01:46:34 +00:00
|
|
|
|
2015-10-14 05:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
if (statusType == CMD_CONTACT_POINT_INFORMATION_FAILED)
|
|
|
|
{
|
|
|
|
b3Warning("Cannot get contact information");
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
if (statusType == CMD_VISUAL_SHAPE_INFO_FAILED)
|
|
|
|
{
|
|
|
|
b3Warning("Cannot get visual shape information");
|
|
|
|
}
|
2016-10-20 17:56:44 +00:00
|
|
|
if (statusType == CMD_VISUAL_SHAPE_UPDATE_FAILED)
|
|
|
|
{
|
|
|
|
b3Warning("Cannot update visual shape");
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
if (statusType == CMD_VISUAL_SHAPE_INFO_COMPLETED)
|
|
|
|
{
|
|
|
|
b3VisualShapeInformation shapeInfo;
|
|
|
|
b3GetVisualShapeInformation(m_physicsClientHandle, &shapeInfo);
|
|
|
|
b3Printf("Num visual shapes: %d", shapeInfo.m_numVisualShapes);
|
|
|
|
}
|
2016-10-20 17:56:44 +00:00
|
|
|
if (statusType == CMD_VISUAL_SHAPE_UPDATE_COMPLETED)
|
|
|
|
{
|
|
|
|
b3Printf("Visual shape update completed.");
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
if (statusType == CMD_CONTACT_POINT_INFORMATION_COMPLETED)
|
|
|
|
{
|
|
|
|
b3ContactInformation contactPointData;
|
|
|
|
b3GetContactPointInformation(m_physicsClientHandle, &contactPointData);
|
|
|
|
b3Printf("Num Contacts: %d\n", contactPointData.m_numContactPoints);
|
|
|
|
|
|
|
|
}
|
2015-10-14 05:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-17 06:09:10 +00:00
|
|
|
if (b3CanSubmitCommand(m_physicsClientHandle))
|
|
|
|
{
|
|
|
|
if (m_userCommandRequests.size())
|
|
|
|
{
|
|
|
|
//b3Printf("Outstanding user command requests: %d\n", m_userCommandRequests.size());
|
|
|
|
int commandId = m_userCommandRequests[0];
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
//a manual 'pop_front', we don't use 'remove' because it will re-order the commands
|
|
|
|
for (int i=1;i<m_userCommandRequests.size();i++)
|
|
|
|
{
|
|
|
|
m_userCommandRequests[i-1] = m_userCommandRequests[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
m_userCommandRequests.pop_back();
|
|
|
|
|
|
|
|
//for the CMD_RESET_SIMULATION we need to do something special: clear the GUI sliders
|
|
|
|
if (commandId ==CMD_RESET_SIMULATION)
|
|
|
|
{
|
2015-10-13 18:32:25 +00:00
|
|
|
m_selectedBody = -1;
|
2015-09-17 06:09:10 +00:00
|
|
|
m_numMotors=0;
|
2016-06-17 01:46:34 +00:00
|
|
|
m_bodyUniqueIds.clear();
|
2015-09-17 06:09:10 +00:00
|
|
|
createButtons();
|
2016-05-18 16:34:42 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitResetSimulationCommand(m_physicsClientHandle);
|
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
while (!b3CanSubmitCommand(m_physicsClientHandle))
|
|
|
|
{
|
|
|
|
m_physicsServer.processClientCommands();
|
|
|
|
b3SharedMemoryStatusHandle status = b3ProcessServerStatus(m_physicsClientHandle);
|
|
|
|
bool hasStatus = (status != 0);
|
|
|
|
if (hasStatus)
|
|
|
|
{
|
2016-06-07 01:54:05 +00:00
|
|
|
//int statusType = b3GetStatusType(status);
|
|
|
|
//b3Printf("Status after reset: %d",statusType);
|
2016-05-18 16:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
prepareAndSubmitCommand(commandId);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
prepareAndSubmitCommand(commandId);
|
|
|
|
}
|
2015-09-17 06:09:10 +00:00
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
if (m_numMotors)
|
|
|
|
{
|
|
|
|
enqueueCommand(CMD_SEND_DESIRED_STATE);
|
|
|
|
}
|
2016-06-13 17:11:28 +00:00
|
|
|
enqueueCommand(CMD_STEP_FORWARD_SIMULATION);
|
|
|
|
if (m_options != eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
2016-07-03 01:53:19 +00:00
|
|
|
//enqueueCommand(CMD_REQUEST_DEBUG_LINES);
|
2016-06-13 17:11:28 +00:00
|
|
|
}
|
2015-09-17 06:09:10 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
extern int gSharedMemoryKey;
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
class CommonExampleInterface* PhysicsClientCreateFunc(struct CommonExampleOptions& options)
|
|
|
|
{
|
2016-05-18 16:34:42 +00:00
|
|
|
PhysicsClientExample* example = new PhysicsClientExample(options.m_guiHelper, options.m_option);
|
2015-08-07 07:13:26 +00:00
|
|
|
if (gSharedMemoryKey>=0)
|
|
|
|
{
|
|
|
|
example->setSharedMemoryKey(gSharedMemoryKey);
|
|
|
|
}
|
|
|
|
return example;
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
2016-07-03 01:53:19 +00:00
|
|
|
|