ci_quadrotor_speed_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 of the velocity (a number)
22  * 2. y coordinate of the velocity (a number)
23  * 3. z coordinate of the velocity (a number)
24  */
25  int LuaSetQuadRotorLinearVelocity(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_linear_velocity() 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_QuadRotorSpeedActuator>(pt_lua_state, "quadrotor")->
35  SetLinearVelocity(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 one value:
48  * 1. x coordinate of the velocity (a number)
49  */
50  int LuaSetQuadRotorRotationalSpeed(lua_State* pt_lua_state) {
51  /* Check parameters */
52  if(lua_gettop(pt_lua_state) != 1) {
53  return luaL_error(pt_lua_state, "robot.quadrotor.set_rotational_speed() expects 1 argument");
54  }
55  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
56  /* Perform action */
57  CLuaUtility::GetDeviceInstance<CCI_QuadRotorSpeedActuator>(pt_lua_state, "quadrotor")->
58  SetRotationalSpeed(CRadians(lua_tonumber(pt_lua_state, 1)));
59  return 0;
60  }
61 #endif
62 
63  /****************************************/
64  /****************************************/
65 
66 #ifdef ARGOS_WITH_LUA
67  void CCI_QuadRotorSpeedActuator::CreateLuaState(lua_State* pt_lua_state) {
68  CLuaUtility::OpenRobotStateTable(pt_lua_state, "quadrotor");
69  CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
70  CLuaUtility::AddToTable(pt_lua_state, "set_linear_velocity", &LuaSetQuadRotorLinearVelocity);
71  CLuaUtility::AddToTable(pt_lua_state, "set_rotational_speed", &LuaSetQuadRotorRotationalSpeed);
73  }
74 #endif
75 
76  /****************************************/
77  /****************************************/
78 
79 }
static void CloseRobotStateTable(lua_State *pt_state)
Closes a table in the robot state.
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 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...
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12