Merge pull request #2287 from erwincoumans/master

fix testlaikago and pd_controller_stable
This commit is contained in:
erwincoumans
2019-06-15 12:58:39 -07:00
committed by GitHub
35 changed files with 1859 additions and 78 deletions

View File

@@ -11,6 +11,13 @@ struct CommonParameterInterface;
struct CommonRenderInterface;
struct CommonGraphicsApp;
struct GUISyncPosition
{
int m_graphicsInstanceId;
float m_pos[4];
float m_orn[4];
};
typedef void (*VisualizerFlagCallback)(int flag, bool enable);
///The Bullet 2 GraphicsPhysicsBridge let's the graphics engine create graphics representation and synchronize
@@ -25,6 +32,8 @@ struct GUIHelperInterface
virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape) = 0;
virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld) = 0;
virtual void syncPhysicsToGraphics2(const btDiscreteDynamicsWorld* rbWorld) {}
virtual void syncPhysicsToGraphics2(const GUISyncPosition* positions, int numPositions) {}
virtual void render(const btDiscreteDynamicsWorld* rbWorld) = 0;
@@ -114,7 +123,10 @@ struct GUIHelperInterface
///the DummyGUIHelper does nothing, so we can test the examples without GUI/graphics (in 'console mode')
struct DummyGUIHelper : public GUIHelperInterface
{
DummyGUIHelper() {}
DummyGUIHelper()
{
}
virtual ~DummyGUIHelper() {}
virtual void createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color) {}

View File

@@ -171,6 +171,14 @@ SET(BulletExampleBrowser_SRCS
../SharedMemory/PhysicsClientSharedMemory_C_API.cpp
../SharedMemory/PhysicsClient.cpp
../SharedMemory/PhysicsClientC_API.cpp
../SharedMemory/GraphicsServerExample.cpp
../SharedMemory/GraphicsClientExample.cpp
../SharedMemory/RemoteGUIHelper.cpp
../SharedMemory/GraphicsServerExample.h
../SharedMemory/GraphicsClientExample.h
../SharedMemory/RemoteGUIHelper.h
../SharedMemory/GraphicsSharedMemoryCommands.h
../SharedMemory/GraphicsSharedMemoryPublic.h
../SharedMemory/PhysicsServerExample.cpp
../SharedMemory/PhysicsServerExampleBullet2.cpp
../SharedMemory/PhysicsClientExample.cpp

View File

@@ -11,6 +11,9 @@
#include "../RenderingExamples/RaytracerSetup.h"
#include "../RenderingExamples/TinyRendererSetup.h"
#include "../RenderingExamples/DynamicTexturedCubeDemo.h"
#include "../SharedMemory/GraphicsServerExample.h"
#include "../SharedMemory/GraphicsClientExample.h"
#include "../ForkLift/ForkLiftDemo.h"
#include "../MultiThreadedDemo/MultiThreadedDemo.h"
#include "../BasicDemo/BasicExample.h"
@@ -150,6 +153,9 @@ static ExampleEntry gDefaultExamples[] =
PhysicsServerCreateFuncBullet2, PHYSICS_SERVER_ENABLE_COMMAND_LOGGING),
ExampleEntry(1, "Physics Server (Replay Log)", "Create a physics server that replay a command log from disk.",
PhysicsServerCreateFuncBullet2, PHYSICS_SERVER_REPLAY_FROM_COMMAND_LOG),
ExampleEntry(1, "Graphics Server", "Create a graphics server.",GraphicsServerCreateFuncBullet),
ExampleEntry(1, "Graphics Client", "Create a graphics client.", GraphicsClientCreateFunc),
//
// ExampleEntry(1, "Physics Client (Direct)", "Create a physics client that can communicate with a physics server directly in-process.", PhysicsClientCreateFunc,eCLIENTEXAMPLE_DIRECT),

View File

@@ -1157,17 +1157,22 @@ void OpenGLExampleBrowser::updateGraphics()
void OpenGLExampleBrowser::update(float deltaTime)
{
b3ChromeUtilsEnableProfiling();
if (!gEnableRenderLoop && !singleStepSimulation)
{
B3_PROFILE("updateGraphics");
sCurrentDemo->updateGraphics();
return;
}
B3_PROFILE("OpenGLExampleBrowser::update");
assert(glGetError() == GL_NO_ERROR);
//assert(glGetError() == GL_NO_ERROR);
{
B3_PROFILE("s_instancingRenderer");
s_instancingRenderer->init();
}
DrawGridData dg;
dg.upAxis = s_app->getUpAxis();
@@ -1215,6 +1220,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
if (gFixedTimeStep > 0)
{
sCurrentDemo->stepSimulation(gFixedTimeStep);
}
else
@@ -1279,6 +1285,8 @@ void OpenGLExampleBrowser::update(float deltaTime)
}
#endif //#ifndef BT_NO_PROFILE
{
B3_PROFILE("updateOpenGL");
if (sUseOpenGL2)
{
saveOpenGLState(s_instancingRenderer->getScreenWidth() * s_window->getRetinaScale(), s_instancingRenderer->getScreenHeight() * s_window->getRetinaScale());
@@ -1297,6 +1305,7 @@ void OpenGLExampleBrowser::update(float deltaTime)
restoreOpenGLState();
}
}
}
singleStepSimulation = false;

View File

@@ -116,6 +116,15 @@ project "App_BulletExampleBrowser"
"../SharedMemory/SharedMemoryCommandProcessor.cpp",
"../SharedMemory/SharedMemoryCommandProcessor.h",
"../SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp",
"../SharedMemory/GraphicsClientExample.cpp",
"../SharedMemory/GraphicsClientExample.h",
"../SharedMemory/GraphicsServerExample.cpp",
"../SharedMemory/GraphicsServerExample.h",
"../SharedMemory/GraphicsSharedMemoryBlock.h",
"../SharedMemory/GraphicsSharedMemoryCommands.h",
"../SharedMemory/GraphicsSharedMemoryPublic.h",
"../SharedMemory/RemoteGUIHelper.cpp",
"../SharedMemory/RemoteGUIHelper.h",
"../SharedMemory/PhysicsClient.cpp",
"../SharedMemory/PosixSharedMemory.cpp",
"../SharedMemory/Win32SharedMemory.cpp",

View File

@@ -2010,6 +2010,7 @@ TransparentDistanceSortPredicate{
void GLInstancingRenderer::renderSceneInternal(int orgRenderMode)
{
B3_PROFILE("renderSceneInternal");
int renderMode = orgRenderMode;
bool reflectionPass = false;
bool reflectionPlanePass = false;
@@ -2047,7 +2048,7 @@ void GLInstancingRenderer::renderSceneInternal(int orgRenderMode)
// Cull triangles which normal is not towards the camera
glEnable(GL_CULL_FACE);
B3_PROFILE("GLInstancingRenderer::RenderScene");
{
B3_PROFILE("init");

View File

@@ -15,6 +15,14 @@ RobotSimulatorMain.cpp
MinitaurSetup.cpp
MinitaurSetup.h
../../examples/ExampleBrowser/InProcessExampleBrowser.cpp
../SharedMemory/GraphicsServerExample.cpp
../SharedMemory/GraphicsClientExample.cpp
../SharedMemory/RemoteGUIHelper.cpp
../SharedMemory/GraphicsServerExample.h
../SharedMemory/GraphicsClientExample.h
../SharedMemory/RemoteGUIHelper.h
../SharedMemory/GraphicsSharedMemoryCommands.h
../SharedMemory/GraphicsSharedMemoryPublic.h
../../examples/SharedMemory/PhysicsServerExample.cpp
../../examples/SharedMemory/PhysicsServerExampleBullet2.cpp
../../examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp

View File

@@ -18,6 +18,13 @@ SET(SharedMemory_SRCS
PhysicsServer.cpp
PhysicsServer.h
PhysicsClientC_API.cpp
GraphicsClientExample.cpp
GraphicsClientExample.h
GraphicsServerExample.cpp
GraphicsServerExample.h
GraphicsSharedMemoryBlock.h
GraphicsSharedMemoryCommands.h
GraphicsSharedMemoryPublic.h
SharedMemoryCommands.h
SharedMemoryPublic.h
PhysicsServer.cpp

View File

@@ -0,0 +1,287 @@
#include "GraphicsClientExample.h"
#include "../CommonInterfaces/CommonExampleInterface.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
#include "Bullet3Common/b3Logging.h"
#include "GraphicsSharedMemoryCommands.h"
#include "PosixSharedMemory.h"
#include "Win32SharedMemory.h"
#include "GraphicsSharedMemoryBlock.h"
#include "Bullet3Common/b3Scalar.h"
class GraphicsClientExample : public CommonExampleInterface
{
protected:
GUIHelperInterface* m_guiHelper;
bool m_waitingForServer;
GraphicsSharedMemoryBlock* m_testBlock1;
SharedMemoryInterface* m_sharedMemory;
GraphicsSharedMemoryStatus m_lastServerStatus;
int m_sharedMemoryKey;
bool m_isConnected;
public:
GraphicsClientExample(GUIHelperInterface* helper, int options);
virtual ~GraphicsClientExample();
virtual void initPhysics();
virtual void stepSimulation(float deltaTime);
virtual void resetCamera()
{
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 isConnected()
{
return m_isConnected;
}
bool canSubmitCommand() const
{
if (m_isConnected && !m_waitingForServer)
{
if (m_testBlock1->m_magicId == GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
{
return true;
}
else
{
return false;
}
}
return false;
}
struct GraphicsSharedMemoryCommand* getAvailableSharedMemoryCommand()
{
static int sequence = 0;
if (m_testBlock1)
{
m_testBlock1->m_clientCommands[0].m_sequenceNumber = sequence++;
return &m_testBlock1->m_clientCommands[0];
}
return 0;
}
bool submitClientCommand(const GraphicsSharedMemoryCommand& command)
{
/// at the moment we allow a maximum of 1 outstanding command, so we check for this
// once the server processed the command and returns a status, we clear the flag
// "m_data->m_waitingForServer" and allow submitting the next command
if (!m_waitingForServer)
{
//printf("submit command of type %d\n", command.m_type);
if (&m_testBlock1->m_clientCommands[0] != &command)
{
m_testBlock1->m_clientCommands[0] = command;
}
m_testBlock1->m_numClientCommands++;
m_waitingForServer = true;
return true;
}
return false;
}
const GraphicsSharedMemoryStatus* processServerStatus()
{
// SharedMemoryStatus* stat = 0;
if (!m_testBlock1)
{
m_lastServerStatus.m_type = GFX_CMD_SHARED_MEMORY_NOT_INITIALIZED;
return &m_lastServerStatus;
}
if (!m_waitingForServer)
{
return 0;
}
if (m_testBlock1->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
{
m_lastServerStatus.m_type = GFX_CMD_SHARED_MEMORY_NOT_INITIALIZED;
return &m_lastServerStatus;
}
if (m_testBlock1->m_numServerCommands >
m_testBlock1->m_numProcessedServerCommands)
{
B3_PROFILE("processServerCMD");
b3Assert(m_testBlock1->m_numServerCommands ==
m_testBlock1->m_numProcessedServerCommands + 1);
const GraphicsSharedMemoryStatus& serverCmd = m_testBlock1->m_serverCommands[0];
m_lastServerStatus = serverCmd;
// EnumSharedMemoryServerStatus s = (EnumSharedMemoryServerStatus)serverCmd.m_type;
// consume the command
switch (serverCmd.m_type)
{
case GFX_CMD_CLIENT_COMMAND_COMPLETED:
{
B3_PROFILE("CMD_CLIENT_COMMAND_COMPLETED");
break;
}
default:
{
}
}
m_testBlock1->m_numProcessedServerCommands++;
// we don't have more than 1 command outstanding (in total, either server or client)
b3Assert(m_testBlock1->m_numProcessedServerCommands ==
m_testBlock1->m_numServerCommands);
if (m_testBlock1->m_numServerCommands ==
m_testBlock1->m_numProcessedServerCommands)
{
m_waitingForServer = false;
}
else
{
m_waitingForServer = true;
}
return &m_lastServerStatus;
}
return 0;
}
bool connect()
{
/// server always has to create and initialize shared memory
bool allowCreation = false;
m_testBlock1 = (GraphicsSharedMemoryBlock*)m_sharedMemory->allocateSharedMemory(
m_sharedMemoryKey, GRAPHICS_SHARED_MEMORY_SIZE, allowCreation);
if (m_testBlock1)
{
if (m_testBlock1->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
{
b3Error("Error connecting to shared memory: please start server before client\n");
m_sharedMemory->releaseSharedMemory(m_sharedMemoryKey,
GRAPHICS_SHARED_MEMORY_SIZE);
m_testBlock1 = 0;
return false;
}
else
{
m_isConnected = true;
}
}
else
{
b3Warning("Cannot connect to shared memory");
return false;
}
return true;
}
void disconnect()
{
if (m_isConnected && m_sharedMemory)
{
m_sharedMemory->releaseSharedMemory(m_sharedMemoryKey, GRAPHICS_SHARED_MEMORY_SIZE);
}
m_isConnected = false;
}
virtual void exitPhysics(){};
virtual void physicsDebugDraw(int debugFlags)
{
}
virtual void renderScene()
{
}
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;
}
};
GraphicsClientExample::GraphicsClientExample(GUIHelperInterface* helper, int options)
: m_guiHelper(helper),
m_waitingForServer(false),
m_testBlock1(0)
{
#ifdef _WIN32
m_sharedMemory = new Win32SharedMemoryClient();
#else
m_sharedMemory = new PosixSharedMemory();
#endif
m_sharedMemoryKey = GRAPHICS_SHARED_MEMORY_KEY;
m_isConnected = false;
b3Printf("Started GraphicsClientExample\n");
connect();
}
GraphicsClientExample::~GraphicsClientExample()
{
disconnect();
delete m_sharedMemory;
}
void GraphicsClientExample::initPhysics()
{
if (m_guiHelper && m_guiHelper->getParameterInterface())
{
int upAxis = 2;
m_guiHelper->setUpAxis(upAxis);
}
}
void GraphicsClientExample::stepSimulation(float deltaTime)
{
GraphicsSharedMemoryCommand* cmd = getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_updateFlags = 0;
cmd->m_type = GFX_CMD_0;
submitClientCommand(*cmd);
}
const GraphicsSharedMemoryStatus* status = processServerStatus();
if (status)
{
//handle it
}
}
class CommonExampleInterface* GraphicsClientCreateFunc(struct CommonExampleOptions& options)
{
GraphicsClientExample* example = new GraphicsClientExample(options.m_guiHelper, options.m_option);
return example;
}

View File

@@ -0,0 +1,7 @@
#ifndef GRAPHICS_CLIENT_EXAMPLE_H
#define GRAPHICS_CLIENT_EXAMPLE_H
class CommonExampleInterface* GraphicsClientCreateFunc(struct CommonExampleOptions& options);
#endif //GRAPHICS_CLIENT_EXAMPLE_H

View File

@@ -0,0 +1,398 @@
#include "GraphicsServerExample.h"
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
#include "../CommonInterfaces/CommonRenderInterface.h"
#include "PosixSharedMemory.h"
#include "Win32SharedMemory.h"
#include "../CommonInterfaces/CommonExampleInterface.h"
#include "LinearMath/btTransform.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
#include "Bullet3Common/b3AlignedObjectArray.h"
#include "GraphicsSharedMemoryBlock.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
#define MAX_GRAPHICS_SHARED_MEMORY_BLOCKS 1
class GraphicsServerExample : public CommonExampleInterface
{
CommonGraphicsApp* m_app;
GUIHelperInterface* m_guiHelper;
SharedMemoryInterface* m_sharedMemory;
int m_sharedMemoryKey;
bool m_verboseOutput;
bool m_areConnected[MAX_GRAPHICS_SHARED_MEMORY_BLOCKS];
GraphicsSharedMemoryBlock* m_testBlocks[MAX_GRAPHICS_SHARED_MEMORY_BLOCKS];
b3AlignedObjectArray< b3AlignedObjectArray<unsigned char> > m_dataSlots;
float m_x;
float m_y;
float m_z;
public:
GraphicsServerExample(GUIHelperInterface* guiHelper)
: m_guiHelper(guiHelper),
m_x(0),
m_y(0),
m_z(0)
{
m_verboseOutput = true;
m_sharedMemoryKey = GRAPHICS_SHARED_MEMORY_KEY;
m_app = guiHelper->getAppInterface();
m_app->setUpAxis(2);
for (int i = 0; i < MAX_GRAPHICS_SHARED_MEMORY_BLOCKS; i++)
{
m_areConnected[i] = false;
}
#ifdef _WIN32
m_sharedMemory = new Win32SharedMemoryServer();
#else
m_sharedMemory = new PosixSharedMemory();
#endif
#if 0
{
int boxId = m_app->registerCubeShape(0.1, 0.1, 0.1);
btVector3 pos(0, 0, 0);
btQuaternion orn(0, 0, 0, 1);
btVector4 color(0.3, 0.3, 0.3, 1);
btVector3 scaling(1, 1, 1);
m_app->m_renderer->registerGraphicsInstance(boxId, pos, orn, color, scaling);
}
m_app->m_renderer->writeTransforms();
#endif
connectSharedMemory(m_guiHelper, m_sharedMemoryKey);
}
virtual ~GraphicsServerExample()
{
disconnectSharedMemory();
}
virtual void initPhysics()
{
}
virtual void exitPhysics()
{
}
GraphicsSharedMemoryStatus& createServerStatus(int statusType, int sequenceNumber, int timeStamp, int blockIndex)
{
GraphicsSharedMemoryStatus& serverCmd = m_testBlocks[blockIndex]->m_serverCommands[0];
serverCmd.m_type = statusType;
serverCmd.m_sequenceNumber = sequenceNumber;
serverCmd.m_timeStamp = timeStamp;
return serverCmd;
}
void submitServerStatus(GraphicsSharedMemoryStatus& status, int blockIndex)
{
m_testBlocks[blockIndex]->m_numServerCommands++;
}
bool processCommand(const struct GraphicsSharedMemoryCommand& clientCmd, struct GraphicsSharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes)
{
//printf("processed command of type:%d\n", clientCmd.m_type);
B3_PROFILE("processCommand");
switch (clientCmd.m_type)
{
case GFX_CMD_0:
{
//either Y or Z can be up axis
int upAxis = (clientCmd.m_upAxisYCommand.m_enableUpAxisY) ? 1 : 2;
m_guiHelper->setUpAxis(upAxis);
break;
}
case GFX_CMD_SET_VISUALIZER_FLAG:
{
//printf("clientCmd.m_visualizerFlag.m_visualizerFlag: %d, clientCmd.m_visualizerFlag.m_enable %d\n",
// clientCmd.m_visualizerFlagCommand.m_visualizerFlag, clientCmd.m_visualizerFlagCommand.m_enable);
this->m_guiHelper->setVisualizerFlag(clientCmd.m_visualizerFlagCommand.m_visualizerFlag, clientCmd.m_visualizerFlagCommand.m_enable);
break;
}
case GFX_CMD_UPLOAD_DATA:
{
//printf("uploadData command: curSize=%d, offset=%d, slot=%d", clientCmd.m_uploadDataCommand.m_numBytes, clientCmd.m_uploadDataCommand.m_dataOffset, clientCmd.m_uploadDataCommand.m_dataSlot);
int dataSlot = clientCmd.m_uploadDataCommand.m_dataSlot;
int dataOffset = clientCmd.m_uploadDataCommand.m_dataOffset;
m_dataSlots.resize(dataSlot + 1);
btAssert(m_dataSlots[dataSlot].size() >= dataOffset);
m_dataSlots[dataSlot].resize(clientCmd.m_uploadDataCommand.m_numBytes + clientCmd.m_uploadDataCommand.m_dataOffset);
for (int i = 0; i < clientCmd.m_uploadDataCommand.m_numBytes; i++)
{
m_dataSlots[dataSlot][dataOffset + i] = bufferServerToClient[i];
}
break;
}
case GFX_CMD_REGISTER_TEXTURE:
{
int dataSlot = 0;
int sizeData = m_dataSlots[dataSlot].size();
btAssert(sizeData > 0);
serverStatusOut.m_type = GFX_CMD_REGISTER_TEXTURE_FAILED;
if (sizeData)
{
unsigned char* texels = &m_dataSlots[dataSlot][0];
int textureId = this->m_guiHelper->registerTexture(texels, clientCmd.m_registerTextureCommand.m_width, clientCmd.m_registerTextureCommand.m_height);
serverStatusOut.m_type = GFX_CMD_REGISTER_TEXTURE_COMPLETED;
serverStatusOut.m_registerTextureStatus.m_textureId = textureId;
}
break;
}
case GFX_CMD_REGISTER_GRAPHICS_SHAPE:
{
int verticesSlot = 0;
int indicesSlot = 1;
serverStatusOut.m_type = GFX_CMD_REGISTER_GRAPHICS_SHAPE_FAILED;
const float* vertices = (const float*) &m_dataSlots[verticesSlot][0];
const int* indices = (const int*) &m_dataSlots[indicesSlot][0];
int numVertices = clientCmd.m_registerGraphicsShapeCommand.m_numVertices;
int numIndices = clientCmd.m_registerGraphicsShapeCommand.m_numIndices;
int primitiveType = clientCmd.m_registerGraphicsShapeCommand.m_primitiveType;
int textureId = clientCmd.m_registerGraphicsShapeCommand.m_textureId;
int shapeId = this->m_guiHelper->registerGraphicsShape(vertices, numVertices, indices, numIndices, primitiveType, textureId);
serverStatusOut.m_registerGraphicsShapeStatus.m_shapeId = shapeId;
serverStatusOut.m_type = GFX_CMD_REGISTER_GRAPHICS_SHAPE_COMPLETED;
break;
}
case GFX_CMD_REGISTER_GRAPHICS_INSTANCE:
{
int graphicsInstanceId = m_guiHelper->registerGraphicsInstance(clientCmd.m_registerGraphicsInstanceCommand.m_shapeIndex,
clientCmd.m_registerGraphicsInstanceCommand.m_position,
clientCmd.m_registerGraphicsInstanceCommand.m_quaternion,
clientCmd.m_registerGraphicsInstanceCommand.m_color,
clientCmd.m_registerGraphicsInstanceCommand.m_scaling);
serverStatusOut.m_registerGraphicsInstanceStatus.m_graphicsInstanceId = graphicsInstanceId;
serverStatusOut.m_type = GFX_CMD_REGISTER_GRAPHICS_INSTANCE_COMPLETED;
break;
}
case GFX_CMD_SYNCHRONIZE_TRANSFORMS:
{
GUISyncPosition* positions = (GUISyncPosition*)bufferServerToClient;
for (int i = 0; i < clientCmd.m_syncTransformsCommand.m_numPositions; i++)
{
m_app->m_renderer->writeSingleInstanceTransformToCPU(positions[i].m_pos, positions[i].m_orn, positions[i].m_graphicsInstanceId);
}
break;
}
case GFX_CMD_REMOVE_ALL_GRAPHICS_INSTANCES:
{
m_guiHelper->removeAllGraphicsInstances();
break;
}
case GFX_CMD_REMOVE_SINGLE_GRAPHICS_INSTANCE:
{
m_app->m_renderer->removeGraphicsInstance(clientCmd.m_removeGraphicsInstanceCommand.m_graphicsUid);
break;
}
default:
{
}
}
return true;
}
void processClientCommands()
{
B3_PROFILE("processClientCommands");
for (int block = 0; block < MAX_GRAPHICS_SHARED_MEMORY_BLOCKS; block++)
{
if (m_areConnected[block] && m_testBlocks[block])
{
///we ignore overflow of integer for now
if (m_testBlocks[block]->m_numClientCommands > m_testBlocks[block]->m_numProcessedClientCommands)
{
//BT_PROFILE("processClientCommand");
//until we implement a proper ring buffer, we assume always maximum of 1 outstanding commands
btAssert(m_testBlocks[block]->m_numClientCommands == m_testBlocks[block]->m_numProcessedClientCommands + 1);
const GraphicsSharedMemoryCommand& clientCmd = m_testBlocks[block]->m_clientCommands[0];
m_testBlocks[block]->m_numProcessedClientCommands++;
//todo, timeStamp
int timeStamp = 0;
GraphicsSharedMemoryStatus& serverStatusOut = createServerStatus(GFX_CMD_CLIENT_COMMAND_FAILED, clientCmd.m_sequenceNumber, timeStamp, block);
bool hasStatus = processCommand(clientCmd, serverStatusOut, &m_testBlocks[block]->m_bulletStreamData[0], GRAPHICS_SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
if (hasStatus)
{
submitServerStatus(serverStatusOut, block);
}
}
}
}
}
virtual void stepSimulation(float deltaTime)
{
B3_PROFILE("stepSimulation");
processClientCommands();
m_x += 0.01f;
m_y += 0.01f;
m_z += 0.01f;
}
virtual void renderScene()
{
B3_PROFILE("renderScene");
{
B3_PROFILE("writeTransforms");
m_app->m_renderer->writeTransforms();
}
{
B3_PROFILE("m_renderer->renderScene");
m_app->m_renderer->renderScene();
}
}
virtual void physicsDebugDraw(int debugDrawFlags)
{
}
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 resetCamera()
{
float dist = 3.5;
float pitch = -32;
float yaw = 136;
float targetPos[3] = {0, 0, 0};
if (m_app->m_renderer && m_app->m_renderer->getActiveCamera())
{
m_app->m_renderer->getActiveCamera()->setCameraDistance(dist);
m_app->m_renderer->getActiveCamera()->setCameraPitch(pitch);
m_app->m_renderer->getActiveCamera()->setCameraYaw(yaw);
m_app->m_renderer->getActiveCamera()->setCameraTargetPosition(targetPos[0], targetPos[1], targetPos[2]);
}
}
bool connectSharedMemory(struct GUIHelperInterface* guiHelper, int sharedMemoryKey);
void disconnectSharedMemory(bool deInitializeSharedMemory=true);
};
bool GraphicsServerExample::connectSharedMemory(struct GUIHelperInterface* guiHelper, int sharedMemoryKey)
{
bool allowCreation = true;
bool allConnected = false;
int numConnected = 0;
int counter = 0;
for (int block = 0; block < MAX_GRAPHICS_SHARED_MEMORY_BLOCKS; block++)
{
if (m_areConnected[block])
{
allConnected = true;
numConnected++;
b3Warning("connectSharedMemory, while already connected");
continue;
}
do
{
m_testBlocks[block] = (GraphicsSharedMemoryBlock*)m_sharedMemory->allocateSharedMemory(m_sharedMemoryKey + block, GRAPHICS_SHARED_MEMORY_SIZE, allowCreation);
if (m_testBlocks[block])
{
int magicId = m_testBlocks[block]->m_magicId;
if (m_verboseOutput)
{
b3Printf("magicId = %d\n", magicId);
}
if (m_testBlocks[block]->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
{
InitSharedMemoryBlock(m_testBlocks[block]);
if (m_verboseOutput)
{
b3Printf("Created and initialized shared memory block\n");
}
m_areConnected[block] = true;
numConnected++;
}
else
{
m_sharedMemory->releaseSharedMemory(m_sharedMemoryKey + block, GRAPHICS_SHARED_MEMORY_SIZE);
m_testBlocks[block] = 0;
m_areConnected[block] = false;
}
}
else
{
//b3Error("Cannot connect to shared memory");
m_areConnected[block] = false;
}
} while (counter++ < 10 && !m_areConnected[block]);
if (!m_areConnected[block])
{
b3Error("Server cannot connect to shared memory.\n");
}
}
allConnected = (numConnected == MAX_GRAPHICS_SHARED_MEMORY_BLOCKS);
return allConnected;
}
void GraphicsServerExample::disconnectSharedMemory(bool deInitializeSharedMemory)
{
//m_data->m_commandProcessor->deleteDynamicsWorld();
if (m_verboseOutput)
{
b3Printf("releaseSharedMemory1\n");
}
for (int block = 0; block < MAX_GRAPHICS_SHARED_MEMORY_BLOCKS; block++)
{
if (m_testBlocks[block])
{
if (m_verboseOutput)
{
b3Printf("m_testBlock1\n");
}
if (deInitializeSharedMemory)
{
m_testBlocks[block]->m_magicId = 0;
if (m_verboseOutput)
{
b3Printf("De-initialized shared memory, magic id = %d\n", m_testBlocks[block]->m_magicId);
}
}
btAssert(m_sharedMemory);
m_sharedMemory->releaseSharedMemory(m_sharedMemoryKey + block, GRAPHICS_SHARED_MEMORY_SIZE);
}
m_testBlocks[block] = 0;
m_areConnected[block] = false;
}
}
CommonExampleInterface* GraphicsServerCreateFuncBullet(struct CommonExampleOptions& options)
{
return new GraphicsServerExample(options.m_guiHelper);
}

View File

@@ -0,0 +1,6 @@
#ifndef GRAPHICS_SERVER_EXAMPLE_H
#define GRAPHICS_SERVER_EXAMPLE_H
class CommonExampleInterface* GraphicsServerCreateFuncBullet(struct CommonExampleOptions& options);
#endif //GRAPHICS_SERVER_EXAMPLE_H

View File

@@ -0,0 +1,41 @@
#ifndef GRAPHICS_SHARED_MEMORY_BLOCK_H
#define GRAPHICS_SHARED_MEMORY_BLOCK_H
#define GRAPHICS_SHARED_MEMORY_MAX_COMMANDS 1
#include "GraphicsSharedMemoryCommands.h"
struct GraphicsSharedMemoryBlock
{
int m_magicId;
struct GraphicsSharedMemoryCommand m_clientCommands[GRAPHICS_SHARED_MEMORY_MAX_COMMANDS];
struct GraphicsSharedMemoryStatus m_serverCommands[GRAPHICS_SHARED_MEMORY_MAX_COMMANDS];
int m_numClientCommands;
int m_numProcessedClientCommands;
int m_numServerCommands;
int m_numProcessedServerCommands;
char m_bulletStreamData[GRAPHICS_SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE];
};
//http://stackoverflow.com/questions/24736304/unable-to-use-inline-in-declaration-get-error-c2054
#ifdef _WIN32
__inline
#else
inline
#endif
void
InitSharedMemoryBlock(struct GraphicsSharedMemoryBlock* sharedMemoryBlock)
{
sharedMemoryBlock->m_numClientCommands = 0;
sharedMemoryBlock->m_numServerCommands = 0;
sharedMemoryBlock->m_numProcessedClientCommands = 0;
sharedMemoryBlock->m_numProcessedServerCommands = 0;
sharedMemoryBlock->m_magicId = GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER;
}
#define GRAPHICS_SHARED_MEMORY_SIZE sizeof(GraphicsSharedMemoryBlock)
#endif //GRAPHICS_SHARED_MEMORY_BLOCK_H

View File

@@ -0,0 +1,159 @@
#ifndef GRAPHICS_SHARED_MEMORY_COMMANDS_H
#define GRAPHICS_SHARED_MEMORY_COMMANDS_H
//this is a very experimental draft of commands. We will iterate on this API (commands, arguments etc)
#include "GraphicsSharedMemoryPublic.h"
#ifdef __GNUC__
#include <stdint.h>
typedef int32_t smInt32a_t;
typedef int64_t smInt64a_t;
typedef uint32_t smUint32a_t;
typedef uint64_t smUint64a_t;
#elif defined(_MSC_VER)
typedef __int32 smInt32a_t;
typedef __int64 smInt64a_t;
typedef unsigned __int32 smUint32a_t;
typedef unsigned __int64 smUint64a_t;
#else
typedef int smInt32a_t;
typedef long long int smInt64a_t;
typedef unsigned int smUint32a_t;
typedef unsigned long long int smUint64a_t;
#endif
#ifdef __APPLE__
#define GRAPHICS_SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (512 * 1024)
#else
#define GRAPHICS_SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE (4 * 1024 * 1024)
#endif
struct GraphicsCommand0
{
int bla;
};
struct GraphicsUpAxisCommand
{
int m_enableUpAxisY;
};
struct GraphicsStatus0
{
int bla;
};
struct GraphicsVisualizerFlagCommand
{
int m_visualizerFlag;
int m_enable;
};
struct GraphicsUploadDataCommand
{
int m_numBytes;
int m_dataOffset;
int m_dataSlot;
};
struct GraphicRegisterTextureCommand
{
int m_width;
int m_height;
};
struct GraphicsRegisterTextureStatus
{
int m_textureId;
};
struct GraphicsRegisterGraphicsShapeCommand
{
int m_numVertices;
int m_numIndices;
int m_primitiveType;
int m_textureId;
};
struct GraphicsRegisterGraphicsShapeStatus
{
int m_shapeId;
};
struct GraphicsRegisterGraphicsInstanceCommand
{
int m_shapeIndex;
float m_position[4];
float m_quaternion[4];
float m_color[4];
float m_scaling[4];
};
struct GraphicsRegisterGraphicsInstanceStatus
{
int m_graphicsInstanceId;
};
struct GraphicsSyncTransformsCommand
{
int m_numPositions;
};
struct GraphicsRemoveInstanceCommand
{
int m_graphicsUid;
};
struct GraphicsSharedMemoryCommand
{
int m_type;
smUint64a_t m_timeStamp;
int m_sequenceNumber;
//m_updateFlags is a bit fields to tell which parameters need updating
//for example m_updateFlags = SIM_PARAM_UPDATE_DELTA_TIME | SIM_PARAM_UPDATE_NUM_SOLVER_ITERATIONS;
int m_updateFlags;
union {
struct GraphicsCommand0 m_graphicsCommand0;
struct GraphicsUpAxisCommand m_upAxisYCommand;
struct GraphicsVisualizerFlagCommand m_visualizerFlagCommand;
struct GraphicsUploadDataCommand m_uploadDataCommand;
struct GraphicRegisterTextureCommand m_registerTextureCommand;
struct GraphicsRegisterGraphicsShapeCommand m_registerGraphicsShapeCommand;
struct GraphicsRegisterGraphicsInstanceCommand m_registerGraphicsInstanceCommand;
struct GraphicsSyncTransformsCommand m_syncTransformsCommand;
struct GraphicsRemoveInstanceCommand m_removeGraphicsInstanceCommand;
};
};
struct GraphicsSharedMemoryStatus
{
int m_type;
smUint64a_t m_timeStamp;
int m_sequenceNumber;
//m_streamBytes is only for internal purposes
int m_numDataStreamBytes;
char* m_dataStream;
//m_updateFlags is a bit fields to tell which parameters were updated,
//m_updateFlags is ignored for most status messages
int m_updateFlags;
union {
struct GraphicsStatus0 m_graphicsStatus0;
struct GraphicsRegisterTextureStatus m_registerTextureStatus;
struct GraphicsRegisterGraphicsShapeStatus m_registerGraphicsShapeStatus;
struct GraphicsRegisterGraphicsInstanceStatus m_registerGraphicsInstanceStatus;
};
};
typedef struct GraphicsSharedMemoryStatus GraphicsSharedMemoryStatus_t;
#endif //GRAPHICS_SHARED_MEMORY_COMMANDS_H

View File

@@ -0,0 +1,47 @@
#ifndef GRAPHICS_SHARED_MEMORY_PUBLIC_H
#define GRAPHICS_SHARED_MEMORY_PUBLIC_H
#define GRAPHICS_SHARED_MEMORY_KEY 11347
///increase the SHARED_MEMORY_MAGIC_NUMBER whenever incompatible changes are made in the structures
///my convention is year/month/day/rev
//Please don't replace an existing magic number:
//instead, only ADD a new one at the top, comment-out previous one
#define GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER 201904030
enum EnumGraphicsSharedMemoryClientCommand
{
GFX_CMD_INVALID = 0,
GFX_CMD_0,
GFX_CMD_SET_VISUALIZER_FLAG,
GFX_CMD_UPLOAD_DATA,
GFX_CMD_REGISTER_TEXTURE,
GFX_CMD_REGISTER_GRAPHICS_SHAPE,
GFX_CMD_REGISTER_GRAPHICS_INSTANCE,
GFX_CMD_SYNCHRONIZE_TRANSFORMS,
GFX_CMD_REMOVE_ALL_GRAPHICS_INSTANCES,
GFX_CMD_REMOVE_SINGLE_GRAPHICS_INSTANCE,
//don't go beyond this command!
GFX_CMD_MAX_CLIENT_COMMANDS,
};
enum EnumGraphicsSharedMemoryServerStatus
{
GFX_CMD_SHARED_MEMORY_NOT_INITIALIZED = 0,
//GFX_CMD_CLIENT_COMMAND_COMPLETED is a generic 'completed' status that doesn't need special handling on the client
GFX_CMD_CLIENT_COMMAND_COMPLETED,
GFX_CMD_CLIENT_COMMAND_FAILED,
GFX_CMD_REGISTER_TEXTURE_COMPLETED,
GFX_CMD_REGISTER_TEXTURE_FAILED,
GFX_CMD_REGISTER_GRAPHICS_SHAPE_COMPLETED,
GFX_CMD_REGISTER_GRAPHICS_SHAPE_FAILED,
GFX_CMD_REGISTER_GRAPHICS_INSTANCE_COMPLETED,
GFX_CMD_REGISTER_GRAPHICS_INSTANCE_FAILED,
//don't go beyond 'CMD_MAX_SERVER_COMMANDS!
GFX_CMD_MAX_SERVER_COMMANDS
};
#endif //GRAPHICS_SHARED_MEMORY_PUBLIC_H

View File

@@ -7717,6 +7717,7 @@ bool PhysicsServerCommandProcessor::processForwardDynamicsCommand(const struct S
}
serverCmd.m_type = CMD_STEP_FORWARD_SIMULATION_COMPLETED;
syncPhysicsToGraphics2();
return hasStatus;
}
@@ -11568,6 +11569,13 @@ void PhysicsServerCommandProcessor::syncPhysicsToGraphics()
m_data->m_guiHelper->syncPhysicsToGraphics(m_data->m_dynamicsWorld);
}
void PhysicsServerCommandProcessor::syncPhysicsToGraphics2()
{
m_data->m_guiHelper->syncPhysicsToGraphics2(m_data->m_dynamicsWorld);
}
void PhysicsServerCommandProcessor::renderScene(int renderFlags)
{
if (m_data->m_guiHelper)

View File

@@ -138,6 +138,7 @@ public:
virtual void physicsDebugDraw(int debugDrawFlags);
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper);
virtual void syncPhysicsToGraphics();
virtual void syncPhysicsToGraphics2();
//@todo(erwincoumans) Should we have shared memory commands for picking objects?
///The pickBody method will try to pick the first body along a ray, return true if succeeds, false otherwise

View File

@@ -823,6 +823,16 @@ public:
}
}
virtual void syncPhysicsToGraphics2(const btDiscreteDynamicsWorld* rbWorld)
{
m_childGuiHelper->syncPhysicsToGraphics2(rbWorld);
}
virtual void syncPhysicsToGraphics2(const GUISyncPosition* positions, int numPositions)
{
m_childGuiHelper->syncPhysicsToGraphics2(positions, numPositions);
}
virtual void render(const btDiscreteDynamicsWorld* rbWorld)
{
m_childGuiHelper->render(0);

View File

@@ -236,8 +236,10 @@ void PhysicsServerSharedMemory::reportNotifications()
void PhysicsServerSharedMemory::processClientCommands()
{
//handle client commands in any of the plugins
m_data->m_commandProcessor->processClientCommands();
//now handle the client commands from the shared memory
for (int block = 0; block < MAX_SHARED_MEMORY_BLOCKS; block++)
{
if (m_data->m_areConnected[block] && m_data->m_testBlocks[block])

View File

@@ -0,0 +1,589 @@
#include "RemoteGUIHelper.h"
#include "../CommonInterfaces/CommonExampleInterface.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
#include "Bullet3Common/b3Logging.h"
#include "GraphicsSharedMemoryCommands.h"
#include "PosixSharedMemory.h"
#include "Win32SharedMemory.h"
#include "GraphicsSharedMemoryBlock.h"
#include "Bullet3Common/b3Scalar.h"
#include "LinearMath/btMinMax.h"
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
#include "Bullet3Common/b3AlignedObjectArray.h"
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
struct RemoteGUIHelperInternalData
{
// GUIHelperInterface* m_guiHelper;
bool m_waitingForServer;
GraphicsSharedMemoryBlock* m_testBlock1;
SharedMemoryInterface* m_sharedMemory;
GraphicsSharedMemoryStatus m_lastServerStatus;
int m_sharedMemoryKey;
bool m_isConnected;
RemoteGUIHelperInternalData()
: m_waitingForServer(false),
m_testBlock1(0)
{
#ifdef _WIN32
m_sharedMemory = new Win32SharedMemoryClient();
#else
m_sharedMemory = new PosixSharedMemory();
#endif
m_sharedMemoryKey = GRAPHICS_SHARED_MEMORY_KEY;
m_isConnected = false;
connect();
}
virtual ~RemoteGUIHelperInternalData()
{
disconnect();
delete m_sharedMemory;
}
virtual bool isConnected()
{
return m_isConnected;
}
bool canSubmitCommand() const
{
if (m_isConnected && !m_waitingForServer)
{
if (m_testBlock1->m_magicId == GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
{
return true;
}
else
{
return false;
}
}
return false;
}
struct GraphicsSharedMemoryCommand* getAvailableSharedMemoryCommand()
{
static int sequence = 0;
if (m_testBlock1)
{
m_testBlock1->m_clientCommands[0].m_sequenceNumber = sequence++;
return &m_testBlock1->m_clientCommands[0];
}
return 0;
}
bool submitClientCommand(const GraphicsSharedMemoryCommand& command)
{
/// at the moment we allow a maximum of 1 outstanding command, so we check for this
// once the server processed the command and returns a status, we clear the flag
// "m_data->m_waitingForServer" and allow submitting the next command
btAssert(!m_waitingForServer);
if (!m_waitingForServer)
{
//printf("submit command of type %d\n", command.m_type);
if (&m_testBlock1->m_clientCommands[0] != &command)
{
m_testBlock1->m_clientCommands[0] = command;
}
m_testBlock1->m_numClientCommands++;
m_waitingForServer = true;
return true;
}
return false;
}
const GraphicsSharedMemoryStatus* processServerStatus()
{
// SharedMemoryStatus* stat = 0;
if (!m_testBlock1)
{
m_lastServerStatus.m_type = GFX_CMD_SHARED_MEMORY_NOT_INITIALIZED;
return &m_lastServerStatus;
}
if (!m_waitingForServer)
{
return 0;
}
if (m_testBlock1->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
{
m_lastServerStatus.m_type = GFX_CMD_SHARED_MEMORY_NOT_INITIALIZED;
return &m_lastServerStatus;
}
if (m_testBlock1->m_numServerCommands >
m_testBlock1->m_numProcessedServerCommands)
{
B3_PROFILE("processServerCMD");
b3Assert(m_testBlock1->m_numServerCommands ==
m_testBlock1->m_numProcessedServerCommands + 1);
const GraphicsSharedMemoryStatus& serverCmd = m_testBlock1->m_serverCommands[0];
m_lastServerStatus = serverCmd;
// EnumSharedMemoryServerStatus s = (EnumSharedMemoryServerStatus)serverCmd.m_type;
// consume the command
switch (serverCmd.m_type)
{
case GFX_CMD_CLIENT_COMMAND_COMPLETED:
{
B3_PROFILE("CMD_CLIENT_COMMAND_COMPLETED");
break;
}
default:
{
}
}
m_testBlock1->m_numProcessedServerCommands++;
// we don't have more than 1 command outstanding (in total, either server or client)
b3Assert(m_testBlock1->m_numProcessedServerCommands ==
m_testBlock1->m_numServerCommands);
if (m_testBlock1->m_numServerCommands ==
m_testBlock1->m_numProcessedServerCommands)
{
m_waitingForServer = false;
}
else
{
m_waitingForServer = true;
}
return &m_lastServerStatus;
}
return 0;
}
bool connect()
{
/// server always has to create and initialize shared memory
bool allowCreation = false;
m_testBlock1 = (GraphicsSharedMemoryBlock*)m_sharedMemory->allocateSharedMemory(
m_sharedMemoryKey, GRAPHICS_SHARED_MEMORY_SIZE, allowCreation);
if (m_testBlock1)
{
if (m_testBlock1->m_magicId != GRAPHICS_SHARED_MEMORY_MAGIC_NUMBER)
{
b3Error("Error connecting to shared memory: please start server before client\n");
m_sharedMemory->releaseSharedMemory(m_sharedMemoryKey,
GRAPHICS_SHARED_MEMORY_SIZE);
m_testBlock1 = 0;
return false;
}
else
{
m_isConnected = true;
}
}
else
{
b3Warning("Cannot connect to shared memory");
return false;
}
return true;
}
void disconnect()
{
if (m_isConnected && m_sharedMemory)
{
m_sharedMemory->releaseSharedMemory(m_sharedMemoryKey, GRAPHICS_SHARED_MEMORY_SIZE);
}
m_isConnected = false;
}
};
RemoteGUIHelper::RemoteGUIHelper()
{
m_data = new RemoteGUIHelperInternalData;
if (m_data->canSubmitCommand())
{
removeAllGraphicsInstances();
}
}
RemoteGUIHelper::~RemoteGUIHelper()
{
delete m_data;
}
void RemoteGUIHelper::setVisualizerFlag(int flag, int enable)
{
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_updateFlags = 0;
cmd->m_visualizerFlagCommand.m_visualizerFlag = flag;
cmd->m_visualizerFlagCommand.m_enable = enable;
cmd->m_type = GFX_CMD_SET_VISUALIZER_FLAG;
m_data->submitClientCommand(*cmd);
}
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
}
void RemoteGUIHelper::createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color)
{
printf("createRigidBodyGraphicsObject\n");
}
void RemoteGUIHelper::createCollisionObjectGraphicsObject(btCollisionObject* body, const btVector3& color)
{
if (body->getUserIndex() < 0)
{
btCollisionShape* shape = body->getCollisionShape();
btTransform startTransform = body->getWorldTransform();
int graphicsShapeId = shape->getUserIndex();
if (graphicsShapeId >= 0)
{
// btAssert(graphicsShapeId >= 0);
//the graphics shape is already scaled
float localScaling[4] = { 1.f, 1.f, 1.f, 1.f };
float colorRGBA[4] = { (float)color[0], (float)color[1], (float)color[2], (float) color[3] };
float pos[4] = { (float)startTransform.getOrigin()[0], (float)startTransform.getOrigin()[1], (float)startTransform.getOrigin()[2], (float)startTransform.getOrigin()[3] };
float orn[4] = { (float)startTransform.getRotation()[0], (float)startTransform.getRotation()[1], (float)startTransform.getRotation()[2], (float)startTransform.getRotation()[3] };
int graphicsInstanceId = registerGraphicsInstance(graphicsShapeId, pos,orn, colorRGBA, localScaling);
body->setUserIndex(graphicsInstanceId);
}
}
}
void RemoteGUIHelper::createCollisionShapeGraphicsObject(btCollisionShape* collisionShape)
{
printf("createCollisionShapeGraphicsObject\n");
}
void RemoteGUIHelper::syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld)
{
}
void RemoteGUIHelper::syncPhysicsToGraphics2(const btDiscreteDynamicsWorld* rbWorld)
{
b3AlignedObjectArray<GUISyncPosition> updatedPositions;
int numCollisionObjects = rbWorld->getNumCollisionObjects();
{
B3_PROFILE("write all InstanceTransformToCPU2");
for (int i = 0; i < numCollisionObjects; i++)
{
//B3_PROFILE("writeSingleInstanceTransformToCPU");
btCollisionObject* colObj = rbWorld->getCollisionObjectArray()[i];
btCollisionShape* collisionShape = colObj->getCollisionShape();
btVector3 pos = colObj->getWorldTransform().getOrigin();
btQuaternion orn = colObj->getWorldTransform().getRotation();
int index = colObj->getUserIndex();
if (index >= 0)
{
GUISyncPosition p;
p.m_graphicsInstanceId = index;
for (int q = 0; q < 4; q++)
{
p.m_pos[q] = pos[q];
p.m_orn[q] = orn[q];
}
updatedPositions.push_back(p);
}
}
}
if (updatedPositions.size())
{
syncPhysicsToGraphics2(&updatedPositions[0], updatedPositions.size());
}
}
void RemoteGUIHelper::syncPhysicsToGraphics2(const GUISyncPosition* positions, int numPositions)
{
uploadData((unsigned char*) positions, numPositions * sizeof(GUISyncPosition), 0);
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_updateFlags = 0;
cmd->m_syncTransformsCommand.m_numPositions = numPositions;
cmd->m_type = GFX_CMD_SYNCHRONIZE_TRANSFORMS;
m_data->submitClientCommand(*cmd);
}
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
}
void RemoteGUIHelper::render(const btDiscreteDynamicsWorld* rbWorld)
{
}
void RemoteGUIHelper::createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld)
{
}
int RemoteGUIHelper::uploadData(const unsigned char* data, int sizeInBytes, int slot)
{
int chunkSize = GRAPHICS_SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE;
int remainingBytes = sizeInBytes;
int offset = 0;
while (remainingBytes)
{
btAssert(remainingBytes >= 0);
int curBytes = btMin(remainingBytes, chunkSize);
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
for (int i = 0; i < curBytes; i++)
{
m_data->m_testBlock1->m_bulletStreamData[i] = data[i+offset];
}
cmd->m_updateFlags = 0;
cmd->m_type = GFX_CMD_UPLOAD_DATA;
cmd->m_uploadDataCommand.m_numBytes = curBytes;
cmd->m_uploadDataCommand.m_dataOffset = offset;
cmd->m_uploadDataCommand.m_dataSlot = slot;
m_data->submitClientCommand(*cmd);
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
offset += curBytes;
remainingBytes -= curBytes;
}
}
return 0;
}
int RemoteGUIHelper::registerTexture(const unsigned char* texels, int width, int height)
{
int textureId = -1;
//first upload all data
int sizeInBytes = width*height * 3;//rgb
uploadData(texels, sizeInBytes, 0);
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_updateFlags = 0;
cmd->m_type = GFX_CMD_REGISTER_TEXTURE;
cmd->m_registerTextureCommand.m_width = width;
cmd->m_registerTextureCommand.m_height = height;
m_data->submitClientCommand(*cmd);
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
if (status->m_type == GFX_CMD_REGISTER_TEXTURE_COMPLETED)
{
textureId = status->m_registerTextureStatus.m_textureId;
}
}
return textureId;
}
int RemoteGUIHelper::registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType, int textureId)
{
int shapeId = -1;
uploadData((unsigned char*)vertices, numvertices * 9*sizeof(float), 0);
uploadData((unsigned char*)indices, numIndices * sizeof(int), 1);
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_type = GFX_CMD_REGISTER_GRAPHICS_SHAPE;
cmd->m_updateFlags = 0;
cmd->m_registerGraphicsShapeCommand.m_numVertices = numvertices;
cmd->m_registerGraphicsShapeCommand.m_numIndices = numIndices;
cmd->m_registerGraphicsShapeCommand.m_primitiveType = primitiveType;
cmd->m_registerGraphicsShapeCommand.m_textureId = textureId;
m_data->submitClientCommand(*cmd);
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
if (status->m_type == GFX_CMD_REGISTER_GRAPHICS_SHAPE_COMPLETED)
{
shapeId = status->m_registerGraphicsShapeStatus.m_shapeId;
}
}
return shapeId;
}
int RemoteGUIHelper::registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
{
int graphicsInstanceId = -1;
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_type = GFX_CMD_REGISTER_GRAPHICS_INSTANCE;
cmd->m_updateFlags = 0;
cmd->m_registerGraphicsInstanceCommand.m_shapeIndex = shapeIndex;
for (int i = 0; i < 4; i++)
{
cmd->m_registerGraphicsInstanceCommand.m_position[i] = position[i];
cmd->m_registerGraphicsInstanceCommand.m_quaternion[i] = quaternion[i];
cmd->m_registerGraphicsInstanceCommand.m_color[i] = color[i];
cmd->m_registerGraphicsInstanceCommand.m_scaling[i] = scaling[i];
}
m_data->submitClientCommand(*cmd);
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
if (status->m_type == GFX_CMD_REGISTER_GRAPHICS_INSTANCE_COMPLETED)
{
graphicsInstanceId = status->m_registerGraphicsInstanceStatus.m_graphicsInstanceId;
}
}
return graphicsInstanceId;
}
void RemoteGUIHelper::removeAllGraphicsInstances()
{
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_updateFlags = 0;
cmd->m_type = GFX_CMD_REMOVE_ALL_GRAPHICS_INSTANCES;
m_data->submitClientCommand(*cmd);
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
}
}
void RemoteGUIHelper::removeGraphicsInstance(int graphicsUid)
{
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_updateFlags = 0;
cmd->m_type = GFX_CMD_REMOVE_SINGLE_GRAPHICS_INSTANCE;
cmd->m_removeGraphicsInstanceCommand.m_graphicsUid = graphicsUid;
m_data->submitClientCommand(*cmd);
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
}
}
void RemoteGUIHelper::changeRGBAColor(int instanceUid, const double rgbaColor[4])
{
}
Common2dCanvasInterface* RemoteGUIHelper::get2dCanvasInterface()
{
return 0;
}
CommonParameterInterface* RemoteGUIHelper::getParameterInterface()
{
return 0;
}
CommonRenderInterface* RemoteGUIHelper::getRenderInterface()
{
return 0;
}
CommonGraphicsApp* RemoteGUIHelper::getAppInterface()
{
return 0;
}
void RemoteGUIHelper::setUpAxis(int axis)
{
GraphicsSharedMemoryCommand* cmd = m_data->getAvailableSharedMemoryCommand();
if (cmd)
{
cmd->m_updateFlags = 0;
cmd->m_upAxisYCommand.m_enableUpAxisY = axis == 1;
cmd->m_type = GFX_CMD_0;
m_data->submitClientCommand(*cmd);
const GraphicsSharedMemoryStatus* status = 0;
while ((status = m_data->processServerStatus()) == 0)
{
}
}
}
void RemoteGUIHelper::resetCamera(float camDist, float yaw, float pitch, float camPosX, float camPosY, float camPosZ)
{
}
void RemoteGUIHelper::copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
float* depthBuffer, int depthBufferSizeInPixels,
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
int startPixelIndex, int width, int height, int* numPixelsCopied)
{
if (numPixelsCopied)
*numPixelsCopied = 0;
}
void RemoteGUIHelper::setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16])
{
}
void RemoteGUIHelper::setProjectiveTexture(bool useProjectiveTexture)
{
}
void RemoteGUIHelper::autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld)
{
}
void RemoteGUIHelper::drawText3D(const char* txt, float posX, float posZY, float posZ, float size)
{
}
void RemoteGUIHelper::drawText3D(const char* txt, float position[3], float orientation[4], float color[4], float size, int optionFlag)
{
}
int RemoteGUIHelper::addUserDebugLine(const double debugLineFromXYZ[3], const double debugLineToXYZ[3], const double debugLineColorRGB[3], double lineWidth, double lifeTime, int trackingVisualShapeIndex, int replaceItemUid)
{
return -1;
}
void RemoteGUIHelper::removeUserDebugItem(int debugItemUniqueId)
{
}
void RemoteGUIHelper::removeAllUserDebugItems()
{
}

View File

@@ -0,0 +1,73 @@
#ifndef REMOTE_HELPER_H
#define REMOTE_HELPER_H
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
///a RemoteGUIHelper will connect to an existing graphics server through shared memory
struct RemoteGUIHelper : public GUIHelperInterface
{
struct RemoteGUIHelperInternalData* m_data;
RemoteGUIHelper();
virtual ~RemoteGUIHelper();
virtual void setVisualizerFlag(int flag, int enable);
virtual void createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color);
virtual void createCollisionObjectGraphicsObject(btCollisionObject* body, const btVector3& color);
virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape);
virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld);
virtual void syncPhysicsToGraphics2(const class btDiscreteDynamicsWorld* rbWorld);
virtual void syncPhysicsToGraphics2(const GUISyncPosition* positions, int numPositions);
virtual void render(const btDiscreteDynamicsWorld* rbWorld);
virtual void createPhysicsDebugDrawer(btDiscreteDynamicsWorld* rbWorld);
virtual int registerTexture(const unsigned char* texels, int width, int height);
virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType, int textureId);
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);
virtual void removeAllGraphicsInstances();
virtual void removeGraphicsInstance(int graphicsUid);
virtual void changeRGBAColor(int instanceUid, const double rgbaColor[4]);
virtual Common2dCanvasInterface* get2dCanvasInterface();
virtual CommonParameterInterface* getParameterInterface();
virtual CommonRenderInterface* getRenderInterface();
virtual CommonGraphicsApp* getAppInterface();
virtual void setUpAxis(int axis);
virtual void resetCamera(float camDist, float yaw, float pitch, float camPosX, float camPosY, float camPosZ);
virtual void copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16],
unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels,
float* depthBuffer, int depthBufferSizeInPixels,
int* segmentationMaskBuffer, int segmentationMaskBufferSizeInPixels,
int startPixelIndex, int width, int height, int* numPixelsCopied);
virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]);
virtual void setProjectiveTexture(bool useProjectiveTexture);
virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld);
virtual void drawText3D(const char* txt, float posX, float posZY, float posZ, float size);
virtual void drawText3D(const char* txt, float position[3], float orientation[4], float color[4], float size, int optionFlag);
virtual int addUserDebugLine(const double debugLineFromXYZ[3], const double debugLineToXYZ[3], const double debugLineColorRGB[3], double lineWidth, double lifeTime, int trackingVisualShapeIndex, int replaceItemUid);
virtual void removeUserDebugItem(int debugItemUniqueId);
virtual void removeAllUserDebugItems();
int uploadData(const unsigned char* data, int sizeInBytes, int slot);
};
#endif //REMOTE_HELPER_H

View File

@@ -1,7 +1,7 @@
#ifndef SHARED_MEMORY_BLOCK_H
#define SHARED_MEMORY_BLOCK_H
#define SHARED_MEMORY_MAX_COMMANDS 4
#define SHARED_MEMORY_MAX_COMMANDS 1
#include "SharedMemoryCommands.h"

View File

@@ -10,6 +10,7 @@
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
#include "../CommonInterfaces/CommonExampleInterface.h"
#include "InProcessMemory.h"
#include "RemoteGUIHelper.h"
#include "Bullet3Common/b3Logging.h"
class InProcessPhysicsClientSharedMemoryMainThread : public PhysicsClientSharedMemory
@@ -281,6 +282,26 @@ B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingEx
return (b3PhysicsClientHandle)cl;
}
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect4(void* guiHelperPtr, int sharedMemoryKey)
{
gSharedMemoryKey = sharedMemoryKey;
GUIHelperInterface* guiHelper = (GUIHelperInterface*)guiHelperPtr;
if (!guiHelper)
{
guiHelper = new RemoteGUIHelper();
}
bool useInprocessMemory = false;
bool skipGraphicsUpdate = false;
InProcessPhysicsClientExistingExampleBrowser* cl = new InProcessPhysicsClientExistingExampleBrowser(guiHelper, useInprocessMemory, skipGraphicsUpdate);
cl->setSharedMemoryKey(sharedMemoryKey + 1);
cl->connect();
//backward compatiblity
gSharedMemoryKey = SHARED_MEMORY_KEY;
return (b3PhysicsClientHandle)cl;
}
//backward compatiblity
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect2(void* guiHelperPtr)
{

View File

@@ -21,6 +21,8 @@ extern "C"
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect2(void* guiHelperPtr);
//create a shared memory physics server, with a DummyGUIHelper (no graphics) and allow to set shared memory key
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect3(void* guiHelperPtr, int sharedMemoryKey);
//create a shared memory physics server, with a RemoteGUIHelper (connect to remote graphics server) and allow to set shared memory key
B3_SHARED_API b3PhysicsClientHandle b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect4(void* guiHelperPtr, int sharedMemoryKey);
///ignore the following APIs, they are for internal use for example browser
void b3InProcessRenderSceneInternal(b3PhysicsClientHandle clientHandle);

View File

@@ -829,6 +829,7 @@ enum eCONNECT_METHOD
eCONNECT_MUJOCO = 11,
eCONNECT_GRPC = 12,
eCONNECT_PHYSX=13,
eCONNECT_SHARED_MEMORY_GUI=14,
};
enum eURDF_Flags

View File

@@ -34,6 +34,15 @@ myfiles =
"PhysicsServer.cpp",
"PhysicsServer.h",
"PhysicsClientC_API.cpp",
"GraphicsClientExample.cpp",
"GraphicsClientExample.h",
"GraphicsServerExample.cpp",
"GraphicsServerExample.h",
"GraphicsSharedMemoryBlock.h",
"GraphicsSharedMemoryCommands.h",
"GraphicsSharedMemoryPublic.h",
"RemoteGUIHelper.cpp",
"RemoteGUIHelper.h",
"SharedMemoryCommands.h",
"SharedMemoryPublic.h",
"PhysicsServer.cpp",

View File

@@ -32,6 +32,14 @@ SET(RobotSimulator_SRCS
../../examples/SharedMemory/PhysicsClient.h
../../examples/SharedMemory/PhysicsServer.cpp
../../examples/SharedMemory/PhysicsServer.h
../SharedMemory/GraphicsServerExample.cpp
../SharedMemory/GraphicsClientExample.cpp
../SharedMemory/RemoteGUIHelper.cpp
../SharedMemory/GraphicsServerExample.h
../SharedMemory/GraphicsClientExample.h
../SharedMemory/RemoteGUIHelper.h
../SharedMemory/GraphicsSharedMemoryCommands.h
../SharedMemory/GraphicsSharedMemoryPublic.h
../../examples/SharedMemory/PhysicsServerExample.cpp
../../examples/SharedMemory/PhysicsServerExampleBullet2.cpp
../../examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp

View File

@@ -55,6 +55,14 @@ SET(pybullet_SRCS
../../examples/SharedMemory/PhysicsClient.h
../../examples/SharedMemory/PhysicsServer.cpp
../../examples/SharedMemory/PhysicsServer.h
../SharedMemory/GraphicsServerExample.cpp
../SharedMemory/GraphicsClientExample.cpp
../SharedMemory/RemoteGUIHelper.cpp
../SharedMemory/GraphicsServerExample.h
../SharedMemory/GraphicsClientExample.h
../SharedMemory/RemoteGUIHelper.h
../SharedMemory/GraphicsSharedMemoryCommands.h
../SharedMemory/GraphicsSharedMemoryPublic.h
../../examples/SharedMemory/PhysicsServerExample.cpp
../../examples/SharedMemory/PhysicsServerExampleBullet2.cpp
../../examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp

View File

@@ -6,6 +6,8 @@ from datetime import datetime
clid = p.connect(p.SHARED_MEMORY)
if (clid < 0):
p.connect(p.GUI)
#p.connect(p.SHARED_MEMORY_GUI)
p.loadURDF("plane.urdf", [0, 0, -0.3])
kukaId = p.loadURDF("kuka_iiwa/model.urdf", [0, 0, 0])
p.resetBasePositionAndOrientation(kukaId, [0, 0, 0], [0, 0, 0, 1])
@@ -38,24 +40,26 @@ useNullSpace = 1
useOrientation = 1
#If we set useSimulation=0, it sets the arm pose to be the IK result directly without using dynamic control.
#This can be used to test the IK result accuracy.
useSimulation = 0
useRealTimeSimulation = 1
useSimulation = 1
useRealTimeSimulation = 0
ikSolver = 0
p.setRealTimeSimulation(useRealTimeSimulation)
#trailDuration is duration (in seconds) after debug lines will be removed automatically
#use 0 for no-removal
trailDuration = 15
i=0
while 1:
p.getCameraImage(320,
200,
flags=p.ER_SEGMENTATION_MASK_OBJECT_AND_LINKINDEX,
renderer=p.ER_BULLET_HARDWARE_OPENGL)
i+=1
#p.getCameraImage(320,
# 200,
# flags=p.ER_SEGMENTATION_MASK_OBJECT_AND_LINKINDEX,
# renderer=p.ER_BULLET_HARDWARE_OPENGL)
if (useRealTimeSimulation):
dt = datetime.now()
t = (dt.second / 60.) * 2. * math.pi
else:
t = t + 0.001
t = t + 0.01
if (useSimulation and useRealTimeSimulation == 0):
p.stepSimulation()
@@ -115,3 +119,4 @@ while 1:
prevPose = pos
prevPose1 = ls[4]
hasPrevPose = 1
p.disconnect()

View File

@@ -104,7 +104,7 @@ def drawInertiaBox(parentUid, parentLinkIndex, color):
toeConstraint = True
useMaximalCoordinates = False
useRealTime = 1
useRealTime = 0
#the fixedTimeStep and numSolverIterations are the most important parameters to trade-off quality versus performance
fixedTimeStep = 1. / 100
@@ -123,7 +123,7 @@ kp = 1
kd = .5
maxKneeForce = 1000
physId = p.connect(p.SHARED_MEMORY)
physId = p.connect(p.SHARED_MEMORY_GUI)
if (physId < 0):
p.connect(p.GUI)
#p.resetSimulation()

View File

@@ -7,6 +7,7 @@ import time
import motion_capture_data
import quadrupedPoseInterpolator
useKinematic = False
useConstraints = False
p = bullet_client.BulletClient(connection_mode=p1.GUI)
@@ -56,7 +57,7 @@ for i in range(4):
jointOffsets.append(-0.7)
jointOffsets.append(0.7)
maxForceId = p.addUserDebugParameter("maxForce", 0, 100, 20)
maxForceId = p.addUserDebugParameter("maxForce", 0, 100, 120)
for j in range(p.getNumJoints(quadruped)):
p.changeDynamics(quadruped, j, linearDamping=0, angularDamping=0)
@@ -103,7 +104,7 @@ for i in range(4):
jointOffsets.append(-0.7)
jointOffsets.append(0.7)
maxForceId = p.addUserDebugParameter("maxForce", 0, 100, 20)
maxUpForceId = p.addUserDebugParameter("maxUpForce", 0, 100, 20)
for j in range(p.getNumJoints(quadruped)):
p.changeDynamics(quadruped, j, linearDamping=0, angularDamping=0)
@@ -162,8 +163,23 @@ while t < 10. * cycleTime:
jointsStr, qdot = qpi.Slerp(frameFraction, frameData, frameDataNext, p)
maxForce = p.readUserDebugParameter(maxForceId)
print("jointIds=", jointIds)
#print("jointIds=", jointIds)
maxUpForce = p.readUserDebugParameter(maxUpForceId)
p.changeConstraint(cid, maxForce=maxUpForce)
if useKinematic:
basePos = startPos
basePos = [float(-jointsStr[0]),-float(jointsStr[1]),float(jointsStr[2])]
baseOrn = [float(jointsStr[4]),float(jointsStr[5]),float(jointsStr[6]), float(jointsStr[3])]
p.resetBasePositionAndOrientation(quadruped, basePos,baseOrn)
for j in range(12):
#skip the base positional dofs
targetPos = float(jointsStr[j + 7])
p.resetJointState(quadruped,jointIds[j],jointDirections[j] * targetPos + jointOffsets[j])
else:
if useConstraints:
for j in range(12):
#skip the base positional dofs
@@ -194,7 +210,7 @@ while t < 10. * cycleTime:
desiredVelocities=desiredVelocities,
kps=[4000] * totalDofs,
kds=[40] * totalDofs,
maxForces=[500] * totalDofs,
maxForces=[maxForce] * totalDofs,
timeStep=timeStep)
dofIndex = 6
@@ -202,7 +218,7 @@ while t < 10. * cycleTime:
for index in range(len(jointIds)):
jointIndex = jointIds[index]
force = [scaling * taus[dofIndex]]
print("force[", jointIndex, "]=", force)
#print("force[", jointIndex, "]=", force)
p.setJointMotorControlMultiDof(quadruped,
jointIndex,
controlMode=p.TORQUE_CONTROL,
@@ -231,8 +247,9 @@ if useOrgData:
force=maxForce)
p.stepSimulation()
for lower_leg in lower_legs:
pass
#print("points for ", quadruped, " link: ", lower_leg)
pts = p.getContactPoints(quadruped, -1, lower_leg)
#pts = p.getContactPoints(quadruped, -1, lower_leg)
#print("num points=",len(pts))
#for pt in pts:
# print(pt[9])

View File

@@ -227,6 +227,6 @@ class PDControllerStable(object):
qddot = np.linalg.solve(A, b)
tau = p + d - Kd.dot(qddot) * timeStep
maxF = np.array(maxForces)
forces = np.clip(tau, -maxF, maxF)
tau = np.clip(tau, -maxF, maxF)
#print("c=",c)
return tau

View File

@@ -124,6 +124,15 @@ if not _OPTIONS["no-enet"] then
"../../examples/SharedMemory/PhysicsServer.h",
"../../examples/SharedMemory/PhysicsServerExample.cpp",
"../../examples/SharedMemory/PhysicsServerExampleBullet2.cpp",
"../SharedMemory/GraphicsClientExample.cpp",
"../SharedMemory/GraphicsClientExample.h",
"../SharedMemory/GraphicsServerExample.cpp",
"../SharedMemory/GraphicsServerExample.h",
"../SharedMemory/GraphicsSharedMemoryBlock.h",
"../SharedMemory/GraphicsSharedMemoryCommands.h",
"../SharedMemory/GraphicsSharedMemoryPublic.h",
"../SharedMemory/RemoteGUIHelper.cpp",
"../SharedMemory/RemoteGUIHelper.h",
"../../examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp",
"../../examples/SharedMemory/PhysicsServerSharedMemory.cpp",
"../../examples/SharedMemory/PhysicsServerSharedMemory.h",

View File

@@ -463,6 +463,14 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
sm = b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect3(0, key);
break;
}
case eCONNECT_SHARED_MEMORY_GUI:
{
sm = b3CreateInProcessPhysicsServerFromExistingExampleBrowserAndConnect4(0, key);
break;
}
case eCONNECT_DIRECT:
{
sm = b3ConnectPhysicsDirect();
@@ -10933,6 +10941,9 @@ initpybullet(void)
PyModule_AddIntConstant(m, "GUI_SERVER", eCONNECT_GUI_SERVER); // user read
PyModule_AddIntConstant(m, "GUI_MAIN_THREAD", eCONNECT_GUI_MAIN_THREAD); // user read
PyModule_AddIntConstant(m, "SHARED_MEMORY_SERVER", eCONNECT_SHARED_MEMORY_SERVER); // user read
PyModule_AddIntConstant(m, "SHARED_MEMORY_GUI", eCONNECT_SHARED_MEMORY_GUI); // user read
#ifdef BT_ENABLE_DART
PyModule_AddIntConstant(m, "DART", eCONNECT_DART); // user read
#endif

View File

@@ -117,6 +117,8 @@ sources = ["examples/pybullet/pybullet.c"]\
+["examples/SharedMemory/InProcessMemory.cpp"]\
+["examples/SharedMemory/PhysicsClient.cpp"]\
+["examples/SharedMemory/PhysicsServer.cpp"]\
+["examples/SharedMemory/GraphicsClientExample.cpp"]\
+["examples/SharedMemory/RemoteGUIHelper.cpp"]\
+["examples/SharedMemory/PhysicsServerExample.cpp"]\
+["examples/SharedMemory/PhysicsServerExampleBullet2.cpp"]\
+["examples/SharedMemory/SharedMemoryInProcessPhysicsC_API.cpp"]\