ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
00001 00033 #include "ci_footbot_base_ground_sensor.h" 00034 00035 #ifdef ARGOS_WITH_LUA 00036 #include <argos3/core/wrappers/lua/lua_utility.h> 00037 #endif 00038 00039 namespace argos { 00040 00041 /****************************************/ 00042 /****************************************/ 00043 00044 CCI_FootBotBaseGroundSensor::CCI_FootBotBaseGroundSensor() : 00045 m_tReadings(8) { 00046 // Set the values for the base ground sensor offset (taken from the CAD model, in cm) 00047 m_tReadings[0].Offset.Set( 8.0, 0.0); 00048 m_tReadings[1].Offset.Set( 4.2, 6.5); 00049 m_tReadings[2].Offset.Set( 0.0, 8.0); 00050 m_tReadings[3].Offset.Set(-4.2, 6.5); 00051 m_tReadings[4].Offset.Set(-8.0, 0.0); 00052 m_tReadings[5].Offset.Set(-4.2,-6.5); 00053 m_tReadings[6].Offset.Set( 0.0,-8.0); 00054 m_tReadings[7].Offset.Set( 4.2,-6.5); 00055 } 00056 00057 /****************************************/ 00058 /****************************************/ 00059 00060 std::ostream& operator<<(std::ostream& c_os, 00061 const CCI_FootBotBaseGroundSensor::SReading& s_reading) { 00062 c_os << "Value=<" << s_reading.Value 00063 << ">, Offset=<" << s_reading.Offset << ">"; 00064 return c_os; 00065 } 00066 00067 /****************************************/ 00068 /****************************************/ 00069 00070 std::ostream& operator<<(std::ostream& c_os, 00071 const CCI_FootBotBaseGroundSensor::TReadings& t_readings) { 00072 if(! t_readings.empty()) { 00073 c_os << "{ " << t_readings[0].Value << " }"; 00074 for(UInt32 i = 1; i < t_readings.size(); ++i) { 00075 c_os << " { " << t_readings[0].Value << " }"; 00076 } 00077 c_os << std::endl; 00078 } 00079 return c_os; 00080 } 00081 00082 /****************************************/ 00083 /****************************************/ 00084 00085 #ifdef ARGOS_WITH_LUA 00086 void CCI_FootBotBaseGroundSensor::CreateLuaState(lua_State* pt_lua_state) { 00087 CLuaUtility::OpenRobotStateTable(pt_lua_state, "base_ground"); 00088 for(size_t i = 0; i < m_tReadings.size(); ++i) { 00089 CLuaUtility::StartTable(pt_lua_state, i+1 ); 00090 CLuaUtility::AddToTable(pt_lua_state, "offset", m_tReadings[i].Offset); 00091 CLuaUtility::AddToTable(pt_lua_state, "value", m_tReadings[i].Value ); 00092 CLuaUtility::EndTable (pt_lua_state ); 00093 } 00094 CLuaUtility::CloseRobotStateTable(pt_lua_state); 00095 } 00096 #endif 00097 00098 /****************************************/ 00099 /****************************************/ 00100 00101 #ifdef ARGOS_WITH_LUA 00102 void CCI_FootBotBaseGroundSensor::ReadingsToLuaState(lua_State* pt_lua_state) { 00103 lua_getfield(pt_lua_state, -1, "base_ground"); 00104 for(size_t i = 0; i < m_tReadings.size(); ++i) { 00105 lua_pushnumber(pt_lua_state, i+1 ); 00106 lua_gettable (pt_lua_state, -2 ); 00107 lua_pushnumber(pt_lua_state, m_tReadings[i].Value); 00108 lua_setfield (pt_lua_state, -2, "value" ); 00109 lua_pop (pt_lua_state, 1 ); 00110 } 00111 lua_pop(pt_lua_state, 1); 00112 } 00113 #endif 00114 00115 00116 /****************************************/ 00117 /****************************************/ 00118 00119 }