ARGoS  3
A parallel, multi-engine simulator for swarm robotics
ci_footbot_encoder_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 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
19  return m_sReading;
20  }
21 
22  /****************************************/
23  /****************************************/
24 
25 #ifdef ARGOS_WITH_LUA
26  void CCI_FootBotEncoderSensor::CreateLuaState(lua_State* pt_lua_state) {
27  CLuaUtility::OpenRobotStateTable (pt_lua_state, "wheels" );
28  CLuaUtility::StartTable (pt_lua_state, "encoder" );
29  CLuaUtility::AddToTable (pt_lua_state, "distance_left", m_sReading.CoveredDistanceLeftWheel );
30  CLuaUtility::AddToTable (pt_lua_state, "distance_right", m_sReading.CoveredDistanceRightWheel);
31  CLuaUtility::AddToTable (pt_lua_state, "axis_length", m_sReading.WheelAxisLength );
32  CLuaUtility::EndTable (pt_lua_state );
33  CLuaUtility::CloseRobotStateTable(pt_lua_state );
34  }
35 #endif
36 
37  /****************************************/
38  /****************************************/
39 
40 #ifdef ARGOS_WITH_LUA
41  void CCI_FootBotEncoderSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
42  lua_getfield(pt_lua_state, -1, "wheels");
43  lua_getfield(pt_lua_state, -1, "encoder");
44  lua_pushnumber(pt_lua_state, m_sReading.CoveredDistanceLeftWheel);
45  lua_setfield(pt_lua_state, -2, "distance_left");
46  lua_pushnumber(pt_lua_state, m_sReading.CoveredDistanceRightWheel);
47  lua_setfield(pt_lua_state, -2, "distance_right");
48  lua_pop(pt_lua_state, 2);
49  }
50 #endif
51 
52 
53  /****************************************/
54  /****************************************/
55 
56 }
argos::CLuaUtility::OpenRobotStateTable
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.
Definition: lua_utility.cpp:289
argos
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
argos::CCI_FootBotEncoderSensor::SReading
The DTO of the encoder It returns the distance covered by the wheels in the last timestep In addition...
Definition: ci_footbot_encoder_sensor.h:39
argos::CLuaUtility::AddToTable
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...
Definition: lua_utility.cpp:337
argos::CCI_FootBotEncoderSensor::SReading::CoveredDistanceLeftWheel
Real CoveredDistanceLeftWheel
Definition: ci_footbot_encoder_sensor.h:40
argos::CLuaUtility::EndTable
static void EndTable(lua_State *pt_state)
Adds a table to the Lua stack.
Definition: lua_utility.cpp:330
argos::CLuaUtility::CloseRobotStateTable
static void CloseRobotStateTable(lua_State *pt_state)
Closes a table in the robot state.
Definition: lua_utility.cpp:305
argos::CCI_FootBotEncoderSensor::m_sReading
SReading m_sReading
Definition: ci_footbot_encoder_sensor.h:78
argos::CCI_FootBotEncoderSensor::SReading::CoveredDistanceRightWheel
Real CoveredDistanceRightWheel
Definition: ci_footbot_encoder_sensor.h:41
argos::CLuaUtility::StartTable
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.
Definition: lua_utility.cpp:312
argos::CCI_FootBotEncoderSensor::SReading::WheelAxisLength
Real WheelAxisLength
Definition: ci_footbot_encoder_sensor.h:42
argos::CCI_FootBotEncoderSensor::GetReading
const SReading & GetReading() const
Returns the reading of the encoder sensor Returns the reading of the encoder sensor.
Definition: ci_footbot_encoder_sensor.cpp:18
ci_footbot_encoder_sensor.h