2015-05-28 23:05:24 +00:00
|
|
|
|
|
|
|
#include "PhysicsClient.h"
|
|
|
|
|
|
|
|
#include "../CommonInterfaces/CommonMultiBodyBase.h"
|
|
|
|
#include "PosixSharedMemory.h"
|
2015-06-04 22:37:18 +00:00
|
|
|
#include "Win32SharedMemory.h"
|
2015-05-29 22:04:05 +00:00
|
|
|
#include "SharedMemoryCommon.h"
|
2015-06-09 23:51:55 +00:00
|
|
|
#include "../CommonInterfaces/CommonParameterInterface.h"
|
2015-07-09 21:04:58 +00:00
|
|
|
#include "../Utils/b3ResourcePath.h"
|
2015-07-11 05:20:06 +00:00
|
|
|
#include "../Extras/Serialize/BulletFileLoader/btBulletFile.h"
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
class PhysicsClient : public SharedMemoryCommon
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
protected:
|
2015-05-28 23:05:24 +00:00
|
|
|
SharedMemoryInterface* m_sharedMemory;
|
|
|
|
SharedMemoryExampleData* m_testBlock1;
|
2015-05-29 22:04:05 +00:00
|
|
|
int m_counter;
|
|
|
|
bool m_wantsTermination;
|
2015-06-09 23:51:55 +00:00
|
|
|
btAlignedObjectArray<int> m_userCommandRequests;
|
|
|
|
|
|
|
|
bool m_serverLoadUrdfOK;
|
|
|
|
bool m_waitingForServer;
|
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
void processServerCommands();
|
|
|
|
void createClientCommand();
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-07-09 21:04:58 +00:00
|
|
|
void createButton(const char* name, int id, bool isTrigger );
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
PhysicsClient(GUIHelperInterface* helper);
|
|
|
|
virtual ~PhysicsClient();
|
|
|
|
|
|
|
|
virtual void initPhysics();
|
|
|
|
|
|
|
|
virtual void stepSimulation(float deltaTime);
|
|
|
|
|
|
|
|
virtual void resetCamera()
|
|
|
|
{
|
|
|
|
float dist = 1;
|
|
|
|
float pitch = 50;
|
|
|
|
float yaw = 35;
|
|
|
|
float targetPos[3]={-3,2.8,-2.5};
|
|
|
|
m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]);
|
|
|
|
}
|
|
|
|
|
2015-05-29 22:04:05 +00:00
|
|
|
virtual bool wantsTermination()
|
|
|
|
{
|
|
|
|
return m_wantsTermination;
|
|
|
|
}
|
2015-06-09 23:51:55 +00:00
|
|
|
void submitCommand(int command);
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
};
|
|
|
|
|
2015-06-09 23:51:55 +00:00
|
|
|
|
|
|
|
void MyCallback(int buttonId, bool buttonState, void* userPtr)
|
|
|
|
{
|
|
|
|
PhysicsClient* cl = (PhysicsClient*) userPtr;
|
|
|
|
switch (buttonId)
|
|
|
|
{
|
|
|
|
case CMD_LOAD_URDF:
|
2015-07-09 21:04:58 +00:00
|
|
|
case CMD_CREATE_BOX_COLLISION_SHAPE:
|
2015-06-21 20:24:36 +00:00
|
|
|
case CMD_REQUEST_ACTUAL_STATE:
|
2015-06-09 23:51:55 +00:00
|
|
|
case CMD_STEP_FORWARD_SIMULATION:
|
|
|
|
case CMD_SHUTDOWN:
|
2015-07-09 21:04:58 +00:00
|
|
|
case CMD_SEND_BULLET_DATA_STREAM:
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-07-09 21:04:58 +00:00
|
|
|
cl->submitCommand(buttonId);
|
2015-06-09 23:51:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
b3Error("Unknown buttonId");
|
|
|
|
btAssert(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PhysicsClient::submitCommand(int command)
|
|
|
|
{
|
|
|
|
m_userCommandRequests.push_back(command);
|
|
|
|
b3Printf("User submitted command request %d (outstanding %d)\n",command, m_userCommandRequests.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
PhysicsClient::PhysicsClient(GUIHelperInterface* helper)
|
2015-05-29 22:04:05 +00:00
|
|
|
:SharedMemoryCommon(helper),
|
|
|
|
m_testBlock1(0),
|
|
|
|
m_counter(0),
|
2015-06-09 23:51:55 +00:00
|
|
|
m_wantsTermination(false),
|
|
|
|
m_serverLoadUrdfOK(false),
|
|
|
|
m_waitingForServer(false)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("Started PhysicsClient\n");
|
2015-06-04 22:37:18 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
m_sharedMemory = new Win32SharedMemoryClient();
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsClient::~PhysicsClient()
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("~PhysicsClient\n");
|
2015-05-28 23:05:24 +00:00
|
|
|
m_sharedMemory->releaseSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
|
|
|
|
delete m_sharedMemory;
|
|
|
|
}
|
|
|
|
|
2015-07-09 21:04:58 +00:00
|
|
|
void PhysicsClient::createButton(const char* name, int buttonId, bool isTrigger )
|
|
|
|
{
|
|
|
|
ButtonParams button(name,buttonId, isTrigger);
|
|
|
|
button.m_callback = MyCallback;
|
|
|
|
button.m_userPointer = this;
|
|
|
|
m_guiHelper->getParameterInterface()->registerButtonParameter(button);
|
|
|
|
}
|
2015-05-28 23:05:24 +00:00
|
|
|
void PhysicsClient::initPhysics()
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
if (m_guiHelper && m_guiHelper->getParameterInterface())
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-07-09 21:04:58 +00:00
|
|
|
bool isTrigger = false;
|
2015-06-22 22:30:57 +00:00
|
|
|
|
2015-07-09 21:04:58 +00:00
|
|
|
createButton("Load URDF",CMD_LOAD_URDF, isTrigger);
|
|
|
|
createButton("Step Sim",CMD_STEP_FORWARD_SIMULATION, isTrigger);
|
|
|
|
createButton("Send Bullet Stream",CMD_SEND_BULLET_DATA_STREAM, isTrigger);
|
|
|
|
createButton("Get State",CMD_REQUEST_ACTUAL_STATE, isTrigger);
|
|
|
|
createButton("Send Desired State",CMD_SEND_DESIRED_STATE, isTrigger);
|
|
|
|
createButton("Create Box Collider",CMD_CREATE_BOX_COLLISION_SHAPE,isTrigger);
|
2015-06-22 22:30:57 +00:00
|
|
|
|
|
|
|
} else
|
2015-06-21 20:24:36 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
m_userCommandRequests.push_back(CMD_LOAD_URDF);
|
|
|
|
m_userCommandRequests.push_back(CMD_REQUEST_ACTUAL_STATE);
|
|
|
|
//m_userCommandRequests.push_back(CMD_SEND_DESIRED_STATE);
|
|
|
|
m_userCommandRequests.push_back(CMD_REQUEST_ACTUAL_STATE);
|
|
|
|
//m_userCommandRequests.push_back(CMD_SET_JOINT_FEEDBACK);
|
2015-07-09 21:04:58 +00:00
|
|
|
m_userCommandRequests.push_back(CMD_CREATE_BOX_COLLISION_SHAPE);
|
2015-06-22 22:30:57 +00:00
|
|
|
//m_userCommandRequests.push_back(CMD_CREATE_RIGID_BODY);
|
|
|
|
m_userCommandRequests.push_back(CMD_STEP_FORWARD_SIMULATION);
|
|
|
|
m_userCommandRequests.push_back(CMD_REQUEST_ACTUAL_STATE);
|
|
|
|
m_userCommandRequests.push_back(CMD_SHUTDOWN);
|
|
|
|
|
|
|
|
}
|
2015-06-09 23:51:55 +00:00
|
|
|
|
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
m_testBlock1 = (SharedMemoryExampleData*)m_sharedMemory->allocateSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
|
|
|
|
if (m_testBlock1)
|
|
|
|
{
|
2015-05-29 00:49:55 +00:00
|
|
|
// btAssert(m_testBlock1->m_magicId == SHARED_MEMORY_MAGIC_NUMBER);
|
|
|
|
if (m_testBlock1->m_magicId !=SHARED_MEMORY_MAGIC_NUMBER)
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Error("Error: please start server before client\n");
|
2015-05-29 00:49:55 +00:00
|
|
|
m_sharedMemory->releaseSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
|
|
|
|
m_testBlock1 = 0;
|
2015-05-29 22:04:05 +00:00
|
|
|
} else
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("Shared Memory status is OK\n");
|
2015-06-09 23:51:55 +00:00
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_wantsTermination = true;
|
|
|
|
}
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
void PhysicsClient::processServerCommands()
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
btAssert(m_testBlock1);
|
|
|
|
|
|
|
|
if (m_testBlock1->m_numServerCommands> m_testBlock1->m_numProcessedServerCommands)
|
|
|
|
{
|
|
|
|
btAssert(m_testBlock1->m_numServerCommands==m_testBlock1->m_numProcessedServerCommands+1);
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
const SharedMemoryCommand& serverCmd =m_testBlock1->m_serverCommands[0];
|
2015-05-29 22:04:05 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
//consume the command
|
|
|
|
switch (serverCmd.m_type)
|
|
|
|
{
|
2015-05-29 22:04:05 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
case CMD_URDF_LOADING_COMPLETED:
|
|
|
|
{
|
|
|
|
m_serverLoadUrdfOK = true;
|
|
|
|
b3Printf("Server loading the URDF OK\n");
|
2015-07-11 05:20:06 +00:00
|
|
|
|
|
|
|
if (serverCmd.m_dataStreamArguments.m_streamChunkLength>0)
|
|
|
|
{
|
|
|
|
bParse::btBulletFile* bf = new bParse::btBulletFile(this->m_testBlock1->m_bulletStreamDataServerToClient,serverCmd.m_dataStreamArguments.m_streamChunkLength);
|
|
|
|
bf->setFileDNAisMemoryDNA();
|
|
|
|
bf->parse(false);
|
|
|
|
for (int i=0;i<bf->m_multiBodies.size();i++)
|
|
|
|
{
|
|
|
|
int flag = bf->getFlags();
|
|
|
|
|
|
|
|
if ((flag&bParse::FD_DOUBLE_PRECISION)!=0)
|
|
|
|
{
|
|
|
|
btMultiBodyDoubleData* mb = (btMultiBodyDoubleData*)bf->m_multiBodies[i];
|
|
|
|
if (mb->m_baseName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_baseName = %s\n",mb->m_baseName);
|
|
|
|
}
|
|
|
|
for (int link=0;link<mb->m_numLinks;link++)
|
|
|
|
{
|
|
|
|
if (mb->m_links[link].m_linkName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_linkName = %s\n",link,mb->m_links[link].m_linkName);
|
|
|
|
}
|
|
|
|
if (mb->m_links[link].m_jointName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_jointName = %s\n",link,mb->m_links[link].m_jointName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
btMultiBodyFloatData* mb = (btMultiBodyFloatData*) bf->m_multiBodies[i];
|
|
|
|
if (mb->m_baseName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_baseName = %s\n",mb->m_baseName);
|
|
|
|
}
|
|
|
|
for (int link=0;link<mb->m_numLinks;link++)
|
|
|
|
{
|
|
|
|
if (mb->m_links[link].m_linkName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_linkName = %s\n",link,mb->m_links[link].m_linkName);
|
|
|
|
}
|
|
|
|
b3Printf("link [%d] type = %d",link, mb->m_links[link].m_jointType);
|
|
|
|
if (mb->m_links[link].m_jointName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_jointName = %s\n",link,mb->m_links[link].m_jointName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("ok!\n");
|
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_STEP_FORWARD_SIMULATION_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_URDF_LOADING_FAILED:
|
|
|
|
{
|
|
|
|
b3Printf("Server failed loading the URDF...\n");
|
|
|
|
m_serverLoadUrdfOK = false;
|
|
|
|
break;
|
|
|
|
}
|
2015-07-09 21:04:58 +00:00
|
|
|
|
|
|
|
case CMD_BULLET_DATA_STREAM_RECEIVED_COMPLETED:
|
|
|
|
{
|
2015-07-11 05:20:06 +00:00
|
|
|
b3Printf("Server received bullet data stream OK\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-09 21:04:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_BULLET_DATA_STREAM_RECEIVED_FAILED:
|
|
|
|
{
|
2015-07-11 05:20:06 +00:00
|
|
|
b3Printf("Server failed receiving bullet data stream\n");
|
|
|
|
|
2015-07-09 21:04:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
case CMD_ACTUAL_STATE_UPDATE_COMPLETED:
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("Received actual state\n");
|
2015-06-21 20:24:36 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
int numQ = m_testBlock1->m_serverCommands[0].m_sendActualStateArgs.m_numDegreeOfFreedomQ;
|
|
|
|
int numU = m_testBlock1->m_serverCommands[0].m_sendActualStateArgs.m_numDegreeOfFreedomU;
|
|
|
|
b3Printf("size Q = %d, size U = %d\n", numQ,numU);
|
|
|
|
char msg[1024];
|
2015-06-21 20:24:36 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
sprintf(msg,"Q=[");
|
2015-06-21 20:24:36 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
for (int i=0;i<numQ;i++)
|
|
|
|
{
|
|
|
|
if (i<numQ-1)
|
|
|
|
{
|
|
|
|
sprintf(msg,"%s%f,",msg,m_testBlock1->m_actualStateQ[i]);
|
|
|
|
} else
|
2015-06-21 20:24:36 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
sprintf(msg,"%s%f",msg,m_testBlock1->m_actualStateQ[i]);
|
2015-06-21 20:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
sprintf(msg,"%s]",msg);
|
|
|
|
|
|
|
|
b3Printf(msg);
|
|
|
|
b3Printf("\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
b3Error("Unknown server command\n");
|
|
|
|
btAssert(0);
|
|
|
|
}
|
|
|
|
};
|
2015-06-09 23:51:55 +00:00
|
|
|
|
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
m_testBlock1->m_numProcessedServerCommands++;
|
|
|
|
//we don't have more than 1 command outstanding (in total, either server or client)
|
|
|
|
btAssert(m_testBlock1->m_numProcessedServerCommands == m_testBlock1->m_numServerCommands);
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
if (m_testBlock1->m_numServerCommands == m_testBlock1->m_numProcessedServerCommands)
|
|
|
|
{
|
|
|
|
m_waitingForServer = false;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_waitingForServer = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsClient::createClientCommand()
|
|
|
|
{
|
|
|
|
if (!m_waitingForServer)
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
|
|
|
//process outstanding requests
|
|
|
|
if (m_userCommandRequests.size())
|
|
|
|
{
|
|
|
|
b3Printf("Outstanding user command requests: %d\n", m_userCommandRequests.size());
|
|
|
|
int command = m_userCommandRequests[0];
|
2015-06-22 22:30:57 +00:00
|
|
|
|
|
|
|
//don't use 'remove' because it will re-order the commands
|
|
|
|
//m_userCommandRequests.remove(command);
|
|
|
|
//pop_front
|
|
|
|
for (int i=1;i<m_userCommandRequests.size();i++)
|
|
|
|
{
|
|
|
|
m_userCommandRequests[i-1] = m_userCommandRequests[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
m_userCommandRequests.pop_back();
|
|
|
|
m_waitingForServer = true;
|
|
|
|
|
2015-06-09 23:51:55 +00:00
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case CMD_LOAD_URDF:
|
|
|
|
{
|
|
|
|
if (!m_serverLoadUrdfOK)
|
|
|
|
{
|
|
|
|
m_testBlock1->m_clientCommands[0].m_type =CMD_LOAD_URDF;
|
|
|
|
sprintf(m_testBlock1->m_clientCommands[0].m_urdfArguments.m_urdfFileName,"r2d2.urdf");
|
2015-07-12 21:48:43 +00:00
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_initialPosition[0] = 0.0;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_initialPosition[1] = 0.0;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_initialPosition[2] = 0.0;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_initialOrientation[0] = 0.0;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_initialOrientation[1] = 0.0;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_initialOrientation[2] = 0.0;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_initialOrientation[3] = 1.0;
|
2015-06-10 01:13:05 +00:00
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_useFixedBase = false;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_urdfArguments.m_useMultiBody = true;
|
|
|
|
|
2015-06-09 23:51:55 +00:00
|
|
|
m_testBlock1->m_numClientCommands++;
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("Client created CMD_LOAD_URDF\n");
|
2015-06-09 23:51:55 +00:00
|
|
|
} else
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Warning("Server already loaded URDF, no client command submitted\n");
|
2015-06-09 23:51:55 +00:00
|
|
|
}
|
2015-07-09 21:04:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_CREATE_BOX_COLLISION_SHAPE:
|
|
|
|
{
|
|
|
|
if (m_serverLoadUrdfOK)
|
|
|
|
{
|
|
|
|
b3Printf("Requesting create box collision shape\n");
|
|
|
|
m_testBlock1->m_clientCommands[0].m_type =CMD_CREATE_BOX_COLLISION_SHAPE;
|
|
|
|
m_testBlock1->m_numClientCommands++;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("No URDF loaded\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SEND_BULLET_DATA_STREAM:
|
|
|
|
{
|
|
|
|
b3Printf("Sending a Bullet Data Stream\n");
|
|
|
|
///The idea is to pass a stream of chunks from client to server
|
|
|
|
///over shared memory. The server will process it
|
|
|
|
///Initially we will just copy an entire .bullet file into shared
|
|
|
|
///memory but we can also send individual chunks one at a time
|
|
|
|
///so it becomes a streaming solution
|
|
|
|
///In addition, we can make a separate API to create those chunks
|
|
|
|
///if needed, instead of using a 3d modeler or the Bullet SDK btSerializer
|
|
|
|
|
|
|
|
char relativeFileName[1024];
|
|
|
|
const char* fileName = "slope.bullet";
|
|
|
|
bool fileFound = b3ResourcePath::findResourcePath(fileName,relativeFileName,1024);
|
|
|
|
if (fileFound)
|
|
|
|
{
|
|
|
|
FILE *fp = fopen(relativeFileName, "rb");
|
|
|
|
if (fp)
|
|
|
|
{
|
|
|
|
fseek(fp, 0L, SEEK_END);
|
|
|
|
int mFileLen = ftell(fp);
|
|
|
|
fseek(fp, 0L, SEEK_SET);
|
|
|
|
if (mFileLen<SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE)
|
|
|
|
{
|
|
|
|
|
|
|
|
fread(m_testBlock1->m_bulletStreamDataClientToServer, mFileLen, 1, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
m_testBlock1->m_clientCommands[0].m_type =CMD_SEND_BULLET_DATA_STREAM;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_dataStreamArguments.m_streamChunkLength = mFileLen;
|
|
|
|
m_testBlock1->m_numClientCommands++;
|
|
|
|
b3Printf("Send bullet data stream command\n");
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("Bullet file size (%d) exceeds of streaming memory chunk size (%d)\n", mFileLen,SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("Cannot open file %s\n", relativeFileName);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("Cannot find file %s\n", fileName);
|
|
|
|
}
|
|
|
|
|
2015-06-09 23:51:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-06-21 20:24:36 +00:00
|
|
|
case CMD_REQUEST_ACTUAL_STATE:
|
|
|
|
{
|
|
|
|
if (m_serverLoadUrdfOK)
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("Requesting actual state\n");
|
2015-06-21 20:24:36 +00:00
|
|
|
m_testBlock1->m_clientCommands[0].m_type =CMD_REQUEST_ACTUAL_STATE;
|
|
|
|
m_testBlock1->m_numClientCommands++;
|
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Warning("No URDF loaded\n");
|
2015-06-21 20:24:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-06-09 23:51:55 +00:00
|
|
|
case CMD_STEP_FORWARD_SIMULATION:
|
|
|
|
{
|
|
|
|
if (m_serverLoadUrdfOK)
|
|
|
|
{
|
|
|
|
|
2015-06-21 20:24:36 +00:00
|
|
|
m_testBlock1->m_clientCommands[0].m_type =CMD_STEP_FORWARD_SIMULATION;
|
2015-06-09 23:51:55 +00:00
|
|
|
m_testBlock1->m_clientCommands[0].m_stepSimulationArguments.m_deltaTimeInSeconds = 1./60.;
|
|
|
|
m_testBlock1->m_numClientCommands++;
|
|
|
|
b3Printf("client created CMD_STEP_FORWARD_SIMULATION %d\n", m_counter++);
|
|
|
|
} else
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Warning("No URDF loaded yet, no client CMD_STEP_FORWARD_SIMULATION submitted\n");
|
2015-06-09 23:51:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SHUTDOWN:
|
|
|
|
{
|
|
|
|
m_wantsTermination = true;
|
|
|
|
m_testBlock1->m_clientCommands[0].m_type =CMD_SHUTDOWN;
|
|
|
|
m_testBlock1->m_numClientCommands++;
|
|
|
|
m_serverLoadUrdfOK = false;
|
|
|
|
b3Printf("client created CMD_SHUTDOWN\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Error("unknown command requested\n");
|
2015-06-09 23:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
}
|
|
|
|
void PhysicsClient::stepSimulation(float deltaTime)
|
|
|
|
{
|
|
|
|
|
2015-06-28 21:09:21 +00:00
|
|
|
// btAssert(m_testBlock1);
|
2015-06-22 22:30:57 +00:00
|
|
|
|
|
|
|
if (m_testBlock1)
|
|
|
|
{
|
|
|
|
processServerCommands();
|
|
|
|
|
|
|
|
if (!m_waitingForServer)
|
|
|
|
{
|
|
|
|
createClientCommand();
|
|
|
|
}
|
|
|
|
}
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CommonExampleInterface* PhysicsClientCreateFunc(struct CommonExampleOptions& options)
|
|
|
|
{
|
|
|
|
return new PhysicsClient(options.m_guiHelper);
|
|
|
|
}
|