ARGoS 3
A parallel, multi-engine simulator for swarm robotics
ci_footbot_light_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
13namespace argos {
14
15 /****************************************/
16 /****************************************/
17
18 static CRadians SPACING = CRadians(ARGOS_PI / 12.0f);
19 static CRadians START_ANGLE = SPACING * 0.5f;
20
21 /****************************************/
22 /****************************************/
23
25 m_tReadings(24) {
26 for(size_t i = 0; i < 24; ++i) {
27 m_tReadings[i].Angle = START_ANGLE + i * SPACING;
29 }
30 }
31
32 /****************************************/
33 /****************************************/
34
38
39 /****************************************/
40 /****************************************/
41
42#ifdef ARGOS_WITH_LUA
43 void CCI_FootBotLightSensor::CreateLuaState(lua_State* pt_lua_state) {
44 CLuaUtility::OpenRobotStateTable(pt_lua_state, "light");
45 for(size_t i = 0; i < GetReadings().size(); ++i) {
46 CLuaUtility::StartTable(pt_lua_state, i+1 );
47 CLuaUtility::AddToTable(pt_lua_state, "angle", m_tReadings[i].Angle);
48 CLuaUtility::AddToTable(pt_lua_state, "value", m_tReadings[i].Value);
49 CLuaUtility::EndTable (pt_lua_state );
50 }
52 }
53#endif
54
55 /****************************************/
56 /****************************************/
57
58#ifdef ARGOS_WITH_LUA
59 void CCI_FootBotLightSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
60 lua_getfield(pt_lua_state, -1, "light");
61 for(size_t i = 0; i < GetReadings().size(); ++i) {
62 lua_pushnumber(pt_lua_state, i+1 );
63 lua_gettable (pt_lua_state, -2 );
64 lua_pushnumber(pt_lua_state, m_tReadings[i].Value);
65 lua_setfield (pt_lua_state, -2, "value" );
66 lua_pop(pt_lua_state, 1);
67 }
68 lua_pop(pt_lua_state, 1);
69 }
70#endif
71
72
73 /****************************************/
74 /****************************************/
75
76 std::ostream& operator<<(std::ostream& c_os,
77 const CCI_FootBotLightSensor::SReading& s_reading) {
78 c_os << "Value=<" << s_reading.Value
79 << ">, Angle=<" << s_reading.Angle << ">";
80 return c_os;
81 }
82
83 /****************************************/
84 /****************************************/
85
86 std::ostream& operator<<(std::ostream& c_os,
87 const CCI_FootBotLightSensor::TReadings& t_readings) {
88 if(! t_readings.empty()) {
89 c_os << "{ " << t_readings[0].Value << " }";
90 for(UInt32 i = 1; i < t_readings.size(); ++i) {
91 c_os << " { " << t_readings[0].Value << " }";
92 }
93 c_os << std::endl;
94 }
95 return c_os;
96 }
97
98 /****************************************/
99 /****************************************/
100
101}
#define ARGOS_PI
To be used when initializing static variables.
Definition angles.h:32
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)
CRadians & SignedNormalize()
Normalizes the value in the range [-PI:PI].
Definition angles.h:137
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 TReadings & GetReadings() const
Returns the readings of this sensor.