Skip to content

Commit

Permalink
[example][boxes] Change to bullet collision detector
Browse files Browse the repository at this point in the history
(cherry picked from commit e98ee95)
  • Loading branch information
jslee02 committed Mar 31, 2024
1 parent d502f2e commit a8af426
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/boxes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ get_filename_component(example_name ${CMAKE_CURRENT_LIST_DIR} NAME)

project(${example_name})

set(required_components utils-urdf gui-osg)
set(required_libraries dart dart-utils-urdf dart-gui-osg)
set(required_components collision-bullet utils-urdf gui-osg)
set(required_libraries dart dart-collision-bullet dart-utils-urdf dart-gui-osg)

if(DART_IN_SOURCE_BUILD)
dart_build_example_in_source(${example_name} LINK_LIBRARIES ${required_libraries})
Expand Down
14 changes: 11 additions & 3 deletions examples/boxes/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include <dart/gui/osg/osg.hpp>

#include <dart/collision/bullet/bullet.hpp>

#include <dart/dart.hpp>

#include <osgShadow/ShadowMap>
Expand Down Expand Up @@ -60,6 +62,7 @@ using namespace dart;
dynamics::CollisionAspect,
dynamics::DynamicsAspect>(boxShape);
shapeNode->getVisualAspect()->setColor(color);
shapeNode->getDynamicsAspect()->setRestitutionCoeff(0.9);

// Put the body into position
Eigen::Isometry3d tf = Eigen::Isometry3d::Identity();
Expand All @@ -74,14 +77,18 @@ int main()
// Create an empty world
auto world = simulation::World::create();

// Set collision detector type
world->getConstraintSolver()->setCollisionDetector(
collision::BulletCollisionDetector::create());

// Create dim x dim x dim boxes
auto dim = 5;
for (auto i = 0; i < dim; ++i) {
for (auto j = 0; j < dim; ++j) {
for (auto k = 0; k < dim; ++k) {
auto x = i - dim / 2;
auto y = j - dim / 2;
auto z = k + 1;
auto z = k + 5;
auto position = Eigen::Vector3d(x, y, z);
auto size = Eigen::Vector3d(0.9, 0.9, 0.9);
auto color = Eigen::Vector3d(
Expand All @@ -104,6 +111,7 @@ int main()
dynamics::DynamicsAspect>(
std::make_shared<dynamics::BoxShape>(Eigen::Vector3d(25.0, 25.0, 0.1)));
groundShapeNode->getVisualAspect()->setColor(dart::Color::LightGray());
groundShapeNode->getDynamicsAspect()->setRestitutionCoeff(0.9);
world->addSkeleton(ground);

// Wrap a WorldNode around it
Expand Down Expand Up @@ -134,8 +142,8 @@ int main()

// Adjust the viewpoint of the Viewer
viewer.getCameraManipulator()->setHomePosition(
::osg::Vec3(15.0f, 15.0f, 10.0f),
::osg::Vec3(0.00f, 0.00f, 2.50f),
::osg::Vec3(20.0f, 20.0f, 15.0f),
::osg::Vec3(0.00f, 0.00f, 3.00f),
::osg::Vec3(0, 0, 1.0f));

// We need to re-dirty the CameraManipulator by passing it into the viewer
Expand Down
33 changes: 19 additions & 14 deletions tests/benchmark/integration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@ dart_benchmarks(
bm_empty.cpp
)

dart_benchmarks(
TYPE BM_INTEGRATION
SOURCES
bm_boxes.cpp
LINK_LIBRARIES
dart
)
if(TARGET dart-collision-bullet)

dart_benchmarks(
TYPE BM_INTEGRATION
SOURCES
bm_boxes.cpp
LINK_LIBRARIES
dart
dart-collision-bullet
)

endif()

if(TARGET dart-utils)

dart_benchmarks(
TYPE BM_INTEGRATION
SOURCES
bm_kinematics.cpp
LINK_LIBRARIES
dart-utils
)
dart_benchmarks(
TYPE BM_INTEGRATION
SOURCES
bm_kinematics.cpp
LINK_LIBRARIES
dart-utils
)

endif()
14 changes: 12 additions & 2 deletions tests/benchmark/integration/bm_boxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

#include <dart/simulation/simulation.hpp>

#include <dart/constraint/constraint.hpp>

#include <dart/collision/bullet/bullet.hpp>

#include <dart/dynamics/dynamics.hpp>

#include <dart/math/math.hpp>
Expand Down Expand Up @@ -63,6 +67,7 @@ namespace {
dynamics::CollisionAspect,
dynamics::DynamicsAspect>(boxShape);
shapeNode->getVisualAspect()->setColor(color);
shapeNode->getDynamicsAspect()->setRestitutionCoeff(0.9);

// Put the body into position
Eigen::Isometry3d tf = Eigen::Isometry3d::Identity();
Expand All @@ -77,13 +82,17 @@ namespace {
// Create an empty world
auto world = simulation::World::create();

// Set collision detector type
world->getConstraintSolver()->setCollisionDetector(
collision::BulletCollisionDetector::create());

// Create dim x dim x dim boxes
for (auto i = 0u; i < dim; ++i) {
for (auto j = 0u; j < dim; ++j) {
for (auto k = 0u; k < dim; ++k) {
auto x = i - dim / 2;
auto y = j - dim / 2;
auto z = k + 1;
auto z = k + 5;
auto position = Eigen::Vector3d(x, y, z);
auto size = Eigen::Vector3d(0.9, 0.9, 0.9);
auto color = Eigen::Vector3d(
Expand All @@ -106,6 +115,7 @@ namespace {
dynamics::DynamicsAspect>(
std::make_shared<dynamics::BoxShape>(Eigen::Vector3d(10.0, 10.0, 0.1)));
groundShapeNode->getVisualAspect()->setColor(dart::Color::LightGray());
groundShapeNode->getDynamicsAspect()->setRestitutionCoeff(0.9);
world->addSkeleton(ground);

return world;
Expand All @@ -115,7 +125,7 @@ namespace {

static void BM_RunBoxes(benchmark::State& state)
{
const auto steps = 1000u;
const auto steps = 2000u;
auto world = createWorld(state.range(0));

for (auto _ : state) {
Expand Down

0 comments on commit a8af426

Please sign in to comment.