ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
00001 00031 #include "ci_footbot_light_sensor.h" 00032 00033 #ifdef ARGOS_WITH_LUA 00034 #include <argos3/core/wrappers/lua/lua_utility.h> 00035 #endif 00036 00037 namespace argos { 00038 00039 /****************************************/ 00040 /****************************************/ 00041 00042 static CRadians SPACING = CRadians(ARGOS_PI / 12.0f); 00043 static CRadians START_ANGLE = SPACING * 0.5f; 00044 00045 /****************************************/ 00046 /****************************************/ 00047 00048 CCI_FootBotLightSensor::CCI_FootBotLightSensor() : 00049 m_tReadings(24) { 00050 for(size_t i = 0; i < 24; ++i) { 00051 m_tReadings[i].Angle = START_ANGLE + i * SPACING; 00052 m_tReadings[i].Angle.SignedNormalize(); 00053 } 00054 } 00055 00056 /****************************************/ 00057 /****************************************/ 00058 00059 #ifdef ARGOS_WITH_LUA 00060 void CCI_FootBotLightSensor::CreateLuaState(lua_State* pt_lua_state) { 00061 CLuaUtility::OpenRobotStateTable(pt_lua_state, "light"); 00062 for(size_t i = 0; i < GetReadings().size(); ++i) { 00063 CLuaUtility::StartTable(pt_lua_state, i+1 ); 00064 CLuaUtility::AddToTable(pt_lua_state, "angle", m_tReadings[i].Angle); 00065 CLuaUtility::AddToTable(pt_lua_state, "value", m_tReadings[i].Value); 00066 CLuaUtility::EndTable (pt_lua_state ); 00067 } 00068 CLuaUtility::CloseRobotStateTable(pt_lua_state); 00069 } 00070 #endif 00071 00072 /****************************************/ 00073 /****************************************/ 00074 00075 #ifdef ARGOS_WITH_LUA 00076 void CCI_FootBotLightSensor::ReadingsToLuaState(lua_State* pt_lua_state) { 00077 lua_getfield(pt_lua_state, -1, "light"); 00078 for(size_t i = 0; i < GetReadings().size(); ++i) { 00079 lua_pushnumber(pt_lua_state, i+1 ); 00080 lua_gettable (pt_lua_state, -2 ); 00081 lua_pushnumber(pt_lua_state, m_tReadings[i].Value); 00082 lua_setfield (pt_lua_state, -2, "value" ); 00083 lua_pop(pt_lua_state, 1); 00084 } 00085 lua_pop(pt_lua_state, 1); 00086 } 00087 #endif 00088 00089 00090 /****************************************/ 00091 /****************************************/ 00092 00093 std::ostream& operator<<(std::ostream& c_os, 00094 const CCI_FootBotLightSensor::SReading& s_reading) { 00095 c_os << "Value=<" << s_reading.Value 00096 << ">, Angle=<" << s_reading.Angle << ">"; 00097 return c_os; 00098 } 00099 00100 /****************************************/ 00101 /****************************************/ 00102 00103 std::ostream& operator<<(std::ostream& c_os, 00104 const CCI_FootBotLightSensor::TReadings& t_readings) { 00105 if(! t_readings.empty()) { 00106 c_os << "{ " << t_readings[0].Value << " }"; 00107 for(UInt32 i = 1; i < t_readings.size(); ++i) { 00108 c_os << " { " << t_readings[0].Value << " }"; 00109 } 00110 c_os << std::endl; 00111 } 00112 return c_os; 00113 } 00114 00115 /****************************************/ 00116 /****************************************/ 00117 00118 }