ci_miniquadrotor_rotor_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 
19  Velocities[0] = 0.0f;
20  Velocities[1] = 0.0f;
21  Velocities[2] = 0.0f;
22  Velocities[3] = 0.0f;
23  }
24 
25  /****************************************/
26  /****************************************/
27 
29  Real f_west_vel,
30  Real f_south_vel,
31  Real f_east_vel) {
32  Velocities[0] = f_north_vel;
33  Velocities[1] = f_west_vel;
34  Velocities[2] = f_south_vel;
35  Velocities[3] = f_east_vel;
36  }
37 
38  /****************************************/
39  /****************************************/
40 
42  Velocities[0] = s_velocities.Velocities[0];
43  Velocities[1] = s_velocities.Velocities[1];
44  Velocities[2] = s_velocities.Velocities[2];
45  Velocities[3] = s_velocities.Velocities[3];
46  }
47 
48  /****************************************/
49  /****************************************/
50 
52  if(&s_velocities != this) {
53  Velocities[0] = s_velocities.Velocities[0];
54  Velocities[1] = s_velocities.Velocities[1];
55  Velocities[2] = s_velocities.Velocities[2];
56  Velocities[3] = s_velocities.Velocities[3];
57  }
58  return *this;
59  }
60 
61  /****************************************/
62  /****************************************/
63 
64 #ifdef ARGOS_WITH_LUA
65  /*
66  * The stack must have four values in this order:
67  * 1. north rotor velocity (a number)
68  * 2. west rotor velocity (a number)
69  * 3. south rotor velocity (a number)
70  * 4. east rotor velocity (a number)
71  */
72  int LuaSetVelocity(lua_State* pt_lua_state) {
73  /* Check parameters */
74  if(lua_gettop(pt_lua_state) != 4) {
75  return luaL_error(pt_lua_state, "robot.rotors.set_velocity() expects 4 arguments");
76  }
77  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
78  luaL_checktype(pt_lua_state, 2, LUA_TNUMBER);
79  luaL_checktype(pt_lua_state, 3, LUA_TNUMBER);
80  luaL_checktype(pt_lua_state, 4, LUA_TNUMBER);
81  /* Perform action */
82  CLuaUtility::GetDeviceInstance<CCI_MiniQuadrotorRotorActuator>(pt_lua_state, "rotors")->
84  lua_tonumber(pt_lua_state, 1),
85  lua_tonumber(pt_lua_state, 2),
86  lua_tonumber(pt_lua_state, 3),
87  lua_tonumber(pt_lua_state, 4)));
88  return 0;
89  }
90 #endif
91 
92  /****************************************/
93  /****************************************/
94 
95 #ifdef ARGOS_WITH_LUA
96  void CCI_MiniQuadrotorRotorActuator::CreateLuaState(lua_State* pt_lua_state) {
97  CLuaUtility::OpenRobotStateTable(pt_lua_state, "rotors");
98  CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
99  CLuaUtility::AddToTable(pt_lua_state, "set_velocity", &LuaSetVelocity);
100  CLuaUtility::CloseRobotStateTable(pt_lua_state);
101  }
102 #endif
103 
104  /****************************************/
105  /****************************************/
106 
107 }
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
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.
virtual void SetRotorVelocities(const SVelocities &s_velocities)=0
SVelocities & operator=(const SVelocities &s_velocities)