ARGoS 3
A parallel, multi-engine simulator for swarm robotics
ci_pan_tilt_camera_actuator.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
13namespace argos {
14
15 /****************************************/
16 /****************************************/
17
18#ifdef ARGOS_WITH_LUA
19 /*
20 * The stack must have one value:
21 * 1. the pan (in radians)
22 */
23 int LuaSetPan(lua_State* pt_lua_state) {
24 /* Check parameters */
25 if(lua_gettop(pt_lua_state) != 1) {
26 return luaL_error(pt_lua_state, "robot.pan_tilt_camera.set_pan() expects 1 argument");
27 }
28 luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
29 /* Perform action */
30 CLuaUtility::GetDeviceInstance<CCI_PanTiltCameraActuator>(pt_lua_state, "pan_tilt_camera")->
31 SetPan(CRadians(lua_tonumber(pt_lua_state, 1)));
32 return 0;
33 }
34#endif
35
36 /****************************************/
37 /****************************************/
38
39#ifdef ARGOS_WITH_LUA
40 /*
41 * The stack must have one value:
42 * 1. the tilt (in radians)
43 */
44 int LuaSetTilt(lua_State* pt_lua_state) {
45 /* Check parameters */
46 if(lua_gettop(pt_lua_state) != 1) {
47 return luaL_error(pt_lua_state, "robot.pan_tilt_camera.set_tilt() expects 1 argument");
48 }
49 luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
50 /* Perform action */
51 CLuaUtility::GetDeviceInstance<CCI_PanTiltCameraActuator>(pt_lua_state, "pan_tilt_camera")->
52 SetTilt(CRadians(lua_tonumber(pt_lua_state, 1)));
53 return 0;
54 }
55#endif
56
57 /****************************************/
58 /****************************************/
59
60#ifdef ARGOS_WITH_LUA
61 void CCI_PanTiltCameraActuator::CreateLuaState(lua_State* pt_lua_state) {
62 CLuaUtility::OpenRobotStateTable(pt_lua_state, "pan_tilt_camera");
63 CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
64 CLuaUtility::AddToTable(pt_lua_state, "set_pan", &LuaSetPan);
65 CLuaUtility::AddToTable(pt_lua_state, "set_tilt", &LuaSetTilt);
67 }
68#endif
69
70 /****************************************/
71 /****************************************/
72
73}
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
virtual void CreateLuaState(lua_State *pt_lua_state)=0
Creates the Lua state for this actuator.
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 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.
static T * GetDeviceInstance(lua_State *pt_state, const std::string &str_key)
Returns a pointer to the instance to the wanted device.