Skip to content

Commit

Permalink
Replace large timeout (1024*1024*1024) using real-time clock timeout …
Browse files Browse the repository at this point in the history
…(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
  • Loading branch information
erwincoumans committed Feb 22, 2017
1 parent 35b92c4 commit bd30ba3
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 80 deletions.
2 changes: 1 addition & 1 deletion build_cmake_pybullet_double.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rm CMakeCache.txt
mkdir build_cmake
cd build_cmake
cmake -DBUILD_PYBULLET=ON -DBUILD_PYBULLET_NUMPY=OFF -DUSE_DOUBLE_PRECISION=ON -DCMAKE_BUILD_TYPE=Release -G Xcode ..
cmake -DBUILD_PYBULLET=ON -DBUILD_PYBULLET_NUMPY=OFF -DUSE_DOUBLE_PRECISION=ON -DCMAKE_BUILD_TYPE=Release ..
make -j12
cd examples
cd pybullet
Expand Down
10 changes: 8 additions & 2 deletions examples/SharedMemory/PhysicsClientC_API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,17 +1033,23 @@ 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);
if (physClient && commandHandle)
{
b3SubmitClientCommand(physClient, commandHandle);

while ((statusHandle == 0) && (timeout-- > 0))
while ((statusHandle == 0) && (clock.getTimeInSeconds()-startTime < timeOutInSeconds))
{
statusHandle = b3ProcessServerStatus(physClient);
}
Expand Down
8 changes: 5 additions & 3 deletions examples/SharedMemory/PhysicsClientSharedMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 10 additions & 1 deletion examples/SharedMemory/PhysicsClientTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 10 additions & 4 deletions examples/SharedMemory/PhysicsClientUDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
57 changes: 40 additions & 17 deletions examples/SharedMemory/PhysicsDirect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions examples/SharedMemory/PhysicsServerExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,12 @@ class PhysicsServerExample : public SharedMemoryCommon
gCreateDefaultRobotAssets = true;
}

if (args.CheckCmdLineFlag("realtimesimulation"))
{
//gEnableRealTimeSimVR = true;
m_physicsServer.enableRealTimeSimulation(true);
}

if (args.CheckCmdLineFlag("norobotassets"))
{
gCreateDefaultRobotAssets = false;
Expand Down
2 changes: 1 addition & 1 deletion examples/SharedMemory/SharedMemoryBlock.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions examples/SharedMemory/SharedMemoryPublic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit bd30ba3

Please sign in to comment.