Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00538_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/a00538_source.php on line 2
The ARGoS Website

ci_eyebot_proximity_sensor.cpp
Go to the documentation of this file.
1 
8 #include <argos3/core/utility/math/angles.h>
9 
10 #ifdef ARGOS_WITH_LUA
11 #include <argos3/core/wrappers/lua/lua_utility.h>
12 #endif
13 
14 namespace argos {
15 
16  /****************************************/
17  /****************************************/
18 
19  static CRadians SPACING = CRadians(ARGOS_PI / 12.0f);
20  static CRadians START_ANGLE = SPACING * 0.5f;
21 
22  /****************************************/
23  /****************************************/
24 
26  m_tReadings(24) {
27  for(size_t i = 0; i < 24; ++i) {
28  m_tReadings[i].Angle = START_ANGLE + i * SPACING;
29  m_tReadings[i].Angle.SignedNormalize();
30  }
31  }
32 
33  /****************************************/
34  /****************************************/
35 
37  return m_tReadings;
38  }
39 
40  /****************************************/
41  /****************************************/
42 
43 #ifdef ARGOS_WITH_LUA
44  void CCI_EyeBotProximitySensor::CreateLuaState(lua_State* pt_lua_state) {
45  CLuaUtility::OpenRobotStateTable(pt_lua_state, "proximity");
46  for(size_t i = 0; i < GetReadings().size(); ++i) {
47  CLuaUtility::StartTable(pt_lua_state, i+1 );
48  CLuaUtility::AddToTable(pt_lua_state, "angle", m_tReadings[i].Angle);
49  CLuaUtility::AddToTable(pt_lua_state, "value", m_tReadings[i].Value);
50  CLuaUtility::EndTable (pt_lua_state );
51  }
53  }
54 #endif
55 
56  /****************************************/
57  /****************************************/
58 
59 #ifdef ARGOS_WITH_LUA
60  void CCI_EyeBotProximitySensor::ReadingsToLuaState(lua_State* pt_lua_state) {
61  lua_getfield(pt_lua_state, -1, "proximity");
62  for(size_t i = 0; i < GetReadings().size(); ++i) {
63  lua_pushnumber(pt_lua_state, i+1 );
64  lua_gettable (pt_lua_state, -2 );
65  lua_pushnumber(pt_lua_state, m_tReadings[i].Value);
66  lua_setfield (pt_lua_state, -2, "value" );
67  lua_pop(pt_lua_state, 1);
68  }
69  lua_pop(pt_lua_state, 1);
70  }
71 #endif
72 
73 
74  /****************************************/
75  /****************************************/
76 
77  std::ostream& operator<<(std::ostream& c_os,
78  const CCI_EyeBotProximitySensor::SReading& s_reading) {
79  c_os << "Value=<" << s_reading.Value
80  << ">, Angle=<" << s_reading.Angle << ">";
81  return c_os;
82  }
83 
84  /****************************************/
85  /****************************************/
86 
87  std::ostream& operator<<(std::ostream& c_os,
88  const CCI_EyeBotProximitySensor::TReadings& t_readings) {
89  if(! t_readings.empty()) {
90  c_os << "{ " << t_readings[0].Value << " }";
91  for(UInt32 i = 1; i < t_readings.size(); ++i) {
92  c_os << " { " << t_readings[0].Value << " }";
93  }
94  c_os << std::endl;
95  }
96  return c_os;
97  }
98 
99  /****************************************/
100  /****************************************/
101 
102 }
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...
std::ostream & operator<<(std::ostream &c_os, const CByteArray &c_byte_array)
Definition: byte_array.cpp:530
const TReadings & GetReadings() const
Returns the readings of this sensor.
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
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.
#define ARGOS_PI
To be used when initializing static variables.
Definition: angles.h:32
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static void CloseRobotStateTable(lua_State *pt_state)
Closes a table in the robot state.
static void EndTable(lua_State *pt_state)
Adds a table to the Lua stack.