ARGoS 3
A parallel, multi-engine simulator for swarm robotics
ci_footbot_motor_ground_sensor.cpp
Go to the documentation of this file.
1
9
10#ifdef ARGOS_WITH_LUA
11#include <argos3/core/wrappers/lua/lua_utility.h>
12#endif
13
14namespace argos {
15
16 /****************************************/
17 /****************************************/
18
20 m_tReadings(4) {
21 // Set the values for the motor ground sensor offset (taken from the CAD model, in cm)
22 m_tReadings[0].Offset.Set( 6.3, 1.16);
23 m_tReadings[1].Offset.Set(-6.3, 1.16);
24 m_tReadings[2].Offset.Set(-6.3,-1.16);
25 m_tReadings[3].Offset.Set( 6.3,-1.16);
26 }
27
28 /****************************************/
29 /****************************************/
30
34
35 /****************************************/
36 /****************************************/
37
38 std::ostream& operator<<(std::ostream& c_os,
40 c_os << "Value=<" << s_reading.Value
41 << ">, Offset=<" << s_reading.Offset << ">";
42 return c_os;
43 }
44
45 /****************************************/
46 /****************************************/
47
48 std::ostream& operator<<(std::ostream& c_os,
50 if(! t_readings.empty()) {
51 c_os << "{ " << t_readings[0].Value << " }";
52 for(UInt32 i = 1; i < t_readings.size(); ++i) {
53 c_os << " { " << t_readings[0].Value << " }";
54 }
55 c_os << std::endl;
56 }
57 return c_os;
58 }
59
60 /****************************************/
61 /****************************************/
62
63#ifdef ARGOS_WITH_LUA
64 void CCI_FootBotMotorGroundSensor::CreateLuaState(lua_State* pt_lua_state) {
65 CLuaUtility::OpenRobotStateTable(pt_lua_state, "motor_ground");
66 for(size_t i = 0; i < m_tReadings.size(); ++i) {
67 CLuaUtility::StartTable(pt_lua_state, i+1 );
68 CLuaUtility::AddToTable(pt_lua_state, "offset", m_tReadings[i].Offset);
69 CLuaUtility::AddToTable(pt_lua_state, "value", m_tReadings[i].Value );
70 CLuaUtility::EndTable (pt_lua_state );
71 }
73 }
74#endif
75
76 /****************************************/
77 /****************************************/
78
79#ifdef ARGOS_WITH_LUA
80 void CCI_FootBotMotorGroundSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
81 lua_getfield(pt_lua_state, -1, "motor_ground");
82 for(size_t i = 0; i < m_tReadings.size(); ++i) {
83 lua_pushnumber(pt_lua_state, i+1 );
84 lua_gettable (pt_lua_state, -2 );
85 lua_pushnumber(pt_lua_state, m_tReadings[i].Value);
86 lua_setfield (pt_lua_state, -2, "value" );
87 lua_pop (pt_lua_state, 1 );
88 }
89 lua_pop(pt_lua_state, 1);
90 }
91#endif
92
93
94 /****************************************/
95 /****************************************/
96
97}
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 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.