Replace large timeout (1024*1024*1024) using real-time clock timeout (10 seconds default)
Change SHARED_MEMORY_MAGIC_NUMBER to make sure server/client are using the same version (shared memory) add --realtimesimulation to physics server (GUI, VR) remove --G Xcode from build_cmake_pybullet_double.sh
This commit is contained in:
@@ -1033,9 +1033,15 @@ int b3SubmitClientCommand(b3PhysicsClientHandle physClient, const b3SharedMemory
|
||||
|
||||
}
|
||||
|
||||
#include "../Utils/b3Clock.h"
|
||||
|
||||
|
||||
b3SharedMemoryStatusHandle b3SubmitClientCommandAndWaitStatus(b3PhysicsClientHandle physClient, const b3SharedMemoryCommandHandle commandHandle)
|
||||
{
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
b3SharedMemoryStatusHandle statusHandle = 0;
|
||||
b3Assert(commandHandle);
|
||||
b3Assert(physClient);
|
||||
@@ -1043,7 +1049,7 @@ b3SharedMemoryStatusHandle b3SubmitClientCommandAndWaitStatus(b3PhysicsClientHan
|
||||
{
|
||||
b3SubmitClientCommand(physClient, commandHandle);
|
||||
|
||||
while ((statusHandle == 0) && (timeout-- > 0))
|
||||
while ((statusHandle == 0) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
statusHandle = b3ProcessServerStatus(physClient);
|
||||
}
|
||||
|
||||
@@ -268,11 +268,13 @@ bool PhysicsClientSharedMemory::connect() {
|
||||
command.m_type = CMD_REQUEST_BODY_INFO;
|
||||
command.m_sdfRequestInfoArgs.m_bodyUniqueId = 37;
|
||||
submitClientCommand(command);
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
|
||||
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
const SharedMemoryStatus* status = 0;
|
||||
|
||||
while ((status == 0) && (timeout-- > 0))
|
||||
while ((status == 0) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
status = processServerStatus();
|
||||
|
||||
|
||||
@@ -64,7 +64,14 @@ struct TcpNetworkedInternalData
|
||||
m_tcpSocket.Initialize();
|
||||
|
||||
m_isConnected = m_tcpSocket.Open(m_hostName.c_str(),m_port);
|
||||
|
||||
if (m_isConnected)
|
||||
{
|
||||
m_tcpSocket.SetSendTimeout(5,0);
|
||||
m_tcpSocket.SetReceiveTimeout(5,0);
|
||||
}
|
||||
int key = SHARED_MEMORY_MAGIC_NUMBER;
|
||||
m_tcpSocket.Send((uint8*)&key,4);
|
||||
|
||||
return m_isConnected;
|
||||
}
|
||||
|
||||
@@ -243,6 +250,8 @@ bool TcpNetworkedPhysicsProcessor::connect()
|
||||
|
||||
void TcpNetworkedPhysicsProcessor::disconnect()
|
||||
{
|
||||
const char msg[16]="disconnect";
|
||||
m_data->m_tcpSocket.Send((const uint8 *)msg,10);
|
||||
m_data->m_tcpSocket.Close();
|
||||
m_data->m_isConnected = false;
|
||||
}
|
||||
|
||||
@@ -464,26 +464,32 @@ bool UdpNetworkedPhysicsProcessor::processCommand(const struct SharedMemoryComma
|
||||
printf("PhysicsClientUDP::processCommand\n");
|
||||
}
|
||||
// int sz = sizeof(SharedMemoryCommand);
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
m_data->m_cs->lock();
|
||||
m_data->m_clientCmd = clientCmd;
|
||||
m_data->m_hasCommand = true;
|
||||
m_data->m_cs->unlock();
|
||||
|
||||
while (m_data->m_hasCommand && (timeout-- > 0))
|
||||
while ((m_data->m_hasCommand) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
b3Clock::usleep(0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
timeout = 1024 * 1024 * 1024;
|
||||
|
||||
bool hasStatus = false;
|
||||
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
const SharedMemoryStatus* stat = 0;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds() - startTime < timeOutInSeconds))
|
||||
{
|
||||
hasStatus = receiveStatus(serverStatusOut, bufferServerToClient, bufferSizeInBytes);
|
||||
b3Clock::usleep(100);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
#include "SharedMemoryCommands.h"
|
||||
#include "PhysicsCommandProcessorInterface.h"
|
||||
|
||||
#include "../Utils/b3Clock.h"
|
||||
|
||||
#include "LinearMath/btHashMap.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
@@ -137,8 +137,10 @@ bool PhysicsDirect::connect()
|
||||
}
|
||||
else
|
||||
{
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double timeSec = clock.getTimeInSeconds();
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-timeSec <10 ))
|
||||
{
|
||||
const SharedMemoryStatus* stat = processServerStatus();
|
||||
if (stat)
|
||||
@@ -226,8 +228,11 @@ bool PhysicsDirect::processDebugLines(const struct SharedMemoryCommand& orgComma
|
||||
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(command,m_data->m_serverStatus,&m_data->m_bulletStreamDataServerToClient[0],SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
const SharedMemoryStatus* stat = processServerStatus();
|
||||
if (stat)
|
||||
@@ -308,8 +313,11 @@ bool PhysicsDirect::processVisualShapeData(const struct SharedMemoryCommand& org
|
||||
{
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
const SharedMemoryStatus* stat = processServerStatus();
|
||||
if (stat)
|
||||
@@ -359,8 +367,11 @@ bool PhysicsDirect::processOverlappingObjects(const struct SharedMemoryCommand&
|
||||
{
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(command, m_data->m_serverStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
const SharedMemoryStatus* stat = processServerStatus();
|
||||
if (stat)
|
||||
@@ -414,8 +425,11 @@ bool PhysicsDirect::processContactPointData(const struct SharedMemoryCommand& or
|
||||
{
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(command,m_data->m_serverStatus,&m_data->m_bulletStreamDataServerToClient[0],SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
const SharedMemoryStatus* stat = processServerStatus();
|
||||
if (stat)
|
||||
@@ -475,8 +489,11 @@ bool PhysicsDirect::processCamera(const struct SharedMemoryCommand& orgCommand)
|
||||
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(command,m_data->m_serverStatus,&m_data->m_bulletStreamDataServerToClient[0],SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
const SharedMemoryStatus* stat = processServerStatus();
|
||||
if (stat)
|
||||
@@ -735,8 +752,11 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(infoRequestCommand, infoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
hasStatus = m_data->m_commandProcessor->receiveStatus(infoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
}
|
||||
@@ -759,8 +779,11 @@ void PhysicsDirect::postProcessStatus(const struct SharedMemoryStatus& serverCmd
|
||||
bool hasStatus = m_data->m_commandProcessor->processCommand(infoRequestCommand, infoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
|
||||
|
||||
int timeout = 1024 * 1024 * 1024;
|
||||
while ((!hasStatus) && (timeout-- > 0))
|
||||
b3Clock clock;
|
||||
double startTime = clock.getTimeInSeconds();
|
||||
double timeOutInSeconds = 10;
|
||||
|
||||
while ((!hasStatus) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
|
||||
{
|
||||
hasStatus = m_data->m_commandProcessor->receiveStatus(infoStatus, &m_data->m_bulletStreamDataServerToClient[0], SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
||||
}
|
||||
|
||||
@@ -1153,6 +1153,12 @@ public:
|
||||
gCreateDefaultRobotAssets = true;
|
||||
}
|
||||
|
||||
if (args.CheckCmdLineFlag("realtimesimulation"))
|
||||
{
|
||||
//gEnableRealTimeSimVR = true;
|
||||
m_physicsServer.enableRealTimeSimulation(true);
|
||||
}
|
||||
|
||||
if (args.CheckCmdLineFlag("norobotassets"))
|
||||
{
|
||||
gCreateDefaultRobotAssets = false;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef SHARED_MEMORY_BLOCK_H
|
||||
#define SHARED_MEMORY_BLOCK_H
|
||||
|
||||
#define SHARED_MEMORY_MAGIC_NUMBER 64738
|
||||
#define SHARED_MEMORY_MAX_COMMANDS 4
|
||||
|
||||
|
||||
#include "SharedMemoryCommands.h"
|
||||
|
||||
struct SharedMemoryBlock
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#define SHARED_MEMORY_PUBLIC_H
|
||||
|
||||
#define SHARED_MEMORY_KEY 12347
|
||||
///increase the SHARED_MEMORY_MAGIC_NUMBER whenever incompatible changes are made in the structures
|
||||
///my convention is year/month/day/rev
|
||||
#define SHARED_MEMORY_MAGIC_NUMBER 201702220
|
||||
|
||||
enum EnumSharedMemoryClientCommand
|
||||
{
|
||||
|
||||
@@ -44,11 +44,8 @@ int main(int argc, char *argv[])
|
||||
sm->setGuiHelper(&guiHelper);
|
||||
|
||||
int port = 6667;
|
||||
if (parseArgs.GetCmdLineArgument("port",port))
|
||||
{
|
||||
printf("Using TCP port %d\n", port);
|
||||
}
|
||||
|
||||
parseArgs.GetCmdLineArgument("port",port);
|
||||
|
||||
gVerboseNetworkMessagesServer = parseArgs.CheckCmdLineFlag("verbose");
|
||||
|
||||
#ifndef NO_SHARED_MEMORY
|
||||
@@ -64,7 +61,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (isPhysicsClientConnected)
|
||||
{
|
||||
|
||||
|
||||
printf("Starting TCP server using port %d\n", port);
|
||||
|
||||
CPassiveSocket socket;
|
||||
CActiveSocket *pClient = NULL;
|
||||
|
||||
@@ -74,7 +73,7 @@ int main(int argc, char *argv[])
|
||||
socket.Initialize();
|
||||
|
||||
socket.Listen("localhost", port);
|
||||
socket.SetBlocking();
|
||||
//socket.SetBlocking();
|
||||
|
||||
int curNumErr = 0;
|
||||
|
||||
@@ -89,7 +88,20 @@ int main(int argc, char *argv[])
|
||||
|
||||
int clientPort = socket.GetClientPort();
|
||||
printf("connected from %s:%d\n", socket.GetClientAddr(),clientPort);
|
||||
|
||||
|
||||
if (pClient->Receive(4))
|
||||
{
|
||||
int clientKey = *(int*)pClient->GetData();
|
||||
|
||||
if (clientKey==SHARED_MEMORY_MAGIC_NUMBER)
|
||||
{
|
||||
printf("Client version OK %d\n", clientKey);
|
||||
} else
|
||||
{
|
||||
printf("Server version (%d) mismatches Client Version (%d)\n", SHARED_MEMORY_MAGIC_NUMBER,clientKey);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Receive request from the client.
|
||||
@@ -102,25 +114,27 @@ int main(int argc, char *argv[])
|
||||
int maxLen = 4 + sizeof(SharedMemoryStatus)+SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE;
|
||||
|
||||
|
||||
//heuristic to detect disconnected clients
|
||||
CSimpleSocket::CSocketError err = pClient->GetSocketError();
|
||||
if (err != CSimpleSocket::SocketSuccess)
|
||||
{
|
||||
b3Clock::usleep(100);
|
||||
|
||||
curNumErr++;
|
||||
|
||||
if (curNumErr>100)
|
||||
{
|
||||
printf("TCP Connection error = %d, curNumErr = %d\n", (int)err, curNumErr);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pClient->Receive(maxLen))
|
||||
{
|
||||
|
||||
//heuristic to detect disconnected clients
|
||||
CSimpleSocket::CSocketError err = pClient->GetSocketError();
|
||||
|
||||
if (err != CSimpleSocket::SocketSuccess || !pClient->IsSocketValid())
|
||||
{
|
||||
b3Clock::usleep(100);
|
||||
|
||||
curNumErr++;
|
||||
|
||||
if (curNumErr>100)
|
||||
{
|
||||
printf("TCP Connection error = %d, curNumErr = %d\n", (int)err, curNumErr);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
curNumErr = 0;
|
||||
char* msg2 = (char*) pClient->GetData();
|
||||
int numBytesRec2 = pClient->GetBytesReceived();
|
||||
@@ -132,9 +146,26 @@ int main(int argc, char *argv[])
|
||||
bytesReceived[curSize+i] = msg2[i];
|
||||
}
|
||||
|
||||
if (bytesReceived.size() == 4 || bytesReceived.size()==sizeof(SharedMemoryCommand))
|
||||
if (bytesReceived.size() >= 4)
|
||||
{
|
||||
int numBytesRec = bytesReceived.size();
|
||||
if (numBytesRec>=10)
|
||||
{
|
||||
if (strncmp(&bytesReceived[0],"disconnect",10)==0)
|
||||
{
|
||||
printf("Disconnect request received\n");
|
||||
bytesReceived.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
if (strncmp(&bytesReceived[0],"terminateserver",10)==0)
|
||||
{
|
||||
printf("Terminate server request received\n");
|
||||
exitRequested = true;
|
||||
bytesReceived.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (gVerboseNetworkMessagesServer)
|
||||
{
|
||||
@@ -143,15 +174,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
receivedData = true;
|
||||
|
||||
if (strncmp(&bytesReceived[0],"stop",4)==0)
|
||||
{
|
||||
printf("Stop request received\n");
|
||||
exitRequested = true;
|
||||
bytesReceived.clear();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
SharedMemoryCommand cmd;
|
||||
|
||||
SharedMemoryCommand* cmdPtr = 0;
|
||||
@@ -233,12 +255,15 @@ int main(int argc, char *argv[])
|
||||
pClient->Send( &packetData[0], packetData.size() );
|
||||
}
|
||||
}
|
||||
|
||||
bytesReceived.clear();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("received packet with unknown contents\n");
|
||||
//likely an incomplete packet, let's append more bytes
|
||||
//printf("received packet with unknown contents\n");
|
||||
}
|
||||
bytesReceived.clear();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -256,7 +281,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
socket.Close();
|
||||
socket.Shutdown(CSimpleSocket::Both);
|
||||
}
|
||||
} else
|
||||
{
|
||||
printf("Error: cannot connect to shared memory physics server.");
|
||||
}
|
||||
|
||||
delete sm;
|
||||
|
||||
|
||||
@@ -377,10 +377,11 @@ static PyObject* pybullet_connectPhysicsServer(PyObject* self, PyObject* args, P
|
||||
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
||||
statusType = b3GetStatusType(statusHandle);
|
||||
#if 0
|
||||
if (statusType != CMD_BODY_INFO_COMPLETED) {
|
||||
PyErr_SetString(SpamError, "b3InitSyncBodyInfoCommand failed.");
|
||||
return NULL;
|
||||
}
|
||||
if (statusType != CMD_BODY_INFO_COMPLETED)
|
||||
{
|
||||
PyErr_SetString(SpamError, "b3InitSyncBodyInfoCommand failed.");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user