ARGoS  3
A parallel, multi-engine simulator for swarm robotics
led_medium.cpp
Go to the documentation of this file.
1 #include "led_medium.h"
2 #include <argos3/core/simulator/simulator.h>
3 #include <argos3/core/simulator/space/space.h>
4 #include <argos3/core/simulator/space/positional_indices/grid.h>
5 #include <argos3/core/utility/configuration/argos_exception.h>
6 #include <argos3/core/utility/logging/argos_log.h>
7 
8 namespace argos {
9 
10  /****************************************/
11  /****************************************/
12 
14  }
15 
16  /****************************************/
17  /****************************************/
18 
20  }
21 
22  /****************************************/
23  /****************************************/
24 
26  try {
27  CMedium::Init(t_tree);
28  /* Get the positional index method */
29  std::string strPosIndexMethod("grid");
30  GetNodeAttributeOrDefault(t_tree, "index", strPosIndexMethod, strPosIndexMethod);
31  /* Get the arena center and size */
32  CVector3 cArenaCenter;
33  CVector3 cArenaSize;
34  TConfigurationNode& tArena = GetNode(CSimulator::GetInstance().GetConfigurationRoot(), "arena");
35  GetNodeAttribute(tArena, "size", cArenaSize);
36  GetNodeAttributeOrDefault(tArena, "center", cArenaCenter, cArenaCenter);
37  /* Create the positional index for LED entities */
38  if(strPosIndexMethod == "grid") {
39  size_t punGridSize[3];
40  if(!NodeAttributeExists(t_tree, "grid_size")) {
41  punGridSize[0] = cArenaSize.GetX();
42  punGridSize[1] = cArenaSize.GetY();
43  punGridSize[2] = cArenaSize.GetZ();
44  }
45  else {
46  std::string strPosGridSize;
47  GetNodeAttribute(t_tree, "grid_size", strPosGridSize);
48  ParseValues<size_t>(strPosGridSize, 3, punGridSize, ',');
49  }
51  cArenaCenter - cArenaSize * 0.5f, cArenaCenter + cArenaSize * 0.5f,
52  punGridSize[0], punGridSize[1], punGridSize[2]);
53  m_pcLEDEntityGridUpdateOperation = new CLEDEntityGridUpdater(*pcGrid);
54  pcGrid->SetUpdateEntityOperation(m_pcLEDEntityGridUpdateOperation);
55  m_pcLEDEntityIndex = pcGrid;
56  }
57  else {
58  THROW_ARGOSEXCEPTION("Unknown method \"" << strPosIndexMethod << "\" for the positional index.");
59  }
60  }
61  catch(CARGoSException& ex) {
62  THROW_ARGOSEXCEPTION_NESTED("Error in initialization of the LED medium", ex);
63  }
64  }
65 
66  /****************************************/
67  /****************************************/
68 
70  Update();
71  }
72 
73  /****************************************/
74  /****************************************/
75 
77  m_pcLEDEntityIndex->Reset();
78  }
79 
80  /****************************************/
81  /****************************************/
82 
84  delete m_pcLEDEntityIndex;
85  if(m_pcLEDEntityGridUpdateOperation != NULL) {
86  delete m_pcLEDEntityGridUpdateOperation;
87  }
88  }
89 
90  /****************************************/
91  /****************************************/
92 
94  m_pcLEDEntityIndex->Update();
95  }
96 
97  /****************************************/
98  /****************************************/
99 
101  m_pcLEDEntityIndex->AddEntity(c_entity);
102  }
103 
104  /****************************************/
105  /****************************************/
106 
108  m_pcLEDEntityIndex->RemoveEntity(c_entity);
109  }
110 
111  /****************************************/
112  /****************************************/
113 
115  "led",
116  "Carlo Pinciroli [ilpincy@gmail.com]",
117  "1.0",
118  "Manages the LEDs.",
119  "This medium is required to manage the LED entities, thus allowing the\n"
120  "associated camera sensors to work properly. If you intend to use a camera\n"
121  "sensor that detects colored blobs, you must add this medium to the XML\n"
122  "configuration file.\n\n"
123  "REQUIRED XML CONFIGURATION\n\n"
124  "<led id=\"led\" />\n\n"
125  "OPTIONAL XML CONFIGURATION\n\n"
126  "None for the time being\n",
127  "Under development"
128  );
129 
130  /****************************************/
131  /****************************************/
132 
133 }
argos::CVector3::GetZ
Real GetZ() const
Returns the z coordinate of this vector.
Definition: vector3.h:125
argos::CSimulator::GetInstance
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
Definition: simulator.cpp:87
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CVector3
A 3D vector class.
Definition: vector3.h:29
argos::CGrid
Definition: grid.h:12
argos::CLEDEntity
Definition: led_entity.h:24
argos::CLEDMedium::~CLEDMedium
virtual ~CLEDMedium()
Class destructor.
Definition: led_medium.cpp:19
argos::GetNode
TConfigurationNode & GetNode(TConfigurationNode &t_node, const std::string &str_tag)
Given a tree root node, returns the first of its child nodes with the wanted name.
Definition: argos_configuration.h:63
argos::CARGoSException
The exception that wraps all errors in ARGoS.
Definition: argos_exception.h:61
argos::REGISTER_MEDIUM
REGISTER_MEDIUM(CLEDMedium, "led", "Carlo Pinciroli [ilpincy@gmail.com]", "1.0", "Manages the LEDs.", "This medium is required to manage the LED entities, thus allowing the\n" "associated camera sensors to work properly. If you intend to use a camera\n" "sensor that detects colored blobs, you must add this medium to the XML\n" "configuration file.\n\n" "REQUIRED XML CONFIGURATION\n\n" "<led id=\"led\" />\n\n" "OPTIONAL XML CONFIGURATION\n\n" "None for the time being\n", "Under development")
argos::TConfigurationNode
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
Definition: argos_configuration.h:27
argos::CLEDMedium
Definition: led_medium.h:15
argos::CVector3::GetX
Real GetX() const
Returns the x coordinate of this vector.
Definition: vector3.h:93
argos::CLEDMedium::Update
virtual void Update()
Updates the state of this medium.
Definition: led_medium.cpp:93
led_medium.h
THROW_ARGOSEXCEPTION_NESTED
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
Definition: argos_exception.h:115
THROW_ARGOSEXCEPTION
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
Definition: argos_exception.h:111
argos::CLEDMedium::CLEDMedium
CLEDMedium()
Class constructor.
Definition: led_medium.cpp:13
argos::CMedium::Init
virtual void Init(TConfigurationNode &t_tree)
Initialized the medium.
Definition: medium.cpp:15
argos::CLEDMedium::AddEntity
void AddEntity(CLEDEntity &c_entity)
Adds the specified entity to the list of managed entities.
Definition: led_medium.cpp:100
argos::CLEDMedium::PostSpaceInit
virtual void PostSpaceInit()
Executes extra initialization activities after the space has been initialized.
Definition: led_medium.cpp:69
argos::GetNodeAttributeOrDefault
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.
Definition: argos_configuration.h:318
argos::GetNodeAttribute
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
Definition: argos_configuration.h:208
argos::CLEDMedium::Destroy
virtual void Destroy()
Undoes whatever was done by Init().
Definition: led_medium.cpp:83
argos::NodeAttributeExists
bool NodeAttributeExists(TConfigurationNode &t_node, const std::string &str_attribute)
Returns true if the specified attribute of a node exists.
Definition: argos_configuration.h:172
argos::CLEDMedium::Init
virtual void Init(TConfigurationNode &t_tree)
Initialized the medium.
Definition: led_medium.cpp:25
argos::CVector3::GetY
Real GetY() const
Returns the y coordinate of this vector.
Definition: vector3.h:109
argos::CGrid::SetUpdateEntityOperation
void SetUpdateEntityOperation(CEntityOperation *pc_operation)
Definition: grid_impl.h:907
argos::CLEDMedium::RemoveEntity
void RemoveEntity(CLEDEntity &c_entity)
Removes the specified entity from the list of managed entities.
Definition: led_medium.cpp:107
argos::CLEDEntityGridUpdater
Definition: led_entity.h:156
argos::CLEDMedium::Reset
virtual void Reset()
Resets the resource.
Definition: led_medium.cpp:76