ci_footbot_base_ground_sensor.cpp
Go to the documentation of this file.
1 
34 
35 #ifdef ARGOS_WITH_LUA
36 #include <argos3/core/wrappers/lua/lua_utility.h>
37 #endif
38 
39 namespace argos {
40 
41  /****************************************/
42  /****************************************/
43 
45  m_tReadings(8) {
46  // Set the values for the base ground sensor offset (taken from the CAD model, in cm)
47  m_tReadings[0].Offset.Set( 8.0, 0.0);
48  m_tReadings[1].Offset.Set( 4.2, 6.5);
49  m_tReadings[2].Offset.Set( 0.0, 8.0);
50  m_tReadings[3].Offset.Set(-4.2, 6.5);
51  m_tReadings[4].Offset.Set(-8.0, 0.0);
52  m_tReadings[5].Offset.Set(-4.2,-6.5);
53  m_tReadings[6].Offset.Set( 0.0,-8.0);
54  m_tReadings[7].Offset.Set( 4.2,-6.5);
55  }
56 
57  /****************************************/
58  /****************************************/
59 
61  return m_tReadings;
62  }
63 
64  /****************************************/
65  /****************************************/
66 
67  std::ostream& operator<<(std::ostream& c_os,
68  const CCI_FootBotBaseGroundSensor::SReading& s_reading) {
69  c_os << "Value=<" << s_reading.Value
70  << ">, Offset=<" << s_reading.Offset << ">";
71  return c_os;
72  }
73 
74  /****************************************/
75  /****************************************/
76 
77  std::ostream& operator<<(std::ostream& c_os,
78  const CCI_FootBotBaseGroundSensor::TReadings& t_readings) {
79  if(! t_readings.empty()) {
80  c_os << "{ " << t_readings[0].Value << " }";
81  for(UInt32 i = 1; i < t_readings.size(); ++i) {
82  c_os << " { " << t_readings[0].Value << " }";
83  }
84  c_os << std::endl;
85  }
86  return c_os;
87  }
88 
89  /****************************************/
90  /****************************************/
91 
92 #ifdef ARGOS_WITH_LUA
93  void CCI_FootBotBaseGroundSensor::CreateLuaState(lua_State* pt_lua_state) {
94  CLuaUtility::OpenRobotStateTable(pt_lua_state, "base_ground");
95  for(size_t i = 0; i < m_tReadings.size(); ++i) {
96  CLuaUtility::StartTable(pt_lua_state, i+1 );
97  CLuaUtility::AddToTable(pt_lua_state, "offset", m_tReadings[i].Offset);
98  CLuaUtility::AddToTable(pt_lua_state, "value", m_tReadings[i].Value );
99  CLuaUtility::EndTable (pt_lua_state );
100  }
101  CLuaUtility::CloseRobotStateTable(pt_lua_state);
102  }
103 #endif
104 
105  /****************************************/
106  /****************************************/
107 
108 #ifdef ARGOS_WITH_LUA
109  void CCI_FootBotBaseGroundSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
110  lua_getfield(pt_lua_state, -1, "base_ground");
111  for(size_t i = 0; i < m_tReadings.size(); ++i) {
112  lua_pushnumber(pt_lua_state, i+1 );
113  lua_gettable (pt_lua_state, -2 );
114  lua_pushnumber(pt_lua_state, m_tReadings[i].Value);
115  lua_setfield (pt_lua_state, -2, "value" );
116  lua_pop (pt_lua_state, 1 );
117  }
118  lua_pop(pt_lua_state, 1);
119  }
120 #endif
121 
122 
123  /****************************************/
124  /****************************************/
125 
126 }
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
std::ostream & operator<<(std::ostream &c_os, const CByteArray &c_byte_array)
Definition: byte_array.cpp:530
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.