2 #include <argos3/core/simulator/entity/embodied_entity.h>
3 #include <argos3/core/simulator/simulator.h>
4 #include <argos3/core/simulator/space/space.h>
5 #include <argos3/core/simulator/space/positional_indices/grid.h>
6 #include <argos3/core/utility/configuration/argos_exception.h>
7 #include <argos3/core/utility/logging/argos_log.h>
15 m_bCheckOcclusions(true) {
33 std::string strPosIndexMethod(
"grid");
42 if(strPosIndexMethod ==
"grid") {
43 size_t punGridSize[3];
45 punGridSize[0] =
static_cast<size_t>(cArenaSize.
GetX());
46 punGridSize[1] =
static_cast<size_t>(cArenaSize.
GetY());
47 punGridSize[2] =
static_cast<size_t>(cArenaSize.
GetZ());
50 std::string strPosGridSize;
52 ParseValues<size_t>(strPosGridSize, 3, punGridSize,
',');
55 cArenaCenter - cArenaSize * 0.5f, cArenaCenter + cArenaSize * 0.5f,
56 punGridSize[0], punGridSize[1], punGridSize[2]);
59 m_pcRABEquippedEntityIndex = pcGrid;
62 THROW_ARGOSEXCEPTION(
"Unknown method \"" << strPosIndexMethod <<
"\" for the positional index.");
82 m_pcRABEquippedEntityIndex->Reset();
84 for(TRoutingTable::iterator it = m_tRoutingTable.begin();
85 it != m_tRoutingTable.end();
95 delete m_pcRABEquippedEntityIndex;
96 if(m_pcRABEquippedEntityGridUpdateOperation !=
nullptr) {
97 delete m_pcRABEquippedEntityGridUpdateOperation;
104 static size_t HashRABPair(
const std::pair<CRABEquippedEntity*, CRABEquippedEntity*>& c_pair) {
106 reinterpret_cast<size_t>(c_pair.first) ^
107 reinterpret_cast<size_t>(c_pair.second);
112 m_pcRABEquippedEntityIndex->Update();
114 for(TRoutingTable::iterator it = m_tRoutingTable.begin();
115 it != m_tRoutingTable.end();
120 unordered_map<ssize_t, std::pair<CRABEquippedEntity*, CRABEquippedEntity*> > mapPairsAlreadyChecked;
122 unordered_map<ssize_t, std::pair<CRABEquippedEntity*, CRABEquippedEntity*> >::iterator itPair;
124 std::pair<CRABEquippedEntity*, CRABEquippedEntity*> cTestKey;
128 CRay3 cOcclusionCheckRay;
136 for(TRoutingTable::iterator it = m_tRoutingTable.begin();
137 it != m_tRoutingTable.end();
145 m_pcRABEquippedEntityIndex->GetEntitiesAt(cOtherRABs, cRAB.
GetPosition());
148 it2 != cOtherRABs.
end();
153 if(&cRAB != &cOtherRAB) {
155 if(&cRAB < &cOtherRAB) {
156 cTestKey.first = &cRAB;
157 cTestKey.second = &cOtherRAB;
160 cTestKey.first = &cOtherRAB;
161 cTestKey.second = &cRAB;
163 unTestHash = HashRABPair(cTestKey);
164 itPair = mapPairsAlreadyChecked.find(unTestHash);
165 if(itPair == mapPairsAlreadyChecked.end() ||
166 itPair->second.first != cTestKey.first ||
167 itPair->second.second != cTestKey.second) {
169 mapPairsAlreadyChecked[unTestHash] = cTestKey;
174 if((!m_bCheckOcclusions) ||
182 fDistance = cOcclusionCheckRay.
GetLength();
183 if(fDistance < cOtherRAB.
GetRange()) {
185 m_tRoutingTable[cRAB.
GetIndex()].insert(&cOtherRAB);
189 m_tRoutingTable[cOtherRAB.
GetIndex()].insert(&cRAB);
203 m_tRoutingTable.insert(
206 m_pcRABEquippedEntityIndex->AddEntity(c_entity);
207 m_pcRABEquippedEntityIndex->Update();
214 m_pcRABEquippedEntityIndex->RemoveEntity(c_entity);
215 m_pcRABEquippedEntityIndex->Update();
216 TRoutingTable::iterator it = m_tRoutingTable.find(c_entity.
GetIndex());
217 if(it != m_tRoutingTable.end())
218 m_tRoutingTable.erase(it);
225 TRoutingTable::const_iterator it = m_tRoutingTable.find(c_entity.
GetIndex());
226 if(it != m_tRoutingTable.end()) {
239 "Carlo Pinciroli [ilpincy@gmail.com]",
241 "It simulates the communication across range-and-bearing-equipped robots.",
242 "This medium is required to simulate communication across range-and-bearing-\n"
243 "equipped robots. You need to add it to the <media> section every time you add\n"
244 "a range-and-bearing-equipped entity whose controller has a range-and-bearing\n"
245 "device activated.\n\n"
246 "REQUIRED XML CONFIGURATION\n\n"
247 "<range_and_bearing id=\"rab\" />\n\n"
248 "OPTIONAL XML CONFIGURATION\n\n"
249 "By default, the RAB medium requires two robots to be in direct line-of-sight in\n"
250 "order to be able to exchange messages. You can toggle this behavior on or off\n"
251 "through the 'check_occlusions' attribute:\n\n"
252 "<range_and_bearing id=\"rab\" check_occlusions=\"false\" />\n\n",
#define THROW_ARGOSEXCEPTION_NESTED(message, nested)
This macro throws an ARGoS exception with the passed message and nesting the passed exception.
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
unsigned long long UInt64
64-bit unsigned integer.
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
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")
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.
bool GetClosestEmbodiedEntityIntersectedByRay(SEmbodiedEntityIntersectionItem &s_item, const CRay3 &c_ray)
Returns the closest intersection with an embodied entity to the ray start.
bool NodeAttributeExists(TConfigurationNode &t_node, const std::string &str_attribute)
Returns true if the specified attribute of a node exists.
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.
void GetNodeAttribute(TConfigurationNode &t_node, const std::string &str_attribute, T &t_buffer)
Returns the value of a node's attribute.
const std::string & GetId() const
Returns the id of this entity.
std::string GetContext() const
Returns the context of this entity.
ssize_t GetIndex() const
Returns the entity index.
const CVector3 & GetPosition() const
virtual void Init(TConfigurationNode &t_tree)
Initialized the medium.
CSpace & GetSpace()
Returns a reference to the ARGoS space.
const std::string & GetId() const
Returns the id of this medium.
CEmbodiedEntity * IntersectedEntity
static CSimulator & GetInstance()
Returns the instance to the CSimulator class.
void SetUpdateEntityOperation(CEntityOperation *pc_operation)
CEntity::TVector & GetEntityVector()
Returns a vector of all the entities in the space.
The exception that wraps all errors in ARGoS.
Defines a very simple double-linked list that stores unique elements.
iterator begin() const
Returns an iterator to the first element.
void clear()
Erases the contents of the list.
iterator end() const
Returns an invalid iterator.
void SetEnd(const CVector3 &c_end)
void SetStart(const CVector3 &c_start)
Real GetX() const
Returns the x coordinate of this vector.
Real GetY() const
Returns the y coordinate of this vector.
Real GetZ() const
Returns the z coordinate of this vector.
size_t GetMsgSize() const
CEmbodiedEntity & GetEntityBody()
virtual void Update()
Updates the state of this medium.
void AddEntity(CRABEquippedEntity &c_entity)
Adds the specified entity to the list of managed entities.
virtual void Destroy()
Undoes whatever was done by Init().
const CSet< CRABEquippedEntity *, SEntityComparator > & GetRABsCommunicatingWith(CRABEquippedEntity &c_entity) const
Returns an immutable vector of RAB entities that can communicated with the given entity.
CRABMedium()
Class constructor.
virtual void PostSpaceInit()
Executes extra initialization activities after the space has been initialized.
void RemoveEntity(CRABEquippedEntity &c_entity)
Removes the specified entity from the list of managed entities.
virtual ~CRABMedium()
Class destructor.
virtual void Reset()
Resets the resource.
virtual void Init(TConfigurationNode &t_tree)
Initialized the medium.