network UDP: transmit structural DNA to deal with version/platform differences.

pybullet: allow to specify shared memory key and hostname/port for UDP.
This commit is contained in:
erwincoumans
2016-11-04 17:06:55 -07:00
parent 0ffd68ac32
commit 5d66ce20e0
5 changed files with 135 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ struct PhysicsDirectInternalData
{
DummyGUIHelper m_noGfx;
btAlignedObjectArray<char> m_serverDNA;
SharedMemoryCommand m_command;
SharedMemoryStatus m_serverStatus;
bool m_hasStatus;
@@ -83,6 +84,31 @@ bool PhysicsDirect::connect()
{
bool connected = m_data->m_commandProcessor->connect();
m_data->m_commandProcessor->setGuiHelper(&m_data->m_noGfx);
//also request serialization data
{
SharedMemoryCommand command;
command.m_type = CMD_REQUEST_INTERNAL_DATA;
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
if (hasStatus)
{
postProcessStatus(m_data->m_serverStatus);
}
else
{
int timeout = 1024 * 1024 * 1024;
while ((!hasStatus) && (timeout-- > 0))
{
const SharedMemoryStatus* stat = processServerStatus();
if (stat)
{
hasStatus = true;
}
}
}
}
return connected;
}
@@ -444,7 +470,14 @@ void PhysicsDirect::processBodyJointInfo(int bodyUniqueId, const SharedMemorySta
bParse::btBulletFile bf(
&m_data->m_bulletStreamDataServerToClient[0],
serverCmd.m_numDataStreamBytes);
bf.setFileDNAisMemoryDNA();
if (m_data->m_serverDNA.size())
{
bf.setFileDNA(false, &m_data->m_serverDNA[0], m_data->m_serverDNA.size());
}
else
{
bf.setFileDNAisMemoryDNA();
}
bf.parse(false);
BodyJointInfoCache2* bodyJoints = new BodyJointInfoCache2;
@@ -469,7 +502,8 @@ void PhysicsDirect::processBodyJointInfo(int bodyUniqueId, const SharedMemorySta
addJointInfoFromMultiBodyData(mb,bodyJoints, m_data->m_verboseOutput);
}
}
if (bf.ok()) {
if (bf.ok())
{
if (m_data->m_verboseOutput)
{
b3Printf("Received robot description ok!\n");
@@ -484,6 +518,19 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
{
switch (serverCmd.m_type)
{
case CMD_REQUEST_INTERNAL_DATA_COMPLETED:
{
if (serverCmd.m_numDataStreamBytes)
{
int numStreamBytes = serverCmd.m_numDataStreamBytes;
m_data->m_serverDNA.resize(numStreamBytes);
for (int i = 0; i < numStreamBytes; i++)
{
m_data->m_serverDNA[i] = m_data->m_bulletStreamDataServerToClient[i];
}
}
break;
}
case CMD_RESET_SIMULATION_COMPLETED:
{
m_data->m_debugLinesFrom.clear();

View File

@@ -2178,6 +2178,28 @@ bool PhysicsServerCommandProcessor::processCommand(const struct SharedMemoryComm
break;
}
case CMD_REQUEST_INTERNAL_DATA:
{
//todo: also check version etc?
SharedMemoryStatus& serverCmd = serverStatusOut;
serverCmd.m_type = CMD_REQUEST_INTERNAL_DATA_FAILED;
hasStatus = true;
int sz = btDefaultSerializer::getMemoryDnaSizeInBytes();
const char* memDna = btDefaultSerializer::getMemoryDna();
if (sz < bufferSizeInBytes)
{
for (int i = 0; i < bufferSizeInBytes; i++)
{
bufferServerToClient[i] = memDna[i];
}
serverCmd.m_type = CMD_REQUEST_INTERNAL_DATA_COMPLETED;
serverCmd.m_numDataStreamBytes = bufferSizeInBytes;
}
break;
};
case CMD_SEND_PHYSICS_SIMULATION_PARAMETERS:
{
if (clientCmd.m_updateFlags&SIM_PARAM_UPDATE_DELTA_TIME)

View File

@@ -21,6 +21,7 @@ enum EnumSharedMemoryClientCommand
CMD_REQUEST_ACTUAL_STATE,
CMD_REQUEST_DEBUG_LINES,
CMD_REQUEST_BODY_INFO,
CMD_REQUEST_INTERNAL_DATA,
CMD_STEP_FORWARD_SIMULATION,
CMD_RESET_SIMULATION,
CMD_PICK_BODY,
@@ -54,6 +55,8 @@ enum EnumSharedMemoryServerStatus
CMD_SDF_LOADING_FAILED,
CMD_URDF_LOADING_COMPLETED,
CMD_URDF_LOADING_FAILED,
CMD_REQUEST_INTERNAL_DATA_COMPLETED,
CMD_REQUEST_INTERNAL_DATA_FAILED,
CMD_BULLET_DATA_STREAM_RECEIVED_COMPLETED,
CMD_BULLET_DATA_STREAM_RECEIVED_FAILED,
CMD_BOX_COLLISION_SHAPE_CREATION_COMPLETED,