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"
|
2017-05-31 02:54:55 +00:00
|
|
|
#include "PhysicsServerCommandProcessor.h"
|
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"
|
2021-03-16 05:44:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define safe_printf _snprintf
|
|
|
|
#else
|
|
|
|
#define safe_printf snprintf
|
|
|
|
#endif
|
2015-08-06 18:59:31 +00:00
|
|
|
struct MyMotorInfo2
|
|
|
|
{
|
|
|
|
btScalar m_velTarget;
|
|
|
|
btScalar m_maxForce;
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar m_posTarget;
|
|
|
|
int m_uIndex;
|
|
|
|
int m_qIndex;
|
2015-08-06 18:59:31 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static int camVisualizerWidth = 228; //1024/3;
|
|
|
|
static int camVisualizerHeight = 192; //768/3;
|
2016-05-31 17:23:04 +00:00
|
|
|
|
2016-10-19 05:05:28 +00:00
|
|
|
enum CustomCommands
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
CMD_CUSTOM_SET_REALTIME_SIMULATION = CMD_MAX_CLIENT_COMMANDS + 1,
|
2016-10-19 05:05:28 +00:00
|
|
|
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:
|
2018-09-23 21:17:31 +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
|
2018-09-23 21:17:31 +00:00
|
|
|
PhysicsServerSharedMemory m_physicsServer;
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
bool m_wantsTermination;
|
2018-09-23 21:17:31 +00:00
|
|
|
btAlignedObjectArray<int> m_userCommandRequests;
|
|
|
|
btAlignedObjectArray<int> m_bodyUniqueIds;
|
|
|
|
|
|
|
|
int m_sharedMemoryKey;
|
|
|
|
int m_selectedBody;
|
2015-10-13 18:32:25 +00:00
|
|
|
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;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
void createButton(const char* name, int id, bool isTrigger);
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
void createButtons();
|
2016-05-18 16:34:42 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
//@todo, add accessor methods
|
2016-04-19 23:52:47 +00:00
|
|
|
// MyMotorInfo2 m_motorTargetVelocities[MAX_NUM_MOTORS];
|
2018-09-23 21:17:31 +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
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
public:
|
2016-05-18 16:34:42 +00:00
|
|
|
PhysicsClientExample(GUIHelperInterface* helper, int options);
|
2015-07-14 22:30:17 +00:00
|
|
|
virtual ~PhysicsClientExample();
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
virtual void initPhysics();
|
|
|
|
void selectComboBox(int comboIndex, const char* name)
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int itemIndex = int(atoi(name));
|
2016-06-17 01:46:34 +00:00
|
|
|
int bodyIndex = m_bodyUniqueIds[itemIndex];
|
2015-10-13 18:32:25 +00:00
|
|
|
if (m_selectedBody != bodyIndex)
|
|
|
|
{
|
|
|
|
m_selectedBody = bodyIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
virtual void stepSimulation(float deltaTime);
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
virtual void resetCamera()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float dist = 3.45;
|
|
|
|
float pitch = -16.2;
|
|
|
|
float yaw = 287;
|
|
|
|
float targetPos[3] = {2.05, 0.02, 0.53}; //-3,2.8,-2.5};
|
|
|
|
m_guiHelper->resetCamera(dist, yaw, pitch, targetPos[0], targetPos[1], targetPos[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool wantsTermination()
|
|
|
|
{
|
|
|
|
return m_wantsTermination;
|
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
virtual bool isConnected()
|
|
|
|
{
|
|
|
|
return (m_physicsClientHandle != 0);
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
void enqueueCommand(int commandId);
|
|
|
|
|
|
|
|
void prepareAndSubmitCommand(int commandId);
|
|
|
|
|
|
|
|
virtual void exitPhysics(){};
|
|
|
|
virtual void renderScene()
|
2015-08-20 05:51:16 +00:00
|
|
|
{
|
2016-05-18 16:34:42 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
2017-05-16 19:19:03 +00:00
|
|
|
int renderFlags = 0;
|
|
|
|
m_physicsServer.renderScene(renderFlags);
|
2016-05-18 16:34:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +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;
|
2018-09-23 21:17:31 +00:00
|
|
|
points.resize(numLines * 2);
|
2015-09-03 21:18:22 +00:00
|
|
|
btAlignedObjectArray<unsigned int> indices;
|
2018-09-23 21:17:31 +00:00
|
|
|
indices.resize(numLines * 2);
|
2015-09-03 21:18:22 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numLines; i++)
|
2015-09-03 21:18:22 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +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];
|
|
|
|
indices[i * 2] = i * 2;
|
|
|
|
indices[i * 2 + 1] = i * 2 + 1;
|
2015-09-03 21:18:22 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
float color[4] = {0.2, 0.2, 1, 1};
|
|
|
|
|
2015-09-03 21:18:22 +00:00
|
|
|
if (points.size() && indices.size())
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_guiHelper->getRenderInterface()->drawLines(&points[0].m_floats[0], color, points.size(), sizeof(btVector3FloatData), &indices[0], indices.size(), lineWidth);
|
2015-09-03 21:18:22 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2015-08-20 05:51:16 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < numLines; i++)
|
2015-09-03 21:18:22 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +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
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < m_numMotors; i++)
|
|
|
|
{
|
|
|
|
btScalar targetPos = m_motorTargetPositions[i].m_posTarget;
|
|
|
|
int qIndex = m_motorTargetPositions[i].m_qIndex;
|
|
|
|
int uIndex = m_motorTargetPositions[i].m_uIndex;
|
|
|
|
static int serial = 0;
|
|
|
|
serial++;
|
|
|
|
// b3Printf("# motors = %d, cmd[%d] qIndex = %d, uIndex = %d, targetPos = %f", m_numMotors, serial, qIndex,uIndex,targetPos);
|
|
|
|
|
|
|
|
b3JointControlSetDesiredPosition(commandHandle, qIndex, targetPos);
|
|
|
|
b3JointControlSetDesiredVelocity(commandHandle, uIndex, 0);
|
|
|
|
b3JointControlSetKp(commandHandle, qIndex, 0.2);
|
|
|
|
b3JointControlSetKd(commandHandle, uIndex, 1.);
|
|
|
|
|
|
|
|
b3JointControlSetMaximumForce(commandHandle, uIndex, 5000);
|
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
virtual void physicsDebugDraw(int debugFlags)
|
2016-05-18 16:34:42 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
2016-05-18 16:34:42 +00:00
|
|
|
{
|
|
|
|
m_physicsServer.physicsDebugDraw(debugFlags);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +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; }
|
2015-08-07 07:13:26 +00:00
|
|
|
|
|
|
|
virtual void setSharedMemoryKey(int key)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_sharedMemoryKey = key;
|
2015-08-07 07:13:26 +00:00
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void MyComboBoxCallback(int combobox, const char* item, void* userPointer)
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
2016-06-17 01:46:34 +00:00
|
|
|
//b3Printf("Item selected %s", item);
|
2015-10-13 18:32:25 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
PhysicsClientExample* cl = (PhysicsClientExample*)userPointer;
|
2015-10-13 18:32:25 +00:00
|
|
|
b3Assert(cl);
|
|
|
|
if (cl)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
cl->selectComboBox(combobox, item);
|
2015-10-13 18:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-06 18:59:31 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
void MyCallback(int buttonId, bool buttonState, void* userPtr)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
PhysicsClientExample* cl = (PhysicsClientExample*)userPtr;
|
2015-10-13 18:32:25 +00:00
|
|
|
b3Assert(cl);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (cl && buttonState)
|
|
|
|
{
|
|
|
|
cl->enqueueCommand(buttonId);
|
|
|
|
}
|
2015-09-17 06:09:10 +00:00
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-09-17 06:09:10 +00:00
|
|
|
void PhysicsClientExample::enqueueCommand(int commandId)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
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)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
switch (commandId)
|
|
|
|
{
|
|
|
|
case CMD_LOAD_URDF:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3LoadUrdfCommandInit(m_physicsClientHandle, "kuka_iiwa/model.urdf");
|
|
|
|
//setting the initial position, orientation and other arguments are optional
|
|
|
|
double startPosX = 0;
|
|
|
|
static double startPosY = 0;
|
|
|
|
double startPosZ = 0;
|
|
|
|
b3LoadUrdfCommandSetStartPosition(commandHandle, startPosX, startPosY, startPosZ);
|
2015-10-13 18:32:25 +00:00
|
|
|
startPosY += 2.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
// ret = b3LoadUrdfCommandSetUseFixedBase(commandHandle, 1);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
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
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3LoadSdfCommandInit(m_physicsClientHandle, "kitchens/1.sdf"); //two_cubes.sdf");//kitchens/1.sdf");//kuka_iiwa/model.sdf");
|
2017-04-07 04:13:23 +00:00
|
|
|
#endif
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_REQUEST_CAMERA_IMAGE_DATA:
|
|
|
|
{
|
|
|
|
///request an image from a simulated camera, using a software renderer.
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitRequestCameraImage(m_physicsClientHandle);
|
|
|
|
//b3RequestCameraImageSelectRenderer(commandHandle,ER_BULLET_HARDWARE_OPENGL);
|
|
|
|
|
|
|
|
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);
|
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);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CREATE_BOX_COLLISION_SHAPE:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CreateBoxShapeCommandInit(m_physicsClientHandle);
|
|
|
|
b3CreateBoxCommandSetStartPosition(commandHandle, 0, 0, -1.5);
|
|
|
|
b3CreateBoxCommandSetColorRGBA(commandHandle, 0, 0, 1, 1);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
2015-10-27 21:55:46 +00:00
|
|
|
case CMD_CREATE_RIGID_BODY:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CreateBoxShapeCommandInit(m_physicsClientHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CreateBoxCommandSetStartPosition(commandHandle, 0, 0, 0);
|
|
|
|
b3CreateBoxCommandSetMass(commandHandle, 1);
|
|
|
|
b3CreateBoxCommandSetCollisionShapeType(commandHandle, COLLISION_SHAPE_TYPE_CYLINDER_Y);
|
|
|
|
b3CreateBoxCommandSetColorRGBA(commandHandle, 1, 1, 0, 1);
|
2015-10-27 21:55:46 +00:00
|
|
|
double radius = 0.2;
|
|
|
|
double halfHeight = 0.5;
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CreateBoxCommandSetHalfExtents(commandHandle, radius, halfHeight, radius);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
2015-10-27 21:55:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CMD_REQUEST_ACTUAL_STATE:
|
|
|
|
{
|
|
|
|
if (m_selectedBody >= 0)
|
2015-10-27 22:46:13 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3RequestActualStateCommandInit(m_physicsClientHandle, m_selectedBody);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_physicsClientHandle, commandHandle);
|
2015-10-27 22:46:13 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
2018-09-23 21:17:31 +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);
|
|
|
|
//b3Printf("Joint %d: %f", i, sensorState.m_jointMotorTorque);
|
|
|
|
}
|
2015-10-27 22:46:13 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
};
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-10-14 05:23:28 +00:00
|
|
|
case CMD_INIT_POSE:
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_selectedBody >= 0)
|
2015-10-14 05:23:28 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CreatePoseCommandInit(m_physicsClientHandle, m_selectedBody);
|
2015-10-14 05:23:28 +00:00
|
|
|
static int toggle = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
double pos[3] = {0, 0, 0};
|
2015-10-14 05:23:28 +00:00
|
|
|
pos[toggle] = 2;
|
2018-09-23 21:17:31 +00:00
|
|
|
toggle++;
|
|
|
|
if (toggle > 2)
|
|
|
|
toggle = 0;
|
2015-10-14 05:23:28 +00:00
|
|
|
|
|
|
|
btQuaternion orn;
|
2018-09-23 21:17:31 +00:00
|
|
|
orn.setValue(0, 0, 0, 1);
|
2015-10-14 05:23:28 +00:00
|
|
|
|
|
|
|
switch (toggle)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
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);
|
2015-10-14 05:23:28 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
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++)
|
2015-10-14 05:23:28 +00:00
|
|
|
{
|
|
|
|
b3JointInfo info;
|
2018-09-23 21:17:31 +00:00
|
|
|
b3GetJointInfo(m_physicsClientHandle, m_selectedBody, i, &info);
|
|
|
|
if ((info.m_jointType == 0) || (info.m_jointType == 1)) //revolute or prismatic
|
2015-10-14 05:23:28 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CreatePoseCommandSetJointPosition(m_physicsClientHandle, commandHandle, i, jointPos);
|
2015-10-14 05:23:28 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
jointPos += SIMD_PI / 8.0;
|
2015-10-14 05:23:28 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +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:
|
|
|
|
{
|
|
|
|
if (m_selectedBody >= 0)
|
|
|
|
{
|
|
|
|
// b3SharedMemoryCommandHandle command = b3JointControlCommandInit( m_physicsClientHandle, m_selectedBody, CONTROL_MODE_VELOCITY);
|
|
|
|
b3SharedMemoryCommandHandle command = b3JointControlCommandInit2(m_physicsClientHandle, m_selectedBody, CONTROL_MODE_POSITION_VELOCITY_PD);
|
|
|
|
// b3Printf("prepare control command for body %d", m_selectedBody);
|
|
|
|
|
|
|
|
prepareControlCommand(command);
|
|
|
|
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, command);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_RESET_SIMULATION:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitResetSimulationCommand(m_physicsClientHandle);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SEND_BULLET_DATA_STREAM:
|
|
|
|
{
|
2015-09-17 06:09:10 +00:00
|
|
|
#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
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CUSTOM_SET_GRAVITY:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitPhysicsParamCommand(m_physicsClientHandle);
|
|
|
|
b3PhysicsParamSetGravity(commandHandle, 0.0, 0.0, -9.8);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-19 05:05:28 +00:00
|
|
|
|
|
|
|
case CMD_CUSTOM_SET_REALTIME_SIMULATION:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitPhysicsParamCommand(m_physicsClientHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3PhysicsParamSetRealTimeSimulation(commandHandle, 1);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
2016-10-19 05:05:28 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +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,
|
2018-09-23 21:17:31 +00:00
|
|
|
m_selectedBody, &jointPositionsQ[0], &jointVelocitiesQdot[0], &jointAccelerations[0]);
|
2016-08-10 01:40:12 +00:00
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-09-01 20:30:07 +00:00
|
|
|
case CMD_REQUEST_CONTACT_POINT_INFORMATION:
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
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:
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3SaveWorldCommandInit(m_physicsClientHandle, "saveWorld.py");
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
2016-10-13 06:03:36 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-09-23 21:17:31 +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;
|
|
|
|
}
|
2017-06-02 06:32:26 +00:00
|
|
|
case CMD_UPDATE_VISUAL_SHAPE:
|
|
|
|
{
|
|
|
|
int objectUniqueId = 0;
|
|
|
|
int linkIndex = -1;
|
|
|
|
int shapeIndex = -1;
|
2018-10-20 23:13:48 +00:00
|
|
|
int textureIndex = -2;
|
2017-06-02 06:32:26 +00:00
|
|
|
double rgbaColor[4] = {0.0, 1.0, 0.0, 1.0};
|
2018-10-21 02:44:39 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitUpdateVisualShape2(m_physicsClientHandle, objectUniqueId, linkIndex, shapeIndex);
|
2017-06-02 06:32:26 +00:00
|
|
|
b3UpdateVisualShapeRGBAColor(commandHandle, rgbaColor);
|
|
|
|
b3SubmitClientCommand(m_physicsClientHandle, commandHandle);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-29 21:19:35 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
b3Error("Unknown buttonId");
|
|
|
|
btAssert(0);
|
|
|
|
}
|
|
|
|
};
|
2015-09-17 06:09:10 +00:00
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2017-05-31 02:54:55 +00:00
|
|
|
struct Bullet2CommandProcessorCreation3 : public CommandProcessorCreationInterface
|
|
|
|
{
|
|
|
|
virtual class CommandProcessorInterface* createCommandProcessor()
|
|
|
|
{
|
|
|
|
PhysicsServerCommandProcessor* proc = new PhysicsServerCommandProcessor;
|
|
|
|
return proc;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void deleteCommandProcessor(CommandProcessorInterface* proc)
|
|
|
|
{
|
|
|
|
delete proc;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static Bullet2CommandProcessorCreation3 sB2PC2;
|
2015-11-11 20:44:26 +00:00
|
|
|
|
2016-05-18 16:34:42 +00:00
|
|
|
PhysicsClientExample::PhysicsClientExample(GUIHelperInterface* helper, int options)
|
2018-09-23 21:17:31 +00:00
|
|
|
: SharedMemoryCommon(helper),
|
|
|
|
m_physicsClientHandle(0),
|
|
|
|
m_physicsServer(&sB2PC2, 0, 0),
|
|
|
|
m_wantsTermination(false),
|
|
|
|
m_sharedMemoryKey(SHARED_MEMORY_KEY),
|
|
|
|
m_selectedBody(-1),
|
|
|
|
m_prevSelectedBody(-1),
|
|
|
|
m_canvas(0),
|
|
|
|
m_canvasRGBIndex(-1),
|
|
|
|
m_canvasDepthIndex(-1),
|
|
|
|
m_canvasSegMaskIndex(-1),
|
|
|
|
m_specularCoeff(1.0),
|
|
|
|
m_numMotors(0),
|
|
|
|
m_options(options),
|
|
|
|
m_isOptionalServerConnected(false)
|
|
|
|
|
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);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-08-11 21:55:30 +00:00
|
|
|
if (m_canvas)
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +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
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
b3Printf("~PhysicsClientExample\n");
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void PhysicsClientExample::createButton(const char* name, int buttonId, bool isTrigger)
|
2015-07-14 22:30:17 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
ButtonParams button(name, buttonId, isTrigger);
|
2015-07-14 22:30:17 +00:00
|
|
|
button.m_callback = MyCallback;
|
|
|
|
button.m_userPointer = this;
|
|
|
|
m_guiHelper->getParameterInterface()->registerButtonParameter(button);
|
|
|
|
}
|
2015-08-07 07:13:26 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void PhysicsClientExample::createButtons()
|
2015-08-07 07:13:26 +00:00
|
|
|
{
|
|
|
|
bool isTrigger = false;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
2015-10-13 18:32:25 +00:00
|
|
|
m_guiHelper->getParameterInterface()->removeAllParameters();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
createButton("Load URDF", CMD_LOAD_URDF, isTrigger);
|
|
|
|
createButton("Load SDF", CMD_LOAD_SDF, isTrigger);
|
|
|
|
createButton("Save World", CMD_SAVE_WORLD, isTrigger);
|
|
|
|
createButton("Set Shadow", CMD_SET_SHADOW, isTrigger);
|
|
|
|
createButton("Update Visual Shape", CMD_UPDATE_VISUAL_SHAPE, isTrigger);
|
|
|
|
createButton("Get Camera Image", CMD_REQUEST_CAMERA_IMAGE_DATA, isTrigger);
|
|
|
|
createButton("Step Sim", CMD_STEP_FORWARD_SIMULATION, isTrigger);
|
|
|
|
createButton("Realtime Sim", CMD_CUSTOM_SET_REALTIME_SIMULATION, isTrigger);
|
|
|
|
createButton("Get Visual Shape Info", CMD_REQUEST_VISUAL_SHAPE_INFO, isTrigger);
|
|
|
|
createButton("Send Bullet Stream", CMD_SEND_BULLET_DATA_STREAM, isTrigger);
|
|
|
|
if (m_options != eCLIENTEXAMPLE_SERVER)
|
2016-05-18 16:34:42 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
createButton("Get State", CMD_REQUEST_ACTUAL_STATE, isTrigger);
|
2016-05-18 16:34:42 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
createButton("Send Desired State", CMD_SEND_DESIRED_STATE, isTrigger);
|
|
|
|
createButton("Create Box Collider", CMD_CREATE_BOX_COLLISION_SHAPE, isTrigger);
|
|
|
|
createButton("Create Cylinder Body", CMD_CREATE_RIGID_BODY, isTrigger);
|
|
|
|
createButton("Reset Simulation", CMD_RESET_SIMULATION, isTrigger);
|
|
|
|
createButton("Initialize Pose", CMD_INIT_POSE, isTrigger);
|
|
|
|
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);
|
2018-09-23 21:17:31 +00:00
|
|
|
createButton("Get Contact Point Info", CMD_REQUEST_CONTACT_POINT_INFORMATION, isTrigger);
|
2015-10-13 18:32:25 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_bodyUniqueIds.size())
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_physicsClientHandle && m_selectedBody >= 0)
|
|
|
|
{
|
|
|
|
m_numMotors = 0;
|
|
|
|
|
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle, m_selectedBody);
|
|
|
|
for (int i = 0; i < numJoints; i++)
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
|
|
|
b3JointInfo info;
|
2018-09-23 21:17:31 +00:00
|
|
|
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);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
if (info.m_flags & JOINT_HAS_MOTORIZED_POWER)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_numMotors < MAX_NUM_MOTORS)
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
2020-04-03 16:47:28 +00:00
|
|
|
char motorName[1026];
|
2021-03-16 05:44:55 +00:00
|
|
|
safe_printf(motorName, sizeof(motorName), "%s q", info.m_jointName);
|
2016-04-19 23:52:47 +00:00
|
|
|
// MyMotorInfo2* motorInfo = &m_motorTargetVelocities[m_numMotors];
|
2018-09-23 21:17:31 +00:00
|
|
|
MyMotorInfo2* motorInfo = &m_motorTargetPositions[m_numMotors];
|
2015-10-13 18:32:25 +00:00
|
|
|
motorInfo->m_velTarget = 0.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
motorInfo->m_posTarget = 0.f;
|
2015-10-13 18:32:25 +00:00
|
|
|
motorInfo->m_uIndex = info.m_uIndex;
|
2018-09-23 21:17:31 +00:00
|
|
|
motorInfo->m_qIndex = info.m_qIndex;
|
|
|
|
|
2016-04-19 23:52:47 +00:00
|
|
|
// SliderParams slider(motorName,&motorInfo->m_velTarget);
|
|
|
|
// slider.m_minVal=-4;
|
|
|
|
// slider.m_maxVal=4;
|
2018-09-23 21:17:31 +00:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2017-05-08 04:09:08 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +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;
|
2017-05-08 04:09:08 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2015-08-07 07:13:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void PhysicsClientExample::initPhysics()
|
2015-07-14 22:30:17 +00:00
|
|
|
{
|
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
int upAxis = 2;
|
|
|
|
m_guiHelper->setUpAxis(upAxis);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
createButtons();
|
|
|
|
}
|
|
|
|
else
|
2015-07-14 22:30:17 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
MyCallback(CMD_LOAD_URDF, true, this);
|
|
|
|
MyCallback(CMD_STEP_FORWARD_SIMULATION, true, this);
|
|
|
|
|
|
|
|
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;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_canvasRGBIndex = m_canvas->createCanvas("Synthetic Camera RGB data", camVisualizerWidth, camVisualizerHeight, 8, 55);
|
|
|
|
m_canvasDepthIndex = m_canvas->createCanvas("Synthetic Camera Depth data", camVisualizerWidth, camVisualizerHeight, 8, 75 + camVisualizerHeight);
|
|
|
|
m_canvasSegMaskIndex = m_canvas->createCanvas("Synthetic Camera Segmentation Mask", camVisualizerWidth, camVisualizerHeight, 8, 95 + camVisualizerHeight * 2);
|
2016-05-31 17:23:04 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < camVisualizerWidth; i++)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < camVisualizerHeight; j++)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
unsigned char red = 255;
|
|
|
|
unsigned char green = 255;
|
|
|
|
unsigned char blue = 255;
|
|
|
|
unsigned char alpha = 255;
|
|
|
|
if (i == j)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
|
|
|
red = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
green = 0;
|
|
|
|
blue = 0;
|
2016-05-31 17:23:04 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +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
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2016-05-31 17:23:04 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
|
|
|
m_isOptionalServerConnected = m_physicsServer.connectSharedMemory(m_guiHelper);
|
2016-05-18 16:34:42 +00:00
|
|
|
}
|
|
|
|
|
2016-06-04 02:03:56 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_DIRECT)
|
|
|
|
{
|
|
|
|
m_physicsClientHandle = b3ConnectPhysicsDirect();
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2016-06-04 02:03:56 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_physicsClientHandle = b3ConnectSharedMemory(m_sharedMemoryKey);
|
2016-06-04 02:03:56 +00:00
|
|
|
//m_physicsClientHandle = b3ConnectPhysicsLoopback(SHARED_MEMORY_KEY);
|
|
|
|
}
|
2018-09-23 21:17:31 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void PhysicsClientExample::stepSimulation(float deltaTime)
|
2015-07-14 22:30:17 +00:00
|
|
|
{
|
2016-05-18 16:34:42 +00:00
|
|
|
if (m_options == eCLIENTEXAMPLE_SERVER)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 100; i++)
|
2016-05-18 16:34:42 +00:00
|
|
|
{
|
|
|
|
m_physicsServer.processClientCommands();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 18:32:25 +00:00
|
|
|
if (m_prevSelectedBody != m_selectedBody)
|
|
|
|
{
|
|
|
|
createButtons();
|
|
|
|
m_prevSelectedBody = m_selectedBody;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
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");
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CAMERA_IMAGE_COMPLETED)
|
|
|
|
{
|
|
|
|
// 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;
|
2018-09-23 21:17:31 +00:00
|
|
|
b3GetCameraImageData(m_physicsClientHandle, &imageData);
|
2016-08-11 21:55:30 +00:00
|
|
|
if (m_canvas)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
//compute depth image range
|
|
|
|
float minDepthValue = 1e20f;
|
|
|
|
float maxDepthValue = -1e20f;
|
|
|
|
|
|
|
|
for (int i = 0; i < camVisualizerWidth; i++)
|
2016-08-11 21:55:30 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < camVisualizerHeight; j++)
|
2016-08-11 21:55:30 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
int xIndex = int(float(i) * (float(imageData.m_pixelWidth) / float(camVisualizerWidth)));
|
|
|
|
int yIndex = int(float(j) * (float(imageData.m_pixelHeight) / float(camVisualizerHeight)));
|
|
|
|
btClamp(xIndex, 0, imageData.m_pixelWidth);
|
|
|
|
btClamp(yIndex, 0, imageData.m_pixelHeight);
|
|
|
|
|
|
|
|
if (m_canvasDepthIndex >= 0)
|
|
|
|
{
|
|
|
|
int depthPixelIndex = (xIndex + yIndex * imageData.m_pixelWidth);
|
|
|
|
float depthValue = imageData.m_depthValues[depthPixelIndex];
|
|
|
|
//todo: rescale the depthValue to [0..255]
|
|
|
|
if (depthValue > -1e20)
|
|
|
|
{
|
|
|
|
maxDepthValue = btMax(maxDepthValue, depthValue);
|
|
|
|
minDepthValue = btMin(minDepthValue, depthValue);
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 21:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < camVisualizerWidth; i++)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int j = 0; j < camVisualizerHeight; j++)
|
2016-05-31 17:23:04 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
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);
|
|
|
|
int bytesPerPixel = 4; //RGBA
|
|
|
|
|
|
|
|
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);
|
|
|
|
float depthValue = imageData.m_depthValues[depthPixelIndex];
|
|
|
|
//todo: rescale the depthValue to [0..255]
|
|
|
|
if (depthValue > -1e20)
|
|
|
|
{
|
2017-04-06 21:31:34 +00:00
|
|
|
int rgb = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (maxDepthValue != minDepthValue)
|
2017-04-06 21:31:34 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
rgb = (depthValue - minDepthValue) * (255. / (btFabs(maxDepthValue - minDepthValue)));
|
|
|
|
if (rgb < 0 || rgb > 255)
|
2017-04-06 21:31:34 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
//printf("rgb=%d\n",rgb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int obIndex = segmentationMask & ((1 << 24) - 1);
|
|
|
|
int linkIndex = (segmentationMask >> 24) - 1;
|
|
|
|
|
|
|
|
btVector4 rgb = palette[(obIndex + linkIndex) & 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
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +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
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// b3Printf(msg);
|
|
|
|
}
|
2016-08-10 01:40:12 +00:00
|
|
|
if (statusType == CMD_CALCULATED_INVERSE_DYNAMICS_COMPLETED)
|
|
|
|
{
|
|
|
|
int bodyUniqueId;
|
|
|
|
int dofCount;
|
|
|
|
|
|
|
|
b3GetStatusInverseDynamicsJointForces(status,
|
2018-09-23 21:17:31 +00:00
|
|
|
&bodyUniqueId,
|
|
|
|
&dofCount,
|
|
|
|
0);
|
2016-08-10 01:40:12 +00:00
|
|
|
|
|
|
|
btAlignedObjectArray<double> jointForces;
|
|
|
|
if (dofCount)
|
|
|
|
{
|
|
|
|
jointForces.resize(dofCount);
|
|
|
|
b3GetStatusInverseDynamicsJointForces(status,
|
2018-09-23 21:17:31 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&jointForces[0]);
|
2016-08-10 01:40:12 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CAMERA_IMAGE_FAILED)
|
2016-06-13 17:11:28 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3Warning("Camera image FAILED\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusType == CMD_SDF_LOADING_COMPLETED)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
m_bodyUniqueIds.push_back(bodyUniqueId);
|
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle, bodyUniqueId);
|
|
|
|
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
|
|
|
|
|
|
|
*/
|
2018-09-23 21:17:31 +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);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (statusType == CMD_URDF_LOADING_COMPLETED)
|
2015-10-14 05:23:28 +00:00
|
|
|
{
|
|
|
|
int bodyIndex = b3GetStatusBodyIndex(status);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (bodyIndex >= 0)
|
2015-10-13 18:32:25 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
m_bodyUniqueIds.push_back(bodyIndex);
|
|
|
|
m_selectedBody = bodyIndex;
|
|
|
|
int numJoints = b3GetNumJoints(m_physicsClientHandle, bodyIndex);
|
|
|
|
|
|
|
|
for (int i = 0; i < numJoints; i++)
|
2015-10-14 05:23:28 +00:00
|
|
|
{
|
|
|
|
b3JointInfo info;
|
2018-09-23 21:17:31 +00:00
|
|
|
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-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");
|
|
|
|
}
|
2018-09-23 21:17:31 +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);
|
|
|
|
}
|
2018-09-23 21:17:31 +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
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +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];
|
|
|
|
|
|
|
|
//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;
|
2018-09-23 21:17:31 +00:00
|
|
|
m_numMotors = 0;
|
|
|
|
m_bodyUniqueIds.clear();
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2016-05-18 16:34:42 +00:00
|
|
|
{
|
|
|
|
prepareAndSubmitCommand(commandId);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
2016-05-18 16:34:42 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
prepareAndSubmitCommand(commandId);
|
2016-05-18 16:34:42 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_numMotors)
|
|
|
|
{
|
|
|
|
enqueueCommand(CMD_SEND_DESIRED_STATE);
|
|
|
|
}
|
|
|
|
enqueueCommand(CMD_STEP_FORWARD_SIMULATION);
|
2016-06-13 17:11:28 +00:00
|
|
|
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
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
extern int gSharedMemoryKey;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
class CommonExampleInterface* PhysicsClientCreateFunc(struct CommonExampleOptions& options)
|
2015-07-14 22:30:17 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
PhysicsClientExample* example = new PhysicsClientExample(options.m_guiHelper, options.m_option);
|
|
|
|
if (gSharedMemoryKey >= 0)
|
2015-08-07 07:13:26 +00:00
|
|
|
{
|
|
|
|
example->setSharedMemoryKey(gSharedMemoryKey);
|
|
|
|
}
|
|
|
|
return example;
|
2015-07-14 22:30:17 +00:00
|
|
|
}
|