2015-05-28 23:05:24 +00:00
|
|
|
#include "PhysicsClient.h"
|
|
|
|
#include "PosixSharedMemory.h"
|
2015-06-04 22:37:18 +00:00
|
|
|
#include "Win32SharedMemory.h"
|
2015-07-14 22:30:17 +00:00
|
|
|
#include "LinearMath/btAlignedObjectArray.h"
|
2015-08-20 05:51:16 +00:00
|
|
|
#include "LinearMath/btVector3.h"
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
#include "Bullet3Common/b3Logging.h"
|
2015-07-09 21:04:58 +00:00
|
|
|
#include "../Utils/b3ResourcePath.h"
|
2015-07-14 22:30:17 +00:00
|
|
|
#include "../../Extras/Serialize/BulletFileLoader/btBulletFile.h"
|
|
|
|
#include "../../Extras/Serialize/BulletFileLoader/autogenerated/bullet.h"
|
2015-07-23 18:51:25 +00:00
|
|
|
#include "SharedMemoryBlock.h"
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-07-21 06:35:29 +00:00
|
|
|
//copied from btMultiBodyLink.h
|
|
|
|
enum JointType
|
|
|
|
{
|
|
|
|
eRevoluteType = 0,
|
|
|
|
ePrismaticType = 1,
|
|
|
|
};
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
struct PhysicsClientSharedMemoryInternalData
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
|
|
|
SharedMemoryInterface* m_sharedMemory;
|
2015-07-23 18:51:25 +00:00
|
|
|
SharedMemoryBlock* m_testBlock1;
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-07-21 06:35:29 +00:00
|
|
|
btAlignedObjectArray<bParse::btBulletFile*> m_robotMultiBodyData;
|
2015-08-02 21:00:43 +00:00
|
|
|
btAlignedObjectArray<b3JointInfo> m_jointInfo;
|
2015-08-20 05:51:16 +00:00
|
|
|
btAlignedObjectArray<btVector3> m_debugLinesFrom;
|
|
|
|
btAlignedObjectArray<btVector3> m_debugLinesTo;
|
|
|
|
btAlignedObjectArray<btVector3> m_debugLinesColor;
|
2015-07-21 06:35:29 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
int m_counter;
|
2015-06-09 23:51:55 +00:00
|
|
|
bool m_serverLoadUrdfOK;
|
2015-07-14 22:30:17 +00:00
|
|
|
bool m_isConnected;
|
2015-06-09 23:51:55 +00:00
|
|
|
bool m_waitingForServer;
|
2015-07-21 06:35:29 +00:00
|
|
|
bool m_hasLastServerStatus;
|
2015-08-20 05:51:16 +00:00
|
|
|
int m_sharedMemoryKey;
|
|
|
|
bool m_verboseOutput;
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
PhysicsClientSharedMemoryInternalData()
|
|
|
|
:m_sharedMemory(0),
|
|
|
|
m_testBlock1(0),
|
|
|
|
m_counter(0),
|
|
|
|
m_serverLoadUrdfOK(false),
|
|
|
|
m_isConnected(false),
|
2015-07-21 06:35:29 +00:00
|
|
|
m_waitingForServer(false),
|
2015-08-07 07:13:26 +00:00
|
|
|
m_hasLastServerStatus(false),
|
2015-08-20 05:51:16 +00:00
|
|
|
m_sharedMemoryKey(SHARED_MEMORY_KEY),
|
|
|
|
m_verboseOutput(false)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
void processServerStatus();
|
|
|
|
|
|
|
|
bool canSubmitCommand() const;
|
|
|
|
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
};
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-07-21 06:35:29 +00:00
|
|
|
|
2015-08-02 21:00:43 +00:00
|
|
|
int PhysicsClientSharedMemory::getNumJoints() const
|
2015-07-21 06:35:29 +00:00
|
|
|
{
|
2015-08-02 21:00:43 +00:00
|
|
|
return m_data->m_jointInfo.size();
|
2015-07-21 06:35:29 +00:00
|
|
|
}
|
|
|
|
|
2015-08-02 21:00:43 +00:00
|
|
|
void PhysicsClientSharedMemory::getJointInfo(int index, b3JointInfo& info) const
|
2015-07-21 06:35:29 +00:00
|
|
|
{
|
2015-08-02 21:00:43 +00:00
|
|
|
info = m_data->m_jointInfo[index];
|
2015-07-21 06:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
PhysicsClientSharedMemory::PhysicsClientSharedMemory()
|
2015-06-09 23:51:55 +00:00
|
|
|
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data = new PhysicsClientSharedMemoryInternalData;
|
2015-08-07 07:13:26 +00:00
|
|
|
|
2015-06-04 22:37:18 +00:00
|
|
|
#ifdef _WIN32
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_sharedMemory = new Win32SharedMemoryClient();
|
2015-06-04 22:37:18 +00:00
|
|
|
#else
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_sharedMemory = new PosixSharedMemory();
|
2015-06-04 22:37:18 +00:00
|
|
|
#endif
|
2015-07-14 22:30:17 +00:00
|
|
|
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
PhysicsClientSharedMemory::~PhysicsClientSharedMemory()
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-08-06 18:59:31 +00:00
|
|
|
if (m_data->m_isConnected)
|
|
|
|
{
|
|
|
|
disconnectSharedMemory();
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
delete m_data->m_sharedMemory;
|
|
|
|
delete m_data;
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 07:13:26 +00:00
|
|
|
void PhysicsClientSharedMemory::setSharedMemoryKey(int key)
|
|
|
|
{
|
|
|
|
m_data->m_sharedMemoryKey = key;
|
|
|
|
}
|
|
|
|
|
2015-08-06 18:59:31 +00:00
|
|
|
void PhysicsClientSharedMemory::disconnectSharedMemory ()
|
|
|
|
{
|
|
|
|
if (m_data->m_isConnected)
|
|
|
|
{
|
2015-08-07 07:13:26 +00:00
|
|
|
m_data->m_sharedMemory->releaseSharedMemory(m_data->m_sharedMemoryKey, SHARED_MEMORY_SIZE);
|
2015-08-06 18:59:31 +00:00
|
|
|
m_data->m_isConnected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
bool PhysicsClientSharedMemory::isConnected() const
|
2015-07-09 21:04:58 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
return m_data->m_isConnected ;
|
2015-07-09 21:04:58 +00:00
|
|
|
}
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-08-06 18:59:31 +00:00
|
|
|
bool PhysicsClientSharedMemory::connect()
|
2015-07-14 22:30:17 +00:00
|
|
|
{
|
2015-08-06 18:59:31 +00:00
|
|
|
///server always has to create and initialize shared memory
|
|
|
|
bool allowCreation = false;
|
2015-08-07 07:13:26 +00:00
|
|
|
m_data->m_testBlock1 = (SharedMemoryBlock*)m_data->m_sharedMemory->allocateSharedMemory(m_data->m_sharedMemoryKey, SHARED_MEMORY_SIZE, allowCreation);
|
2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
if (m_data->m_testBlock1)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
if (m_data->m_testBlock1->m_magicId !=SHARED_MEMORY_MAGIC_NUMBER)
|
2015-05-29 00:49:55 +00:00
|
|
|
{
|
2015-08-06 18:59:31 +00:00
|
|
|
b3Error("Error: please start server before client\n");
|
2015-08-07 07:13:26 +00:00
|
|
|
m_data->m_sharedMemory->releaseSharedMemory(m_data->m_sharedMemoryKey, SHARED_MEMORY_SIZE);
|
2015-08-06 18:59:31 +00:00
|
|
|
m_data->m_testBlock1 = 0;
|
|
|
|
return false;
|
|
|
|
} else
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Connected to existing shared memory, status OK.\n");
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_isConnected = true;
|
2015-06-09 23:51:55 +00:00
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
} else
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
b3Error("Cannot connect to shared memory");
|
|
|
|
return false;
|
2015-06-22 22:30:57 +00:00
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
return true;
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-23 18:51:25 +00:00
|
|
|
bool PhysicsClientSharedMemory::processServerStatus(SharedMemoryStatus& serverStatus)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
bool hasStatus = false;
|
|
|
|
|
2015-07-31 06:22:44 +00:00
|
|
|
if (!m_data->m_testBlock1)
|
|
|
|
{
|
|
|
|
serverStatus.m_type = CMD_SHARED_MEMORY_NOT_INITIALIZED;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_data->m_waitingForServer)
|
|
|
|
{
|
|
|
|
serverStatus.m_type = CMD_WAITING_FOR_CLIENT_COMMAND;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
if (m_data->m_testBlock1->m_numServerCommands> m_data->m_testBlock1->m_numProcessedServerCommands)
|
2015-06-22 22:30:57 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
btAssert(m_data->m_testBlock1->m_numServerCommands==m_data->m_testBlock1->m_numProcessedServerCommands+1);
|
2015-05-28 23:05:24 +00:00
|
|
|
|
2015-07-22 04:46:28 +00:00
|
|
|
const SharedMemoryStatus& serverCmd =m_data->m_testBlock1->m_serverCommands[0];
|
2015-07-21 06:35:29 +00:00
|
|
|
hasStatus = true;
|
|
|
|
serverStatus = serverCmd;
|
2015-08-02 21:00:43 +00:00
|
|
|
EnumSharedMemoryServerStatus s = (EnumSharedMemoryServerStatus)serverCmd.m_type;
|
2015-06-22 22:30:57 +00:00
|
|
|
//consume the command
|
|
|
|
switch (serverCmd.m_type)
|
|
|
|
{
|
2015-07-31 06:22:44 +00:00
|
|
|
case CMD_CLIENT_COMMAND_COMPLETED:
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Server completed command");
|
|
|
|
}
|
2015-07-31 06:22:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
case CMD_URDF_LOADING_COMPLETED:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_serverLoadUrdfOK = true;
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Server loading the URDF OK\n");
|
|
|
|
}
|
2015-07-11 05:20:06 +00:00
|
|
|
|
|
|
|
if (serverCmd.m_dataStreamArguments.m_streamChunkLength>0)
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
bParse::btBulletFile* bf = new bParse::btBulletFile(this->m_data->m_testBlock1->m_bulletStreamDataServerToClient,serverCmd.m_dataStreamArguments.m_streamChunkLength);
|
2015-07-11 05:20:06 +00:00
|
|
|
bf->setFileDNAisMemoryDNA();
|
|
|
|
bf->parse(false);
|
2015-07-21 06:35:29 +00:00
|
|
|
m_data->m_robotMultiBodyData.push_back(bf);
|
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
for (int i=0;i<bf->m_multiBodies.size();i++)
|
|
|
|
{
|
|
|
|
int flag = bf->getFlags();
|
2015-07-21 06:35:29 +00:00
|
|
|
int qOffset = 7;
|
|
|
|
int uOffset=6;
|
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
if ((flag&bParse::FD_DOUBLE_PRECISION)!=0)
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
Bullet::btMultiBodyDoubleData* mb = (Bullet::btMultiBodyDoubleData*)bf->m_multiBodies[i];
|
2015-07-11 05:20:06 +00:00
|
|
|
if (mb->m_baseName)
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_baseName = %s\n",mb->m_baseName);
|
|
|
|
}
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
for (int link=0;link<mb->m_numLinks;link++)
|
|
|
|
{
|
|
|
|
{
|
2015-08-02 21:00:43 +00:00
|
|
|
b3JointInfo info;
|
2015-08-26 22:26:53 +00:00
|
|
|
info.m_flags = 0;
|
|
|
|
info.m_qIndex = (0 < mb->m_links[link].m_posVarCount) ? qOffset : -1;
|
|
|
|
info.m_uIndex = (0 < mb->m_links[link].m_dofCount) ? uOffset : -1;
|
|
|
|
|
2015-07-21 06:35:29 +00:00
|
|
|
if (mb->m_links[link].m_linkName)
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_linkName = %s\n",link,mb->m_links[link].m_linkName);
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
info.m_linkName = mb->m_links[link].m_linkName;
|
|
|
|
}
|
|
|
|
if (mb->m_links[link].m_jointName)
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_jointName = %s\n",link,mb->m_links[link].m_jointName);
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
info.m_jointName = mb->m_links[link].m_jointName;
|
|
|
|
info.m_jointType = mb->m_links[link].m_jointType;
|
|
|
|
}
|
2015-08-02 21:00:43 +00:00
|
|
|
if ((mb->m_links[link].m_jointType == eRevoluteType)||
|
|
|
|
(mb->m_links[link].m_jointType == ePrismaticType))
|
|
|
|
{
|
|
|
|
info.m_flags |= JOINT_HAS_MOTORIZED_POWER;
|
|
|
|
}
|
|
|
|
m_data->m_jointInfo.push_back(info);
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
qOffset+= mb->m_links[link].m_posVarCount;
|
|
|
|
uOffset+= mb->m_links[link].m_dofCount;
|
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
} else
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
Bullet::btMultiBodyFloatData* mb = (Bullet::btMultiBodyFloatData*) bf->m_multiBodies[i];
|
2015-07-11 05:20:06 +00:00
|
|
|
if (mb->m_baseName)
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_baseName = %s\n",mb->m_baseName);
|
|
|
|
}
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
|
|
|
for (int link=0;link<mb->m_numLinks;link++)
|
|
|
|
{
|
|
|
|
{
|
2015-08-02 21:00:43 +00:00
|
|
|
b3JointInfo info;
|
|
|
|
info.m_flags = 0;
|
2015-08-26 22:26:53 +00:00
|
|
|
info.m_qIndex = (0 < mb->m_links[link].m_posVarCount) ? qOffset : -1;
|
|
|
|
info.m_uIndex = (0 < mb->m_links[link].m_dofCount) ? uOffset : -1;
|
2015-07-21 06:35:29 +00:00
|
|
|
|
|
|
|
if (mb->m_links[link].m_linkName)
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_linkName = %s\n",link,mb->m_links[link].m_linkName);
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
info.m_linkName = mb->m_links[link].m_linkName;
|
|
|
|
}
|
|
|
|
if (mb->m_links[link].m_jointName)
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_jointName = %s\n",link,mb->m_links[link].m_jointName);
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
info.m_jointName = mb->m_links[link].m_jointName;
|
|
|
|
info.m_jointType = mb->m_links[link].m_jointType;
|
|
|
|
}
|
2015-08-02 21:00:43 +00:00
|
|
|
if ((mb->m_links[link].m_jointType == eRevoluteType)||
|
|
|
|
(mb->m_links[link].m_jointType == ePrismaticType))
|
|
|
|
{
|
|
|
|
info.m_flags |= JOINT_HAS_MOTORIZED_POWER;
|
|
|
|
}
|
|
|
|
m_data->m_jointInfo.push_back(info);
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
qOffset+= mb->m_links[link].m_posVarCount;
|
|
|
|
uOffset+= mb->m_links[link].m_dofCount;
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
if (bf->ok())
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Received robot description ok!\n");
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("Robot description not received");
|
|
|
|
}
|
2015-07-11 05:20:06 +00:00
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-14 15:34:02 +00:00
|
|
|
case CMD_DESIRED_STATE_RECEIVED_COMPLETED:
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Server received desired state");
|
|
|
|
}
|
2015-07-14 15:34:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
case CMD_STEP_FORWARD_SIMULATION_COMPLETED:
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Server completed step simulation");
|
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_URDF_LOADING_FAILED:
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Server failed loading the URDF...\n");
|
|
|
|
}
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_serverLoadUrdfOK = false;
|
2015-06-22 22:30:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-09 21:04:58 +00:00
|
|
|
|
|
|
|
case CMD_BULLET_DATA_STREAM_RECEIVED_COMPLETED:
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Server received bullet data stream OK\n");
|
|
|
|
}
|
2015-07-11 05:20:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-07-09 21:04:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_BULLET_DATA_STREAM_RECEIVED_FAILED:
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Server failed receiving bullet data stream\n");
|
|
|
|
}
|
2015-07-11 05:20:06 +00:00
|
|
|
|
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-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Received actual state\n");
|
|
|
|
}
|
2015-07-22 04:46:28 +00:00
|
|
|
SharedMemoryStatus& command = m_data->m_testBlock1->m_serverCommands[0];
|
2015-07-15 22:23:40 +00:00
|
|
|
|
|
|
|
int numQ = command.m_sendActualStateArgs.m_numDegreeOfFreedomQ;
|
|
|
|
int numU = command.m_sendActualStateArgs.m_numDegreeOfFreedomU;
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("size Q = %d, size U = %d\n", numQ,numU);
|
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
char msg[1024];
|
2015-06-21 20:24:36 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
sprintf(msg,"Q=[");
|
|
|
|
|
|
|
|
for (int i=0;i<numQ;i++)
|
2015-06-22 22:30:57 +00:00
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
if (i<numQ-1)
|
|
|
|
{
|
|
|
|
sprintf(msg,"%s%f,",msg,command.m_sendActualStateArgs.m_actualStateQ[i]);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
sprintf(msg,"%s%f",msg,command.m_sendActualStateArgs.m_actualStateQ[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sprintf(msg,"%s]",msg);
|
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf(msg);
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
sprintf(msg,"U=[");
|
|
|
|
|
|
|
|
for (int i=0;i<numU;i++)
|
2015-06-21 20:24:36 +00:00
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
if (i<numU-1)
|
|
|
|
{
|
|
|
|
sprintf(msg,"%s%f,",msg,command.m_sendActualStateArgs.m_actualStateQdot[i]);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
sprintf(msg,"%s%f",msg,command.m_sendActualStateArgs.m_actualStateQdot[i]);
|
|
|
|
}
|
2015-06-21 20:24:36 +00:00
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
sprintf(msg,"%s]",msg);
|
2015-06-22 22:30:57 +00:00
|
|
|
|
2015-07-21 06:35:29 +00:00
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf(msg);
|
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
|
|
|
|
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_DEBUG_LINES_COMPLETED:
|
|
|
|
{
|
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("Success receiving %d debug lines",serverCmd.m_sendDebugLinesArgs.m_numDebugLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
int numLines = serverCmd.m_sendDebugLinesArgs.m_numDebugLines;
|
2015-09-03 21:18:22 +00:00
|
|
|
float* linesFrom = (float*)&m_data->m_testBlock1->m_bulletStreamDataServerToClient[0];
|
|
|
|
float* linesTo = (float*)(&m_data->m_testBlock1->m_bulletStreamDataServerToClient[0]+numLines*3*sizeof(float));
|
|
|
|
float* linesColor = (float*)(&m_data->m_testBlock1->m_bulletStreamDataServerToClient[0]+2*numLines*3*sizeof(float));
|
2015-08-20 05:51:16 +00:00
|
|
|
|
2015-09-03 21:18:22 +00:00
|
|
|
m_data->m_debugLinesFrom.resize(serverCmd.m_sendDebugLinesArgs.m_startingLineIndex+numLines);
|
|
|
|
m_data->m_debugLinesTo.resize(serverCmd.m_sendDebugLinesArgs.m_startingLineIndex+numLines);
|
|
|
|
m_data->m_debugLinesColor.resize(serverCmd.m_sendDebugLinesArgs.m_startingLineIndex+numLines);
|
2015-08-20 05:51:16 +00:00
|
|
|
|
|
|
|
for (int i=0;i<numLines;i++)
|
|
|
|
{
|
2015-09-03 21:18:22 +00:00
|
|
|
btVector3 from(linesFrom[i*3],linesFrom[i*3+1],linesFrom[i*3+2]);
|
|
|
|
btVector3 to(linesTo[i*3],linesTo[i*3+1],linesTo[i*3+2]);
|
|
|
|
btVector3 color(linesColor[i*3],linesColor[i*3+1],linesColor[i*3+2]);
|
2015-08-20 15:09:22 +00:00
|
|
|
|
2015-09-03 21:18:22 +00:00
|
|
|
m_data->m_debugLinesFrom[serverCmd.m_sendDebugLinesArgs.m_startingLineIndex+i] = from;
|
|
|
|
m_data->m_debugLinesTo[serverCmd.m_sendDebugLinesArgs.m_startingLineIndex+i] = to;
|
|
|
|
m_data->m_debugLinesColor[serverCmd.m_sendDebugLinesArgs.m_startingLineIndex+i] = color;
|
2015-08-20 05:51:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_DEBUG_LINES_OVERFLOW_FAILED:
|
|
|
|
{
|
|
|
|
b3Warning("Error receiving debug lines");
|
|
|
|
m_data->m_debugLinesFrom.resize(0);
|
|
|
|
m_data->m_debugLinesTo.resize(0);
|
|
|
|
m_data->m_debugLinesColor.resize(0);
|
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
default:
|
|
|
|
{
|
2015-08-02 21:00:43 +00:00
|
|
|
b3Error("Unknown server status\n");
|
2015-06-22 22:30:57 +00:00
|
|
|
btAssert(0);
|
|
|
|
}
|
|
|
|
};
|
2015-06-09 23:51:55 +00:00
|
|
|
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_testBlock1->m_numProcessedServerCommands++;
|
2015-06-22 22:30:57 +00:00
|
|
|
//we don't have more than 1 command outstanding (in total, either server or client)
|
2015-07-14 22:30:17 +00:00
|
|
|
btAssert(m_data->m_testBlock1->m_numProcessedServerCommands == m_data->m_testBlock1->m_numServerCommands);
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
if (m_data->m_testBlock1->m_numServerCommands == m_data->m_testBlock1->m_numProcessedServerCommands)
|
2015-06-22 22:30:57 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_waitingForServer = false;
|
2015-06-22 22:30:57 +00:00
|
|
|
} else
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_waitingForServer = true;
|
2015-06-22 22:30:57 +00:00
|
|
|
}
|
2015-08-02 21:00:43 +00:00
|
|
|
} else
|
|
|
|
{
|
2015-08-20 05:51:16 +00:00
|
|
|
if (m_data->m_verboseOutput)
|
|
|
|
{
|
|
|
|
b3Printf("m_numServerStatus = %d, processed = %d\n", m_data->m_testBlock1->m_numServerCommands,
|
2015-08-02 21:00:43 +00:00
|
|
|
m_data->m_testBlock1->m_numProcessedServerCommands);
|
2015-08-20 05:51:16 +00:00
|
|
|
}
|
2015-08-02 21:00:43 +00:00
|
|
|
}
|
2015-07-21 06:35:29 +00:00
|
|
|
return hasStatus;
|
2015-06-22 22:30:57 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
bool PhysicsClientSharedMemory::canSubmitCommand() const
|
2015-06-22 22:30:57 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
return (m_data->m_isConnected && !m_data->m_waitingForServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsClientSharedMemory::submitClientCommand(const SharedMemoryCommand& command)
|
|
|
|
{
|
2015-07-31 06:22:44 +00:00
|
|
|
///at the moment we allow a maximum of 1 outstanding command, so we check for this
|
|
|
|
//once the server processed the command and returns a status, we clear the flag "m_data->m_waitingForServer" and allow submitting the next command
|
2015-08-02 21:00:43 +00:00
|
|
|
btAssert(!m_data->m_waitingForServer);
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
if (!m_data->m_waitingForServer)
|
2015-07-31 06:22:44 +00:00
|
|
|
{
|
2015-08-07 07:13:26 +00:00
|
|
|
//a reset simulation command needs special attention, cleanup state
|
|
|
|
if (command.m_type==CMD_RESET_SIMULATION)
|
|
|
|
{
|
|
|
|
for (int i=0;i<m_data->m_robotMultiBodyData.size();i++)
|
|
|
|
{
|
|
|
|
delete m_data->m_robotMultiBodyData[i];
|
|
|
|
}
|
|
|
|
m_data->m_robotMultiBodyData.clear();
|
|
|
|
|
|
|
|
m_data->m_jointInfo.clear();
|
|
|
|
}
|
2015-08-20 05:51:16 +00:00
|
|
|
|
2015-07-31 06:22:44 +00:00
|
|
|
m_data->m_testBlock1->m_clientCommands[0] = command;
|
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
|
|
|
m_data->m_waitingForServer = true;
|
2015-07-14 22:30:17 +00:00
|
|
|
return true;
|
2015-07-31 06:22:44 +00:00
|
|
|
}
|
|
|
|
return false;
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 05:51:16 +00:00
|
|
|
void PhysicsClientSharedMemory::uploadBulletFileToSharedMemory(const char* data, int len)
|
|
|
|
{
|
|
|
|
btAssert(len<SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
if (len>=SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE)
|
|
|
|
{
|
|
|
|
b3Warning("uploadBulletFileToSharedMemory %d exceeds max size %d\n",len,SHARED_MEMORY_MAX_STREAM_CHUNK_SIZE);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
for (int i=0;i<len;i++)
|
|
|
|
{
|
|
|
|
m_data->m_testBlock1->m_bulletStreamDataClientToServer[i] = data[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const btVector3* PhysicsClientSharedMemory::getDebugLinesFrom() const
|
|
|
|
{
|
|
|
|
if (m_data->m_debugLinesFrom.size())
|
|
|
|
{
|
|
|
|
return &m_data->m_debugLinesFrom[0];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const btVector3* PhysicsClientSharedMemory::getDebugLinesTo() const
|
|
|
|
{
|
|
|
|
if (m_data->m_debugLinesTo.size())
|
|
|
|
{
|
|
|
|
return &m_data->m_debugLinesTo[0];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const btVector3* PhysicsClientSharedMemory::getDebugLinesColor() const
|
|
|
|
{
|
|
|
|
if (m_data->m_debugLinesColor.size())
|
|
|
|
{
|
|
|
|
return &m_data->m_debugLinesColor[0];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int PhysicsClientSharedMemory::getNumDebugLines() const
|
|
|
|
{
|
|
|
|
return m_data->m_debugLinesFrom.size();
|
2015-08-20 15:09:22 +00:00
|
|
|
}
|