ARGoS 3
A parallel, multi-engine simulator for swarm robotics
ci_epuck_proximity_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
19 //static CRadians SPACING = CRadians(ARGOS_PI / 4.0f);
20 //static CRadians START_ANGLE = SPACING * 0.5f;
21
22 /****************************************/
23 /****************************************/
24
26 m_tReadings(8)
27 {
28 /* for(size_t i = 0; i < 8; ++i)
29 {
30 m_tReadings[i].Angle = START_ANGLE + i * SPACING;
31 m_tReadings[i].Angle.SignedNormalize();
32
33 m_tReadings_Noiseless[i].Angle = m_tReadings[i].Angle;
34 m_tReadings_Noiseless[i].Angle.SignedNormalize();
35 }*/
36
37 // Set the values for the proximity sensor angles
38 m_tReadings[0].Angle = CRadians::PI / 10.5884f;
39 m_tReadings[1].Angle = CRadians::PI / 3.5999f;
40 m_tReadings[2].Angle = CRadians::PI_OVER_TWO; //side sensor
41 m_tReadings[3].Angle = CRadians::PI / 1.2f; // back sensor
42 m_tReadings[4].Angle = CRadians::PI / 0.8571f; // back sensor
43 m_tReadings[5].Angle = CRadians::PI / 0.6667f; //side sensor
44 m_tReadings[6].Angle = CRadians::PI / 0.5806f;
45 m_tReadings[7].Angle = CRadians::PI / 0.5247f;
46
47 for(size_t i = 0; i < 8; ++i)
48 {
49 m_tReadings[i].Angle.SignedNormalize();
50 }
51
52 }
53
54 /****************************************/
55 /****************************************/
56
57
58#ifdef ARGOS_WITH_LUA
59 void CCI_EPuckProximitySensor::CreateLuaState(lua_State* pt_lua_state) {
60 CLuaUtility::OpenRobotStateTable(pt_lua_state, "proximity");
61 for(size_t i = 0; i < GetReadings().size(); ++i) {
62 CLuaUtility::StartTable(pt_lua_state, i+1 );
63 CLuaUtility::AddToTable(pt_lua_state, "angle", m_tReadings[i].Angle);
64 CLuaUtility::AddToTable(pt_lua_state, "value", m_tReadings[i].Value);
65 CLuaUtility::EndTable (pt_lua_state );
66 }
68 }
69#endif
70
71 /****************************************/
72 /****************************************/
73
74#ifdef ARGOS_WITH_LUA
75 void CCI_EPuckProximitySensor::ReadingsToLuaState(lua_State* pt_lua_state) {
76 lua_getfield(pt_lua_state, -1, "proximity");
77 for(size_t i = 0; i < GetReadings().size(); ++i) {
78 lua_pushnumber(pt_lua_state, i+1 );
79 lua_gettable (pt_lua_state, -2 );
80 lua_pushnumber(pt_lua_state, m_tReadings[i].Value);
81 lua_setfield (pt_lua_state, -2, "value" );
82 lua_pop(pt_lua_state, 1);
83 }
84 lua_pop(pt_lua_state, 1);
85 }
86#endif
87
88
89 /****************************************/
90 /****************************************/
91
92 std::ostream& operator<<(std::ostream& c_os,
93 const CCI_EPuckProximitySensor::SReading& s_reading) {
94 c_os << "Value=<" << s_reading.Value
95 << ">, Angle=<" << s_reading.Angle << ">";
96 return c_os;
97 }
98
99 /****************************************/
100 /****************************************/
101
102 std::ostream& operator<<(std::ostream& c_os,
103 const CCI_EPuckProximitySensor::TReadings& t_readings) {
104 if(! t_readings.empty()) {
105 c_os << "{ " << t_readings[0].Value << " }";
106 for(UInt32 i = 1; i < t_readings.size(); ++i) {
107 c_os << " { " << t_readings[0].Value << " }";
108 }
109 c_os << std::endl;
110 }
111 return c_os;
112 }
113
114 /****************************************/
115 /****************************************/
116
117}
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)
static const CRadians PI
The PI constant.
Definition angles.h:49
static const CRadians PI_OVER_TWO
Set to PI / 2.
Definition angles.h:59
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.