Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00790_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00790_source.php on line 2
The ARGoS Website

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