DART 6.13.2
Loading...
Searching...
No Matches
World.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * This code incorporates portions of Open Dynamics Engine
19 * (Copyright (c) 2001-2004, Russell L. Smith. All rights
20 * reserved.) and portions of FCL (Copyright (c) 2011, Willow
21 * Garage, Inc. All rights reserved.), which were released under
22 * the same BSD license as below
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
32 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef DART_SIMULATION_WORLD_HPP_
40#define DART_SIMULATION_WORLD_HPP_
41
42#include <set>
43#include <string>
44#include <vector>
45
46#include <Eigen/Dense>
47
57
58namespace dart {
59
60namespace integration {
61class Integrator;
62} // namespace integration
63
64namespace dynamics {
65class Skeleton;
66} // namespace dynamics
67
68namespace constraint {
69class ConstraintSolver;
70} // namespace constraint
71
72namespace collision {
73class CollisionResult;
74} // namespace collision
75
76namespace simulation {
77
79
80
82class World : public virtual common::Subject
83{
84public:
86 const std::string& _oldName, const std::string& _newName)>;
87
89 template <typename... Args>
90 static WorldPtr create(Args&&... args);
91
92 //--------------------------------------------------------------------------
93 // Constructor and Destructor
94 //--------------------------------------------------------------------------
95
97 static std::shared_ptr<World> create(const std::string& name = "world");
98
100 World(const std::string& _name = "world");
101
103 virtual ~World();
104
107 std::shared_ptr<World> clone() const;
108
109 //--------------------------------------------------------------------------
110 // Properties
111 //--------------------------------------------------------------------------
112
114 const std::string& setName(const std::string& _newName);
115
117 const std::string& getName() const;
118
120 void setGravity(const Eigen::Vector3d& _gravity);
121
123 void setGravity(double x, double y, double z);
124
126 const Eigen::Vector3d& getGravity() const;
127
129 void setTimeStep(double _timeStep);
130
132 double getTimeStep() const;
133
134 //--------------------------------------------------------------------------
135 // Structural Properties
136 //--------------------------------------------------------------------------
137
139 dynamics::SkeletonPtr getSkeleton(std::size_t _index) const;
140
144 dynamics::SkeletonPtr getSkeleton(const std::string& _name) const;
145
147 std::size_t getNumSkeletons() const;
148
150 std::string addSkeleton(const dynamics::SkeletonPtr& _skeleton);
151
153 void removeSkeleton(const dynamics::SkeletonPtr& _skeleton);
154
157 std::set<dynamics::SkeletonPtr> removeAllSkeletons();
158
160 bool hasSkeleton(const dynamics::ConstSkeletonPtr& skeleton) const;
161
163 bool hasSkeleton(const std::string& skeletonName) const;
164
166 int getIndex(int _index) const;
167
169 dynamics::SimpleFramePtr getSimpleFrame(std::size_t _index) const;
170
172 dynamics::SimpleFramePtr getSimpleFrame(const std::string& _name) const;
173
175 std::size_t getNumSimpleFrames() const;
176
178 std::string addSimpleFrame(const dynamics::SimpleFramePtr& _frame);
179
182
185 std::set<dynamics::SimpleFramePtr> removeAllSimpleFrames();
186
187 //--------------------------------------------------------------------------
188 // Collision checking
189 //--------------------------------------------------------------------------
190
192 DART_DEPRECATED(6.0)
193 bool checkCollision(bool checkAllCollisions);
194
200 bool checkCollision(
201 const collision::CollisionOption& option
202 = collision::CollisionOption(false, 1u, nullptr),
203 collision::CollisionResult* result = nullptr);
204
209 const collision::CollisionResult& getLastCollisionResult() const;
210
211 //--------------------------------------------------------------------------
212 // Simulation
213 //--------------------------------------------------------------------------
214
216 void reset();
217
221 void step(bool _resetCommand = true);
222
224 void setTime(double _time);
225
227 double getTime() const;
228
233 int getSimFrames() const;
234
235 //--------------------------------------------------------------------------
236 // Constraint
237 //--------------------------------------------------------------------------
238
243 void setConstraintSolver(constraint::UniqueConstraintSolverPtr solver);
244
246 constraint::ConstraintSolver* getConstraintSolver();
247
249 const constraint::ConstraintSolver* getConstraintSolver() const;
250
252 void bake();
253
256
258
283 template <typename Func>
284 void eachSkeleton(Func func) const;
285
294 template <typename Func>
295 void eachSkeleton(Func func);
296
305 template <typename Func>
306 void eachSimpleFrame(Func func) const;
307
316 template <typename Func>
317 void eachSimpleFrame(Func func);
318
320
321protected:
324 const dynamics::ConstMetaSkeletonPtr& _skeleton);
325
327 void handleSimpleFrameNameChange(const dynamics::Entity* _entity);
328
330 std::string mName;
331
333 std::vector<dynamics::SkeletonPtr> mSkeletons;
334
335 std::map<dynamics::ConstMetaSkeletonPtr, dynamics::SkeletonPtr>
337
340 std::vector<common::Connection> mNameConnectionsForSkeletons;
341
343 dart::common::NameManager<dynamics::SkeletonPtr> mNameMgrForSkeletons;
344
346 std::vector<dynamics::SimpleFramePtr> mSimpleFrames;
347
350 std::vector<common::Connection> mNameConnectionsForSimpleFrames;
351
353 std::map<const dynamics::SimpleFrame*, dynamics::SimpleFramePtr>
355
357 dart::common::NameManager<dynamics::SimpleFramePtr> mNameMgrForSimpleFrames;
358
363 std::vector<int> mIndices;
364
366 Eigen::Vector3d mGravity;
367
369 double mTimeStep;
370
372 double mTime;
373
376
378 std::unique_ptr<constraint::ConstraintSolver> mConstraintSolver;
379
382
383 //--------------------------------------------------------------------------
384 // Signals
385 //--------------------------------------------------------------------------
387
388public:
389 //--------------------------------------------------------------------------
390 // Slot registers
391 //--------------------------------------------------------------------------
392 common::SlotRegister<NameChangedSignal> onNameChanged;
393};
395
396} // namespace simulation
397} // namespace dart
398
399#include "dart/simulation/detail/World-impl.hpp"
400
401#endif // DART_SIMULATION_WORLD_HPP_
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
Definition ClassWithVirtualBase.hpp:44
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
Definition ClassWithVirtualBase.hpp:43
#define DART_DEPRECATED(version)
Definition Deprecated.hpp:51
const CollisionOption & option
Collision option of DART.
Definition FCLCollisionDetector.cpp:157
CollisionResult * result
Collision result of DART.
Definition FCLCollisionDetector.cpp:160
std::string * name
Definition SkelParser.cpp:1698
The Subject class is a base class for any object that wants to report when it gets destroyed.
Definition Subject.hpp:58
class Recording
Definition Recording.hpp:58
class World
Definition World.hpp:83
virtual ~World()
Destructor.
Definition World.cpp:80
std::size_t getNumSkeletons() const
Get the number of skeletons.
Definition World.cpp:289
std::map< dynamics::ConstMetaSkeletonPtr, dynamics::SkeletonPtr > mMapForSkeletons
Definition World.hpp:336
std::unique_ptr< constraint::ConstraintSolver > mConstraintSolver
Constraint solver.
Definition World.hpp:378
int getIndex(int _index) const
Get the dof index for the indexed skeleton.
Definition World.cpp:424
const std::string & getName() const
Get the name of this World.
Definition World.cpp:244
double getTimeStep() const
Get time step.
Definition World.cpp:152
void handleSimpleFrameNameChange(const dynamics::Entity *_entity)
Register when a SimpleFrame's name is changed.
Definition World.cpp:672
std::string mName
Name of this World.
Definition World.hpp:330
dart::common::NameManager< dynamics::SkeletonPtr > mNameMgrForSkeletons
NameManager for keeping track of Skeletons.
Definition World.hpp:343
std::map< const dynamics::SimpleFrame *, dynamics::SimpleFramePtr > mSimpleFrameToShared
Map from raw SimpleFrame pointers to their shared_ptrs.
Definition World.hpp:354
void setTime(double _time)
Set current time.
Definition World.cpp:209
std::set< dynamics::SkeletonPtr > removeAllSkeletons()
Remove all the skeletons in this world, and return a set of shared pointers to them,...
Definition World.cpp:395
void step(bool _resetCommand=true)
Calculate the dynamics and integrate the world for one step.
Definition World.cpp:167
void setConstraintSolver(constraint::UniqueConstraintSolverPtr solver)
Sets the constraint solver.
Definition World.cpp:563
Eigen::Vector3d mGravity
Gravity.
Definition World.hpp:366
std::vector< dynamics::SkeletonPtr > mSkeletons
Skeletons in this world.
Definition World.hpp:333
void removeSkeleton(const dynamics::SkeletonPtr &_skeleton)
Remove a skeleton from this world.
Definition World.cpp:336
common::SlotRegister< NameChangedSignal > onNameChanged
Definition World.hpp:392
const collision::CollisionResult & getLastCollisionResult() const
Return the collision checking result of the last simulation step.
Definition World.cpp:557
std::size_t getNumSimpleFrames() const
Get the number of Entities.
Definition World.cpp:445
std::vector< dynamics::SimpleFramePtr > mSimpleFrames
Entities in this world.
Definition World.hpp:346
void setTimeStep(double _timeStep)
Set time step.
Definition World.cpp:135
double mTimeStep
Simulation time step.
Definition World.hpp:369
std::vector< int > mIndices
The first indeices of each skeleton's dof in mDofs.
Definition World.hpp:363
void bake()
Bake simulated current state and store it into mRecording.
Definition World.cpp:592
std::string addSimpleFrame(const dynamics::SimpleFramePtr &_frame)
Add an Entity to this world.
Definition World.cpp:451
void removeSimpleFrame(const dynamics::SimpleFramePtr &_frame)
Remove a SimpleFrame from this world.
Definition World.cpp:485
void eachSimpleFrame(Func func) const
Iterates all the SimpleFrames and invokes the callback function.
Definition World-impl.hpp:102
void eachSkeleton(Func func) const
Iterates all the Skeletons and invokes the callback function.
Definition World-impl.hpp:56
int getSimFrames() const
Get the number of simulated frames.
Definition World.cpp:221
const std::string & setName(const std::string &_newName)
Set the name of this World.
Definition World.cpp:227
void reset()
Reset the time, frame counter and recorded histories.
Definition World.cpp:158
std::vector< common::Connection > mNameConnectionsForSimpleFrames
Connections for noticing changes in Frame names TODO(MXG): Consider putting this functionality into N...
Definition World.hpp:350
int mFrame
Current simulation frame number.
Definition World.hpp:375
NameChangedSignal mNameChangedSignal
Definition World.hpp:386
bool checkCollision(bool checkAllCollisions)
Deprecated. Please use checkCollision(~) instead.
Definition World.cpp:536
const Eigen::Vector3d & getGravity() const
Get gravity.
Definition World.cpp:268
void setGravity(const Eigen::Vector3d &_gravity)
Set gravity.
Definition World.cpp:250
constraint::ConstraintSolver * getConstraintSolver()
Get the constraint solver.
Definition World.cpp:580
std::shared_ptr< World > clone() const
Create a clone of this World.
Definition World.cpp:92
void handleSkeletonNameChange(const dynamics::ConstMetaSkeletonPtr &_skeleton)
Register when a Skeleton's name is changed.
Definition World.cpp:622
dynamics::SkeletonPtr getSkeleton(std::size_t _index) const
Get the indexed skeleton.
Definition World.cpp:274
std::set< dynamics::SimpleFramePtr > removeAllSimpleFrames()
Remove all SimpleFrames in this world, and return a set of shared pointers to them,...
Definition World.cpp:519
dart::common::NameManager< dynamics::SimpleFramePtr > mNameMgrForSimpleFrames
NameManager for keeping track of Entities.
Definition World.hpp:357
std::string addSkeleton(const dynamics::SkeletonPtr &_skeleton)
Add a skeleton to this world.
Definition World.cpp:295
bool hasSkeleton(const dynamics::ConstSkeletonPtr &skeleton) const
Returns whether this World contains a Skeleton.
Definition World.cpp:411
Recording * getRecording()
Get recording.
Definition World.cpp:616
std::vector< common::Connection > mNameConnectionsForSkeletons
Connections for noticing changes in Skeleton names TODO(MXG): Consider putting this functionality int...
Definition World.hpp:340
static WorldPtr create(Args &&... args)
Creates World as shared_ptr.
Definition World-impl.hpp:49
Recording * mRecording
Definition World.hpp:381
double getTime() const
Get current time.
Definition World.cpp:215
dynamics::SimpleFramePtr getSimpleFrame(std::size_t _index) const
Get the indexed Entity.
Definition World.cpp:430
double mTime
Current simulation time.
Definition World.hpp:372
#define DART_COMMON_DECLARE_SHARED_WEAK(X)
Definition SmartPointer.hpp:41
Definition Random-impl.hpp:92
::fcl::CollisionResult CollisionResult
Definition BackwardCompatibility.hpp:158
std::shared_ptr< const Skeleton > ConstSkeletonPtr
Definition SmartPointer.hpp:60
std::shared_ptr< SimpleFrame > SimpleFramePtr
Definition SmartPointer.hpp:53
std::shared_ptr< Skeleton > SkeletonPtr
Definition SmartPointer.hpp:60
std::shared_ptr< World > WorldPtr
Definition SmartPointer.hpp:41
Integrator
This attribute selects the numerical integrator to be used.
Definition Types.hpp:72
Definition BulletCollisionDetector.cpp:60