ARGoS 3
A parallel, multi-engine simulator for swarm robotics
ci_camera_sensor_tag_detector_algorithm.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
14namespace argos {
15
16 /****************************************/
17 /****************************************/
18
19#ifdef ARGOS_WITH_LUA
20 void CCI_CameraSensorTagDetectorAlgorithm::CreateLuaState(lua_State* pt_lua_state) {
21 for(size_t i = 0; i < m_vecReadings.size(); ++i) {
22 CLuaUtility::StartTable(pt_lua_state, i + 1);
23 CLuaUtility::AddToTable(pt_lua_state, "payload", m_vecReadings[i].Payload);
24 CLuaUtility::AddToTable(pt_lua_state, "center", m_vecReadings[i].Center);
25 CLuaUtility::StartTable(pt_lua_state, "corners");
26 for(size_t j = 0; j < m_vecReadings[i].Corners.size(); ++j) {
27 CLuaUtility::AddToTable(pt_lua_state, j + 1, m_vecReadings[i].Corners[j]);
28 }
29 CLuaUtility::EndTable(pt_lua_state);
30 CLuaUtility::EndTable(pt_lua_state);
31 }
32 }
33#endif
34
35 /****************************************/
36 /****************************************/
37
38#ifdef ARGOS_WITH_LUA
39 void CCI_CameraSensorTagDetectorAlgorithm::ReadingsToLuaState(lua_State* pt_lua_state) {
40 size_t unLastReadingsNum = lua_rawlen(pt_lua_state, -1);
41 for(size_t i = 0; i < m_vecReadings.size(); ++i) {
42 CLuaUtility::StartTable(pt_lua_state, i + 1);
43 CLuaUtility::AddToTable(pt_lua_state, "payload", m_vecReadings[i].Payload);
44 CLuaUtility::AddToTable(pt_lua_state, "center", m_vecReadings[i].Center);
45 CLuaUtility::StartTable(pt_lua_state, "corners");
46 for(size_t j = 0; j < m_vecReadings[i].Corners.size(); ++j) {
47 CLuaUtility::AddToTable(pt_lua_state, j + 1, m_vecReadings[i].Corners[j]);
48 }
49 CLuaUtility::EndTable(pt_lua_state);
50 CLuaUtility::EndTable(pt_lua_state);
51 }
52 if(m_vecReadings.size() < unLastReadingsNum) {
53 /* Remove extra readings from last update by setting them to nil */
54 for(size_t i = m_vecReadings.size() + 1; i <= unLastReadingsNum; ++i) {
55 lua_pushnumber(pt_lua_state, i);
56 lua_pushnil (pt_lua_state );
57 lua_settable (pt_lua_state, -3);
58 }
59 }
60 }
61#endif
62
63 /****************************************/
64 /****************************************/
65
66}
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
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.