ARGoS 3
A parallel, multi-engine simulator for swarm robotics
dynamics3d_gravity_plugin.cpp
Go to the documentation of this file.
1
8
9#include <argos3/plugins/simulator/physics_engines/dynamics3d/dynamics3d_model.h>
10#include <algorithm>
11#include <vector>
12
13namespace argos {
14
15 /****************************************/
16 /****************************************/
17
19 GetNodeAttributeOrDefault(t_tree, "g", m_fAcceleration, m_fAcceleration);
20 }
21
22 /****************************************/
23 /****************************************/
24
26 std::vector<std::shared_ptr<CDynamics3DModel::CAbstractBody> >& vecBodies = c_model.GetBodies();
27 m_vecTargets.insert(std::end(m_vecTargets),
28 std::begin(vecBodies),
29 std::end(vecBodies));
30 }
31
32 /****************************************/
33 /****************************************/
34
36 auto itRemove =
37 std::remove_if(std::begin(m_vecTargets),
38 std::end(m_vecTargets),
39 [&c_model] (const std::shared_ptr<CDynamics3DModel::CAbstractBody>& ptr_body) {
40 return (&ptr_body->GetModel() == &c_model);
41 });
42 m_vecTargets.erase(itRemove, std::end(m_vecTargets));
43 }
44
45 /****************************************/
46 /****************************************/
47
49 for(std::shared_ptr<CDynamics3DModel::CAbstractBody>& ptr_body : m_vecTargets) {
50 btVector3 cGravity(0.0, -m_fAcceleration * ptr_body->GetData().Mass, 0.0);
51 ptr_body->ApplyForce(cGravity);
52 }
53 }
54
55 /****************************************/
56 /****************************************/
57
59 "gravity",
60 "Michael Allwright [allsey87@gmail.com]",
61 "1.0",
62 "Applies a gravity force to all bodies in the simulation",
63 "For a description on how to use this plugin, please consult the documentation\n"
64 "for the dynamics3d physics engine plugin",
65 "Usable");
66
67 /****************************************/
68 /****************************************/
69
70}
#define REGISTER_DYNAMICS3D_PLUGIN(CLASSNAME, LABEL, AUTHOR, VERSION, BRIEF_DESCRIPTION, LONG_DESCRIPTION, STATUS)
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
void GetNodeAttributeOrDefault(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer, const T &t_default)
Returns the value of a node's attribute, or the passed default value.
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
virtual void Init(TConfigurationNode &t_tree)
virtual void UnregisterModel(CDynamics3DModel &c_model)
virtual void RegisterModel(CDynamics3DModel &c_model)
std::vector< std::shared_ptr< CAbstractBody > > & GetBodies()