Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate bullet into ign-physics3 #208

Merged
merged 73 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
ea0e401
base and entity features
Lobotuerk Nov 18, 2020
6aab0af
Add base Cmake and plugin dummy feature
Blast545 Nov 18, 2020
a48a799
Replace dummy features with base ones
Blast545 Nov 18, 2020
7adcf18
Added Simulation Features (#168)
Lobotuerk Nov 24, 2020
7a92539
[Bullet] Bullet classic, Add sdf entities (#167)
Blast545 Nov 24, 2020
e6d1f5a
Kinematics features (#169)
Lobotuerk Nov 25, 2020
0399636
Free Group Features (#171)
Lobotuerk Nov 30, 2020
a93872c
[bullet] Basic Features (#172)
Lobotuerk Dec 1, 2020
1dfc2e7
[Bullet] Collision Features (#173)
Lobotuerk Dec 3, 2020
24041d8
[bullet] Add find or construct link (#175)
Blast545 Dec 10, 2020
8469df1
[Bullet] Mesh features (#178)
Lobotuerk Dec 15, 2020
a30f612
[bullet] Joints implementation (#190)
Blast545 Jan 12, 2021
bc53a8b
[BULLET] Compound Collisions (#188)
Lobotuerk Jan 18, 2021
0e9e897
[Bullet] Parameter tuning (#192)
Lobotuerk Jan 18, 2021
98048ee
[bullet] Getters for revolute joints (#197)
Blast545 Jan 20, 2021
70e4b81
[Bullet] Adds missing getters/setters revolute joints (#206)
Blast545 Jan 28, 2021
75c26e8
Add some reformat and copyright notices
Blast545 Feb 3, 2021
1dfdce6
Add collision group filter for models
Blast545 Feb 8, 2021
fa9eb5f
Add friction elements read from sdf
Blast545 Feb 12, 2021
052542c
Linter
Feb 12, 2021
b84ab6e
Linter
Feb 12, 2021
5c7868b
Add SDF files for testing features
Blast545 Feb 26, 2021
7d7b990
Debug commit
Blast545 Feb 26, 2021
963904c
Update friction/collision parameters
Lobotuerk Mar 2, 2021
d94918e
Add test friction values mu and mu2
Blast545 Mar 3, 2021
d54e78a
Remove collision groups implementation
Blast545 Mar 3, 2021
851196b
Remove unused variable
Blast545 Mar 3, 2021
30d6c36
Swap mu and mu2 coefficients placement
Blast545 Mar 3, 2021
bd64076
Update old comments
Blast545 Mar 3, 2021
d4afa61
Remove debug code
Blast545 Mar 3, 2021
86ad9c1
Add code to remove joints when a model is removed
Blast545 Mar 3, 2021
62cf0d9
Divide inertia for angular acceleration calculus
Blast545 Mar 3, 2021
ac19e4d
Improve joint getters/setters with switch statement
Blast545 Mar 11, 2021
ec47b47
Add namespace closure comment
Blast545 Mar 11, 2021
c19a576
Simplify iterators syntax, add missing delete
Blast545 Mar 11, 2021
00f8311
Replace raw pointers with shared pointers
Blast545 Mar 12, 2021
5c39f4d
Master branch updates (#221)
chapulina Mar 15, 2021
edd439b
Add ResolveSDFPose function and test case
Blast545 Mar 16, 2021
db8b26e
Add links and joints creation with world
Blast545 Mar 17, 2021
54064d6
removed GetContactFromLastStep Feature (#236)
Lobotuerk Mar 19, 2021
901e645
Change cast to dynamic
Blast545 Mar 22, 2021
12c28e9
Remove not included features
Blast545 Mar 23, 2021
950b82f
Improve partially implemented joint features
Blast545 Mar 23, 2021
d9c011d
[Bullet] Inertial Pose Update (#226)
Lobotuerk Mar 23, 2021
2c51269
Remove extra call to new
Blast545 Mar 23, 2021
392995f
Rename variable
Blast545 Mar 23, 2021
de90ff7
Reformat to reuse removeModel code
Blast545 Mar 24, 2021
c7c78bf
Resolve XYZ pose
Blast545 Mar 24, 2021
835d251
Fix linter issues 1
Blast545 Mar 24, 2021
b79e01b
[Bullet] Auxiliar PR to add index to identity conversion (#240)
Blast545 Mar 25, 2021
4cba451
castToMesh + angular cross
Lobotuerk Mar 25, 2021
8734d4c
proper linear
Lobotuerk Mar 25, 2021
9adb64d
Remove torque limit
Blast545 Apr 5, 2021
482d30f
[TPE] Update link pose and velocity (#179)
claireyywang Apr 5, 2021
75b7914
angular velocity frame
Lobotuerk Apr 12, 2021
5282e90
fixed math angular vel
Lobotuerk Apr 12, 2021
96272c6
linter
Lobotuerk Apr 12, 2021
d5f14a1
linter
Lobotuerk Apr 13, 2021
a1fe46d
🎈 2.4.0 (#247)
chapulina Apr 15, 2021
45a8f16
Add extra null check
Blast545 Apr 19, 2021
21334f8
Add basic tests
Blast545 Apr 19, 2021
6332266
Remove not needed comment
Blast545 Apr 19, 2021
696bf6a
Add missing override keyword
Blast545 Apr 19, 2021
535140f
Fix codecheck
Apr 19, 2021
cdd5aea
Dates
Apr 19, 2021
b533c24
🎈 3.2.0 (#252)
chapulina Apr 28, 2021
625e6b2
Updated CMake and replaced using with structs for feature lists
Lobotuerk Apr 29, 2021
ec5c2bd
cleared the ambiguity warn
Lobotuerk Apr 30, 2021
c3e0be6
Save base when adding a mesh
Blast545 Apr 30, 2021
210dfa7
deleted worlds
Lobotuerk May 10, 2021
b27dbf5
Linter, reduce line length
Blast545 May 13, 2021
2592a48
nits
Lobotuerk May 19, 2021
3792981
Merge branch 'ign-physics3' into bulletDev/blast545/bulletPhysicsDome
Lobotuerk May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ message(STATUS "\n\n-- ====== Finding Dependencies ======")
# Find ignition-common
ign_find_package(ignition-common3
COMPONENTS graphics profiler
REQUIRED_BY mesh dartsim tpe tpelib)
REQUIRED_BY mesh dartsim tpe tpelib bullet)
set(IGN_COMMON_VER ${ignition-common3_VERSION_MAJOR})

#--------------------------------------
Expand All @@ -57,7 +57,7 @@ ign_find_package(EIGEN3 REQUIRED)
#--------------------------------------
# Find SDFormat for the SDF features
ign_find_package(sdformat10
REQUIRED_BY sdf dartsim tpe)
REQUIRED_BY sdf dartsim tpe bullet)

#--------------------------------------
# Find dartsim for the dartsim plugin wrapper
Expand All @@ -72,6 +72,13 @@ ign_find_package(DART
PKGCONFIG dart
PKGCONFIG_VER_COMPARISON >=)

#--------------------------------------
# Find bullet for the bullet plugin wrapper
ign_find_package(IgnBullet
VERSION 2.87
REQUIRED_BY bullet
PKGCONFIG bullet
PKGCONFIG_VER_COMPARISON >=)

message(STATUS "-------------------------------------------\n")

Expand All @@ -86,7 +93,7 @@ set(IGNITION_PHYSICS_ENGINE_INSTALL_DIR
# Configure the build
#============================================================================
ign_configure_build(QUIT_IF_BUILD_ERRORS
COMPONENTS sdf mesh dartsim tpe)
COMPONENTS sdf mesh dartsim tpe bullet)


#============================================================================
Expand Down
74 changes: 74 additions & 0 deletions bullet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This component expresses custom features of the bullet plugin, which can
# expose native bullet data types.
ign_add_component(bullet INTERFACE
DEPENDS_ON_COMPONENTS sdf mesh
GET_TARGET_NAME features)

link_directories(${BULLET_LIBRARY_DIRS})
target_link_libraries(${features} INTERFACE IgnBullet::IgnBullet)

ign_get_libsources_and_unittests(sources test_sources)

# TODO(MXG): Think about an ign_add_plugin(~) macro for ign-cmake
set(engine_name bullet-plugin)
ign_add_component(${engine_name}
SOURCES ${sources}
DEPENDS_ON_COMPONENTS bullet
GET_TARGET_NAME bullet_plugin)

target_link_libraries(${bullet_plugin}
PUBLIC
${features}
${PROJECT_LIBRARY_TARGET_NAME}-sdf
${PROJECT_LIBRARY_TARGET_NAME}-mesh
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
ignition-math${IGN_MATH_VER}::eigen3)

# Note that plugins are currently being installed in 2 places: /lib and the engine-plugins dir
install(TARGETS ${bullet_plugin} DESTINATION ${IGNITION_PHYSICS_ENGINE_INSTALL_DIR})

# The library created by `ign_add_component` includes the ign-physics version
# (i.e. libignition-physics1-name-plugin.so), but for portability,
# we also install an unversioned symlink into the same versioned folder.
set(versioned ${CMAKE_SHARED_LIBRARY_PREFIX}${bullet_plugin}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(unversioned ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME_NO_VERSION_LOWER}-${engine_name}${CMAKE_SHARED_LIBRARY_SUFFIX})
if (WIN32)
# disable MSVC inherit via dominance warning
target_compile_options(${dartsim_plugin} PUBLIC "/wd4250")
INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy
${IGNITION_PHYSICS_ENGINE_INSTALL_DIR}\/${versioned}
${IGNITION_PHYSICS_ENGINE_INSTALL_DIR}\/${unversioned})")
else()
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink ${versioned} ${unversioned})
INSTALL(FILES ${PROJECT_BINARY_DIR}/${unversioned} DESTINATION ${IGNITION_PHYSICS_ENGINE_INSTALL_DIR})
endif()
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink ${versioned} ${unversioned})
INSTALL(FILES ${PROJECT_BINARY_DIR}/${unversioned} DESTINATION ${IGNITION_PHYSICS_ENGINE_INSTALL_DIR})

# Testing
ign_build_tests(
TYPE UNIT_bullet
SOURCES ${test_sources}
LIB_DEPS
${features}
ignition-plugin${IGN_PLUGIN_VER}::loader
ignition-common${IGN_COMMON_VER}::ignition-common${IGN_COMMON_VER}
${PROJECT_LIBRARY_TARGET_NAME}-sdf
${PROJECT_LIBRARY_TARGET_NAME}-mesh
TEST_LIST tests)

foreach(test ${tests})

target_compile_definitions(${test} PRIVATE
"bullet_plugin_LIB=\"$<TARGET_FILE:${bullet_plugin}>\""
"TEST_WORLD_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/worlds/\""
"IGNITION_PHYSICS_RESOURCE_DIR=\"${IGNITION_PHYSICS_RESOURCE_DIR}\"")

endforeach()

if(TARGET UNIT_FindFeatures_TEST)

target_compile_definitions(UNIT_FindFeatures_TEST PRIVATE
"bullet_plugin_LIB=\"$<TARGET_FILE:${bullet_plugin}>\"")

endif()
266 changes: 266 additions & 0 deletions bullet/src/Base.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef IGNITION_PHYSICS_BULLET_BASE_HH_
#define IGNITION_PHYSICS_BULLET_BASE_HH_

#include <btBulletDynamicsCommon.h>
#include <Eigen/Geometry>

#include <assert.h>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <map>

#include <ignition/common/Console.hh>
#include <ignition/physics/Implements.hh>
#include <ignition/math/eigen3/Conversions.hh>

namespace ignition {
namespace physics {
namespace bullet {

/// \brief The Info structs are used for three reasons:
/// 1) Holding extra information such as the name
/// that will be different from the underlying engine
/// 2) Wrap shared pointers to Bullet entities to use as parameters to
/// GenerateIdentity.
/// 3) Hold explicit copies of raw pointers that can be deallocated

// TO-DO(): Consider using unique_ptrs instead of shared pointers
// for Bullet internal objects

// Note: For Bullet library it's important the order in which the elements
// are destroyed. The current implementation relies on C++ destroying the
// elements in the opposite order stated in the structure
struct WorldInfo
{
std::string name;
std::shared_ptr<btDefaultCollisionConfiguration> collisionConfiguration;
std::shared_ptr<btCollisionDispatcher> dispatcher;
std::shared_ptr<btBroadphaseInterface> broadphase;
std::shared_ptr<btConstraintSolver> solver;
std::shared_ptr<btDiscreteDynamicsWorld> world;
};

struct ModelInfo
{
std::string name;
Identity world;
// cppcheck-suppress unusedStructMember
bool fixed;
math::Pose3d pose;
std::vector<std::size_t> links = {};
};

struct LinkInfo
{
std::string name;
Identity model;
math::Pose3d pose;
math::Pose3d inertialPose;
// cppcheck-suppress unusedStructMember
double mass;
btVector3 inertia;
std::shared_ptr<btDefaultMotionState> motionState;
std::shared_ptr<btCompoundShape> collisionShape;
std::shared_ptr<btRigidBody> link;
};

struct CollisionInfo
{
std::string name;
std::shared_ptr<btCollisionShape> shape;
Identity link;
Identity model;
math::Pose3d pose;
// cppcheck-suppress unusedStructMember
bool isMesh;
std::shared_ptr<btTriangleMesh> mesh;
};

struct JointInfo
{
std::string name;
// Base class for all the constraint objects,
std::shared_ptr<btTypedConstraint> joint;
// cppcheck-suppress unusedStructMember
std::size_t childLinkId;
// cppcheck-suppress unusedStructMember
std::size_t parentLinkId;
// cppcheck-suppress unusedStructMember
int constraintType;
ignition::math::Vector3d axis;
};

inline btMatrix3x3 convertMat(Eigen::Matrix3d mat)
{
return btMatrix3x3(mat(0, 0), mat(0, 1), mat(0, 2),
mat(1, 0), mat(1, 1), mat(1, 2),
mat(2, 0), mat(2, 1), mat(2, 2));
}

inline btVector3 convertVec(Eigen::Vector3d vec)
{
return btVector3(vec(0), vec(1), vec(2));
}

inline Eigen::Matrix3d convert(btMatrix3x3 mat)
{
Eigen::Matrix3d val;
val << mat[0][0], mat[0][1], mat[0][2],
mat[1][0], mat[1][1], mat[1][2],
mat[2][0], mat[2][1], mat[2][2];
return val;
}

inline Eigen::Vector3d convert(btVector3 vec)
{
Eigen::Vector3d val;
val << vec[0], vec[1], vec[2];
return val;
}

class Base : public Implements3d<FeatureList<Feature>>
{
public: std::size_t entityCount = 0;

public: inline std::size_t GetNextEntity()
{
return entityCount++;
}

public: inline Identity InitiateEngine(std::size_t /*_engineID*/) override
{
const auto id = this->GetNextEntity();
assert(id == 0);

return this->GenerateIdentity(0);
}

public: inline std::size_t idToIndexInContainer(std::size_t _id) const
{
auto it = this->childIdToParentId.find(_id);
if (it != this->childIdToParentId.end())
{
std::size_t index = 0;
for (const auto &pair : this->childIdToParentId)
{
if (pair.first == _id && pair.second == it->second)
{
return index;
}
else if (pair.second == it->second)
{
++index;
}
}
}
// return invalid index if not found in id map
return -1;
}

public: inline std::size_t indexInContainerToId(
const std::size_t _containerId, const std::size_t _index) const
{
std::size_t counter = 0;
auto it = this->childIdToParentId.begin();

while (counter <= _index && it != this->childIdToParentId.end())
{
if (it->second == _containerId && counter == _index)
{
return it->first;
}
else if (it->second == _containerId)
{
++counter;
}
++it;
}
// return invalid id if entity not found
return -1;
}

public: inline Identity AddWorld(WorldInfo _worldInfo)
{
const auto id = this->GetNextEntity();
this->worlds[id] = std::make_shared<WorldInfo>(_worldInfo);
this->childIdToParentId.insert({id, -1});
return this->GenerateIdentity(id, this->worlds.at(id));
}

public: inline Identity AddModel(std::size_t _worldId, ModelInfo _modelInfo)
{
const auto id = this->GetNextEntity();
this->models[id] = std::make_shared<ModelInfo>(_modelInfo);
this->childIdToParentId.insert({id, _worldId});
return this->GenerateIdentity(id, this->models.at(id));
}

public: inline Identity AddLink(std::size_t _modelId, LinkInfo _linkInfo)
{
const auto id = this->GetNextEntity();
this->links[id] = std::make_shared<LinkInfo>(_linkInfo);

auto model = this->models.at(_linkInfo.model);
model->links.push_back(id);

this->childIdToParentId.insert({id, _modelId});
return this->GenerateIdentity(id, this->links.at(id));
}
public: inline Identity AddCollision(
std::size_t _linkId, CollisionInfo _collisionInfo)
{
const auto id = this->GetNextEntity();
this->collisions[id] = std::make_shared<CollisionInfo>(_collisionInfo);
this->childIdToParentId.insert({id, _linkId});
return this->GenerateIdentity(id, this->collisions.at(id));
}

public: inline Identity AddJoint(JointInfo _jointInfo)
{
const auto id = this->GetNextEntity();
this->joints[id] = std::make_shared<JointInfo>(_jointInfo);

return this->GenerateIdentity(id, this->joints.at(id));
}

public: using WorldInfoPtr = std::shared_ptr<WorldInfo>;
public: using ModelInfoPtr = std::shared_ptr<ModelInfo>;
public: using LinkInfoPtr = std::shared_ptr<LinkInfo>;
public: using CollisionInfoPtr = std::shared_ptr<CollisionInfo>;
public: using JointInfoPtr = std::shared_ptr<JointInfo>;
Comment on lines +245 to +249
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for shared vs unique here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those in particular can't be changed because the GenerateIdentity templated function from ignition takes a shared pointer to generate new identities.


public: std::unordered_map<std::size_t, WorldInfoPtr> worlds;
public: std::unordered_map<std::size_t, ModelInfoPtr> models;
public: std::unordered_map<std::size_t, LinkInfoPtr> links;
public: std::unordered_map<std::size_t, CollisionInfoPtr> collisions;
public: std::unordered_map<std::size_t, JointInfoPtr> joints;

// childIdToParentId needs to be an ordered map so this iteration proceeds
// in ascending order of the keys of that map. Do not change.
public: std::map<std::size_t, std::size_t> childIdToParentId;
};

} // namespace bullet
} // namespace physics
} // namespace ignition

#endif
Loading