2018-06-05 01:41:41 +00:00
|
|
|
#include "b3RobotSimulatorClientAPI_NoDirect.h"
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
#include "PhysicsClientC_API.h"
|
2018-02-03 02:33:29 +00:00
|
|
|
#include "b3RobotSimulatorClientAPI_InternalData.h"
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
#include "SharedMemoryPublic.h"
|
2018-02-03 02:33:29 +00:00
|
|
|
#include "Bullet3Common/b3Logging.h"
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static void scalarToDouble3(btScalar a[3], double b[3])
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 3; i++)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b[i] = a[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
static void scalarToDouble4(btScalar a[4], double b[4])
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-06-05 01:41:41 +00:00
|
|
|
for (int i = 0; i < 4; i++)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b[i] = a[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
b3RobotSimulatorClientAPI_NoDirect::b3RobotSimulatorClientAPI_NoDirect()
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
m_data = new b3RobotSimulatorClientAPI_InternalData();
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
b3RobotSimulatorClientAPI_NoDirect::~b3RobotSimulatorClientAPI_NoDirect()
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
delete m_data;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::isConnected() const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
return (m_data->m_physicsClientHandle != 0);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setTimeOut(double timeOutInSec)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SetTimeOut(m_data->m_physicsClientHandle, timeOutInSec);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::disconnect()
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
2018-06-05 01:41:41 +00:00
|
|
|
#ifndef BT_DISABLE_PHYSICS_DIRECT
|
2018-02-03 02:33:29 +00:00
|
|
|
b3DisconnectSharedMemory(m_data->m_physicsClientHandle);
|
|
|
|
m_data->m_physicsClientHandle = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::syncBodies()
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
command = b3InitSyncBodyInfoCommand(m_data->m_physicsClientHandle);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::resetSimulation()
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(
|
|
|
|
m_data->m_physicsClientHandle, b3InitResetSimulationCommand(m_data->m_physicsClientHandle));
|
|
|
|
}
|
|
|
|
|
2019-12-13 22:33:54 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::resetSimulation(int flag)
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitResetSimulationCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3InitResetSimulationSetFlags(command, flag);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::canSubmitCommand() const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (b3CanSubmitCommand(m_data->m_physicsClientHandle) != 0);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::stepSimulation()
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
if (b3CanSubmitCommand(m_data->m_physicsClientHandle))
|
|
|
|
{
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, b3InitStepSimulationCommand(m_data->m_physicsClientHandle));
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-05-27 00:42:33 +00:00
|
|
|
//btAssert(statusType == CMD_STEP_FORWARD_SIMULATION_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setGravity(const btVector3& gravityAcceleration)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(b3CanSubmitCommand(m_data->m_physicsClientHandle));
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
b3PhysicsParamSetGravity(command, gravityAcceleration[0], gravityAcceleration[1], gravityAcceleration[2]);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
2018-05-27 00:42:33 +00:00
|
|
|
// btAssert(b3GetStatusType(statusHandle) == CMD_CLIENT_COMMAND_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
btQuaternion b3RobotSimulatorClientAPI_NoDirect::getQuaternionFromEuler(const btVector3& rollPitchYaw)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-05-27 00:42:33 +00:00
|
|
|
btQuaternion q;
|
2018-09-23 21:17:31 +00:00
|
|
|
q.setEulerZYX(rollPitchYaw[2], rollPitchYaw[1], rollPitchYaw[0]);
|
2018-02-03 02:33:29 +00:00
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
btVector3 b3RobotSimulatorClientAPI_NoDirect::getEulerFromQuaternion(const btQuaternion& quat)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar roll, pitch, yaw;
|
|
|
|
quat.getEulerZYX(yaw, pitch, roll);
|
|
|
|
btVector3 rpy2 = btVector3(roll, pitch, yaw);
|
2018-02-03 02:33:29 +00:00
|
|
|
return rpy2;
|
|
|
|
}
|
|
|
|
|
2018-07-08 09:23:12 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::loadTexture(const std::string& fileName)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
btAssert(b3CanSubmitCommand(m_data->m_physicsClientHandle));
|
2018-07-08 09:23:12 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
{
|
|
|
|
commandHandle = b3InitLoadTexture(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType == CMD_LOAD_TEXTURE_COMPLETED)
|
|
|
|
{
|
|
|
|
return b3GetStatusTextureUniqueId(statusHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2018-07-08 09:23:12 +00:00
|
|
|
|
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::changeVisualShape(const struct b3RobotSimulatorChangeVisualShapeArgs& args)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int objectUniqueId = args.m_objectUniqueId;
|
|
|
|
int jointIndex = args.m_linkIndex;
|
|
|
|
int shapeIndex = args.m_shapeIndex;
|
|
|
|
int textureUniqueId = args.m_textureUniqueId;
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
2018-10-21 02:44:39 +00:00
|
|
|
commandHandle = b3InitUpdateVisualShape2(m_data->m_physicsClientHandle, objectUniqueId, jointIndex, shapeIndex);
|
2018-10-20 22:56:56 +00:00
|
|
|
|
|
|
|
if (textureUniqueId>=-1)
|
|
|
|
{
|
|
|
|
b3UpdateVisualShapeTexture(commandHandle, textureUniqueId);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (args.m_hasSpecularColor)
|
|
|
|
{
|
|
|
|
double specularColor[3] = {args.m_specularColor[0], args.m_specularColor[1], args.m_specularColor[2]};
|
|
|
|
b3UpdateVisualShapeSpecularColor(commandHandle, specularColor);
|
|
|
|
}
|
|
|
|
if (args.m_hasRgbaColor)
|
|
|
|
{
|
|
|
|
double rgbaColor[4] = {args.m_rgbaColor[0], args.m_rgbaColor[1], args.m_rgbaColor[2], args.m_rgbaColor[3]};
|
|
|
|
b3UpdateVisualShapeRGBAColor(commandHandle, rgbaColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
|
|
|
return (statusType == CMD_VISUAL_SHAPE_UPDATE_COMPLETED);
|
2018-07-08 09:23:12 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::loadURDF(const std::string& fileName, const struct b3RobotSimulatorLoadUrdfFileArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
int robotUniqueId = -1;
|
|
|
|
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return robotUniqueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command = b3LoadUrdfCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
|
|
|
|
//setting the initial position, orientation and other arguments are optional
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3LoadUrdfCommandSetFlags(command, args.m_flags);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
b3LoadUrdfCommandSetStartPosition(command, args.m_startPosition[0],
|
2018-09-23 21:17:31 +00:00
|
|
|
args.m_startPosition[1],
|
|
|
|
args.m_startPosition[2]);
|
2018-02-03 02:33:29 +00:00
|
|
|
b3LoadUrdfCommandSetStartOrientation(command, args.m_startOrientation[0], args.m_startOrientation[1], args.m_startOrientation[2], args.m_startOrientation[3]);
|
|
|
|
if (args.m_forceOverrideFixedBase)
|
|
|
|
{
|
|
|
|
b3LoadUrdfCommandSetUseFixedBase(command, true);
|
|
|
|
}
|
|
|
|
b3LoadUrdfCommandSetUseMultiBody(command, args.m_useMultiBody);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(statusType == CMD_URDF_LOADING_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
if (statusType == CMD_URDF_LOADING_COMPLETED)
|
|
|
|
{
|
|
|
|
robotUniqueId = b3GetStatusBodyIndex(statusHandle);
|
|
|
|
}
|
|
|
|
return robotUniqueId;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::loadMJCF(const std::string& fileName, b3RobotSimulatorLoadFileResults& results)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
|
|
|
|
command = b3LoadMJCFCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType != CMD_MJCF_LOADING_COMPLETED)
|
|
|
|
{
|
|
|
|
b3Warning("Couldn't load .mjcf file.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int numBodies = b3GetStatusBodyIndices(statusHandle, 0, 0);
|
|
|
|
if (numBodies)
|
|
|
|
{
|
|
|
|
results.m_uniqueObjectIds.resize(numBodies);
|
|
|
|
int numBodies;
|
|
|
|
numBodies = b3GetStatusBodyIndices(statusHandle, &results.m_uniqueObjectIds[0], results.m_uniqueObjectIds.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-10 02:40:12 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::savePythonWorld(const std::string& fileName)
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (fileName.length() == 0)
|
2018-06-10 02:40:12 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
command = b3SaveWorldCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType != CMD_SAVE_WORLD_COMPLETED)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::saveBullet(const std::string& fileName)
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (fileName.length() == 0)
|
2018-06-10 02:40:12 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
command = b3SaveBulletCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType != CMD_BULLET_SAVING_COMPLETED)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::loadBullet(const std::string& fileName, b3RobotSimulatorLoadFileResults& results)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
|
|
|
|
command = b3LoadBulletCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType != CMD_BULLET_LOADING_COMPLETED)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int numBodies = b3GetStatusBodyIndices(statusHandle, 0, 0);
|
|
|
|
if (numBodies)
|
|
|
|
{
|
|
|
|
results.m_uniqueObjectIds.resize(numBodies);
|
|
|
|
int numBodies;
|
|
|
|
numBodies = b3GetStatusBodyIndices(statusHandle, &results.m_uniqueObjectIds[0], results.m_uniqueObjectIds.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::loadSDF(const std::string& fileName, b3RobotSimulatorLoadFileResults& results, const struct b3RobotSimulatorLoadSdfFileArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool statusOk = false;
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command = b3LoadSdfCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
b3LoadSdfCommandSetUseMultiBody(command, args.m_useMultiBody);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(statusType == CMD_SDF_LOADING_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
if (statusType == CMD_SDF_LOADING_COMPLETED)
|
|
|
|
{
|
|
|
|
int numBodies = b3GetStatusBodyIndices(statusHandle, 0, 0);
|
|
|
|
if (numBodies)
|
|
|
|
{
|
|
|
|
results.m_uniqueObjectIds.resize(numBodies);
|
|
|
|
int numBodies;
|
|
|
|
numBodies = b3GetStatusBodyIndices(statusHandle, &results.m_uniqueObjectIds[0], results.m_uniqueObjectIds.size());
|
|
|
|
}
|
|
|
|
statusOk = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return statusOk;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getBodyInfo(int bodyUniqueId, struct b3BodyInfo* bodyInfo)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = b3GetBodyInfo(m_data->m_physicsClientHandle, bodyUniqueId, bodyInfo);
|
|
|
|
return (result != 0);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getBasePositionAndOrientation(int bodyUniqueId, btVector3& basePosition, btQuaternion& baseOrientation) const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle cmd_handle =
|
|
|
|
b3RequestActualStateCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
b3SharedMemoryStatusHandle status_handle =
|
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, cmd_handle);
|
|
|
|
|
|
|
|
const int status_type = b3GetStatusType(status_handle);
|
|
|
|
const double* actualStateQ;
|
|
|
|
|
|
|
|
if (status_type != CMD_ACTUAL_STATE_UPDATE_COMPLETED)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3GetStatusActualState(
|
|
|
|
status_handle, 0 /* body_unique_id */,
|
|
|
|
0 /* num_degree_of_freedom_q */, 0 /* num_degree_of_freedom_u */,
|
|
|
|
0 /*root_local_inertial_frame*/, &actualStateQ,
|
|
|
|
0 /* actual_state_q_dot */, 0 /* joint_reaction_forces */);
|
|
|
|
|
|
|
|
basePosition[0] = actualStateQ[0];
|
|
|
|
basePosition[1] = actualStateQ[1];
|
|
|
|
basePosition[2] = actualStateQ[2];
|
|
|
|
|
|
|
|
baseOrientation[0] = actualStateQ[3];
|
|
|
|
baseOrientation[1] = actualStateQ[4];
|
|
|
|
baseOrientation[2] = actualStateQ[5];
|
|
|
|
baseOrientation[3] = actualStateQ[6];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::resetBasePositionAndOrientation(int bodyUniqueId, btVector3& basePosition, btQuaternion& baseOrientation)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
|
|
|
|
commandHandle = b3CreatePoseCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
|
|
|
|
b3CreatePoseCommandSetBasePosition(commandHandle, basePosition[0], basePosition[1], basePosition[2]);
|
|
|
|
b3CreatePoseCommandSetBaseOrientation(commandHandle, baseOrientation[0], baseOrientation[1],
|
2018-09-23 21:17:31 +00:00
|
|
|
baseOrientation[2], baseOrientation[3]);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getBaseVelocity(int bodyUniqueId, btVector3& baseLinearVelocity, btVector3& baseAngularVelocity) const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3RequestActualStateCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
|
|
|
|
const int status_type = b3GetStatusType(statusHandle);
|
|
|
|
const double* actualStateQdot;
|
|
|
|
|
|
|
|
if (status_type != CMD_ACTUAL_STATE_UPDATE_COMPLETED)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3GetStatusActualState(statusHandle, 0 /* body_unique_id */,
|
2018-09-23 21:17:31 +00:00
|
|
|
0 /* num_degree_of_freedom_q */, 0 /* num_degree_of_freedom_u */,
|
|
|
|
0 /*root_local_inertial_frame*/, 0,
|
|
|
|
&actualStateQdot, 0 /* joint_reaction_forces */);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
baseLinearVelocity[0] = actualStateQdot[0];
|
|
|
|
baseLinearVelocity[1] = actualStateQdot[1];
|
|
|
|
baseLinearVelocity[2] = actualStateQdot[2];
|
|
|
|
|
|
|
|
baseAngularVelocity[0] = actualStateQdot[3];
|
|
|
|
baseAngularVelocity[1] = actualStateQdot[4];
|
|
|
|
baseAngularVelocity[2] = actualStateQdot[5];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::resetBaseVelocity(int bodyUniqueId, const btVector3& linearVelocity, const btVector3& angularVelocity) const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
|
|
|
|
commandHandle = b3CreatePoseCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
btVector3DoubleData linVelDouble;
|
2018-02-03 02:33:29 +00:00
|
|
|
linearVelocity.serializeDouble(linVelDouble);
|
|
|
|
b3CreatePoseCommandSetBaseLinearVelocity(commandHandle, linVelDouble.m_floats);
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
btVector3DoubleData angVelDouble;
|
2018-02-03 02:33:29 +00:00
|
|
|
angularVelocity.serializeDouble(angVelDouble);
|
|
|
|
b3CreatePoseCommandSetBaseAngularVelocity(commandHandle, angVelDouble.m_floats);
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setInternalSimFlags(int flags)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
b3PhysicsParamSetInternalSimFlags(command, flags);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setRealTimeSimulation(bool enableRealTimeSimulation)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
|
2018-06-06 23:33:52 +00:00
|
|
|
b3PhysicsParamSetRealTimeSimulation(command, enableRealTimeSimulation);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(b3GetStatusType(statusHandle) == CMD_CLIENT_COMMAND_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::getNumJoints(int bodyUniqueId) const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return b3GetNumJoints(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getJointInfo(int bodyUniqueId, int jointIndex, b3JointInfo* jointInfo)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (b3GetJointInfo(m_data->m_physicsClientHandle, bodyUniqueId, jointIndex, jointInfo) != 0);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::createConstraint(int parentBodyIndex, int parentJointIndex, int childBodyIndex, int childJointIndex, b3JointInfo* jointInfo)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(b3CanSubmitCommand(m_data->m_physicsClientHandle));
|
2018-02-03 02:33:29 +00:00
|
|
|
if (b3CanSubmitCommand(m_data->m_physicsClientHandle))
|
|
|
|
{
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, b3InitCreateUserConstraintCommand(m_data->m_physicsClientHandle, parentBodyIndex, parentJointIndex, childBodyIndex, childJointIndex, jointInfo));
|
|
|
|
int statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType == CMD_USER_CONSTRAINT_COMPLETED)
|
|
|
|
{
|
|
|
|
int userConstraintUid = b3GetStatusUserConstraintUniqueId(statusHandle);
|
|
|
|
return userConstraintUid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-01-10 01:56:21 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::changeConstraint(int constraintId, b3RobotUserConstraint* jointInfo)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitChangeUserConstraintCommand(m_data->m_physicsClientHandle, constraintId);
|
|
|
|
|
2020-01-10 01:56:21 +00:00
|
|
|
if (jointInfo->m_userUpdateFlags & USER_CONSTRAINT_CHANGE_MAX_FORCE)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2020-01-10 01:56:21 +00:00
|
|
|
b3InitChangeUserConstraintSetMaxForce(commandHandle, jointInfo->m_maxAppliedForce);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 01:56:21 +00:00
|
|
|
if (jointInfo->m_userUpdateFlags & USER_CONSTRAINT_CHANGE_GEAR_RATIO)
|
|
|
|
{
|
|
|
|
b3InitChangeUserConstraintSetGearRatio(commandHandle, jointInfo->m_gearRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jointInfo->m_userUpdateFlags & USER_CONSTRAINT_CHANGE_ERP)
|
|
|
|
{
|
|
|
|
b3InitChangeUserConstraintSetERP(commandHandle, jointInfo->m_erp);
|
|
|
|
}
|
|
|
|
if (jointInfo->m_userUpdateFlags & USER_CONSTRAINT_CHANGE_GEAR_AUX_LINK)
|
|
|
|
{
|
|
|
|
b3InitChangeUserConstraintSetGearAuxLink(commandHandle, jointInfo->m_gearAuxLink);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jointInfo->m_userUpdateFlags & USER_CONSTRAINT_CHANGE_RELATIVE_POSITION_TARGET)
|
|
|
|
{
|
|
|
|
b3InitChangeUserConstraintSetRelativePositionTarget(commandHandle, jointInfo->m_relativePositionTarget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jointInfo->m_userUpdateFlags & USER_CONSTRAINT_CHANGE_PIVOT_IN_B)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3InitChangeUserConstraintSetPivotInB(commandHandle, &jointInfo->m_childFrame[0]);
|
|
|
|
}
|
2020-01-10 01:56:21 +00:00
|
|
|
if (jointInfo->m_userUpdateFlags & USER_CONSTRAINT_CHANGE_FRAME_ORN_IN_B)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3InitChangeUserConstraintSetFrameInB(commandHandle, &jointInfo->m_childFrame[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
int statusType = b3GetStatusType(statusHandle);
|
|
|
|
return statusType;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::removeConstraint(int constraintId)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitRemoveUserConstraintCommand(m_data->m_physicsClientHandle, constraintId);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
2018-06-06 23:10:20 +00:00
|
|
|
b3GetStatusType(statusHandle);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-10 02:40:12 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getConstraintInfo(int constraintUniqueId, struct b3UserConstraint& constraintInfo)
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2018-06-10 02:40:12 +00:00
|
|
|
if (b3GetUserConstraintInfo(m_data->m_physicsClientHandle, constraintUniqueId, &constraintInfo))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getJointState(int bodyUniqueId, int jointIndex, struct b3JointSensorState* state)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3RequestActualStateCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
int statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType == CMD_ACTUAL_STATE_UPDATE_COMPLETED)
|
|
|
|
{
|
|
|
|
if (b3GetJointState(m_data->m_physicsClientHandle, statusHandle, jointIndex, state))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getJointStates(int bodyUniqueId, b3JointStates2& state)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SharedMemoryCommandHandle command = b3RequestActualStateCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
|
|
|
|
if (statusHandle)
|
|
|
|
{
|
|
|
|
// double rootInertialFrame[7];
|
|
|
|
const double* rootLocalInertialFrame;
|
|
|
|
const double* actualStateQ;
|
|
|
|
const double* actualStateQdot;
|
|
|
|
const double* jointReactionForces;
|
|
|
|
|
|
|
|
int stat = b3GetStatusActualState(statusHandle,
|
2018-09-23 21:17:31 +00:00
|
|
|
&state.m_bodyUniqueId,
|
|
|
|
&state.m_numDegreeOfFreedomQ,
|
|
|
|
&state.m_numDegreeOfFreedomU,
|
|
|
|
&rootLocalInertialFrame,
|
|
|
|
&actualStateQ,
|
|
|
|
&actualStateQdot,
|
|
|
|
&jointReactionForces);
|
2018-02-03 02:33:29 +00:00
|
|
|
if (stat)
|
|
|
|
{
|
|
|
|
state.m_actualStateQ.resize(state.m_numDegreeOfFreedomQ);
|
|
|
|
state.m_actualStateQdot.resize(state.m_numDegreeOfFreedomU);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < state.m_numDegreeOfFreedomQ; i++)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
state.m_actualStateQ[i] = actualStateQ[i];
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < state.m_numDegreeOfFreedomU; i++)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
state.m_actualStateQdot[i] = actualStateQdot[i];
|
|
|
|
}
|
|
|
|
int numJoints = getNumJoints(bodyUniqueId);
|
2018-09-23 21:17:31 +00:00
|
|
|
state.m_jointReactionForces.resize(6 * numJoints);
|
|
|
|
for (int i = 0; i < numJoints * 6; i++)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
state.m_jointReactionForces[i] = jointReactionForces[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//rootInertialFrame,
|
|
|
|
// &state.m_actualStateQ[0],
|
|
|
|
// &state.m_actualStateQdot[0],
|
|
|
|
// &state.m_jointReactionForces[0]);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::resetJointState(int bodyUniqueId, int jointIndex, double targetValue)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int numJoints;
|
|
|
|
|
|
|
|
numJoints = b3GetNumJoints(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
if ((jointIndex >= numJoints) || (jointIndex < 0))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
commandHandle = b3CreatePoseCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
|
|
|
|
b3CreatePoseCommandSetJointPosition(m_data->m_physicsClientHandle, commandHandle, jointIndex,
|
2018-09-23 21:17:31 +00:00
|
|
|
targetValue);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setJointMotorControl(int bodyUniqueId, int jointIndex, const b3RobotSimulatorJointMotorArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
switch (args.m_controlMode)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
case CONTROL_MODE_VELOCITY:
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle command = b3JointControlCommandInit2(m_data->m_physicsClientHandle, bodyUniqueId, CONTROL_MODE_VELOCITY);
|
|
|
|
b3JointInfo jointInfo;
|
|
|
|
b3GetJointInfo(m_data->m_physicsClientHandle, bodyUniqueId, jointIndex, &jointInfo);
|
|
|
|
int uIndex = jointInfo.m_uIndex;
|
2018-09-04 06:13:15 +00:00
|
|
|
if (uIndex >= 0)
|
|
|
|
{
|
|
|
|
b3JointControlSetKd(command, uIndex, args.m_kd);
|
|
|
|
b3JointControlSetDesiredVelocity(command, uIndex, args.m_targetVelocity);
|
|
|
|
b3JointControlSetMaximumForce(command, uIndex, args.m_maxTorqueValue);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CONTROL_MODE_POSITION_VELOCITY_PD:
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle command = b3JointControlCommandInit2(m_data->m_physicsClientHandle, bodyUniqueId, CONTROL_MODE_POSITION_VELOCITY_PD);
|
|
|
|
b3JointInfo jointInfo;
|
|
|
|
b3GetJointInfo(m_data->m_physicsClientHandle, bodyUniqueId, jointIndex, &jointInfo);
|
|
|
|
int uIndex = jointInfo.m_uIndex;
|
|
|
|
int qIndex = jointInfo.m_qIndex;
|
|
|
|
|
|
|
|
b3JointControlSetDesiredPosition(command, qIndex, args.m_targetPosition);
|
|
|
|
b3JointControlSetKp(command, uIndex, args.m_kp);
|
|
|
|
b3JointControlSetDesiredVelocity(command, uIndex, args.m_targetVelocity);
|
|
|
|
b3JointControlSetKd(command, uIndex, args.m_kd);
|
|
|
|
b3JointControlSetMaximumForce(command, uIndex, args.m_maxTorqueValue);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CONTROL_MODE_TORQUE:
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle command = b3JointControlCommandInit2(m_data->m_physicsClientHandle, bodyUniqueId, CONTROL_MODE_TORQUE);
|
|
|
|
b3JointInfo jointInfo;
|
|
|
|
b3GetJointInfo(m_data->m_physicsClientHandle, bodyUniqueId, jointIndex, &jointInfo);
|
|
|
|
int uIndex = jointInfo.m_uIndex;
|
2018-09-04 06:13:15 +00:00
|
|
|
if (uIndex >= 0)
|
|
|
|
{
|
|
|
|
b3JointControlSetDesiredForceTorque(command, uIndex, args.m_maxTorqueValue);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
case CONTROL_MODE_PD:
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle command = b3JointControlCommandInit2(m_data->m_physicsClientHandle, bodyUniqueId, CONTROL_MODE_PD);
|
|
|
|
b3JointInfo jointInfo;
|
|
|
|
b3GetJointInfo(m_data->m_physicsClientHandle, bodyUniqueId, jointIndex, &jointInfo);
|
|
|
|
int uIndex = jointInfo.m_uIndex;
|
|
|
|
int qIndex = jointInfo.m_qIndex;
|
|
|
|
|
|
|
|
b3JointControlSetDesiredPosition(command, qIndex, args.m_targetPosition);
|
|
|
|
b3JointControlSetKp(command, uIndex, args.m_kp);
|
|
|
|
b3JointControlSetDesiredVelocity(command, uIndex, args.m_targetVelocity);
|
|
|
|
b3JointControlSetKd(command, uIndex, args.m_kd);
|
|
|
|
b3JointControlSetMaximumForce(command, uIndex, args.m_maxTorqueValue);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3Error("Unknown control command in b3RobotSimulationClientAPI::setJointMotorControl");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setNumSolverIterations(int numIterations)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
b3PhysicsParamSetNumSolverIterations(command, numIterations);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(b3GetStatusType(statusHandle) == CMD_CLIENT_COMMAND_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setContactBreakingThreshold(double threshold)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
b3PhysicsParamSetContactBreakingThreshold(command, threshold);
|
2018-02-03 02:33:29 +00:00
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(b3GetStatusType(statusHandle) == CMD_CLIENT_COMMAND_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setTimeStep(double timeStepInSeconds)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int ret;
|
|
|
|
ret = b3PhysicsParamSetTimeStep(command, timeStepInSeconds);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setNumSimulationSubSteps(int numSubSteps)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(m_data->m_physicsClientHandle);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
b3PhysicsParamSetNumSubSteps(command, numSubSteps);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(b3GetStatusType(statusHandle) == CMD_CLIENT_COMMAND_COMPLETED);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::calculateInverseKinematics(const struct b3RobotSimulatorInverseKinematicArgs& args, struct b3RobotSimulatorInverseKinematicsResults& results)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-27 00:42:33 +00:00
|
|
|
btAssert(args.m_endEffectorLinkIndex >= 0);
|
|
|
|
btAssert(args.m_bodyUniqueId >= 0);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3CalculateInverseKinematicsCommandInit(m_data->m_physicsClientHandle, args.m_bodyUniqueId);
|
|
|
|
if ((args.m_flags & B3_HAS_IK_TARGET_ORIENTATION) && (args.m_flags & B3_HAS_NULL_SPACE_VELOCITY))
|
|
|
|
{
|
|
|
|
b3CalculateInverseKinematicsPosOrnWithNullSpaceVel(command, args.m_numDegreeOfFreedom, args.m_endEffectorLinkIndex, args.m_endEffectorTargetPosition, args.m_endEffectorTargetOrientation, &args.m_lowerLimits[0], &args.m_upperLimits[0], &args.m_jointRanges[0], &args.m_restPoses[0]);
|
|
|
|
}
|
|
|
|
else if (args.m_flags & B3_HAS_IK_TARGET_ORIENTATION)
|
|
|
|
{
|
|
|
|
b3CalculateInverseKinematicsAddTargetPositionWithOrientation(command, args.m_endEffectorLinkIndex, args.m_endEffectorTargetPosition, args.m_endEffectorTargetOrientation);
|
|
|
|
}
|
|
|
|
else if (args.m_flags & B3_HAS_NULL_SPACE_VELOCITY)
|
|
|
|
{
|
|
|
|
b3CalculateInverseKinematicsPosWithNullSpaceVel(command, args.m_numDegreeOfFreedom, args.m_endEffectorLinkIndex, args.m_endEffectorTargetPosition, &args.m_lowerLimits[0], &args.m_upperLimits[0], &args.m_jointRanges[0], &args.m_restPoses[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b3CalculateInverseKinematicsAddTargetPurePosition(command, args.m_endEffectorLinkIndex, args.m_endEffectorTargetPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.m_flags & B3_HAS_JOINT_DAMPING)
|
|
|
|
{
|
|
|
|
b3CalculateInverseKinematicsSetJointDamping(command, args.m_numDegreeOfFreedom, &args.m_jointDamping[0]);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_flags & B3_HAS_CURRENT_POSITIONS)
|
|
|
|
{
|
|
|
|
b3CalculateInverseKinematicsSetCurrentPositions(command, args.m_numDegreeOfFreedom, &args.m_currentJointPositions[0]);
|
|
|
|
}
|
2018-08-23 20:19:15 +00:00
|
|
|
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
|
|
|
|
int numPos = 0;
|
|
|
|
|
|
|
|
bool result = b3GetStatusInverseKinematicsJointPositions(statusHandle,
|
2018-09-23 21:17:31 +00:00
|
|
|
&results.m_bodyUniqueId,
|
|
|
|
&numPos,
|
|
|
|
0) != 0;
|
2018-02-03 02:33:29 +00:00
|
|
|
if (result && numPos)
|
|
|
|
{
|
|
|
|
results.m_calculatedJointPositions.resize(numPos);
|
|
|
|
result = b3GetStatusInverseKinematicsJointPositions(statusHandle,
|
2018-09-23 21:17:31 +00:00
|
|
|
&results.m_bodyUniqueId,
|
|
|
|
&numPos,
|
|
|
|
&results.m_calculatedJointPositions[0]) != 0;
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getBodyJacobian(int bodyUniqueId, int linkIndex, const double* localPosition, const double* jointPositions, const double* jointVelocities, const double* jointAccelerations, double* linearJacobian, double* angularJacobian)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3CalculateJacobianCommandInit(m_data->m_physicsClientHandle, bodyUniqueId, linkIndex, localPosition, jointPositions, jointVelocities, jointAccelerations);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
|
|
|
|
if (b3GetStatusType(statusHandle) == CMD_CALCULATED_JACOBIAN_COMPLETED)
|
|
|
|
{
|
|
|
|
int dofCount;
|
|
|
|
b3GetStatusJacobian(statusHandle, &dofCount, linearJacobian, angularJacobian);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getLinkState(int bodyUniqueId, int linkIndex, int computeLinkVelocity, int computeForwardKinematics, b3LinkState* linkState)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3RequestActualStateCommandInit(m_data->m_physicsClientHandle, bodyUniqueId);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (computeLinkVelocity)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3RequestActualStateCommandComputeLinkVelocity(command, computeLinkVelocity);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (computeForwardKinematics)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3RequestActualStateCommandComputeForwardKinematics(command, computeForwardKinematics);
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (b3GetStatusType(statusHandle) == CMD_ACTUAL_STATE_UPDATE_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3GetLinkState(m_data->m_physicsClientHandle, statusHandle, linkIndex, linkState);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::configureDebugVisualizer(b3ConfigureDebugVisualizerEnum flag, int enable)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitConfigureOpenGLVisualizer(m_data->m_physicsClientHandle);
|
|
|
|
b3ConfigureOpenGLVisualizerSetVisualizationFlags(commandHandle, flag, enable);
|
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::getVREvents(b3VREventsData* vrEventsData, int deviceTypeFilter)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
vrEventsData->m_numControllerEvents = 0;
|
|
|
|
vrEventsData->m_controllerEvents = 0;
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3RequestVREventsCommandInit(m_data->m_physicsClientHandle);
|
|
|
|
b3VREventsSetDeviceTypeFilter(commandHandle, deviceTypeFilter);
|
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
b3GetVREventsData(m_data->m_physicsClientHandle, vrEventsData);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::getKeyboardEvents(b3KeyboardEventsData* keyboardEventsData)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
keyboardEventsData->m_numKeyboardEvents = 0;
|
|
|
|
keyboardEventsData->m_keyboardEvents = 0;
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3RequestKeyboardEventsCommandInit(m_data->m_physicsClientHandle);
|
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
b3GetKeyboardEventsData(m_data->m_physicsClientHandle, keyboardEventsData);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::startStateLogging(b3StateLoggingType loggingType, const std::string& fileName, const btAlignedObjectArray<int>& objectUniqueIds, int maxLogDof)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int loggingUniqueId = -1;
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
commandHandle = b3StateLoggingCommandInit(m_data->m_physicsClientHandle);
|
|
|
|
|
|
|
|
b3StateLoggingStart(commandHandle, loggingType, fileName.c_str());
|
|
|
|
|
|
|
|
for (int i = 0; i < objectUniqueIds.size(); i++)
|
|
|
|
{
|
|
|
|
int objectUid = objectUniqueIds[i];
|
|
|
|
b3StateLoggingAddLoggingObjectUniqueId(commandHandle, objectUid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maxLogDof > 0)
|
|
|
|
{
|
|
|
|
b3StateLoggingSetMaxLogDof(commandHandle, maxLogDof);
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
if (statusType == CMD_STATE_LOGGING_START_COMPLETED)
|
|
|
|
{
|
|
|
|
loggingUniqueId = b3GetStatusLoggingUniqueId(statusHandle);
|
|
|
|
}
|
|
|
|
return loggingUniqueId;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::stopStateLogging(int stateLoggerUniqueId)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
commandHandle = b3StateLoggingCommandInit(m_data->m_physicsClientHandle);
|
|
|
|
b3StateLoggingStop(commandHandle, stateLoggerUniqueId);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::resetDebugVisualizerCamera(double cameraDistance, double cameraPitch, double cameraYaw, const btVector3& targetPos)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3InitConfigureOpenGLVisualizer(m_data->m_physicsClientHandle);
|
|
|
|
if (commandHandle)
|
|
|
|
{
|
|
|
|
if ((cameraDistance >= 0))
|
|
|
|
{
|
2018-05-27 00:42:33 +00:00
|
|
|
btVector3FloatData camTargetPos;
|
2018-02-03 02:33:29 +00:00
|
|
|
targetPos.serializeFloat(camTargetPos);
|
2018-09-23 21:17:31 +00:00
|
|
|
b3ConfigureOpenGLVisualizerSetViewMatrix(commandHandle, cameraDistance, cameraPitch, cameraYaw, camTargetPos.m_floats);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 18:40:14 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::submitProfileTiming(const std::string& profileName)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3ProfileTimingCommandInit(m_data->m_physicsClientHandle, profileName.c_str());
|
2020-01-09 18:40:14 +00:00
|
|
|
|
|
|
|
if (profileName.length())
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2020-01-09 18:40:14 +00:00
|
|
|
b3SetProfileTimingType(commandHandle, 0);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
2020-01-09 18:40:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
b3SetProfileTimingType(commandHandle, 1);
|
|
|
|
}
|
|
|
|
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
}
|
|
|
|
|
2019-05-01 00:41:46 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::loadSoftBody(const std::string& fileName, const struct b3RobotSimulatorLoadSoftBodyArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3LoadSoftBodyCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
2019-05-02 21:09:26 +00:00
|
|
|
b3LoadSoftBodySetStartPosition(command, args.m_startPosition[0], args.m_startPosition[1], args.m_startPosition[2]);
|
2019-05-01 00:41:46 +00:00
|
|
|
b3LoadSoftBodySetStartOrientation(command, args.m_startOrientation[0], args.m_startOrientation[1], args.m_startOrientation[2], args.m_startOrientation[3]);
|
|
|
|
b3LoadSoftBodySetScale(command, args.m_scale);
|
|
|
|
b3LoadSoftBodySetMass(command, args.m_mass);
|
|
|
|
b3LoadSoftBodySetCollisionMargin(command, args.m_collisionMargin);
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
2019-12-13 22:33:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::loadDeformableBody(const std::string& fileName, const struct b3RobotSimulatorLoadDeformableBodyArgs& args)
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3LoadSoftBodyCommandInit(m_data->m_physicsClientHandle, fileName.c_str());
|
|
|
|
b3LoadSoftBodySetStartPosition(command, args.m_startPosition[0], args.m_startPosition[1], args.m_startPosition[2]);
|
|
|
|
b3LoadSoftBodySetStartOrientation(command, args.m_startOrientation[0], args.m_startOrientation[1], args.m_startOrientation[2], args.m_startOrientation[3]);
|
|
|
|
b3LoadSoftBodySetScale(command, args.m_scale);
|
|
|
|
b3LoadSoftBodySetMass(command, args.m_mass);
|
|
|
|
b3LoadSoftBodySetCollisionMargin(command, args.m_collisionMargin);
|
2019-12-20 05:51:54 +00:00
|
|
|
if (args.m_NeoHookeanMu > 0)
|
|
|
|
{
|
|
|
|
b3LoadSoftBodyAddNeoHookeanForce(command, args.m_NeoHookeanMu, args.m_NeoHookeanLambda, args.m_NeoHookeanDamping);
|
|
|
|
}
|
|
|
|
if (args.m_springElasticStiffness > 0)
|
|
|
|
{
|
|
|
|
b3LoadSoftBodyAddMassSpringForce(command, args.m_springElasticStiffness, args.m_springDampingStiffness);
|
|
|
|
}
|
2019-12-18 02:27:23 +00:00
|
|
|
b3LoadSoftBodySetSelfCollision(command, args.m_useSelfCollision);
|
2019-12-13 22:33:54 +00:00
|
|
|
b3LoadSoftBodyUseFaceContact(command, args.m_useFaceContact);
|
|
|
|
b3LoadSoftBodySetFrictionCoefficient(command, args.m_frictionCoeff);
|
|
|
|
b3LoadSoftBodyUseBendingSprings(command, args.m_useBendingSprings, args.m_springBendingStiffness);
|
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::getMouseEvents(b3MouseEventsData* mouseEventsData)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
mouseEventsData->m_numMouseEvents = 0;
|
|
|
|
mouseEventsData->m_mouseEvents = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command = b3RequestMouseEventsCommandInit(m_data->m_physicsClientHandle);
|
|
|
|
b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
b3GetMouseEventsData(m_data->m_physicsClientHandle, mouseEventsData);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getCameraImage(int width, int height, struct b3RobotSimulatorGetCameraImageArgs args, struct b3CameraImageData& imageData)
|
2018-03-15 00:33:51 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
|
|
|
|
command = b3InitRequestCameraImage(m_data->m_physicsClientHandle);
|
|
|
|
|
|
|
|
b3RequestCameraImageSetPixelResolution(command, width, height);
|
|
|
|
|
|
|
|
// Check and apply optional arguments
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_viewMatrix && args.m_projectionMatrix)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetCameraMatrices(command, args.m_viewMatrix, args.m_projectionMatrix);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_lightDirection != NULL)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetLightDirection(command, args.m_lightDirection);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_lightColor != NULL)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetLightColor(command, args.m_lightColor);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_lightDistance >= 0)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetLightDistance(command, args.m_lightDistance);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_hasShadow >= 0)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetShadow(command, args.m_hasShadow);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_lightAmbientCoeff >= 0)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetLightAmbientCoeff(command, args.m_lightAmbientCoeff);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_lightDiffuseCoeff >= 0)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetLightDiffuseCoeff(command, args.m_lightDiffuseCoeff);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_lightSpecularCoeff >= 0)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSetLightSpecularCoeff(command, args.m_lightSpecularCoeff);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_renderer >= 0)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3RequestCameraImageSelectRenderer(command, args.m_renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually retrieve the image
|
2018-09-23 21:17:31 +00:00
|
|
|
if (b3CanSubmitCommand(m_data->m_physicsClientHandle))
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CAMERA_IMAGE_COMPLETED)
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
b3GetCameraImageData(m_data->m_physicsClientHandle, &imageData);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-15 00:33:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::calculateInverseDynamics(int bodyUniqueId, double* jointPositions, double* jointVelocities,
|
|
|
|
double* jointAccelerations, double* jointForcesOutput)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-06 23:10:20 +00:00
|
|
|
b3GetNumJoints(m_data->m_physicsClientHandle, bodyUniqueId);
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle commandHandle = b3CalculateInverseDynamicsCommandInit(m_data->m_physicsClientHandle, bodyUniqueId, jointPositions,
|
2018-09-23 21:17:31 +00:00
|
|
|
jointVelocities, jointAccelerations);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, commandHandle);
|
|
|
|
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CALCULATED_INVERSE_DYNAMICS_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
int bodyUniqueId;
|
|
|
|
int dofCount;
|
|
|
|
|
|
|
|
b3GetStatusInverseDynamicsJointForces(statusHandle, &bodyUniqueId, &dofCount, 0);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (dofCount)
|
|
|
|
{
|
|
|
|
b3GetStatusInverseDynamicsJointForces(statusHandle, 0, 0, jointForcesOutput);
|
2018-02-03 02:33:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::getNumBodies() const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return b3GetNumBodies(m_data->m_physicsClientHandle);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::getBodyUniqueId(int bodyId) const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return b3GetBodyUniqueId(m_data->m_physicsClientHandle, bodyId);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::removeBody(int bodyUniqueId)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (b3CanSubmitCommand(m_data->m_physicsClientHandle))
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, b3InitRemoveBodyCommand(m_data->m_physicsClientHandle, bodyUniqueId));
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_REMOVE_BODY_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
return true;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("getDynamicsInfo did not complete");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b3Warning("removeBody could not submit command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getDynamicsInfo(int bodyUniqueId, int linkIndex, b3DynamicsInfo* dynamicsInfo)
|
|
|
|
{
|
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int status_type = 0;
|
|
|
|
b3SharedMemoryCommandHandle cmd_handle;
|
|
|
|
b3SharedMemoryStatusHandle status_handle;
|
|
|
|
// struct b3DynamicsInfo info;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (bodyUniqueId < 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("getDynamicsInfo failed; invalid bodyUniqueId");
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (linkIndex < -1)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("getDynamicsInfo failed; invalid linkIndex");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (b3CanSubmitCommand(m_data->m_physicsClientHandle))
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
cmd_handle = b3GetDynamicsInfoCommandInit(m_data->m_physicsClientHandle, bodyUniqueId, linkIndex);
|
|
|
|
status_handle = b3SubmitClientCommandAndWaitStatus(m_data->m_physicsClientHandle, cmd_handle);
|
|
|
|
status_type = b3GetStatusType(status_handle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (status_type == CMD_GET_DYNAMICS_INFO_COMPLETED)
|
|
|
|
{
|
2018-05-29 14:41:37 +00:00
|
|
|
b3GetDynamicsInfo(status_handle, dynamicsInfo);
|
2018-02-03 02:33:29 +00:00
|
|
|
return true;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("getDynamicsInfo did not complete");
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("getDynamicsInfo could not submit command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::changeDynamics(int bodyUniqueId, int linkIndex, struct b3RobotSimulatorChangeDynamicsArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected to physics server.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitChangeDynamicsInfo(sm);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
|
2018-08-26 23:14:36 +00:00
|
|
|
if (args.m_activationState >= 0)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
b3ChangeDynamicsInfoSetActivationState(command, bodyUniqueId, args.m_activationState);
|
2018-08-26 23:14:36 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_mass >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetMass(command, bodyUniqueId, linkIndex, args.m_mass);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_lateralFriction >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetLateralFriction(command, bodyUniqueId, linkIndex, args.m_lateralFriction);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_spinningFriction >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetSpinningFriction(command, bodyUniqueId, linkIndex, args.m_spinningFriction);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_rollingFriction >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetRollingFriction(command, bodyUniqueId, linkIndex, args.m_rollingFriction);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_linearDamping >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetLinearDamping(command, bodyUniqueId, args.m_linearDamping);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_angularDamping >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetAngularDamping(command, bodyUniqueId, args.m_angularDamping);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_restitution >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetRestitution(command, bodyUniqueId, linkIndex, args.m_restitution);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_contactStiffness >= 0 && args.m_contactDamping >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3ChangeDynamicsInfoSetContactStiffnessAndDamping(command, bodyUniqueId, linkIndex, args.m_contactStiffness, args.m_contactDamping);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_frictionAnchor >= 0)
|
|
|
|
{
|
|
|
|
b3ChangeDynamicsInfoSetFrictionAnchor(command, bodyUniqueId, linkIndex, args.m_frictionAnchor);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::addUserDebugParameter(char* paramName, double rangeMin, double rangeMax, double startValue)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected to physics server.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
commandHandle = b3InitUserDebugAddParameter(sm, paramName, rangeMin, rangeMax, startValue);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_USER_DEBUG_DRAW_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
int debugItemUniqueId = b3GetDebugItemUniqueId(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
return debugItemUniqueId;
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
b3Warning("addUserDebugParameter failed.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
double b3RobotSimulatorClientAPI_NoDirect::readUserDebugParameter(int itemUniqueId)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected to physics server.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
commandHandle = b3InitUserDebugReadParameter(sm, itemUniqueId);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_USER_DEBUG_DRAW_PARAMETER_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
double paramValue = 0.f;
|
|
|
|
int ok = b3GetStatusDebugParameterValue(statusHandle, ¶mValue);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (ok)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
return paramValue;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
b3Warning("readUserDebugParameter failed.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::removeUserDebugItem(int itemUniqueId)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected to physics server.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
commandHandle = b3InitUserDebugDrawRemove(sm, itemUniqueId);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::addUserDebugText(char* text, double* textPosition, struct b3RobotSimulatorAddUserDebugTextArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected to physics server.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
2018-06-01 00:58:12 +00:00
|
|
|
commandHandle = b3InitUserDebugDrawAddText3D(sm, text, textPosition, &args.m_colorRGB[0], args.m_size, args.m_lifeTime);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_parentObjectUniqueId >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3UserDebugItemSetParentObject(commandHandle, args.m_parentObjectUniqueId, args.m_parentLinkIndex);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_flags & DEBUG_TEXT_HAS_ORIENTATION)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3UserDebugTextSetOrientation(commandHandle, &args.m_textOrientation[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_USER_DEBUG_DRAW_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
int debugItemUniqueId = b3GetDebugItemUniqueId(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
return debugItemUniqueId;
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
b3Warning("addUserDebugText3D failed.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::addUserDebugText(char* text, btVector3& textPosition, struct b3RobotSimulatorAddUserDebugTextArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
double dposXYZ[3];
|
2018-06-01 00:58:12 +00:00
|
|
|
dposXYZ[0] = textPosition.x();
|
|
|
|
dposXYZ[1] = textPosition.y();
|
|
|
|
dposXYZ[2] = textPosition.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
return addUserDebugText(text, &dposXYZ[0], args);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::addUserDebugLine(double* fromXYZ, double* toXYZ, struct b3RobotSimulatorAddUserDebugLineArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected to physics server.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
commandHandle = b3InitUserDebugDrawAddLine3D(sm, fromXYZ, toXYZ, &args.m_colorRGB[0], args.m_lineWidth, args.m_lifeTime);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_parentObjectUniqueId >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3UserDebugItemSetParentObject(commandHandle, args.m_parentObjectUniqueId, args.m_parentLinkIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_USER_DEBUG_DRAW_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
int debugItemUniqueId = b3GetDebugItemUniqueId(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
return debugItemUniqueId;
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
b3Warning("addUserDebugLine failed.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::addUserDebugLine(btVector3& fromXYZ, btVector3& toXYZ, struct b3RobotSimulatorAddUserDebugLineArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
double dfromXYZ[3];
|
|
|
|
double dtoXYZ[3];
|
2018-05-27 00:42:33 +00:00
|
|
|
dfromXYZ[0] = fromXYZ.x();
|
|
|
|
dfromXYZ[1] = fromXYZ.y();
|
|
|
|
dfromXYZ[2] = fromXYZ.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
dtoXYZ[0] = toXYZ.x();
|
|
|
|
dtoXYZ[1] = toXYZ.y();
|
|
|
|
dtoXYZ[2] = toXYZ.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
return addUserDebugLine(&dfromXYZ[0], &dtoXYZ[0], args);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::setJointMotorControlArray(int bodyUniqueId, struct b3RobotSimulatorJointMotorArrayArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected to physics server.");
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-06 23:10:20 +00:00
|
|
|
b3GetNumJoints(sm, bodyUniqueId);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
// int statusType;
|
|
|
|
struct b3JointInfo info;
|
|
|
|
|
|
|
|
commandHandle = b3JointControlCommandInit2(sm, bodyUniqueId, args.m_controlMode);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < args.m_numControlledDofs; i++)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
double targetVelocity = 0.0;
|
|
|
|
double targetPosition = 0.0;
|
|
|
|
double force = 100000.0;
|
|
|
|
double kp = 0.1;
|
|
|
|
double kd = 1.0;
|
|
|
|
int jointIndex;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_jointIndices)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
jointIndex = args.m_jointIndices[i];
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
jointIndex = i;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_targetVelocities)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
targetVelocity = args.m_targetVelocities[i];
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_targetPositions)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
targetPosition = args.m_targetPositions[i];
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_forces)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
force = args.m_forces[i];
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_kps)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
kp = args.m_kps[i];
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_kds)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
kd = args.m_kds[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
b3GetJointInfo(sm, bodyUniqueId, jointIndex, &info);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
switch (args.m_controlMode)
|
|
|
|
{
|
|
|
|
case CONTROL_MODE_VELOCITY:
|
|
|
|
{
|
|
|
|
b3JointControlSetDesiredVelocity(commandHandle, info.m_uIndex, targetVelocity);
|
|
|
|
b3JointControlSetKd(commandHandle, info.m_uIndex, kd);
|
|
|
|
b3JointControlSetMaximumForce(commandHandle, info.m_uIndex, force);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CONTROL_MODE_TORQUE:
|
|
|
|
{
|
|
|
|
b3JointControlSetDesiredForceTorque(commandHandle, info.m_uIndex, force);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case CONTROL_MODE_POSITION_VELOCITY_PD:
|
|
|
|
{
|
|
|
|
b3JointControlSetDesiredPosition(commandHandle, info.m_qIndex, targetPosition);
|
|
|
|
b3JointControlSetKp(commandHandle, info.m_uIndex, kp);
|
|
|
|
b3JointControlSetDesiredVelocity(commandHandle, info.m_uIndex, targetVelocity);
|
|
|
|
b3JointControlSetKd(commandHandle, info.m_uIndex, kd);
|
|
|
|
b3JointControlSetMaximumForce(commandHandle, info.m_uIndex, force);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getPhysicsEngineParameters(struct b3RobotSimulatorSetPhysicsEngineParameters& args)
|
2018-06-10 02:40:12 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-06-10 02:40:12 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitRequestPhysicsParamCommand(sm);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType != CMD_REQUEST_PHYSICS_SIMULATION_PARAMETERS_COMPLETED)
|
2018-06-10 02:40:12 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
b3GetStatusPhysicsSimulationParameters(statusHandle, &args);
|
2018-06-10 02:40:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::setPhysicsEngineParameter(const struct b3RobotSimulatorSetPhysicsEngineParameters& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command = b3InitPhysicsParamCommand(sm);
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_numSolverIterations >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsParamSetNumSolverIterations(command, args.m_numSolverIterations);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_collisionFilterMode >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsParamSetCollisionFilterMode(command, args.m_collisionFilterMode);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_numSimulationSubSteps >= 0)
|
|
|
|
{
|
2018-06-10 02:40:12 +00:00
|
|
|
b3PhysicsParamSetNumSubSteps(command, args.m_numSimulationSubSteps);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_deltaTime >= 0)
|
|
|
|
{
|
2018-06-10 02:40:12 +00:00
|
|
|
b3PhysicsParamSetTimeStep(command, args.m_deltaTime);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_useSplitImpulse >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsParamSetUseSplitImpulse(command, args.m_useSplitImpulse);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_splitImpulsePenetrationThreshold >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsParamSetSplitImpulsePenetrationThreshold(command, args.m_splitImpulsePenetrationThreshold);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_contactBreakingThreshold >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsParamSetContactBreakingThreshold(command, args.m_contactBreakingThreshold);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_restitutionVelocityThreshold >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsParamSetRestitutionVelocityThreshold(command, args.m_restitutionVelocityThreshold);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_enableFileCaching >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3PhysicsParamSetEnableFileCaching(command, args.m_enableFileCaching);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_defaultNonContactERP >= 0)
|
|
|
|
{
|
|
|
|
b3PhysicsParamSetDefaultNonContactERP(command, args.m_defaultNonContactERP);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_defaultContactERP >= 0)
|
|
|
|
{
|
|
|
|
b3PhysicsParamSetDefaultContactERP(command, args.m_defaultContactERP);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_frictionERP >= 0)
|
|
|
|
{
|
|
|
|
b3PhysicsParamSetDefaultFrictionERP(command, args.m_frictionERP);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_solverResidualThreshold >= 0)
|
|
|
|
{
|
2018-05-29 14:23:17 +00:00
|
|
|
b3PhysicsParamSetSolverResidualThreshold(command, args.m_solverResidualThreshold);
|
|
|
|
}
|
|
|
|
|
2018-08-26 23:14:36 +00:00
|
|
|
if (args.m_constraintSolverType >= 0)
|
|
|
|
{
|
|
|
|
b3PhysicsParameterSetConstraintSolverType(command, args.m_constraintSolverType);
|
|
|
|
}
|
|
|
|
if (args.m_minimumSolverIslandSize >= 0)
|
|
|
|
{
|
|
|
|
b3PhysicsParameterSetMinimumSolverIslandSize(command, args.m_minimumSolverIslandSize);
|
|
|
|
}
|
|
|
|
|
2018-02-03 02:33:29 +00:00
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::applyExternalForce(int objectUniqueId, int linkIndex, double* force, double* position, int flags)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
|
|
|
|
command = b3ApplyExternalForceCommandInit(sm);
|
|
|
|
b3ApplyExternalForce(command, objectUniqueId, linkIndex, force, position, flags);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::applyExternalForce(int objectUniqueId, int linkIndex, btVector3& force, btVector3& position, int flags)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
double dforce[3];
|
|
|
|
double dposition[3];
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
dforce[0] = force.x();
|
|
|
|
dforce[1] = force.y();
|
|
|
|
dforce[2] = force.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
dposition[0] = position.x();
|
|
|
|
dposition[1] = position.y();
|
|
|
|
dposition[2] = position.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
return applyExternalForce(objectUniqueId, linkIndex, &dforce[0], &dposition[0], flags);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::applyExternalTorque(int objectUniqueId, int linkIndex, double* torque, int flags)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
|
|
|
|
command = b3ApplyExternalForceCommandInit(sm);
|
|
|
|
b3ApplyExternalTorque(command, objectUniqueId, linkIndex, torque, flags);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::applyExternalTorque(int objectUniqueId, int linkIndex, btVector3& torque, int flags)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
double dtorque[3];
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
dtorque[0] = torque.x();
|
|
|
|
dtorque[1] = torque.y();
|
|
|
|
dtorque[2] = torque.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
return applyExternalTorque(objectUniqueId, linkIndex, &dtorque[0], flags);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::enableJointForceTorqueSensor(int bodyUniqueId, int jointIndex, bool enable)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int numJoints = b3GetNumJoints(sm, bodyUniqueId);
|
2018-09-23 21:17:31 +00:00
|
|
|
if ((jointIndex < 0) || (jointIndex >= numJoints))
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Error: invalid jointIndex.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
command = b3CreateSensorCommandInit(sm, bodyUniqueId);
|
|
|
|
b3CreateSensorEnable6DofJointForceTorqueSensor(command, jointIndex, enable);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CLIENT_COMMAND_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getDebugVisualizerCamera(struct b3OpenGLVisualizerCameraInfo* cameraInfo)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
command = b3InitRequestOpenGLVisualizerCameraCommand(sm);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusOpenGLVisualizerCamera(statusHandle, cameraInfo);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getContactPoints(struct b3RobotSimulatorGetContactPointsArgs& args, struct b3ContactInformation* contactInfo)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
command = b3InitRequestContactPointInformation(sm);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_bodyUniqueIdA >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SetContactFilterBodyA(command, args.m_bodyUniqueIdA);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_bodyUniqueIdB >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SetContactFilterBodyB(command, args.m_bodyUniqueIdB);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_linkIndexA >= -1)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SetContactFilterLinkA(command, args.m_linkIndexA);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_linkIndexB >= -1)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SetContactFilterLinkB(command, args.m_linkIndexB);
|
|
|
|
}
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CONTACT_POINT_INFORMATION_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3GetContactPointInformation(sm, contactInfo);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getClosestPoints(struct b3RobotSimulatorGetContactPointsArgs& args, double distance, struct b3ContactInformation* contactInfo)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
command = b3InitClosestDistanceQuery(sm);
|
|
|
|
|
|
|
|
b3SetClosestDistanceFilterBodyA(command, args.m_bodyUniqueIdA);
|
|
|
|
b3SetClosestDistanceFilterBodyB(command, args.m_bodyUniqueIdB);
|
|
|
|
b3SetClosestDistanceThreshold(command, distance);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_linkIndexA >= -1)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SetClosestDistanceFilterLinkA(command, args.m_linkIndexA);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (args.m_linkIndexB >= -1)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3SetClosestDistanceFilterLinkB(command, args.m_linkIndexB);
|
|
|
|
}
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CONTACT_POINT_INFORMATION_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3GetContactPointInformation(sm, contactInfo);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getOverlappingObjects(double* aabbMin, double* aabbMax, struct b3AABBOverlapData* overlapData)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
// int statusType;
|
|
|
|
|
|
|
|
command = b3InitAABBOverlapQuery(sm, aabbMin, aabbMax);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
b3GetAABBOverlapResults(sm, overlapData);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getOverlappingObjects(btVector3& aabbMin, btVector3& aabbMax, struct b3AABBOverlapData* overlapData)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
double daabbMin[3];
|
|
|
|
double daabbMax[3];
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
daabbMin[0] = aabbMin.x();
|
|
|
|
daabbMin[1] = aabbMin.y();
|
|
|
|
daabbMin[2] = aabbMin.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
daabbMax[0] = aabbMax.x();
|
|
|
|
daabbMax[1] = aabbMax.y();
|
|
|
|
daabbMax[2] = aabbMax.z();
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
return getOverlappingObjects(&daabbMin[0], &daabbMax[0], overlapData);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getAABB(int bodyUniqueId, int linkIndex, double* aabbMin, double* aabbMax)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (bodyUniqueId < 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Invalid bodyUniqueId");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (linkIndex < -1)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Invalid linkIndex");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (aabbMin == NULL || aabbMax == NULL)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Output AABB matrix is NULL");
|
|
|
|
return false;
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
command = b3RequestCollisionInfoCommandInit(sm, bodyUniqueId);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType != CMD_REQUEST_COLLISION_INFO_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (b3GetStatusAABB(statusHandle, linkIndex, aabbMin, aabbMax))
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getAABB(int bodyUniqueId, int linkIndex, btVector3& aabbMin, btVector3& aabbMax)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
double daabbMin[3];
|
|
|
|
double daabbMax[3];
|
|
|
|
|
|
|
|
bool status = getAABB(bodyUniqueId, linkIndex, &daabbMin[0], &daabbMax[0]);
|
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
aabbMin[0] = (float)daabbMin[0];
|
|
|
|
aabbMin[1] = (float)daabbMin[1];
|
|
|
|
aabbMin[2] = (float)daabbMin[2];
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-05-27 00:42:33 +00:00
|
|
|
aabbMax[0] = (float)daabbMax[0];
|
|
|
|
aabbMax[1] = (float)daabbMax[1];
|
|
|
|
aabbMax[2] = (float)daabbMax[2];
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::createCollisionShape(int shapeType, struct b3RobotSimulatorCreateCollisionShapeArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
int shapeIndex = -1;
|
|
|
|
|
|
|
|
command = b3CreateCollisionShapeCommandInit(sm);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeType == GEOM_SPHERE && args.m_radius > 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
shapeIndex = b3CreateCollisionShapeAddSphere(command, args.m_radius);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeType == GEOM_BOX)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
double halfExtents[3];
|
|
|
|
scalarToDouble3(args.m_halfExtents, halfExtents);
|
|
|
|
shapeIndex = b3CreateCollisionShapeAddBox(command, halfExtents);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeType == GEOM_CAPSULE && args.m_radius > 0 && args.m_height >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
shapeIndex = b3CreateCollisionShapeAddCapsule(command, args.m_radius, args.m_height);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeType == GEOM_CYLINDER && args.m_radius > 0 && args.m_height >= 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
shapeIndex = b3CreateCollisionShapeAddCylinder(command, args.m_radius, args.m_height);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeType == GEOM_MESH && args.m_fileName)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
double meshScale[3];
|
|
|
|
scalarToDouble3(args.m_meshScale, meshScale);
|
|
|
|
shapeIndex = b3CreateCollisionShapeAddMesh(command, args.m_fileName, meshScale);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeType == GEOM_PLANE)
|
|
|
|
{
|
|
|
|
double planeConstant = 0;
|
2018-02-03 02:33:29 +00:00
|
|
|
double planeNormal[3];
|
|
|
|
scalarToDouble3(args.m_planeNormal, planeNormal);
|
|
|
|
shapeIndex = b3CreateCollisionShapeAddPlane(command, planeNormal, planeConstant);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (shapeIndex >= 0 && args.m_flags)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3CreateCollisionSetFlag(command, shapeIndex, args.m_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CREATE_COLLISION_SHAPE_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
int uid = b3GetStatusCollisionShapeUniqueId(statusHandle);
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::createMultiBody(struct b3RobotSimulatorCreateMultiBodyArgs& args)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType, baseIndex;
|
|
|
|
|
|
|
|
double doubleBasePosition[3];
|
|
|
|
double doubleBaseInertialFramePosition[3];
|
|
|
|
scalarToDouble3(args.m_basePosition.m_floats, doubleBasePosition);
|
|
|
|
scalarToDouble3(args.m_baseInertialFramePosition.m_floats, doubleBaseInertialFramePosition);
|
|
|
|
|
|
|
|
double doubleBaseOrientation[4];
|
|
|
|
double doubleBaseInertialFrameOrientation[4];
|
2018-05-27 00:42:33 +00:00
|
|
|
scalarToDouble4(args.m_baseOrientation, doubleBaseOrientation);
|
|
|
|
scalarToDouble4(args.m_baseInertialFrameOrientation, doubleBaseInertialFrameOrientation);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
command = b3CreateMultiBodyCommandInit(sm);
|
|
|
|
|
2019-02-12 18:36:01 +00:00
|
|
|
if (args.m_useMaximalCoordinates)
|
|
|
|
{
|
|
|
|
b3CreateMultiBodyUseMaximalCoordinates(command);
|
|
|
|
}
|
|
|
|
if (args.m_batchPositions.size())
|
|
|
|
{
|
|
|
|
btAlignedObjectArray<double> positionArray;
|
|
|
|
for (int i = 0; i < args.m_batchPositions.size(); i++)
|
|
|
|
{
|
|
|
|
positionArray.push_back(args.m_batchPositions[i][0]);
|
|
|
|
positionArray.push_back(args.m_batchPositions[i][1]);
|
|
|
|
positionArray.push_back(args.m_batchPositions[i][2]);
|
|
|
|
}
|
|
|
|
b3CreateMultiBodySetBatchPositions(sm, command, &positionArray[0], args.m_batchPositions.size());
|
|
|
|
}
|
2018-02-03 02:33:29 +00:00
|
|
|
baseIndex = b3CreateMultiBodyBase(command, args.m_baseMass, args.m_baseCollisionShapeIndex, args.m_baseVisualShapeIndex,
|
2018-09-23 21:17:31 +00:00
|
|
|
doubleBasePosition, doubleBaseOrientation, doubleBaseInertialFramePosition, doubleBaseInertialFrameOrientation);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < args.m_numLinks; i++)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
double linkMass = args.m_linkMasses[i];
|
|
|
|
int linkCollisionShapeIndex = args.m_linkCollisionShapeIndices[i];
|
|
|
|
int linkVisualShapeIndex = args.m_linkVisualShapeIndices[i];
|
2018-05-27 00:42:33 +00:00
|
|
|
btVector3 linkPosition = args.m_linkPositions[i];
|
|
|
|
btQuaternion linkOrientation = args.m_linkOrientations[i];
|
|
|
|
btVector3 linkInertialFramePosition = args.m_linkInertialFramePositions[i];
|
|
|
|
btQuaternion linkInertialFrameOrientation = args.m_linkInertialFrameOrientations[i];
|
2018-02-03 02:33:29 +00:00
|
|
|
int linkParentIndex = args.m_linkParentIndices[i];
|
|
|
|
int linkJointType = args.m_linkJointTypes[i];
|
2018-05-27 00:42:33 +00:00
|
|
|
btVector3 linkJointAxis = args.m_linkJointAxes[i];
|
2018-02-03 02:33:29 +00:00
|
|
|
|
|
|
|
double doubleLinkPosition[3];
|
|
|
|
double doubleLinkInertialFramePosition[3];
|
|
|
|
double doubleLinkJointAxis[3];
|
|
|
|
scalarToDouble3(linkPosition.m_floats, doubleLinkPosition);
|
|
|
|
scalarToDouble3(linkInertialFramePosition.m_floats, doubleLinkInertialFramePosition);
|
|
|
|
scalarToDouble3(linkJointAxis.m_floats, doubleLinkJointAxis);
|
|
|
|
|
|
|
|
double doubleLinkOrientation[4];
|
|
|
|
double doubleLinkInertialFrameOrientation[4];
|
2018-05-27 00:42:33 +00:00
|
|
|
scalarToDouble4(linkOrientation, doubleLinkOrientation);
|
|
|
|
scalarToDouble4(linkInertialFrameOrientation, doubleLinkInertialFrameOrientation);
|
2018-02-03 02:33:29 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CreateMultiBodyLink(command,
|
|
|
|
linkMass,
|
|
|
|
linkCollisionShapeIndex,
|
|
|
|
linkVisualShapeIndex,
|
|
|
|
doubleLinkPosition,
|
|
|
|
doubleLinkOrientation,
|
|
|
|
doubleLinkInertialFramePosition,
|
|
|
|
doubleLinkInertialFrameOrientation,
|
|
|
|
linkParentIndex,
|
|
|
|
linkJointType,
|
|
|
|
doubleLinkJointAxis);
|
2018-02-03 02:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_CREATE_MULTI_BODY_COMPLETED)
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
int uid = b3GetStatusBodyIndex(statusHandle);
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::getNumConstraints() const
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return b3GetNumUserConstraints(m_data->m_physicsClientHandle);
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::getConstraintUniqueId(int serialIndex)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (!isConnected())
|
|
|
|
{
|
2018-02-03 02:33:29 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
int userConstraintId = -1;
|
|
|
|
userConstraintId = b3GetUserConstraintId(m_data->m_physicsClientHandle, serialIndex);
|
|
|
|
return userConstraintId;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setGuiHelper(struct GUIHelperInterface* guiHelper)
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
m_data->m_guiHelper = guiHelper;
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
struct GUIHelperInterface* b3RobotSimulatorClientAPI_NoDirect::getGuiHelper()
|
2018-02-03 02:33:29 +00:00
|
|
|
{
|
|
|
|
return m_data->m_guiHelper;
|
2018-06-01 00:58:12 +00:00
|
|
|
}
|
2018-05-29 14:23:17 +00:00
|
|
|
|
2018-06-05 01:41:41 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setInternalData(struct b3RobotSimulatorClientAPI_InternalData* data)
|
|
|
|
{
|
|
|
|
*m_data = *data;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getCollisionShapeData(int bodyUniqueId, int linkIndex,
|
2018-09-23 21:17:31 +00:00
|
|
|
b3CollisionShapeInformation& collisionShapeInfo)
|
2018-05-29 14:23:17 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-05-29 14:23:17 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
{
|
|
|
|
command = b3InitRequestCollisionShapeInformation(sm, bodyUniqueId, linkIndex);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
btAssert(statusType == CMD_COLLISION_SHAPE_INFO_COMPLETED);
|
2018-09-23 21:17:31 +00:00
|
|
|
if (statusType == CMD_COLLISION_SHAPE_INFO_COMPLETED)
|
|
|
|
{
|
2018-05-29 14:23:17 +00:00
|
|
|
b3GetCollisionShapeInformation(sm, &collisionShapeInfo);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-09 20:54:22 +00:00
|
|
|
int b3RobotSimulatorClientAPI_NoDirect::saveStateToMemory()
|
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-06-09 20:54:22 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-06-09 20:54:22 +00:00
|
|
|
int stateId = -1;
|
|
|
|
|
|
|
|
if (sm == 0)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
command = b3SaveStateCommandInit(sm);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
|
|
|
|
if (statusType != CMD_SAVE_STATE_COMPLETED)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
stateId = b3GetStatusGetStateId(statusHandle);
|
|
|
|
return stateId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::restoreStateFromMemory(int stateId)
|
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-06-09 20:54:22 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int statusType;
|
|
|
|
b3SharedMemoryCommandHandle command;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int physicsClientId = 0;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2018-06-09 20:54:22 +00:00
|
|
|
command = b3LoadStateCommandInit(sm);
|
|
|
|
if (stateId >= 0)
|
|
|
|
{
|
|
|
|
b3LoadStateSetStateId(command, stateId);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
// if (fileName)
|
|
|
|
// {
|
|
|
|
// b3LoadStateSetFileName(command, fileName);
|
|
|
|
// }
|
2018-06-09 20:54:22 +00:00
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool b3RobotSimulatorClientAPI_NoDirect::getVisualShapeData(int bodyUniqueId, b3VisualShapeInformation& visualShapeInfo)
|
2018-05-29 14:23:17 +00:00
|
|
|
{
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-07-08 09:23:12 +00:00
|
|
|
if (sm == 0)
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
2018-05-29 14:23:17 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
commandHandle = b3InitRequestVisualShapeInformation(sm, bodyUniqueId);
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
2018-05-29 14:23:17 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btAssert(statusType == CMD_VISUAL_SHAPE_INFO_COMPLETED);
|
|
|
|
if (statusType == CMD_VISUAL_SHAPE_INFO_COMPLETED)
|
|
|
|
{
|
|
|
|
b3GetVisualShapeInformation(sm, &visualShapeInfo);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-05-29 14:23:17 +00:00
|
|
|
}
|
2018-06-09 20:54:22 +00:00
|
|
|
|
2018-06-13 04:26:34 +00:00
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setAdditionalSearchPath(const std::string& path)
|
2018-06-09 20:54:22 +00:00
|
|
|
{
|
|
|
|
int physicsClientId = 0;
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
2018-09-23 21:17:31 +00:00
|
|
|
if (sm == 0)
|
|
|
|
{
|
2018-06-09 20:54:22 +00:00
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (path.length())
|
|
|
|
{
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
commandHandle = b3SetAdditionalSearchPath(sm, path.c_str());
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 20:12:49 +00:00
|
|
|
|
|
|
|
void b3RobotSimulatorClientAPI_NoDirect::setCollisionFilterGroupMask(int bodyUniqueIdA, int linkIndexA, int collisionFilterGroup, int collisionFilterMask)
|
|
|
|
{
|
|
|
|
int physicsClientId = 0;
|
|
|
|
b3PhysicsClientHandle sm = m_data->m_physicsClientHandle;
|
|
|
|
if (sm == 0)
|
|
|
|
{
|
|
|
|
b3Warning("Not connected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
b3SharedMemoryCommandHandle commandHandle;
|
|
|
|
b3SharedMemoryStatusHandle statusHandle;
|
|
|
|
int statusType;
|
|
|
|
|
|
|
|
commandHandle = b3CollisionFilterCommandInit(sm);
|
|
|
|
b3SetCollisionFilterGroupMask(commandHandle, bodyUniqueIdA, linkIndexA, collisionFilterGroup, collisionFilterMask);
|
|
|
|
|
|
|
|
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
|
|
|
|
statusType = b3GetStatusType(statusHandle);
|
|
|
|
}
|
|
|
|
|