leave m_useGlobalVelocities to false, until enabled, for backward compatibility

use URDF_GLOBAL_VELOCITIES_MB flag in PyBullet loadURDF.
fix robot_bases.py due to new fields in getJointInfo.
backward compabitibility: BulletMJCFImporter, keep creating btMultiSphereShape for MJCF capsules with fromto, instead of shifted btCapsuleShapeZ, unless if CUF_USE_IMPLICIT_CYLINDER is used.
This commit is contained in:
erwincoumans
2018-01-10 11:16:50 -08:00
parent c4b1b84687
commit 22b4809891
11 changed files with 61 additions and 47 deletions

Binary file not shown.

View File

@@ -7,6 +7,7 @@
#include "../../Utils/b3ResourcePath.h" #include "../../Utils/b3ResourcePath.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include "../ImportURDFDemo/URDF2Bullet.h"
#include "../ImportURDFDemo/UrdfParser.h" #include "../ImportURDFDemo/UrdfParser.h"
#include "../ImportURDFDemo/urdfStringSplit.h" #include "../ImportURDFDemo/urdfStringSplit.h"
#include "../ImportURDFDemo/urdfLexicalCast.h" #include "../ImportURDFDemo/urdfLexicalCast.h"
@@ -190,10 +191,13 @@ struct BulletMJCFImporterInternalData
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes; btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
mutable btAlignedObjectArray<btTriangleMesh*> m_allocatedMeshInterfaces; mutable btAlignedObjectArray<btTriangleMesh*> m_allocatedMeshInterfaces;
int m_flags;
BulletMJCFImporterInternalData() BulletMJCFImporterInternalData()
:m_inertiaFromGeom(true), :m_inertiaFromGeom(true),
m_activeModel(-1), m_activeModel(-1),
m_activeBodyUniqueId(-1) m_activeBodyUniqueId(-1),
m_flags(0)
{ {
m_pathPrefix[0] = 0; m_pathPrefix[0] = 0;
} }
@@ -1370,11 +1374,12 @@ struct BulletMJCFImporterInternalData
}; };
BulletMJCFImporter::BulletMJCFImporter(struct GUIHelperInterface* helper, LinkVisualShapesConverter* customConverter) BulletMJCFImporter::BulletMJCFImporter(struct GUIHelperInterface* helper, LinkVisualShapesConverter* customConverter, int flags)
{ {
m_data = new BulletMJCFImporterInternalData(); m_data = new BulletMJCFImporterInternalData();
m_data->m_guiHelper = helper; m_data->m_guiHelper = helper;
m_data->m_customVisualShapesConverter = customConverter; m_data->m_customVisualShapesConverter = customConverter;
m_data->m_flags = flags;
} }
BulletMJCFImporter::~BulletMJCFImporter() BulletMJCFImporter::~BulletMJCFImporter()
@@ -1897,43 +1902,45 @@ class btCompoundShape* BulletMJCFImporter::convertLinkCollisionShapes( int linkI
{ {
if (col->m_geometry.m_hasFromTo) if (col->m_geometry.m_hasFromTo)
{ {
#if 0 if (m_data->m_flags&CUF_USE_IMPLICIT_CYLINDER)
btVector3 f = col->m_geometry.m_capsuleFrom;
btVector3 t = col->m_geometry.m_capsuleTo;
btVector3 fromto[2] = {f,t};
btScalar radii[2] = {btScalar(col->m_geometry.m_capsuleRadius)
,btScalar(col->m_geometry.m_capsuleRadius)};
btMultiSphereShape* ms = new btMultiSphereShape(fromto,radii,2);
childShape = ms;
#else
btVector3 f = col->m_geometry.m_capsuleFrom;
btVector3 t = col->m_geometry.m_capsuleTo;
//compute the local 'fromto' transform
btVector3 localPosition = btScalar(0.5)*(t+f);
btQuaternion localOrn;
localOrn = btQuaternion::getIdentity();
btVector3 diff = t-f;
btScalar lenSqr = diff.length2();
btScalar height = 0.f;
if (lenSqr > SIMD_EPSILON)
{ {
height = btSqrt(lenSqr); btVector3 f = col->m_geometry.m_capsuleFrom;
btVector3 ax = diff / height; btVector3 t = col->m_geometry.m_capsuleTo;
//compute the local 'fromto' transform
btVector3 localPosition = btScalar(0.5)*(t+f);
btQuaternion localOrn;
localOrn = btQuaternion::getIdentity();
btVector3 zAxis(0,0,1); btVector3 diff = t-f;
localOrn = shortestArcQuat(zAxis,ax); btScalar lenSqr = diff.length2();
btScalar height = 0.f;
if (lenSqr > SIMD_EPSILON)
{
height = btSqrt(lenSqr);
btVector3 ax = diff / height;
btVector3 zAxis(0,0,1);
localOrn = shortestArcQuat(zAxis,ax);
}
btCapsuleShapeZ* capsule= new btCapsuleShapeZ(col->m_geometry.m_capsuleRadius,height);
btCompoundShape* compound = new btCompoundShape();
btTransform localTransform(localOrn,localPosition);
compound->addChildShape(localTransform,capsule);
childShape = compound;
} else
{
btVector3 f = col->m_geometry.m_capsuleFrom;
btVector3 t = col->m_geometry.m_capsuleTo;
btVector3 fromto[2] = {f,t};
btScalar radii[2] = {btScalar(col->m_geometry.m_capsuleRadius)
,btScalar(col->m_geometry.m_capsuleRadius)};
btMultiSphereShape* ms = new btMultiSphereShape(fromto,radii,2);
childShape = ms;
} }
btCapsuleShapeZ* capsule= new btCapsuleShapeZ(col->m_geometry.m_capsuleRadius,height);
btCompoundShape* compound = new btCompoundShape();
btTransform localTransform(localOrn,localPosition);
compound->addChildShape(localTransform,capsule);
childShape = compound;
#endif
} else } else
{ {
btCapsuleShapeZ* cap = new btCapsuleShapeZ(col->m_geometry.m_capsuleRadius, btCapsuleShapeZ* cap = new btCapsuleShapeZ(col->m_geometry.m_capsuleRadius,

View File

@@ -19,7 +19,7 @@ class BulletMJCFImporter : public URDFImporterInterface
struct BulletMJCFImporterInternalData* m_data; struct BulletMJCFImporterInternalData* m_data;
public: public:
BulletMJCFImporter(struct GUIHelperInterface* helper, LinkVisualShapesConverter* customConverter); BulletMJCFImporter(struct GUIHelperInterface* helper, LinkVisualShapesConverter* customConverter, int flags);
virtual ~BulletMJCFImporter(); virtual ~BulletMJCFImporter();
virtual bool parseMJCFString(const char* xmlString, MJCFErrorLogger* logger); virtual bool parseMJCFString(const char* xmlString, MJCFErrorLogger* logger);

View File

@@ -216,7 +216,8 @@ void ImportMJCFSetup::initPhysics()
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider); m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
} }
BulletMJCFImporter importer(m_guiHelper, 0); int flags=0;
BulletMJCFImporter importer(m_guiHelper, 0,flags);
MyMJCFLogger logger; MyMJCFLogger logger;
bool result = importer.loadMJCF(m_fileName,&logger); bool result = importer.loadMJCF(m_fileName,&logger);
if (result) if (result)

View File

@@ -344,9 +344,9 @@ void ConvertURDF2BulletInternal(
bool isFixedBase = (mass==0);//todo: figure out when base is fixed bool isFixedBase = (mass==0);//todo: figure out when base is fixed
int totalNumJoints = cache.m_totalNumJoints1; int totalNumJoints = cache.m_totalNumJoints1;
cache.m_bulletMultiBody = creation.allocateMultiBody(urdfLinkIndex, totalNumJoints,mass, localInertiaDiagonal, isFixedBase, canSleep); cache.m_bulletMultiBody = creation.allocateMultiBody(urdfLinkIndex, totalNumJoints,mass, localInertiaDiagonal, isFixedBase, canSleep);
if (flags & CUF_NO_GLOBAL_VELOCITIES_MB) if (flags & CUF_GLOBAL_VELOCITIES_MB)
{ {
cache.m_bulletMultiBody->useGlobalVelocities(false); cache.m_bulletMultiBody->useGlobalVelocities(true);
} }
if (flags & CUF_USE_MJCF) if (flags & CUF_USE_MJCF)
{ {

View File

@@ -24,7 +24,7 @@ enum ConvertURDFFlags {
CUF_USE_SELF_COLLISION_EXCLUDE_ALL_PARENTS=32, CUF_USE_SELF_COLLISION_EXCLUDE_ALL_PARENTS=32,
CUF_RESERVED=64, CUF_RESERVED=64,
CUF_USE_IMPLICIT_CYLINDER=128, CUF_USE_IMPLICIT_CYLINDER=128,
CUF_NO_GLOBAL_VELOCITIES_MB=256, CUF_GLOBAL_VELOCITIES_MB=256,
}; };
void ConvertURDF2Bullet(const URDFImporterInterface& u2b, void ConvertURDF2Bullet(const URDFImporterInterface& u2b,

View File

@@ -2704,7 +2704,7 @@ bool PhysicsServerCommandProcessor::loadMjcf(const char* fileName, char* bufferS
m_data->m_sdfRecentLoadedBodies.clear(); m_data->m_sdfRecentLoadedBodies.clear();
BulletMJCFImporter u2b(m_data->m_guiHelper, &m_data->m_visualConverter); BulletMJCFImporter u2b(m_data->m_guiHelper, &m_data->m_visualConverter, flags);
bool useFixedBase = false; bool useFixedBase = false;
MyMJCFLogger2 logger; MyMJCFLogger2 logger;

View File

@@ -673,7 +673,7 @@ enum eURDF_Flags
URDF_USE_SELF_COLLISION_EXCLUDE_ALL_PARENTS=32, URDF_USE_SELF_COLLISION_EXCLUDE_ALL_PARENTS=32,
URDF_RESERVED=64, URDF_RESERVED=64,
URDF_USE_IMPLICIT_CYLINDER =128, URDF_USE_IMPLICIT_CYLINDER =128,
URDF_NO_GLOBAL_VELOCITIES_MB =256, URDF_GLOBAL_VELOCITIES_MB =256,
}; };
enum eUrdfGeomTypes //sync with UrdfParser UrdfGeomTypes enum eUrdfGeomTypes //sync with UrdfParser UrdfGeomTypes

View File

@@ -55,7 +55,9 @@ class MJCFBasedRobot:
parts[part_name] = BodyPart(part_name, bodies, i, -1) parts[part_name] = BodyPart(part_name, bodies, i, -1)
for j in range(p.getNumJoints(bodies[i])): for j in range(p.getNumJoints(bodies[i])):
p.setJointMotorControl2(bodies[i],j,p.POSITION_CONTROL,positionGain=0.1,velocityGain=0.1,force=0) p.setJointMotorControl2(bodies[i],j,p.POSITION_CONTROL,positionGain=0.1,velocityGain=0.1,force=0)
_,joint_name,_,_,_,_,_,_,_,_,_,_,part_name = p.getJointInfo(bodies[i], j) jointInfo = p.getJointInfo(bodies[i], j)
joint_name=jointInfo[1]
part_name=jointInfo[12]
joint_name = joint_name.decode("utf8") joint_name = joint_name.decode("utf8")
part_name = part_name.decode("utf8") part_name = part_name.decode("utf8")
@@ -172,7 +174,11 @@ class Joint:
self.bodyIndex = bodyIndex self.bodyIndex = bodyIndex
self.jointIndex = jointIndex self.jointIndex = jointIndex
self.joint_name = joint_name self.joint_name = joint_name
_,_,_,_,_,_,_,_,self.lowerLimit, self.upperLimit,_,_,_ = p.getJointInfo(self.bodies[self.bodyIndex], self.jointIndex)
jointInfo = p.getJointInfo(self.bodies[self.bodyIndex], self.jointIndex)
self.lowerLimit = jointInfo[8]
self.upperLimit = jointInfo[9]
self.power_coeff = 0 self.power_coeff = 0
def set_state(self, x, vx): def set_state(self, x, vx):

View File

@@ -8817,7 +8817,7 @@ initpybullet(void)
PyModule_AddIntConstant(m, "URDF_USE_INERTIA_FROM_FILE", URDF_USE_INERTIA_FROM_FILE); PyModule_AddIntConstant(m, "URDF_USE_INERTIA_FROM_FILE", URDF_USE_INERTIA_FROM_FILE);
PyModule_AddIntConstant(m, "URDF_USE_IMPLICIT_CYLINDER", URDF_USE_IMPLICIT_CYLINDER); PyModule_AddIntConstant(m, "URDF_USE_IMPLICIT_CYLINDER", URDF_USE_IMPLICIT_CYLINDER);
PyModule_AddIntConstant(m, "URDF_NO_GLOBAL_VELOCITIES_MB", URDF_NO_GLOBAL_VELOCITIES_MB); PyModule_AddIntConstant(m, "URDF_GLOBAL_VELOCITIES_MB", URDF_GLOBAL_VELOCITIES_MB);
PyModule_AddIntConstant(m, "URDF_USE_SELF_COLLISION", URDF_USE_SELF_COLLISION); PyModule_AddIntConstant(m, "URDF_USE_SELF_COLLISION", URDF_USE_SELF_COLLISION);
PyModule_AddIntConstant(m, "URDF_USE_SELF_COLLISION_EXCLUDE_PARENT", URDF_USE_SELF_COLLISION_EXCLUDE_PARENT); PyModule_AddIntConstant(m, "URDF_USE_SELF_COLLISION_EXCLUDE_PARENT", URDF_USE_SELF_COLLISION_EXCLUDE_PARENT);

View File

@@ -122,7 +122,7 @@ btMultiBody::btMultiBody(int n_links,
m_dofCount(0), m_dofCount(0),
m_posVarCnt(0), m_posVarCnt(0),
m_useRK4(false), m_useRK4(false),
m_useGlobalVelocities(true), m_useGlobalVelocities(false),
m_internalNeedsJointFeedback(false) m_internalNeedsJointFeedback(false)
{ {
m_cachedInertiaTopLeft.setValue(0,0,0,0,0,0,0,0,0); m_cachedInertiaTopLeft.setValue(0,0,0,0,0,0,0,0,0);