Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00615_source.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00615_source.php on line 2
The ARGoS Website

ci_colored_blob_omnidirectional_camera_sensor.cpp
Go to the documentation of this file.
2 
3 #ifdef ARGOS_WITH_LUA
4 #include <argos3/core/wrappers/lua/lua_utility.h>
5 #endif
6 
7 namespace argos {
8 
9  /****************************************/
10  /****************************************/
11 
12 #ifdef ARGOS_WITH_LUA
13  int LuaEnableOmnidirectionalCamera(lua_State* pt_lua_state) {
14  /* Perform action */
15  CLuaUtility::GetDeviceInstance<CCI_ColoredBlobOmnidirectionalCameraSensor>(pt_lua_state, "colored_blob_omnidirectional_camera")->Enable();
16  return 0;
17  }
18 #endif
19 
20  /****************************************/
21  /****************************************/
22 
23 #ifdef ARGOS_WITH_LUA
24  int LuaDisableOmnidirectionalCamera(lua_State* pt_lua_state) {
25  /* Perform action */
26  CLuaUtility::GetDeviceInstance<CCI_ColoredBlobOmnidirectionalCameraSensor>(pt_lua_state, "colored_blob_omnidirectional_camera")->Disable();
27  return 0;
28  }
29 #endif
30 
31  /****************************************/
32  /****************************************/
33 
34 #ifdef ARGOS_WITH_LUA
35  void CCI_ColoredBlobOmnidirectionalCameraSensor::CreateLuaState(lua_State* pt_lua_state) {
36  CLuaUtility::OpenRobotStateTable(pt_lua_state, "colored_blob_omnidirectional_camera");
37  CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
38  CLuaUtility::AddToTable(pt_lua_state, "enable", &LuaEnableOmnidirectionalCamera);
39  CLuaUtility::AddToTable(pt_lua_state, "disable", &LuaDisableOmnidirectionalCamera);
40  for(size_t i = 0; i < m_sReadings.BlobList.size(); ++i) {
41  SBlob& sBlob = *(m_sReadings.BlobList[i]);
42  CLuaUtility::StartTable(pt_lua_state, i+1);
43  CLuaUtility::AddToTable(pt_lua_state, "distance", sBlob.Distance);
44  CLuaUtility::AddToTable(pt_lua_state, "angle", sBlob.Angle);
45  CLuaUtility::AddToTable(pt_lua_state, "color", sBlob.Color);
46  CLuaUtility::EndTable(pt_lua_state);
47  }
49  }
50 #endif
51 
52  /****************************************/
53  /****************************************/
54 
55 #ifdef ARGOS_WITH_LUA
56  void CCI_ColoredBlobOmnidirectionalCameraSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
57  lua_getfield(pt_lua_state, -1, "colored_blob_omnidirectional_camera");
58  /* Save the number of elements in the blob list */
59  size_t unLastBlobNum = lua_rawlen(pt_lua_state, -1);
60  /* Overwrite the table with the new messages */
61  for(size_t i = 0; i < m_sReadings.BlobList.size(); ++i) {
62  SBlob& sBlob = *(m_sReadings.BlobList[i]);
63  CLuaUtility::StartTable(pt_lua_state, i+1);
64  CLuaUtility::AddToTable(pt_lua_state, "distance", sBlob.Distance);
65  CLuaUtility::AddToTable(pt_lua_state, "angle", sBlob.Angle);
66  CLuaUtility::AddToTable(pt_lua_state, "color", sBlob.Color);
67  CLuaUtility::EndTable(pt_lua_state);
68  }
69  /* Are the new messages less than the old ones? */
70  if(m_sReadings.BlobList.size() < unLastBlobNum) {
71  /* Yes, set to nil all the extra entries */
72  for(size_t i = m_sReadings.BlobList.size()+1; i <= unLastBlobNum; ++i) {
73  lua_pushnumber(pt_lua_state, i);
74  lua_pushnil (pt_lua_state );
75  lua_settable (pt_lua_state, -3);
76  }
77  }
78  lua_pop(pt_lua_state, 1);
79  }
80 #endif
81 
82  /****************************************/
83  /****************************************/
84 
86  return m_sReadings;
87  }
88 
89 }
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...
const SReadings & GetReadings() const
Returns a reference to the current camera readings.
It represents the readings collected through the camera at a specific time step.
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.
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static void CloseRobotStateTable(lua_State *pt_state)
Closes a table in the robot state.
static void EndTable(lua_State *pt_state)
Adds a table to the Lua stack.