ci_footbot_distance_scanner_sensor.cpp
Go to the documentation of this file.
1 
8 
9 #ifdef ARGOS_WITH_LUA
10 #include <argos3/core/wrappers/lua/lua_utility.h>
11 #endif
12 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
19  return m_tReadingsMap;
20  }
21 
22  /****************************************/
23  /****************************************/
24 
26  return m_tShortReadingsMap;
27  }
28 
29  /****************************************/
30  /****************************************/
31 
33  return m_tLongReadingsMap;
34  }
35 
36 
37 #ifdef ARGOS_WITH_LUA
38  void CCI_FootBotDistanceScannerSensor::CreateLuaState(lua_State* pt_lua_state) {
39  CLuaUtility::OpenRobotStateTable (pt_lua_state, "distance_scanner");
40  CLuaUtility::StartTable (pt_lua_state, "short_range" );
41  CLuaUtility::EndTable (pt_lua_state );
42  CLuaUtility::StartTable (pt_lua_state, "long_range" );
43  CLuaUtility::EndTable (pt_lua_state );
44  CLuaUtility::CloseRobotStateTable(pt_lua_state );
45  }
46 #endif
47 
48  /****************************************/
49  /****************************************/
50 
51 #ifdef ARGOS_WITH_LUA
52  void CCI_FootBotDistanceScannerSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
53  lua_getfield(pt_lua_state, -1, "distance_scanner");
54  CLuaUtility::StartTable(pt_lua_state, "short_range");
55  int nCounter = 1;
56  for(TReadingsMap::iterator it = m_tShortReadingsMap.begin();
57  it != m_tShortReadingsMap.end(); ++it) {
58  CLuaUtility::StartTable(pt_lua_state, nCounter);
59  CLuaUtility::AddToTable(pt_lua_state, "angle", it->first);
60  CLuaUtility::AddToTable(pt_lua_state, "distance", it->second);
61  CLuaUtility::EndTable(pt_lua_state);
62  ++nCounter;
63  }
64  CLuaUtility::EndTable(pt_lua_state);
65  CLuaUtility::StartTable(pt_lua_state, "long_range");
66  nCounter = 1;
67  for(TReadingsMap::iterator it = m_tLongReadingsMap.begin();
68  it != m_tLongReadingsMap.end(); ++it) {
69  CLuaUtility::StartTable(pt_lua_state, nCounter);
70  CLuaUtility::AddToTable(pt_lua_state, "angle", it->first);
71  CLuaUtility::AddToTable(pt_lua_state, "distance", it->second);
72  CLuaUtility::EndTable(pt_lua_state);
73  ++nCounter;
74  }
75  CLuaUtility::EndTable(pt_lua_state);
76  lua_pop(pt_lua_state, 1);
77  }
78 #endif
79 
80 
81  /****************************************/
82  /****************************************/
83 
84 }
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static void EndTable(lua_State *pt_state)
Adds a table to the Lua stack.
static void AddToTable(lua_State *pt_state, const std::string &str_key, void *pt_data)
Adds a pointer to a chunk of data with the given string key to the table located at the top of the st...
static void StartTable(lua_State *pt_state, const std::string &str_key)
Adds a table with the given string key to the table located at the top of the stack.
static void OpenRobotStateTable(lua_State *pt_state, const std::string &str_key)
Opens a table in the robot state, creating it if it does not exist.
static void CloseRobotStateTable(lua_State *pt_state)
Closes a table in the robot state.
const TReadingsMap & GetShortReadingsMap()
Return a map of the readings of the ds, short sensor readings A map of the readings of the ds short s...
const TReadingsMap & GetLongReadingsMap()
Return a map of the readings of the ds, long sensor readings A map of the readings of the ds long sen...
TReadingsMap m_tLongReadingsMap
Map storing the last received packets from the long distance sensors.
TReadingsMap m_tReadingsMap
Map storing all the last received packets.
TReadingsMap m_tShortReadingsMap
Map storing the last received packets from the short distance sensors.
const TReadingsMap & GetReadingsMap()
Return a map of the readings of the ds A map of the readings of the ds in the following format: angle...