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"
|
|
|
|
#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-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;
|
|
|
|
SharedMemoryExampleData* m_testBlock1;
|
2015-06-09 23:51:55 +00:00
|
|
|
|
2015-07-21 06:35:29 +00:00
|
|
|
btAlignedObjectArray<bParse::btBulletFile*> m_robotMultiBodyData;
|
|
|
|
btAlignedObjectArray<PoweredJointInfo> m_poweredJointInfo;
|
|
|
|
|
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-06-09 23:51:55 +00:00
|
|
|
|
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),
|
|
|
|
m_hasLastServerStatus(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
|
|
|
|
|
|
|
int PhysicsClientSharedMemory::getNumPoweredJoints() const
|
|
|
|
{
|
|
|
|
return m_data->m_poweredJointInfo.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsClientSharedMemory::getPoweredJointInfo(int index, PoweredJointInfo& info) const
|
|
|
|
{
|
|
|
|
info = m_data->m_poweredJointInfo[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-06-09 23:51:55 +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-07-14 22:30:17 +00:00
|
|
|
m_data->m_sharedMemory->releaseSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
|
|
|
|
delete m_data->m_sharedMemory;
|
|
|
|
delete m_data;
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|
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-07-14 22:30:17 +00:00
|
|
|
bool PhysicsClientSharedMemory::connect(bool allowSharedMemoryInitialization)
|
|
|
|
{
|
|
|
|
bool allowCreation = true;
|
|
|
|
m_data->m_testBlock1 = (SharedMemoryExampleData*)m_data->m_sharedMemory->allocateSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE, allowCreation);
|
|
|
|
|
|
|
|
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-07-14 22:30:17 +00:00
|
|
|
if (allowSharedMemoryInitialization)
|
|
|
|
{
|
|
|
|
InitSharedMemoryExampleData(m_data->m_testBlock1);
|
|
|
|
b3Printf("Created and initialized shared memory block");
|
|
|
|
m_data->m_isConnected = true;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Error("Error: please start server before client\n");
|
|
|
|
m_data->m_sharedMemory->releaseSharedMemory(SHARED_MEMORY_KEY, SHARED_MEMORY_SIZE);
|
|
|
|
m_data->m_testBlock1 = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-29 22:04:05 +00:00
|
|
|
} else
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
b3Printf("Connected to existing shared memory, status OK.\n");
|
|
|
|
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-21 06:35:29 +00:00
|
|
|
bool PhysicsClientSharedMemory::processServerStatus(ServerStatus& serverStatus)
|
2015-05-28 23:05:24 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
btAssert(m_data->m_testBlock1);
|
2015-07-21 06:35:29 +00:00
|
|
|
bool hasStatus = false;
|
|
|
|
|
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-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:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_serverLoadUrdfOK = true;
|
2015-06-22 22:30:57 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_baseName = %s\n",mb->m_baseName);
|
|
|
|
}
|
|
|
|
for (int link=0;link<mb->m_numLinks;link++)
|
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
if ((mb->m_links[link].m_jointType == eRevoluteType)||
|
|
|
|
(mb->m_links[link].m_jointType == ePrismaticType))
|
2015-07-11 05:20:06 +00:00
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
PoweredJointInfo info;
|
|
|
|
info.m_qIndex = qOffset;
|
|
|
|
info.m_uIndex = uOffset;
|
|
|
|
|
|
|
|
if (mb->m_links[link].m_linkName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_linkName = %s\n",link,mb->m_links[link].m_linkName);
|
|
|
|
info.m_linkName = 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);
|
|
|
|
info.m_jointName = mb->m_links[link].m_jointName;
|
|
|
|
info.m_jointType = mb->m_links[link].m_jointType;
|
|
|
|
}
|
|
|
|
m_data->m_poweredJointInfo.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)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_baseName = %s\n",mb->m_baseName);
|
|
|
|
}
|
|
|
|
for (int link=0;link<mb->m_numLinks;link++)
|
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
if ((mb->m_links[link].m_jointType == eRevoluteType)||
|
|
|
|
(mb->m_links[link].m_jointType == ePrismaticType))
|
2015-07-11 05:20:06 +00:00
|
|
|
{
|
2015-07-21 06:35:29 +00:00
|
|
|
PoweredJointInfo info;
|
|
|
|
info.m_qIndex = qOffset;
|
|
|
|
info.m_uIndex = uOffset;
|
|
|
|
|
|
|
|
if (mb->m_links[link].m_linkName)
|
|
|
|
{
|
|
|
|
b3Printf("mb->m_links[%d].m_linkName = %s\n",link,mb->m_links[link].m_linkName);
|
|
|
|
info.m_linkName = 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);
|
|
|
|
info.m_jointName = mb->m_links[link].m_jointName;
|
|
|
|
info.m_jointType = mb->m_links[link].m_jointType;
|
|
|
|
}
|
|
|
|
m_data->m_poweredJointInfo.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())
|
|
|
|
{
|
|
|
|
b3Printf("Received robot description ok!\n");
|
|
|
|
} 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:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-06-22 22:30:57 +00:00
|
|
|
case CMD_STEP_FORWARD_SIMULATION_COMPLETED:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_URDF_LOADING_FAILED:
|
|
|
|
{
|
|
|
|
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-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-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-06-22 22:30:57 +00:00
|
|
|
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
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
b3Printf(msg);
|
|
|
|
|
|
|
|
{
|
|
|
|
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-06-22 22:30:57 +00:00
|
|
|
b3Printf(msg);
|
2015-07-21 06:35:29 +00:00
|
|
|
|
|
|
|
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
b3Error("Unknown server command\n");
|
|
|
|
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-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)
|
|
|
|
{
|
|
|
|
if (!m_data->m_waitingForServer)
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
//process command
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_waitingForServer = true;
|
2015-06-22 22:30:57 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
switch (command.m_type)
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-07-14 15:34:02 +00:00
|
|
|
|
2015-06-09 23:51:55 +00:00
|
|
|
case CMD_LOAD_URDF:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
if (!m_data->m_serverLoadUrdfOK)
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
2015-07-15 22:23:40 +00:00
|
|
|
m_data->m_testBlock1->m_clientCommands[0] = command;
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->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:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
if (m_data->m_serverLoadUrdfOK)
|
2015-07-09 21:04:58 +00:00
|
|
|
{
|
|
|
|
b3Printf("Requesting create box collision shape\n");
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_testBlock1->m_clientCommands[0].m_type =CMD_CREATE_BOX_COLLISION_SHAPE;
|
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
2015-07-09 21:04:58 +00:00
|
|
|
} 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)
|
|
|
|
{
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
fread(m_data->m_testBlock1->m_bulletStreamDataClientToServer, mFileLen, 1, fp);
|
2015-07-09 21:04:58 +00:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_testBlock1->m_clientCommands[0].m_type =CMD_SEND_BULLET_DATA_STREAM;
|
|
|
|
m_data->m_testBlock1->m_clientCommands[0].m_dataStreamArguments.m_streamChunkLength = mFileLen;
|
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
2015-07-09 21:04:58 +00:00
|
|
|
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-07-22 04:46:28 +00:00
|
|
|
|
|
|
|
case CMD_INIT_POSE:
|
|
|
|
{
|
|
|
|
if (m_data->m_serverLoadUrdfOK)
|
|
|
|
{
|
|
|
|
b3Printf("Initialize Pose");
|
|
|
|
m_data->m_testBlock1->m_clientCommands[0] = command;
|
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CMD_SEND_PHYSICS_SIMULATION_PARAMETERS:
|
|
|
|
{
|
|
|
|
b3Printf("Send Physics Simulation Parameters");
|
|
|
|
m_data->m_testBlock1->m_clientCommands[0] = command;
|
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-21 20:24:36 +00:00
|
|
|
case CMD_REQUEST_ACTUAL_STATE:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
if (m_data->m_serverLoadUrdfOK)
|
2015-06-21 20:24:36 +00:00
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Printf("Requesting actual state\n");
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_testBlock1->m_clientCommands[0].m_type =CMD_REQUEST_ACTUAL_STATE;
|
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
2015-06-21 20:24:36 +00:00
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
2015-06-22 22:30:57 +00:00
|
|
|
b3Warning("No URDF loaded\n");
|
2015-06-21 20:24:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-07-14 15:34:02 +00:00
|
|
|
case CMD_SEND_DESIRED_STATE:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
if (m_data->m_serverLoadUrdfOK)
|
2015-07-14 15:34:02 +00:00
|
|
|
{
|
|
|
|
b3Printf("Sending desired state (pos, vel, torque)\n");
|
2015-07-15 22:23:40 +00:00
|
|
|
m_data->m_testBlock1->m_clientCommands[0] = command;
|
2015-07-14 15:34:02 +00:00
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
2015-07-14 15:34:02 +00:00
|
|
|
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
b3Warning("Cannot send CMD_SEND_DESIRED_STATE, no URDF loaded\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-06-09 23:51:55 +00:00
|
|
|
case CMD_STEP_FORWARD_SIMULATION:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
if (m_data->m_serverLoadUrdfOK)
|
2015-06-09 23:51:55 +00:00
|
|
|
{
|
|
|
|
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_testBlock1->m_clientCommands[0].m_type =CMD_STEP_FORWARD_SIMULATION;
|
2015-07-21 06:35:29 +00:00
|
|
|
// m_data->m_testBlock1->m_clientCommands[0].m_stepSimulationArguments.m_deltaTimeInSeconds = 1./60.;
|
2015-07-14 22:30:17 +00:00
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
|
|
|
b3Printf("client created CMD_STEP_FORWARD_SIMULATION %d\n", m_data->m_counter++);
|
2015-06-09 23:51:55 +00:00
|
|
|
} 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:
|
|
|
|
{
|
2015-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
m_data->m_testBlock1->m_clientCommands[0].m_type =CMD_SHUTDOWN;
|
|
|
|
m_data->m_testBlock1->m_numClientCommands++;
|
|
|
|
m_data->m_serverLoadUrdfOK = false;
|
2015-06-09 23:51:55 +00:00
|
|
|
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-07-14 22:30:17 +00:00
|
|
|
|
|
|
|
return true;
|
2015-05-28 23:05:24 +00:00
|
|
|
}
|
|
|
|
|