ARGoS  3
A parallel, multi-engine simulator for swarm robotics
plugins/robots/foot-bot/control_interface/ci_footbot_motor_ground_sensor.cpp
Go to the documentation of this file.
00001 
00008 #include "ci_footbot_motor_ground_sensor.h"
00009 
00010 #ifdef ARGOS_WITH_LUA
00011 #include <argos3/core/wrappers/lua/lua_utility.h>
00012 #endif
00013 
00014 namespace argos {
00015 
00016    /****************************************/
00017    /****************************************/
00018 
00019    CCI_FootBotMotorGroundSensor::CCI_FootBotMotorGroundSensor() :
00020       m_tReadings(4) {
00021       // Set the values for the motor ground sensor offset (taken from the CAD model, in cm)
00022       m_tReadings[0].Offset.Set( 6.3, 1.16);
00023       m_tReadings[1].Offset.Set(-6.3, 1.16);
00024       m_tReadings[2].Offset.Set(-6.3,-1.16);
00025       m_tReadings[3].Offset.Set( 6.3,-1.16);
00026    }
00027     
00028    /****************************************/
00029    /****************************************/
00030 
00031    std::ostream& operator<<(std::ostream& c_os,
00032                             const CCI_FootBotMotorGroundSensor::SReading& s_reading) {
00033       c_os << "Value=<" << s_reading.Value
00034            << ">, Offset=<" << s_reading.Offset << ">";
00035       return c_os;
00036    }
00037 
00038    /****************************************/
00039    /****************************************/
00040    
00041    std::ostream& operator<<(std::ostream& c_os,
00042                             const CCI_FootBotMotorGroundSensor::TReadings& t_readings) {
00043       if(! t_readings.empty()) {
00044          c_os << "{ " << t_readings[0].Value << " }";
00045          for(UInt32 i = 1; i < t_readings.size(); ++i) {
00046             c_os << " { " << t_readings[0].Value << " }";
00047          }
00048          c_os << std::endl;
00049       }
00050       return c_os;
00051    }
00052 
00053    /****************************************/
00054    /****************************************/
00055    
00056 #ifdef ARGOS_WITH_LUA
00057    void CCI_FootBotMotorGroundSensor::CreateLuaState(lua_State* pt_lua_state) {
00058       CLuaUtility::OpenRobotStateTable(pt_lua_state, "motor_ground");
00059       for(size_t i = 0; i < m_tReadings.size(); ++i) {
00060          CLuaUtility::StartTable(pt_lua_state, i+1                            );
00061          CLuaUtility::AddToTable(pt_lua_state, "offset", m_tReadings[i].Offset);
00062          CLuaUtility::AddToTable(pt_lua_state, "value",  m_tReadings[i].Value );
00063          CLuaUtility::EndTable  (pt_lua_state                                 );
00064       }
00065       CLuaUtility::CloseRobotStateTable(pt_lua_state);
00066    }
00067 #endif
00068 
00069    /****************************************/
00070    /****************************************/
00071 
00072 #ifdef ARGOS_WITH_LUA
00073    void CCI_FootBotMotorGroundSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
00074       lua_getfield(pt_lua_state, -1, "motor_ground");
00075       for(size_t i = 0; i < m_tReadings.size(); ++i) {
00076          lua_pushnumber(pt_lua_state, i+1                 );
00077          lua_gettable  (pt_lua_state, -2                  );
00078          lua_pushnumber(pt_lua_state, m_tReadings[i].Value);
00079          lua_setfield  (pt_lua_state, -2, "value"         );
00080          lua_pop       (pt_lua_state, 1                   );
00081       }
00082       lua_pop(pt_lua_state, 1);
00083    }
00084 #endif
00085 
00086 
00087    /****************************************/
00088    /****************************************/
00089 
00090 }