ci_quadrotor_position_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 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
18 #ifdef ARGOS_WITH_LUA
19  /*
20  * The stack must have three values in this order:
21  * 1. x coordinate (a number)
22  * 2. y coordinate (a number)
23  * 3. z coordinate (a number)
24  */
25  int LuaSetAbsolutePosition(lua_State* pt_lua_state) {
26  /* Check parameters */
27  if(lua_gettop(pt_lua_state) != 3) {
28  return luaL_error(pt_lua_state, "robot.quadrotor.set_absolute_position() expects 3 arguments");
29  }
30  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
31  luaL_checktype(pt_lua_state, 2, LUA_TNUMBER);
32  luaL_checktype(pt_lua_state, 3, LUA_TNUMBER);
33  /* Perform action */
34  CLuaUtility::GetDeviceInstance<CCI_QuadRotorPositionActuator>(pt_lua_state, "quadrotor")->
35  SetAbsolutePosition(CVector3(lua_tonumber(pt_lua_state, 1),
36  lua_tonumber(pt_lua_state, 2),
37  lua_tonumber(pt_lua_state, 3)));
38  return 0;
39  }
40 #endif
41 
42  /****************************************/
43  /****************************************/
44 
45 #ifdef ARGOS_WITH_LUA
46  /*
47  * The stack must have three values in this order:
48  * 1. x coordinate (a number)
49  * 2. y coordinate (a number)
50  * 3. z coordinate (a number)
51  */
52  int LuaSetRelativePosition(lua_State* pt_lua_state) {
53  /* Check parameters */
54  if(lua_gettop(pt_lua_state) != 3) {
55  return luaL_error(pt_lua_state, "robot.quadrotor.set_relative_position() expects 3 arguments");
56  }
57  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
58  luaL_checktype(pt_lua_state, 2, LUA_TNUMBER);
59  luaL_checktype(pt_lua_state, 3, LUA_TNUMBER);
60  /* Perform action */
61  CLuaUtility::GetDeviceInstance<CCI_QuadRotorPositionActuator>(pt_lua_state, "quadrotor")->
62  SetRelativePosition(CVector3(lua_tonumber(pt_lua_state, 1),
63  lua_tonumber(pt_lua_state, 2),
64  lua_tonumber(pt_lua_state, 3)));
65  return 0;
66  }
67 #endif
68 
69  /****************************************/
70  /****************************************/
71 
72 #ifdef ARGOS_WITH_LUA
73  /*
74  * The stack must have one value:
75  * 1. yaw angle (in radians)
76  */
77  int LuaSetAbsoluteYaw(lua_State* pt_lua_state) {
78  /* Check parameters */
79  if(lua_gettop(pt_lua_state) != 1) {
80  return luaL_error(pt_lua_state, "robot.quadrotor.set_absolute_yaw() expects 1 argument");
81  }
82  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
83  /* Perform action */
84  CLuaUtility::GetDeviceInstance<CCI_QuadRotorPositionActuator>(pt_lua_state, "quadrotor")->
85  SetAbsoluteYaw(CRadians(lua_tonumber(pt_lua_state, 1) / 180.0f * CRadians::PI));
86  return 0;
87  }
88 #endif
89 
90  /****************************************/
91  /****************************************/
92 
93 #ifdef ARGOS_WITH_LUA
94  /*
95  * The stack must have one value:
96  * 1. yaw angle (in radians)
97  */
98  int LuaSetRelativeYaw(lua_State* pt_lua_state) {
99  /* Check parameters */
100  if(lua_gettop(pt_lua_state) != 1) {
101  return luaL_error(pt_lua_state, "robot.quadrotor.set_relative_yaw() expects 1 argument");
102  }
103  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
104  /* Perform action */
105  CLuaUtility::GetDeviceInstance<CCI_QuadRotorPositionActuator>(pt_lua_state, "quadrotor")->
106  SetRelativeYaw(CRadians(lua_tonumber(pt_lua_state, 1) / 180.0f * CRadians::PI));
107  return 0;
108  }
109 #endif
110 
111  /****************************************/
112  /****************************************/
113 
114 #ifdef ARGOS_WITH_LUA
115  void CCI_QuadRotorPositionActuator::CreateLuaState(lua_State* pt_lua_state) {
116  CLuaUtility::OpenRobotStateTable(pt_lua_state, "quadrotor");
117  CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
118  CLuaUtility::AddToTable(pt_lua_state, "set_absolute_position", &LuaSetAbsolutePosition);
119  CLuaUtility::AddToTable(pt_lua_state, "set_absolute_yaw", &LuaSetAbsoluteYaw);
120  CLuaUtility::AddToTable(pt_lua_state, "set_relative_position", &LuaSetRelativePosition);
121  CLuaUtility::AddToTable(pt_lua_state, "set_relative_yaw", &LuaSetRelativeYaw);
122  CLuaUtility::CloseRobotStateTable(pt_lua_state);
123  }
124 #endif
125 
126  /****************************************/
127  /****************************************/
128 
129 }
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static const CRadians PI
The PI constant.
Definition: angles.h:49
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.