PyBullet / BulletRobotics: prepare for pdControlPlugin and collisionFilterPlugin

Split examples/SharedMemory/b3RobotSimulatorClientAPI_NoGUI.* and move to examples/SharedMemory/b3RobotSimulatorClientAPI_NoGUI.cpp and examples/SharedMemory/b3RobotSimulatorClientAPI_NoDirect.cpp
This commit is contained in:
Erwin Coumans
2018-06-05 11:41:41 +10:00
parent e4cd88e24f
commit 7bd84740d7
23 changed files with 719 additions and 198 deletions

View File

@@ -45,6 +45,9 @@
#include "../Extras/Serialize/BulletFileLoader/btBulletFile.h"
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
#ifdef STATIC_PD_CONTROL_PLUGIN
#include "plugins/pdControlPlugin/pdControlPlugin.h"
#endif //STATIC_PD_CONTROL_PLUGIN
#ifdef STATIC_LINK_VR_PLUGIN
#include "plugins/vrSyncPlugin/vrSyncPlugin.h"
@@ -1647,7 +1650,7 @@ struct PhysicsServerCommandProcessorInternalData
btVector3 m_hitPos;
btScalar m_oldPickingDist;
bool m_prevCanSleep;
int m_pdControlPlugin;
#ifdef B3_ENABLE_TINY_AUDIO
b3SoundEngine m_soundEngine;
#endif
@@ -1679,15 +1682,23 @@ struct PhysicsServerCommandProcessorInternalData
m_verboseOutput(false),
m_pickedBody(0),
m_pickedConstraint(0),
m_pickingMultiBodyPoint2Point(0)
m_pickingMultiBodyPoint2Point(0),
m_pdControlPlugin(-1)
{
{
//register static plugins:
#ifdef STATIC_LINK_VR_PLUGIN
m_pluginManager.registerStaticLinkedPlugin("vrSyncPlugin", initPlugin_vrSyncPlugin, exitPlugin_vrSyncPlugin, executePluginCommand_vrSyncPlugin,preTickPluginCallback_vrSyncPlugin,0,0);
m_pluginManager.registerStaticLinkedPlugin("vrSyncPlugin", initPlugin_vrSyncPlugin, exitPlugin_vrSyncPlugin, executePluginCommand_vrSyncPlugin, preTickPluginCallback_vrSyncPlugin, 0, 0);
#endif //STATIC_LINK_VR_PLUGIN
#ifdef STATIC_PD_CONTROL_PLUGIN
{
m_pdControlPlugin = m_pluginManager.registerStaticLinkedPlugin("pdControlPlugin", initPlugin_pdControlPlugin, exitPlugin_pdControlPlugin, executePluginCommand_pdControlPlugin, preTickPluginCallback_pdControlPlugin, postTickPluginCallback_pdControlPlugin, 0);
}
#endif //STATIC_PD_CONTROL_PLUGIN
#ifndef SKIP_STATIC_TINYRENDERER_PLUGIN
int renderPluginId = m_pluginManager.registerStaticLinkedPlugin("tinyRendererPlugin", initPlugin_tinyRendererPlugin, exitPlugin_tinyRendererPlugin, executePluginCommand_tinyRendererPlugin,0,0,getRenderInterface_tinyRendererPlugin);
m_pluginManager.selectPluginRenderer(renderPluginId);
@@ -4949,6 +4960,13 @@ bool PhysicsServerCommandProcessor::processSendDesiredStateCommand(const struct
switch (clientCmd.m_sendDesiredStateCommandArgument.m_controlMode)
{
/* case CONTROL_MODE_PD:
{
b3PluginArguments args;
m_data->m_pluginManager.executePluginCommand(pdControlPlugin, args);
//#p.executePluginCommand(plugin ,"r2d2.urdf", [1,2,3],[50.0,3.3])
}
*/
case CONTROL_MODE_TORQUE:
{
if (m_data->m_verboseOutput)

View File

@@ -0,0 +1,18 @@
#ifndef B3_ROBOT_SIMULATOR_CLIENT_API_INTERNAL_DATA_H
#define B3_ROBOT_SIMULATOR_CLIENT_API_INTERNAL_DATA_H
#include "../SharedMemory/PhysicsClientC_API.h"
struct b3RobotSimulatorClientAPI_InternalData
{
b3PhysicsClientHandle m_physicsClientHandle;
struct GUIHelperInterface* m_guiHelper;
b3RobotSimulatorClientAPI_InternalData()
: m_physicsClientHandle(0),
m_guiHelper(0)
{
}
};
#endif //B3_ROBOT_SIMULATOR_CLIENT_API_INTERNAL_DATA_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,589 @@
#ifndef B3_ROBOT_SIMULATOR_CLIENT_API_NO_DIRECT_H
#define B3_ROBOT_SIMULATOR_CLIENT_API_NO_DIRECT_H
///The b3RobotSimulatorClientAPI is pretty much the C++ version of pybullet
///as documented in the pybullet Quickstart Guide
///https://docs.google.com/document/d/10sXEhzFRSnvFcl3XxNGhnD4N2SedqwdAvK3dsihxVUA
#include "SharedMemoryPublic.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btQuaternion.h"
#include "LinearMath/btTransform.h"
#include "LinearMath/btAlignedObjectArray.h"
#include <string>
struct b3RobotSimulatorLoadUrdfFileArgs
{
btVector3 m_startPosition;
btQuaternion m_startOrientation;
bool m_forceOverrideFixedBase;
bool m_useMultiBody;
int m_flags;
b3RobotSimulatorLoadUrdfFileArgs(const btVector3& startPos, const btQuaternion& startOrn)
: m_startPosition(startPos),
m_startOrientation(startOrn),
m_forceOverrideFixedBase(false),
m_useMultiBody(true),
m_flags(0)
{
}
b3RobotSimulatorLoadUrdfFileArgs()
: m_startPosition(btVector3(0, 0, 0)),
m_startOrientation(btQuaternion(0, 0, 0, 1)),
m_forceOverrideFixedBase(false),
m_useMultiBody(true),
m_flags(0)
{
}
};
struct b3RobotSimulatorLoadSdfFileArgs
{
bool m_forceOverrideFixedBase;
bool m_useMultiBody;
b3RobotSimulatorLoadSdfFileArgs()
: m_forceOverrideFixedBase(false),
m_useMultiBody(true)
{
}
};
struct b3RobotSimulatorLoadFileResults
{
btAlignedObjectArray<int> m_uniqueObjectIds;
b3RobotSimulatorLoadFileResults()
{
}
};
struct b3RobotSimulatorJointMotorArgs
{
int m_controlMode;
double m_targetPosition;
double m_kp;
double m_targetVelocity;
double m_kd;
double m_maxTorqueValue;
b3RobotSimulatorJointMotorArgs(int controlMode)
: m_controlMode(controlMode),
m_targetPosition(0),
m_kp(0.1),
m_targetVelocity(0),
m_kd(0.9),
m_maxTorqueValue(1000)
{
}
};
enum b3RobotSimulatorInverseKinematicsFlags
{
B3_HAS_IK_TARGET_ORIENTATION = 1,
B3_HAS_NULL_SPACE_VELOCITY = 2,
B3_HAS_JOINT_DAMPING = 4,
};
struct b3RobotSimulatorInverseKinematicArgs
{
int m_bodyUniqueId;
// double* m_currentJointPositions;
// int m_numPositions;
double m_endEffectorTargetPosition[3];
double m_endEffectorTargetOrientation[4];
int m_endEffectorLinkIndex;
int m_flags;
int m_numDegreeOfFreedom;
btAlignedObjectArray<double> m_lowerLimits;
btAlignedObjectArray<double> m_upperLimits;
btAlignedObjectArray<double> m_jointRanges;
btAlignedObjectArray<double> m_restPoses;
btAlignedObjectArray<double> m_jointDamping;
b3RobotSimulatorInverseKinematicArgs()
: m_bodyUniqueId(-1),
m_endEffectorLinkIndex(-1),
m_flags(0)
{
m_endEffectorTargetPosition[0] = 0;
m_endEffectorTargetPosition[1] = 0;
m_endEffectorTargetPosition[2] = 0;
m_endEffectorTargetOrientation[0] = 0;
m_endEffectorTargetOrientation[1] = 0;
m_endEffectorTargetOrientation[2] = 0;
m_endEffectorTargetOrientation[3] = 1;
}
};
struct b3RobotSimulatorInverseKinematicsResults
{
int m_bodyUniqueId;
btAlignedObjectArray<double> m_calculatedJointPositions;
};
struct b3JointStates2
{
int m_bodyUniqueId;
int m_numDegreeOfFreedomQ;
int m_numDegreeOfFreedomU;
btTransform m_rootLocalInertialFrame;
btAlignedObjectArray<double> m_actualStateQ;
btAlignedObjectArray<double> m_actualStateQdot;
btAlignedObjectArray<double> m_jointReactionForces;
};
struct b3RobotSimulatorJointMotorArrayArgs
{
int m_controlMode;
int m_numControlledDofs;
int *m_jointIndices;
double *m_targetPositions;
double *m_kps;
double *m_targetVelocities;
double *m_kds;
double *m_forces;
b3RobotSimulatorJointMotorArrayArgs(int controlMode, int numControlledDofs)
: m_controlMode(controlMode),
m_numControlledDofs(numControlledDofs),
m_jointIndices(NULL),
m_targetPositions(NULL),
m_kps(NULL),
m_targetVelocities(NULL),
m_kds(NULL),
m_forces(NULL)
{
}
};
struct b3RobotSimulatorGetCameraImageArgs
{
int m_width;
int m_height;
float *m_viewMatrix;
float *m_projectionMatrix;
float *m_lightDirection;
float *m_lightColor;
float m_lightDistance;
int m_hasShadow;
float m_lightAmbientCoeff;
float m_lightDiffuseCoeff;
float m_lightSpecularCoeff;
int m_renderer;
b3RobotSimulatorGetCameraImageArgs(int width, int height)
: m_width(width),
m_height(height),
m_viewMatrix(NULL),
m_projectionMatrix(NULL),
m_lightDirection(NULL),
m_lightColor(NULL),
m_lightDistance(-1),
m_hasShadow(-1),
m_lightAmbientCoeff(-1),
m_lightDiffuseCoeff(-1),
m_lightSpecularCoeff(-1),
m_renderer(-1)
{
}
};
struct b3RobotSimulatorSetPhysicsEngineParameters
{
double m_fixedTimeStep;
int m_numSolverIterations;
int m_useSplitImpulse;
double m_splitImpulsePenetrationThreshold;
int m_numSubSteps;
int m_collisionFilterMode;
double m_contactBreakingThreshold;
int m_maxNumCmdPer1ms;
int m_enableFileCaching;
double m_restitutionVelocityThreshold;
double m_erp;
double m_contactERP;
double m_frictionERP;
double m_solverResidualThreshold;
b3RobotSimulatorSetPhysicsEngineParameters()
: m_fixedTimeStep(-1),
m_numSolverIterations(-1),
m_useSplitImpulse(-1),
m_splitImpulsePenetrationThreshold(-1),
m_numSubSteps(-1),
m_collisionFilterMode(-1),
m_contactBreakingThreshold(-1),
m_maxNumCmdPer1ms(-1),
m_enableFileCaching(-1),
m_restitutionVelocityThreshold(-1),
m_erp(-1),
m_contactERP(-1),
m_frictionERP(-1),
m_solverResidualThreshold(-1)
{}
};
struct b3RobotSimulatorChangeDynamicsArgs
{
double m_mass;
double m_lateralFriction;
double m_spinningFriction;
double m_rollingFriction;
double m_restitution;
double m_linearDamping;
double m_angularDamping;
double m_contactStiffness;
double m_contactDamping;
int m_frictionAnchor;
b3RobotSimulatorChangeDynamicsArgs()
: m_mass(-1),
m_lateralFriction(-1),
m_spinningFriction(-1),
m_rollingFriction(-1),
m_restitution(-1),
m_linearDamping(-1),
m_angularDamping(-1),
m_contactStiffness(-1),
m_contactDamping(-1),
m_frictionAnchor(-1)
{}
};
struct b3RobotSimulatorAddUserDebugLineArgs
{
double m_colorRGB[3];
double m_lineWidth;
double m_lifeTime;
int m_parentObjectUniqueId;
int m_parentLinkIndex;
b3RobotSimulatorAddUserDebugLineArgs()
:
m_lineWidth(1),
m_lifeTime(0),
m_parentObjectUniqueId(-1),
m_parentLinkIndex(-1)
{
m_colorRGB[0] = 1;
m_colorRGB[1] = 1;
m_colorRGB[2] = 1;
}
};
enum b3AddUserDebugTextFlags {
DEBUG_TEXT_HAS_ORIENTATION = 1
};
struct b3RobotSimulatorAddUserDebugTextArgs
{
double m_colorRGB[3];
double m_size;
double m_lifeTime;
double m_textOrientation[4];
int m_parentObjectUniqueId;
int m_parentLinkIndex;
int m_flags;
b3RobotSimulatorAddUserDebugTextArgs()
: m_size(1),
m_lifeTime(0),
m_parentObjectUniqueId(-1),
m_parentLinkIndex(-1),
m_flags(0)
{
m_colorRGB[0] = 1;
m_colorRGB[1] = 1;
m_colorRGB[2] = 1;
m_textOrientation[0] = 0;
m_textOrientation[1] = 0;
m_textOrientation[2] = 0;
m_textOrientation[3] = 1;
}
};
struct b3RobotSimulatorGetContactPointsArgs
{
int m_bodyUniqueIdA;
int m_bodyUniqueIdB;
int m_linkIndexA;
int m_linkIndexB;
b3RobotSimulatorGetContactPointsArgs()
: m_bodyUniqueIdA(-1),
m_bodyUniqueIdB(-1),
m_linkIndexA(-2),
m_linkIndexB(-2)
{}
};
struct b3RobotSimulatorCreateCollisionShapeArgs
{
int m_shapeType;
double m_radius;
btVector3 m_halfExtents;
double m_height;
char* m_fileName;
btVector3 m_meshScale;
btVector3 m_planeNormal;
int m_flags;
b3RobotSimulatorCreateCollisionShapeArgs()
: m_shapeType(-1),
m_radius(0.5),
m_height(1),
m_fileName(NULL),
m_flags(0)
{
m_halfExtents.m_floats[0] = 1;
m_halfExtents.m_floats[1] = 1;
m_halfExtents.m_floats[2] = 1;
m_meshScale.m_floats[0] = 1;
m_meshScale.m_floats[1] = 1;
m_meshScale.m_floats[2] = 1;
m_planeNormal.m_floats[0] = 0;
m_planeNormal.m_floats[1] = 0;
m_planeNormal.m_floats[2] = 1;
}
};
struct b3RobotSimulatorCreateMultiBodyArgs
{
double m_baseMass;
int m_baseCollisionShapeIndex;
int m_baseVisualShapeIndex;
btVector3 m_basePosition;
btQuaternion m_baseOrientation;
btVector3 m_baseInertialFramePosition;
btQuaternion m_baseInertialFrameOrientation;
int m_numLinks;
double *m_linkMasses;
int *m_linkCollisionShapeIndices;
int *m_linkVisualShapeIndices;
btVector3 *m_linkPositions;
btQuaternion *m_linkOrientations;
btVector3 *m_linkInertialFramePositions;
btQuaternion *m_linkInertialFrameOrientations;
int *m_linkParentIndices;
int *m_linkJointTypes;
btVector3 *m_linkJointAxes;
int m_useMaximalCoordinates;
b3RobotSimulatorCreateMultiBodyArgs()
: m_numLinks(0), m_baseMass(0), m_baseCollisionShapeIndex(-1), m_baseVisualShapeIndex(-1), m_useMaximalCoordinates(0),
m_linkMasses(NULL),
m_linkCollisionShapeIndices(NULL),
m_linkVisualShapeIndices(NULL),
m_linkPositions(NULL),
m_linkOrientations(NULL),
m_linkInertialFramePositions(NULL),
m_linkInertialFrameOrientations(NULL),
m_linkParentIndices(NULL),
m_linkJointTypes(NULL),
m_linkJointAxes(NULL)
{
m_basePosition.setValue(0,0,0);
m_baseOrientation.setValue(0,0,0,1);
m_baseInertialFramePosition.setValue(0,0,0);
m_baseInertialFrameOrientation.setValue(0,0,0,1);
}
};
class b3RobotSimulatorClientAPI_NoDirect
{
protected:
struct b3RobotSimulatorClientAPI_InternalData* m_data;
public:
b3RobotSimulatorClientAPI_NoDirect();
virtual ~b3RobotSimulatorClientAPI_NoDirect();
bool connect(int mode, const std::string& hostName = "localhost", int portOrKey = -1);
void disconnect();
bool isConnected() const;
void setTimeOut(double timeOutInSec);
void syncBodies();
void resetSimulation();
btQuaternion getQuaternionFromEuler(const btVector3& rollPitchYaw);
btVector3 getEulerFromQuaternion(const btQuaternion& quat);
int loadURDF(const std::string& fileName, const struct b3RobotSimulatorLoadUrdfFileArgs& args = b3RobotSimulatorLoadUrdfFileArgs());
bool loadSDF(const std::string& fileName, b3RobotSimulatorLoadFileResults& results, const struct b3RobotSimulatorLoadSdfFileArgs& args = b3RobotSimulatorLoadSdfFileArgs());
bool loadMJCF(const std::string& fileName, b3RobotSimulatorLoadFileResults& results);
bool loadBullet(const std::string& fileName, b3RobotSimulatorLoadFileResults& results);
bool getBodyInfo(int bodyUniqueId, struct b3BodyInfo* bodyInfo);
bool getBasePositionAndOrientation(int bodyUniqueId, btVector3& basePosition, btQuaternion& baseOrientation) const;
bool resetBasePositionAndOrientation(int bodyUniqueId, btVector3& basePosition, btQuaternion& baseOrientation);
bool getBaseVelocity(int bodyUniqueId, btVector3& baseLinearVelocity, btVector3& baseAngularVelocity) const;
bool resetBaseVelocity(int bodyUniqueId, const btVector3& linearVelocity, const btVector3& angularVelocity) const;
int getNumJoints(int bodyUniqueId) const;
bool getJointInfo(int bodyUniqueId, int jointIndex, b3JointInfo* jointInfo);
int createConstraint(int parentBodyIndex, int parentJointIndex, int childBodyIndex, int childJointIndex, b3JointInfo* jointInfo);
int changeConstraint(int constraintId, b3JointInfo* jointInfo);
void removeConstraint(int constraintId);
bool getJointState(int bodyUniqueId, int jointIndex, struct b3JointSensorState* state);
bool getJointStates(int bodyUniqueId, b3JointStates2& state);
bool resetJointState(int bodyUniqueId, int jointIndex, double targetValue);
void setJointMotorControl(int bodyUniqueId, int jointIndex, const struct b3RobotSimulatorJointMotorArgs& args);
bool setJointMotorControlArray(int bodyUniqueId, int controlMode, int numControlledDofs,
int *jointIndices, double *targetVelocities, double *targetPositions,
double *forces, double *kps, double *kds);
void stepSimulation();
bool canSubmitCommand() const;
void setRealTimeSimulation(bool enableRealTimeSimulation);
void setInternalSimFlags(int flags);
void setGravity(const btVector3& gravityAcceleration);
void setTimeStep(double timeStepInSeconds);
void setNumSimulationSubSteps(int numSubSteps);
void setNumSolverIterations(int numIterations);
void setContactBreakingThreshold(double threshold);
bool calculateInverseKinematics(const struct b3RobotSimulatorInverseKinematicArgs& args, struct b3RobotSimulatorInverseKinematicsResults& results);
bool getBodyJacobian(int bodyUniqueId, int linkIndex, const double* localPosition, const double* jointPositions, const double* jointVelocities, const double* jointAccelerations, double* linearJacobian, double* angularJacobian);
bool getLinkState(int bodyUniqueId, int linkIndex, b3LinkState* linkState);
void configureDebugVisualizer(enum b3ConfigureDebugVisualizerEnum flag, int enable);
void resetDebugVisualizerCamera(double cameraDistance, double cameraPitch, double cameraYaw, const btVector3& targetPos);
int startStateLogging(b3StateLoggingType loggingType, const std::string& fileName, const btAlignedObjectArray<int>& objectUniqueIds=btAlignedObjectArray<int>(), int maxLogDof = -1);
void stopStateLogging(int stateLoggerUniqueId);
void getVREvents(b3VREventsData* vrEventsData, int deviceTypeFilter);
void getKeyboardEvents(b3KeyboardEventsData* keyboardEventsData);
void submitProfileTiming(const std::string& profileName, int durationInMicroSeconds=1);
// JFC: added these 24 methods
void getMouseEvents(b3MouseEventsData* mouseEventsData);
bool getLinkState(int bodyUniqueId, int linkIndex, int computeLinkVelocity, int computeInverseKinematics, b3LinkState* linkState);
bool getCameraImage(int width, int height, struct b3RobotSimulatorGetCameraImageArgs args, b3CameraImageData &imageData);
bool calculateInverseDynamics(int bodyUniqueId, double *jointPositions, double *jointVelocities, double *jointAccelerations, double *jointForcesOutput);
int getNumBodies() const;
int getBodyUniqueId(int bodyId) const;
bool removeBody(int bodyUniqueId);
bool getDynamicsInfo(int bodyUniqueId, int linkIndex, b3DynamicsInfo *dynamicsInfo);
bool changeDynamics(int bodyUniqueId, int linkIndex, struct b3RobotSimulatorChangeDynamicsArgs &args);
int addUserDebugParameter(char *paramName, double rangeMin, double rangeMax, double startValue);
double readUserDebugParameter(int itemUniqueId);
bool removeUserDebugItem(int itemUniqueId);
int addUserDebugText(char *text, double *textPosition, struct b3RobotSimulatorAddUserDebugTextArgs &args);
int addUserDebugText(char *text, btVector3 &textPosition, struct b3RobotSimulatorAddUserDebugTextArgs &args);
int addUserDebugLine(double *fromXYZ, double *toXYZ, struct b3RobotSimulatorAddUserDebugLineArgs &args);
int addUserDebugLine(btVector3 &fromXYZ, btVector3 &toXYZ, struct b3RobotSimulatorAddUserDebugLineArgs &args);
bool setJointMotorControlArray(int bodyUniqueId, struct b3RobotSimulatorJointMotorArrayArgs &args);
bool setPhysicsEngineParameter(struct b3RobotSimulatorSetPhysicsEngineParameters &args);
bool applyExternalForce(int objectUniqueId, int linkIndex, double *force, double *position, int flags);
bool applyExternalForce(int objectUniqueId, int linkIndex, btVector3 &force, btVector3 &position, int flags);
bool applyExternalTorque(int objectUniqueId, int linkIndex, double *torque, int flags);
bool applyExternalTorque(int objectUniqueId, int linkIndex, btVector3 &torque, int flags);
bool enableJointForceTorqueSensor(int bodyUniqueId, int linkIndex, bool enable);
bool getDebugVisualizerCamera(struct b3OpenGLVisualizerCameraInfo *cameraInfo);
bool getContactPoints(struct b3RobotSimulatorGetContactPointsArgs &args, struct b3ContactInformation *contactInfo);
bool getClosestPoints(struct b3RobotSimulatorGetContactPointsArgs &args, double distance, struct b3ContactInformation *contactInfo);
bool getOverlappingObjects(double *aabbMin, double *aabbMax, struct b3AABBOverlapData *overlapData);
bool getOverlappingObjects(btVector3 &aabbMin, btVector3 &aabbMax, struct b3AABBOverlapData *overlapData);
bool getAABB(int bodyUniqueId, int linkIndex, double *aabbMin, double *aabbMax);
bool getAABB(int bodyUniqueId, int linkIndex, btVector3 &aabbMin, btVector3 &aabbMax);
int createCollisionShape(int shapeType, struct b3RobotSimulatorCreateCollisionShapeArgs &args);
int createMultiBody(struct b3RobotSimulatorCreateMultiBodyArgs &args);
int getNumConstraints() const;
int getConstraintUniqueId(int serialIndex);
void loadSoftBody(const std::string& fileName, double scale, double mass, double collisionMargin);
virtual void setGuiHelper(struct GUIHelperInterface* guiHelper);
virtual struct GUIHelperInterface* getGuiHelper();
bool getCollisionShapeData(int bodyUniqueId, int linkIndex, b3CollisionShapeInformation &collisionShapeInfo);
bool getVisualShapeData(int bodyUniqueId, b3VisualShapeInformation &visualShapeInfo);
virtual void setInternalData(struct b3RobotSimulatorClientAPI_InternalData* data);
};
#endif //B3_ROBOT_SIMULATOR_CLIENT_API_NO_DIRECT_H

View File

@@ -0,0 +1,112 @@
#include "b3RobotSimulatorClientAPI_NoGUI.h"
#include "PhysicsClientC_API.h"
#include "b3RobotSimulatorClientAPI_InternalData.h"
#ifdef BT_ENABLE_ENET
#include "PhysicsClientUDP_C_API.h"
#endif //PHYSICS_UDP
#ifdef BT_ENABLE_CLSOCKET
#include "PhysicsClientTCP_C_API.h"
#endif //PHYSICS_TCP
#ifndef BT_DISABLE_PHYSICS_DIRECT
#include "PhysicsDirectC_API.h"
#endif //BT_DISABLE_PHYSICS_DIRECT
#include "SharedMemoryPublic.h"
#include "Bullet3Common/b3Logging.h"
b3RobotSimulatorClientAPI_NoGUI::b3RobotSimulatorClientAPI_NoGUI()
{
}
b3RobotSimulatorClientAPI_NoGUI::~b3RobotSimulatorClientAPI_NoGUI()
{
}
bool b3RobotSimulatorClientAPI_NoGUI::connect(int mode, const std::string& hostName, int portOrKey)
{
if (m_data->m_physicsClientHandle)
{
b3Warning("Already connected, disconnect first.");
return false;
}
b3PhysicsClientHandle sm = 0;
int udpPort = 1234;
int tcpPort = 6667;
int key = SHARED_MEMORY_KEY;
bool connected = false;
switch (mode)
{
case eCONNECT_DIRECT:
{
#ifndef BT_DISABLE_PHYSICS_DIRECT
sm = b3ConnectPhysicsDirect();
#endif //BT_DISABLE_PHYSICS_DIRECT
break;
}
case eCONNECT_SHARED_MEMORY:
{
if (portOrKey >= 0)
{
key = portOrKey;
}
sm = b3ConnectSharedMemory(key);
break;
}
case eCONNECT_UDP:
{
if (portOrKey >= 0)
{
udpPort = portOrKey;
}
#ifdef BT_ENABLE_ENET
sm = b3ConnectPhysicsUDP(hostName.c_str(), udpPort);
#else
b3Warning("UDP is not enabled in this build");
#endif //BT_ENABLE_ENET
break;
}
case eCONNECT_TCP:
{
if (portOrKey >= 0)
{
tcpPort = portOrKey;
}
#ifdef BT_ENABLE_CLSOCKET
sm = b3ConnectPhysicsTCP(hostName.c_str(), tcpPort);
#else
b3Warning("TCP is not enabled in this pybullet build");
#endif //BT_ENABLE_CLSOCKET
break;
}
default:
{
b3Warning("connectPhysicsServer unexpected argument");
}
};
if (sm)
{
m_data->m_physicsClientHandle = sm;
if (!b3CanSubmitCommand(m_data->m_physicsClientHandle))
{
disconnect();
return false;
}
return true;
}
return false;
}

View File

@@ -0,0 +1,22 @@
#ifndef B3_ROBOT_SIMULATOR_CLIENT_API_H
#define B3_ROBOT_SIMULATOR_CLIENT_API_H
#include "b3RobotSimulatorClientAPI_NoDirect.h"
///The b3RobotSimulatorClientAPI is pretty much the C++ version of pybullet
///as documented in the pybullet Quickstart Guide
///https://docs.google.com/document/d/10sXEhzFRSnvFcl3XxNGhnD4N2SedqwdAvK3dsihxVUA
class b3RobotSimulatorClientAPI_NoGUI : public b3RobotSimulatorClientAPI_NoDirect
{
public:
b3RobotSimulatorClientAPI_NoGUI();
virtual ~b3RobotSimulatorClientAPI_NoGUI();
bool connect(int mode, const std::string& hostName = "localhost", int portOrKey = -1);
};
#endif //B3_ROBOT_SIMULATOR_CLIENT_API_H

View File

@@ -0,0 +1,98 @@
//tinyRendererPlugin implements the TinyRenderer as a plugin
//it is statically linked when using preprocessor #define STATIC_LINK_VR_PLUGIN
//otherwise you can dynamically load it using pybullet.loadPlugin
#include "collisionFilterPlugin.h"
#include "../../SharedMemoryPublic.h"
#include "../b3PluginContext.h"
#include <stdio.h>
struct MyClass
{
int m_testData;
MyClass()
:m_testData(42)
{
}
virtual ~MyClass()
{
}
};
B3_SHARED_API int initPlugin_testPlugin(struct b3PluginContext* context)
{
MyClass* obj = new MyClass();
context->m_userPointer = obj;
printf("hi!\n");
return SHARED_MEMORY_MAGIC_NUMBER;
}
B3_SHARED_API int preTickPluginCallback_testPlugin(struct b3PluginContext* context)
{
//apply pd control here, apply forces using the PD gains
return 0;
}
B3_SHARED_API int postTickPluginCallback_testPlugin(struct b3PluginContext* context)
{
MyClass* obj = (MyClass* )context->m_userPointer;
obj->m_testData++;
return 0;
}
B3_SHARED_API int executePluginCommand_testPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments)
{
//set the PD gains
printf("text argument:%s\n",arguments->m_text);
printf("int args: [");
for (int i=0;i<arguments->m_numInts;i++)
{
printf("%d", arguments->m_ints[i]);
if ((i+1)<arguments->m_numInts)
{
printf(",");
}
}
printf("]\nfloat args: [");
for (int i=0;i<arguments->m_numFloats;i++)
{
printf("%f", arguments->m_floats[i]);
if ((i+1)<arguments->m_numFloats)
{
printf(",");
}
}
printf("]\n");
MyClass* obj = (MyClass*) context->m_userPointer;
b3SharedMemoryStatusHandle statusHandle;
int statusType = -1;
int bodyUniqueId = -1;
b3SharedMemoryCommandHandle command =
b3LoadUrdfCommandInit(context->m_physClient, arguments->m_text);
statusHandle = b3SubmitClientCommandAndWaitStatus(context->m_physClient, command);
statusType = b3GetStatusType(statusHandle);
if (statusType == CMD_URDF_LOADING_COMPLETED)
{
bodyUniqueId = b3GetStatusBodyIndex(statusHandle);
}
return bodyUniqueId;
}
B3_SHARED_API void exitPlugin_testPlugin(struct b3PluginContext* context)
{
MyClass* obj = (MyClass*) context->m_userPointer;
delete obj;
context->m_userPointer = 0;
printf("bye!\n");
}

View File

@@ -0,0 +1,25 @@
#ifndef COLLISION_FILTER_PLUGIN_H
#define COLLISION_FILTER_PLUGIN_H
#include "../b3PluginAPI.h"
#ifdef __cplusplus
extern "C"
{
#endif
//the following 3 APIs are required
B3_SHARED_API int initPlugin_collisionFilterPlugin(struct b3PluginContext* context);
B3_SHARED_API void exitPlugin_collisionFilterPlugin(struct b3PluginContext* context);
B3_SHARED_API int executePluginCommand_collisionFilterPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments);
//all the APIs below are optional
B3_SHARED_API int preTickPluginCallback_collisionFilterPlugin(struct b3PluginContext* context);
B3_SHARED_API int postTickPluginCallback_collisionFilterPlugin(struct b3PluginContext* context);
#ifdef __cplusplus
};
#endif
#endif//#define COLLISION_FILTER_PLUGIN_H

View File

@@ -0,0 +1,42 @@
project ("pybullet_collisionFilterPlugin")
language "C++"
kind "SharedLib"
includedirs {".","../../../../src", "../../../../examples",
"../../../ThirdPartyLibs"}
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"}
hasCL = findOpenCL("clew")
links{"BulletFileLoader", "Bullet3Common", "LinearMath"}
if os.is("MacOSX") then
-- targetextension {"so"}
links{"Cocoa.framework","Python"}
end
files {
"collisionFilterPlugin.cpp",
"../../PhysicsClient.cpp",
"../../PhysicsClient.h",
"../../PhysicsClientSharedMemory.cpp",
"../../PhysicsClientSharedMemory.h",
"../../PhysicsClientSharedMemory_C_API.cpp",
"../../PhysicsClientSharedMemory_C_API.h",
"../../PhysicsClientC_API.cpp",
"../../PhysicsClientC_API.h",
"../../Win32SharedMemory.cpp",
"../../Win32SharedMemory.h",
"../../PosixSharedMemory.cpp",
"../../PosixSharedMemory.h",
"../../../Utils/b3Clock.cpp",
"../../../Utils/b3Clock.h",
"../../../Utils/b3ResourcePath.cpp",
"../../../Utils/b3ResourcePath.h",
}

View File

@@ -0,0 +1,162 @@
#include "pdControlPlugin.h"
#include "../../SharedMemoryPublic.h"
#include "../b3PluginContext.h"
#include <stdio.h>
#include "LinearMath/btScalar.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "../../b3RobotSimulatorClientAPI_NoDirect.h"
#include "../../b3RobotSimulatorClientAPI_InternalData.h"
struct MyPDControl
{
int m_objectUniqueId;
int m_linkIndex;
btScalar m_desiredPosition;
btScalar m_desiredVelocity;
btScalar m_kd;
btScalar m_kp;
btScalar m_maxForce;
};
struct MyPDControlContainer
{
int m_testData;
btAlignedObjectArray<MyPDControl> m_controllers;
b3RobotSimulatorClientAPI_NoDirect m_api;
MyPDControlContainer()
:m_testData(42)
{
}
virtual ~MyPDControlContainer()
{
}
};
B3_SHARED_API int initPlugin_pdControlPlugin(struct b3PluginContext* context)
{
MyPDControlContainer* obj = new MyPDControlContainer();
b3RobotSimulatorClientAPI_InternalData data;
data.m_physicsClientHandle = context->m_physClient;
data.m_guiHelper = 0;
obj->m_api.setInternalData(&data);
context->m_userPointer = obj;
return SHARED_MEMORY_MAGIC_NUMBER;
}
B3_SHARED_API int preTickPluginCallback_pdControlPlugin(struct b3PluginContext* context)
{
//apply pd control here, apply forces using the PD gains
MyPDControlContainer* obj = (MyPDControlContainer*)context->m_userPointer;
for (int i = 0; i < obj->m_controllers.size(); i++)
{
const MyPDControl& pdControl = obj->m_controllers[i];
//compute torque
//apply torque
}
//for each registered pd controller, execute PD control
return 0;
}
B3_SHARED_API int postTickPluginCallback_pdControlPlugin(struct b3PluginContext* context)
{
MyPDControlContainer* obj = (MyPDControlContainer* )context->m_userPointer;
obj->m_testData++;
return 0;
}
B3_SHARED_API int executePluginCommand_pdControlPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments)
{
MyPDControlContainer* obj = (MyPDControlContainer*)context->m_userPointer;
int numObj = obj->m_api.getNumBodies();
printf("numObj = %d\n", numObj);
//protocol:
//first int is the type of command
//second int is body unique id
//third int is link index
if (arguments->m_numInts != 3)
return -1;
switch (arguments->m_ints[0])
{
case eAddPDControl:
{
if (arguments->m_numFloats < 5)
return -1;
MyPDControl controller;
controller.m_desiredPosition = arguments->m_floats[0];
controller.m_desiredVelocity = arguments->m_floats[1];
controller.m_kd = arguments->m_floats[2];
controller.m_kp = arguments->m_floats[3];
controller.m_maxForce = arguments->m_floats[4];
controller.m_objectUniqueId = arguments->m_ints[1];
controller.m_linkIndex = arguments->m_ints[2];
obj->m_controllers.push_back(controller);
}
case eSetPDControl:
{
if (arguments->m_numFloats < 5)
return -1;
MyPDControl controller;
controller.m_desiredPosition = arguments->m_floats[0];
controller.m_desiredVelocity = arguments->m_floats[1];
controller.m_kd = arguments->m_floats[2];
controller.m_kp = arguments->m_floats[3];
controller.m_maxForce = arguments->m_floats[4];
controller.m_objectUniqueId = arguments->m_ints[1];
controller.m_linkIndex = arguments->m_ints[2];
for (int i = 0; i < obj->m_controllers.size(); i++)
{
if (obj->m_controllers[i].m_objectUniqueId == controller.m_objectUniqueId && obj->m_controllers[i].m_linkIndex == controller.m_linkIndex)
{
obj->m_controllers[i] = controller;
break;
}
}
break;
}
case eRemovePDControl:
{
MyPDControl controller;
controller.m_objectUniqueId = arguments->m_ints[1];
controller.m_linkIndex = arguments->m_ints[2];
for (int i = 0; i < obj->m_controllers.size(); i++)
{
if (obj->m_controllers[i].m_objectUniqueId == controller.m_objectUniqueId && obj->m_controllers[i].m_linkIndex == controller.m_linkIndex)
{
obj->m_controllers.removeAtIndex(i);
break;
}
}
break;
}
default:
{
return -1;
}
}
int result = 42;
return result;
}
B3_SHARED_API void exitPlugin_pdControlPlugin(struct b3PluginContext* context)
{
MyPDControlContainer* obj = (MyPDControlContainer*) context->m_userPointer;
delete obj;
context->m_userPointer = 0;
}

View File

@@ -0,0 +1,33 @@
#ifndef PID_CONTROL_PLUGIN_H
#define PID_CONTROL_PLUGIN_H
#include "../b3PluginAPI.h"
#ifdef __cplusplus
extern "C"
{
#endif
//the following 3 APIs are required
B3_SHARED_API int initPlugin_pdControlPlugin(struct b3PluginContext* context);
B3_SHARED_API void exitPlugin_pdControlPlugin(struct b3PluginContext* context);
B3_SHARED_API int executePluginCommand_pdControlPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments);
///
enum PDControlCommandEnum
{
eAddPDControl = 1,
eSetPDControl = 2,
eRemovePDControl = 4,
};
//all the APIs below are optional
B3_SHARED_API int preTickPluginCallback_pdControlPlugin(struct b3PluginContext* context);
B3_SHARED_API int postTickPluginCallback_pdControlPlugin(struct b3PluginContext* context);
#ifdef __cplusplus
};
#endif
#endif//#define PID_CONTROL_PLUGIN_H

View File

@@ -0,0 +1,44 @@
project ("pybullet_pdControlPlugin")
language "C++"
kind "SharedLib"
includedirs {".","../../../../src", "../../../../examples",
"../../../ThirdPartyLibs"}
defines {"PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"}
hasCL = findOpenCL("clew")
links{"BulletFileLoader", "Bullet3Common", "LinearMath"}
if os.is("MacOSX") then
-- targetextension {"so"}
links{"Cocoa.framework","Python"}
end
files {
"pdControlPlugin.cpp",
"../../b3RobotSimulatorClientAPI_NoDirect.cpp",
"../../b3RobotSimulatorClientAPI_NoDirect.h",
"../../PhysicsClient.cpp",
"../../PhysicsClient.h",
"../../PhysicsClientSharedMemory.cpp",
"../../PhysicsClientSharedMemory.h",
"../../PhysicsClientSharedMemory_C_API.cpp",
"../../PhysicsClientSharedMemory_C_API.h",
"../../PhysicsClientC_API.cpp",
"../../PhysicsClientC_API.h",
"../../Win32SharedMemory.cpp",
"../../Win32SharedMemory.h",
"../../PosixSharedMemory.cpp",
"../../PosixSharedMemory.h",
"../../../Utils/b3Clock.cpp",
"../../../Utils/b3Clock.h",
"../../../Utils/b3ResourcePath.cpp",
"../../../Utils/b3ResourcePath.h",
}

View File

@@ -29,7 +29,7 @@ struct MyClass
}
};
B3_SHARED_API int initPlugin(struct b3PluginContext* context)
B3_SHARED_API int initPlugin_testPlugin(struct b3PluginContext* context)
{
MyClass* obj = new MyClass();
context->m_userPointer = obj;
@@ -39,67 +39,23 @@ B3_SHARED_API int initPlugin(struct b3PluginContext* context)
}
B3_SHARED_API int preTickPluginCallback(struct b3PluginContext* context)
B3_SHARED_API int preTickPluginCallback_testPlugin(struct b3PluginContext* context)
{
MyClass* obj = (MyClass* )context->m_userPointer;
{
b3SharedMemoryCommandHandle commandHandle = b3RequestVREventsCommandInit(context->m_physClient);
int deviceTypeFilter = VR_DEVICE_CONTROLLER;
b3VREventsSetDeviceTypeFilter(commandHandle, deviceTypeFilter);
b3SharedMemoryStatusHandle statusHandle = b3SubmitClientCommandAndWaitStatus(context->m_physClient, commandHandle);
int statusType = b3GetStatusType(statusHandle);
if (statusType == CMD_REQUEST_VR_EVENTS_DATA_COMPLETED)
{
struct b3VREventsData vrEvents;
int i = 0;
b3GetVREventsData(context->m_physClient, &vrEvents);
if (vrEvents.m_numControllerEvents)
{
//this is only for a test, normally you wouldn't print to the console at each simulation substep!
printf("got %d VR controller events!\n", vrEvents.m_numControllerEvents);
}
}
}
{
b3KeyboardEventsData keyboardEventsData;
b3SharedMemoryCommandHandle commandHandle = b3RequestKeyboardEventsCommandInit(context->m_physClient);
b3SubmitClientCommandAndWaitStatus(context->m_physClient, commandHandle);
b3GetKeyboardEventsData(context->m_physClient, &keyboardEventsData);
if (keyboardEventsData.m_numKeyboardEvents)
{
//this is only for a test, normally you wouldn't print to the console at each simulation substep!
printf("got %d keyboard events\n", keyboardEventsData.m_numKeyboardEvents);
}
}
{
b3MouseEventsData mouseEventsData;
b3SharedMemoryCommandHandle commandHandle = b3RequestMouseEventsCommandInit(context->m_physClient);
b3SubmitClientCommandAndWaitStatus(context->m_physClient, commandHandle);
b3GetMouseEventsData(context->m_physClient, &mouseEventsData);
if (mouseEventsData.m_numMouseEvents)
{
//this is only for a test, normally you wouldn't print to the console at each simulation substep!
printf("got %d mouse events\n", mouseEventsData.m_numMouseEvents);
}
}
return 0;
}
B3_SHARED_API int postTickPluginCallback(struct b3PluginContext* context)
B3_SHARED_API int postTickPluginCallback_testPlugin(struct b3PluginContext* context)
{
MyClass* obj = (MyClass* )context->m_userPointer;
obj->m_testData++;
return 0;
}
B3_SHARED_API int executePluginCommand(struct b3PluginContext* context, const struct b3PluginArguments* arguments)
B3_SHARED_API int executePluginCommand_testPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments)
{
printf("text argument:%s\n",arguments->m_text);
printf("int args: [");
for (int i=0;i<arguments->m_numInts;i++)
@@ -140,7 +96,7 @@ B3_SHARED_API int executePluginCommand(struct b3PluginContext* context, const st
}
B3_SHARED_API void exitPlugin(struct b3PluginContext* context)
B3_SHARED_API void exitPlugin_testPlugin(struct b3PluginContext* context)
{
MyClass* obj = (MyClass*) context->m_userPointer;
delete obj;

View File

@@ -9,14 +9,13 @@ extern "C"
#endif
//initPlugin, exitPlugin and executePluginCommand are required, otherwise plugin won't load
B3_SHARED_API int initPlugin(struct b3PluginContext* context);
B3_SHARED_API void exitPlugin(struct b3PluginContext* context);
B3_SHARED_API int executePluginCommand(struct b3PluginContext* context, const struct b3PluginArguments* arguments);
B3_SHARED_API int initPlugin_testPlugin(struct b3PluginContext* context);
B3_SHARED_API void exitPlugin_testPlugin(struct b3PluginContext* context);
B3_SHARED_API int executePluginCommand_testPlugin(struct b3PluginContext* context, const struct b3PluginArguments* arguments);
//all the APIs below are optional
B3_SHARED_API int preTickPluginCallback(struct b3PluginContext* context);
B3_SHARED_API int postTickPluginCallback(struct b3PluginContext* context);
B3_SHARED_API struct UrdfRenderingInterface* getRenderInterface(struct b3PluginContext* context);
B3_SHARED_API int preTickPluginCallback_testPlugin(struct b3PluginContext* context);
B3_SHARED_API int postTickPluginCallback_testPlugin(struct b3PluginContext* context);
#ifdef __cplusplus

View File

@@ -465,4 +465,7 @@ include "plugins/testPlugin"
include "plugins/vrSyncPlugin"
include "plugins/tinyRendererPlugin"
include "plugins/pdControlPlugin"
include "plugins/collisionFilterPlugin"