2015-05-28 23:05:24 +00:00
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
#include "PhysicsServer.h"
|
|
|
|
|
|
|
|
#include "PosixSharedMemory.h"
|
2015-06-04 22:37:18 +00:00
|
|
|
#include "Win32SharedMemory.h"
|
|
|
|
|
2015-07-04 01:17:14 +00:00
|
|
|
#include "../Importers/ImportURDFDemo/BulletUrdfImporter.h"
|
2015-05-29 00:49:55 +00:00
|
|
|
#include "../Importers/ImportURDFDemo/MyMultiBodyCreator.h"
|
|
|
|
#include "../Importers/ImportURDFDemo/URDF2Bullet.h"
|
2015-07-09 21:04:58 +00:00
|
|
|
#include "../Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h"
|
2015-05-29 00:49:55 +00:00
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
#include "SharedMemoryCommon.h"
|
2015-07-11 05:20:06 +00:00
|
|
|
const char* blaatnaam = "basename";
|
|
|
|
struct UrdfLinkNameMapUtil
|
|
|
|
{
|
|
|
|
btMultiBody* m_mb;
|
|
|
|
btDefaultSerializer* m_memSerializer;
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
UrdfLinkNameMapUtil():m_mb(0),m_memSerializer(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
class PhysicsServer : public SharedMemoryCommon
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
|
|
|
SharedMemoryInterface* m_sharedMemory;
|
|
|
|
SharedMemoryExampleData* m_testBlock1;
|
2015-06-10 01:13:05 +00:00
|
|
|
|
|
|
|
btAlignedObjectArray<btJointFeedback*> m_jointFeedbacks;
|
2015-07-09 21:04:58 +00:00
|
|
|
btAlignedObjectArray<btBulletWorldImporter*> m_worldImporters;
|
2015-07-11 05:20:06 +00:00
|
|
|
btAlignedObjectArray<UrdfLinkNameMapUtil*> m_urdfLinkNameMapper;
|
|
|
|
btAlignedObjectArray<std::string*> m_strings;
|
2015-05-29 22:04:05 +00:00
|
|
|
bool m_wantsShutdown;
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
PhysicsServer(GUIHelperInterface* helper);
|
|
|
|
|
|
|
|
virtual ~PhysicsServer();
|
|
|
|
|
|
|
|
virtual void initPhysics();
|
|
|
|
|
|
|
|
virtual void stepSimulation(float deltaTime);
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
void releaseSharedMemory();
|
|
|
|
|
2015-05-29 00:49:55 +00:00
|
|
|
bool loadUrdf(const char* fileName, const btVector3& pos, const btQuaternion& orn,
|
|
|
|
bool useMultiBody, bool useFixedBase);
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
virtual void resetCamera()
|
|
|
|
{
|
2015-06-09 23:51:55 +00:00
|
|
|
float dist = 5;
|
2015-05-28 23:05:24 +00:00
|
|
|
float pitch = 50;
|
|
|
|
float yaw = 35;
|
2015-06-09 23:51:55 +00:00
|
|
|
float targetPos[3]={0,0,0};//-3,2.8,-2.5};
|
2015-05-28 23:05:24 +00:00
|
|
|
m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]);
|
|
|
|
}
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
virtual bool wantsTermination();
|
2015-05-28 23:05:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PhysicsServer::PhysicsServer(GUIHelperInterface* helper)
|
2015-05-29 22:04:05 +00:00
|
|
|
:SharedMemoryCommon(helper),
|
|
|
|
m_testBlock1(0),
|
|
|
|
m_wantsShutdown(false)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
|
|
|
b3Printf("Started PhysicsServer\n");
|
2015-06-04 22:37:18 +00:00
|
|
|
bool useServer = true;
|
|
|
|
#ifdef _WIN32
|
|
|
|
m_sharedMemory = new Win32SharedMemoryServer();
|
|
|
|
#else
|
2015-05-28 23:05:24 +00:00
|
|
|
m_sharedMemory = new PosixSharedMemory();
|
2015-06-04 22:37:18 +00:00
|
|
|
#endif
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
void PhysicsServer::releaseSharedMemory()
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("releaseSharedMemory1\n");
|
2015-05-28 23:05:24 +00:00
|
|
|
if (m_testBlock1)
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("m_testBlock1\n");
|
2015-05-28 23:05:24 +00:00
|
|
|
m_testBlock1->m_magicId = 0;
|
|
|
|
b3Printf("magic id = %d\n",m_testBlock1->m_magicId);
|
2015-05-29 22:04:05 +00:00
|
|
|
btAssert(m_sharedMemory);
|
|
|
|
m_sharedMemory->releaseSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
|
|
|
|
}
|
|
|
|
if (m_sharedMemory)
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("m_sharedMemory\n");
|
2015-05-29 22:04:05 +00:00
|
|
|
delete m_sharedMemory;
|
|
|
|
m_sharedMemory = 0;
|
|
|
|
m_testBlock1 = 0;
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
2015-05-29 22:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsServer::~PhysicsServer()
|
|
|
|
{
|
|
|
|
releaseSharedMemory();
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsServer::initPhysics()
|
|
|
|
{
|
2015-06-09 23:51:55 +00:00
|
|
|
///for this testing we use Z-axis up
|
|
|
|
int upAxis = 2;
|
|
|
|
m_guiHelper->setUpAxis(upAxis);
|
|
|
|
|
2015-05-29 00:49:55 +00:00
|
|
|
createEmptyDynamicsWorld();
|
2015-06-10 01:13:05 +00:00
|
|
|
//todo: create a special debug drawer that will cache the lines, so we can send the debug info over the wire
|
|
|
|
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
2015-06-09 23:51:55 +00:00
|
|
|
btVector3 grav(0,0,0);
|
2015-06-10 01:13:05 +00:00
|
|
|
grav[upAxis] = -9.8;
|
2015-06-09 23:51:55 +00:00
|
|
|
this->m_dynamicsWorld->setGravity(grav);
|
2015-05-29 00:49:55 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
m_testBlock1 = (SharedMemoryExampleData*) m_sharedMemory->allocateSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
|
|
|
|
|
|
|
|
// btAssert(m_testBlock1);
|
|
|
|
if (m_testBlock1)
|
|
|
|
{
|
|
|
|
// btAssert(m_testBlock1->m_magicId != SHARED_MEMORY_MAGIC_NUMBER);
|
|
|
|
if (m_testBlock1->m_magicId == SHARED_MEMORY_MAGIC_NUMBER)
|
|
|
|
{
|
|
|
|
b3Printf("Warning: shared memory is already initialized, did you already spawn a server?\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
m_testBlock1->m_numClientCommands = 0;
|
|
|
|
m_testBlock1->m_numServerCommands = 0;
|
|
|
|
m_testBlock1->m_numProcessedClientCommands=0;
|
|
|
|
m_testBlock1->m_numProcessedServerCommands=0;
|
|
|
|
|
|
|
|
m_testBlock1->m_magicId = SHARED_MEMORY_MAGIC_NUMBER;
|
|
|
|
b3Printf("Shared memory succesfully allocated\n");
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Error("Couldn't allocated shared memory, is it implemented on your operating system?\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
|
|
|
|
bool PhysicsServer::wantsTermination()
|
|
|
|
{
|
|
|
|
return m_wantsShutdown;
|
|
|
|
}
|
|
|
|
|
2015-05-29 00:49:55 +00:00
|
|
|
bool PhysicsServer::loadUrdf(const char* fileName, const btVector3& pos, const btQuaternion& orn,
|
|
|
|
bool useMultiBody, bool useFixedBase)
|
|
|
|
{
|
|
|
|
|
2015-07-04 01:17:14 +00:00
|
|
|
BulletURDFImporter u2b(m_guiHelper);
|
2015-05-29 00:49:55 +00:00
|
|
|
bool loadOk = u2b.loadURDF(fileName);
|
|
|
|
if (loadOk)
|
|
|
|
{
|
|
|
|
b3Printf("loaded %s OK!", fileName);
|
|
|
|
|
|
|
|
btTransform tr;
|
|
|
|
tr.setIdentity();
|
|
|
|
tr.setOrigin(pos);
|
|
|
|
tr.setRotation(orn);
|
|
|
|
int rootLinkIndex = u2b.getRootLinkIndex();
|
|
|
|
// printf("urdf root link index = %d\n",rootLinkIndex);
|
|
|
|
MyMultiBodyCreator creation(m_guiHelper);
|
2015-05-29 22:04:05 +00:00
|
|
|
|
2015-05-29 00:49:55 +00:00
|
|
|
ConvertURDF2Bullet(u2b,creation, tr,m_dynamicsWorld,useMultiBody,u2b.getPathPrefix());
|
|
|
|
btMultiBody* mb = creation.getBulletMultiBody();
|
2015-06-10 01:13:05 +00:00
|
|
|
if (useMultiBody)
|
|
|
|
{
|
|
|
|
if (mb)
|
|
|
|
{
|
2015-07-11 05:20:06 +00:00
|
|
|
UrdfLinkNameMapUtil* util = new UrdfLinkNameMapUtil;
|
|
|
|
m_urdfLinkNameMapper.push_back(util);
|
|
|
|
util->m_mb = mb;
|
|
|
|
util->m_memSerializer = new btDefaultSerializer(SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE,(unsigned char*)m_testBlock1->m_bulletStreamDataServerToClient);
|
|
|
|
//disable serialization of the collision objects (they are too big, and the client likely doesn't need them);
|
|
|
|
util->m_memSerializer->m_skipPointers.insert(mb->getBaseCollider(),0);
|
|
|
|
|
|
|
|
for (int i=0;i<mb->getNumLinks();i++)
|
|
|
|
{
|
|
|
|
//disable serialization of the collision objects
|
|
|
|
util->m_memSerializer->m_skipPointers.insert(mb->getLink(i).m_collider,0);
|
|
|
|
int urdfLinkIndex = creation.m_mb2urdfLink[i];
|
|
|
|
std::string* linkName = new std::string(u2b.getLinkName(urdfLinkIndex).c_str());
|
|
|
|
m_strings.push_back(linkName);
|
|
|
|
util->m_memSerializer->registerNameForPointer(linkName->c_str(),linkName->c_str());
|
|
|
|
mb->getLink(i).m_linkName = linkName->c_str();
|
|
|
|
|
|
|
|
std::string* jointName = new std::string(u2b.getJointName(urdfLinkIndex).c_str());
|
|
|
|
m_strings.push_back(jointName);
|
|
|
|
util->m_memSerializer->registerNameForPointer(jointName->c_str(),jointName->c_str());
|
|
|
|
mb->getLink(i).m_jointName = jointName->c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string* baseName = new std::string(u2b.getLinkName(u2b.getRootLinkIndex()));
|
|
|
|
m_strings.push_back(baseName);
|
|
|
|
|
|
|
|
|
|
|
|
util->m_memSerializer->registerNameForPointer(baseName->c_str(),baseName->c_str());
|
|
|
|
mb->setBaseName(baseName->c_str());
|
|
|
|
|
|
|
|
|
|
|
|
util->m_memSerializer->insertHeader();
|
|
|
|
|
|
|
|
int len = mb->calculateSerializeBufferSize();
|
|
|
|
btChunk* chunk = util->m_memSerializer->allocate(len,1);
|
|
|
|
const char* structType = mb->serialize(chunk->m_oldPtr, util->m_memSerializer);
|
|
|
|
util->m_memSerializer->finalizeChunk(chunk,structType,BT_MULTIBODY_CODE,mb);
|
|
|
|
|
2015-06-10 01:13:05 +00:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("No multibody loaded from URDF");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
for (int i=0;i<m_dynamicsWorld->getNumConstraints();i++)
|
|
|
|
{
|
|
|
|
btTypedConstraint* c = m_dynamicsWorld->getConstraint(i);
|
|
|
|
btJointFeedback* fb = new btJointFeedback();
|
|
|
|
m_jointFeedbacks.push_back(fb);
|
|
|
|
c->setJointFeedback(fb);
|
2015-05-29 00:49:55 +00:00
|
|
|
|
2015-06-10 01:13:05 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-29 00:49:55 +00:00
|
|
|
}
|
2015-05-29 22:04:05 +00:00
|
|
|
|
|
|
|
return false;
|
2015-05-29 00:49:55 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
void PhysicsServer::stepSimulation(float deltaTime)
|
|
|
|
{
|
2015-05-29 00:49:55 +00:00
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
bool wantsShutdown = false;
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
if (m_testBlock1)
|
|
|
|
{
|
|
|
|
///we ignore overflow of integer for now
|
|
|
|
if (m_testBlock1->m_numClientCommands> m_testBlock1->m_numProcessedClientCommands)
|
|
|
|
{
|
|
|
|
|
|
|
|
//until we implement a proper ring buffer, we assume always maximum of 1 outstanding commands
|
|
|
|
btAssert(m_testBlock1->m_numClientCommands==m_testBlock1->m_numProcessedClientCommands+1);
|
|
|
|
|
2015-05-29 00:49:55 +00:00
|
|
|
const SharedMemoryCommand& clientCmd =m_testBlock1->m_clientCommands[0];
|
2015-05-29 22:04:05 +00:00
|
|
|
m_testBlock1->m_numProcessedClientCommands++;
|
2015-05-29 00:49:55 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
//consume the command
|
2015-05-29 00:49:55 +00:00
|
|
|
switch (clientCmd.m_type)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-07-09 21:04:58 +00:00
|
|
|
case CMD_SEND_BULLET_DATA_STREAM:
|
|
|
|
{
|
|
|
|
b3Printf("Processed CMD_SEND_BULLET_DATA_STREAM length %d",clientCmd.m_dataStreamArguments.m_streamChunkLength);
|
|
|
|
|
|
|
|
btBulletWorldImporter* worldImporter = new btBulletWorldImporter(m_dynamicsWorld);
|
|
|
|
this->m_worldImporters.push_back(worldImporter);
|
|
|
|
bool completedOk = worldImporter->loadFileFromMemory(m_testBlock1->m_bulletStreamDataClientToServer,clientCmd.m_dataStreamArguments.m_streamChunkLength);
|
|
|
|
|
|
|
|
m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
|
|
|
|
|
|
|
|
SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
|
|
|
|
|
|
|
|
if (completedOk)
|
|
|
|
{
|
|
|
|
serverCmd.m_type =CMD_BULLET_DATA_STREAM_RECEIVED_COMPLETED;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
serverCmd.m_type =CMD_BULLET_DATA_STREAM_RECEIVED_FAILED;
|
|
|
|
|
|
|
|
}
|
|
|
|
m_testBlock1->m_numServerCommands++;
|
|
|
|
break;
|
|
|
|
}
|
2015-05-28 23:05:24 +00:00
|
|
|
case CMD_LOAD_URDF:
|
|
|
|
{
|
2015-05-29 00:49:55 +00:00
|
|
|
b3Printf("Processed CMD_LOAD_URDF:%s",clientCmd.m_urdfArguments.m_urdfFileName);
|
2015-05-28 23:05:24 +00:00
|
|
|
|
|
|
|
//load the actual URDF and send a report: completed or failed
|
|
|
|
|
|
|
|
|
2015-06-10 01:13:05 +00:00
|
|
|
|
2015-05-29 00:49:55 +00:00
|
|
|
bool completedOk = loadUrdf(clientCmd.m_urdfArguments.m_urdfFileName,
|
2015-06-10 01:13:05 +00:00
|
|
|
btVector3(0,0,0), btQuaternion(0,0,0,1),clientCmd.m_urdfArguments.m_useMultiBody,clientCmd.m_urdfArguments.m_useFixedBase);
|
2015-05-29 00:49:55 +00:00
|
|
|
SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
|
|
|
|
|
|
|
|
if (completedOk)
|
|
|
|
{
|
2015-07-11 05:20:06 +00:00
|
|
|
if (this->m_urdfLinkNameMapper.size())
|
|
|
|
{
|
|
|
|
serverCmd.m_dataStreamArguments.m_streamChunkLength = m_urdfLinkNameMapper.at(m_urdfLinkNameMapper.size()-1)->m_memSerializer->getCurrentBufferSize();
|
|
|
|
}
|
2015-05-29 00:49:55 +00:00
|
|
|
serverCmd.m_type =CMD_URDF_LOADING_COMPLETED;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
serverCmd.m_type =CMD_URDF_LOADING_FAILED;
|
|
|
|
|
|
|
|
}
|
|
|
|
m_testBlock1->m_numServerCommands++;
|
2015-07-11 05:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-06-21 20:24:36 +00:00
|
|
|
case CMD_REQUEST_ACTUAL_STATE:
|
|
|
|
{
|
|
|
|
b3Printf("Sending the actual state (Q,U)");
|
|
|
|
if (m_dynamicsWorld->getNumMultibodies()>0)
|
|
|
|
{
|
|
|
|
btMultiBody* mb = m_dynamicsWorld->getMultiBody(0);
|
|
|
|
SharedMemoryCommand& serverCmd = m_testBlock1->m_serverCommands[0];
|
|
|
|
serverCmd.m_type = CMD_ACTUAL_STATE_UPDATE_COMPLETED;
|
|
|
|
|
|
|
|
serverCmd.m_sendActualStateArgs.m_bodyUniqueId = 0;
|
|
|
|
int totalDegreeOfFreedomQ = 0;
|
|
|
|
int totalDegreeOfFreedomU = 0;
|
|
|
|
|
|
|
|
//always add the base, even for static (non-moving objects)
|
|
|
|
//so that we can easily move the 'fixed' base when needed
|
|
|
|
//do we don't use this conditional "if (!mb->hasFixedBase())"
|
|
|
|
{
|
|
|
|
btTransform tr;
|
|
|
|
tr.setOrigin(mb->getBasePos());
|
|
|
|
tr.setRotation(mb->getWorldToBaseRot().inverse());
|
|
|
|
|
|
|
|
//base position in world space, carthesian
|
|
|
|
m_testBlock1->m_actualStateQ[0] = tr.getOrigin()[0];
|
|
|
|
m_testBlock1->m_actualStateQ[1] = tr.getOrigin()[1];
|
|
|
|
m_testBlock1->m_actualStateQ[2] = tr.getOrigin()[2];
|
|
|
|
|
|
|
|
//base orientation, quaternion x,y,z,w, in world space, carthesian
|
|
|
|
m_testBlock1->m_actualStateQ[3] = tr.getRotation()[0];
|
|
|
|
m_testBlock1->m_actualStateQ[4] = tr.getRotation()[1];
|
|
|
|
m_testBlock1->m_actualStateQ[5] = tr.getRotation()[2];
|
|
|
|
m_testBlock1->m_actualStateQ[6] = tr.getRotation()[3];
|
|
|
|
totalDegreeOfFreedomQ +=7;//pos + quaternion
|
|
|
|
|
|
|
|
//base linear velocity (in world space, carthesian)
|
|
|
|
m_testBlock1->m_actualStateQdot[0] = mb->getBaseVel()[0];
|
|
|
|
m_testBlock1->m_actualStateQdot[1] = mb->getBaseVel()[1];
|
|
|
|
m_testBlock1->m_actualStateQdot[2] = mb->getBaseVel()[2];
|
|
|
|
|
|
|
|
//base angular velocity (in world space, carthesian)
|
|
|
|
m_testBlock1->m_actualStateQdot[3] = mb->getBaseOmega()[0];
|
|
|
|
m_testBlock1->m_actualStateQdot[4] = mb->getBaseOmega()[1];
|
|
|
|
m_testBlock1->m_actualStateQdot[5] = mb->getBaseOmega()[2];
|
|
|
|
totalDegreeOfFreedomU += 6;//3 linear and 3 angular DOF
|
|
|
|
}
|
|
|
|
for (int l=0;l<mb->getNumLinks();l++)
|
|
|
|
{
|
|
|
|
for (int d=0;d<mb->getLink(l).m_posVarCount;d++)
|
|
|
|
{
|
|
|
|
m_testBlock1->m_actualStateQ[totalDegreeOfFreedomQ++] = mb->getJointPosMultiDof(l)[d];
|
|
|
|
}
|
|
|
|
for (int d=0;d<mb->getLink(l).m_dofCount;d++)
|
|
|
|
{
|
|
|
|
m_testBlock1->m_actualStateQdot[totalDegreeOfFreedomU++] = mb->getJointVelMultiDof(l)[d];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-06-10 01:13:05 +00:00
|
|
|
|
2015-06-21 20:24:36 +00:00
|
|
|
serverCmd.m_sendActualStateArgs.m_numDegreeOfFreedomQ = totalDegreeOfFreedomQ;
|
|
|
|
serverCmd.m_sendActualStateArgs.m_numDegreeOfFreedomU = totalDegreeOfFreedomU;
|
|
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("Request state but no multibody available");
|
|
|
|
//rigid bodies?
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
|
|
|
|
//now we send back the actual q, q' and force/torque and IMU sensor values
|
2015-06-10 01:13:05 +00:00
|
|
|
for (int i=0;i<m_jointFeedbacks.size();i++)
|
|
|
|
{
|
|
|
|
printf("Applied force A:(%f,%f,%f), torque A:(%f,%f,%f)\nForce B:(%f,%f,%f), torque B:(%f,%f,%f)\n",
|
|
|
|
m_jointFeedbacks[i]->m_appliedForceBodyA.x(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedForceBodyA.y(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedForceBodyA.z(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedTorqueBodyA.x(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedTorqueBodyA.y(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedTorqueBodyA.z(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedForceBodyB.x(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedForceBodyB.y(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedForceBodyB.z(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedTorqueBodyB.x(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedTorqueBodyB.y(),
|
|
|
|
m_jointFeedbacks[i]->m_appliedTorqueBodyB.z());
|
|
|
|
}
|
2015-06-21 20:24:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
m_testBlock1->m_numServerCommands++;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_STEP_FORWARD_SIMULATION:
|
|
|
|
{
|
|
|
|
|
|
|
|
b3Printf("Step simulation request");
|
|
|
|
double timeStep = clientCmd.m_stepSimulationArguments.m_deltaTimeInSeconds;
|
|
|
|
m_dynamicsWorld->stepSimulation(timeStep);
|
|
|
|
|
|
|
|
SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
|
|
|
|
|
|
|
|
serverCmd.m_type =CMD_STEP_FORWARD_SIMULATION_COMPLETED;
|
|
|
|
m_testBlock1->m_numServerCommands++;
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SHUTDOWN:
|
|
|
|
{
|
|
|
|
wantsShutdown = true;
|
|
|
|
break;
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
2015-07-09 21:04:58 +00:00
|
|
|
case CMD_CREATE_BOX_COLLISION_SHAPE:
|
|
|
|
{
|
|
|
|
btVector3 halfExtents(30,30,1);
|
|
|
|
btTransform startTrans;
|
|
|
|
startTrans.setIdentity();
|
|
|
|
startTrans.setOrigin(btVector3(0,0,-4));
|
|
|
|
btCollisionShape* shape = createBoxShape(halfExtents);
|
|
|
|
btScalar mass = 0.f;
|
|
|
|
createRigidBody(mass,startTrans,shape);
|
|
|
|
this->m_guiHelper->autogenerateGraphicsObjects(this->m_dynamicsWorld);
|
|
|
|
SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
|
|
|
|
serverCmd.m_type =CMD_STEP_FORWARD_SIMULATION_COMPLETED;
|
|
|
|
m_testBlock1->m_numServerCommands++;
|
|
|
|
break;
|
|
|
|
}
|
2015-05-28 23:05:24 +00:00
|
|
|
default:
|
|
|
|
{
|
2015-05-29 22:04:05 +00:00
|
|
|
b3Error("Unsupported command encountered");
|
|
|
|
btAssert(0);
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
|
|
|
|
//process the command right now
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2015-05-29 22:04:05 +00:00
|
|
|
if (wantsShutdown)
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("releaseSharedMemory!\n");
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
m_wantsShutdown = true;
|
|
|
|
releaseSharedMemory();
|
|
|
|
}
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOptions& options)
|
|
|
|
{
|
|
|
|
return new PhysicsServer(options.m_guiHelper);
|
|
|
|
}
|
|
|
|
|
|
|
|
|