ci_footbot_turret_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  const CRange<SInt32> CCI_FootBotTurretActuator::SPEED_RANGE(-4,4);
19  const CRange<Real> CCI_FootBotTurretActuator::NORMALIZED_SPEED_RANGE(-1.0,1.0);
20 
21  /****************************************/
22  /****************************************/
23 
24 #ifdef ARGOS_WITH_LUA
25  int LuaTurretSetRotation(lua_State* pt_lua_state) {
26  /* Check parameters */
27  if(lua_gettop(pt_lua_state) != 1) {
28  return luaL_error(pt_lua_state, "robot.turret.set_rotation() expects 1 argument");
29  }
30  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
31  /* Perform action */
32  CLuaUtility::GetDeviceInstance<CCI_FootBotTurretActuator>(pt_lua_state, "turret")->
33  SetRotation(CRadians(lua_tonumber(pt_lua_state, 1)));
34  return 0;
35  }
36 #endif
37 
38 #ifdef ARGOS_WITH_LUA
39  int LuaTurretSetRotationSpeed(lua_State* pt_lua_state) {
40  /* Check parameters */
41  if(lua_gettop(pt_lua_state) != 1) {
42  return luaL_error(pt_lua_state, "robot.turret.set_rotation_speed() expects 1 argument");
43  }
44  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
45  /* Perform action */
46  CLuaUtility::GetDeviceInstance<CCI_FootBotTurretActuator>(pt_lua_state, "turret")->
47  SetRotationSpeed(lua_tonumber(pt_lua_state, 1));
48  return 0;
49  }
50 #endif
51 
52 #ifdef ARGOS_WITH_LUA
53  int LuaTurretSetSpeedControlMode(lua_State* pt_lua_state) {
54  /* Check parameters */
55  if(lua_gettop(pt_lua_state) != 0) {
56  return luaL_error(pt_lua_state, "robot.turret.set_speed_control_mode() expects no arguments");
57  }
58  /* Perform action */
59  CLuaUtility::GetDeviceInstance<CCI_FootBotTurretActuator>(pt_lua_state, "turret")->
60  SetSpeedControlMode();
61  return 0;
62  }
63 #endif
64 
65 #ifdef ARGOS_WITH_LUA
66  int LuaTurretSetPositionControlMode(lua_State* pt_lua_state) {
67  /* Check parameters */
68  if(lua_gettop(pt_lua_state) != 0) {
69  return luaL_error(pt_lua_state, "robot.turret.set_position_control_mode() expects no arguments");
70  }
71  /* Perform action */
72  CLuaUtility::GetDeviceInstance<CCI_FootBotTurretActuator>(pt_lua_state, "turret")->
73  SetPositionControlMode();
74  return 0;
75  }
76 #endif
77 
78 #ifdef ARGOS_WITH_LUA
79  int LuaTurretSetPassiveMode(lua_State* pt_lua_state) {
80  /* Check parameters */
81  if(lua_gettop(pt_lua_state) != 0) {
82  return luaL_error(pt_lua_state, "robot.turret.set_passive_mode() expects no arguments");
83  }
84  /* Perform action */
85  CLuaUtility::GetDeviceInstance<CCI_FootBotTurretActuator>(pt_lua_state, "turret")->
86  SetPassiveMode();
87  return 0;
88  }
89 #endif
90 
91  /****************************************/
92  /****************************************/
93 
96  SetRotation(c_angle);
97  }
98 
99  /****************************************/
100  /****************************************/
101 
104  }
105 
106  /****************************************/
107  /****************************************/
108 
111  }
112 
113  /****************************************/
114  /****************************************/
115 
118  }
119 
120  /****************************************/
121  /****************************************/
122 
123 #ifdef ARGOS_WITH_LUA
124  void CCI_FootBotTurretActuator::CreateLuaState(lua_State* pt_lua_state) {
125  CLuaUtility::OpenRobotStateTable(pt_lua_state, "turret");
126  CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
127  CLuaUtility::AddToTable(pt_lua_state, "set_rotation", &LuaTurretSetRotation);
128  CLuaUtility::AddToTable(pt_lua_state, "set_rotation_speed", &LuaTurretSetRotationSpeed);
129  CLuaUtility::AddToTable(pt_lua_state, "set_position_control_mode", &LuaTurretSetPositionControlMode);
130  CLuaUtility::AddToTable(pt_lua_state, "set_speed_control_mode", &LuaTurretSetSpeedControlMode);
131  CLuaUtility::AddToTable(pt_lua_state, "set_passive_mode", &LuaTurretSetPassiveMode);
132  CLuaUtility::CloseRobotStateTable(pt_lua_state);
133  }
134 #endif
135 
136  /****************************************/
137  /****************************************/
138 
139 }
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 const CRange< Real > NORMALIZED_SPEED_RANGE
It defines the basic type CRadians, used to store an angle value in radians.
Definition: angles.h:42
void SetPositionControlMode()
Sets the turret control mode to position control.
virtual void SetRotation(const CRadians &c_angle)=0
Sets the turret rotation Turret rotation is expressed in radians, positive values rotate the turret c...
void SetPassiveMode()
Sets the turret control mode to passive.
void SetActiveWithRotation(const CRadians &c_angle)
Sets the turret control mode to active, and sets the target rotation to the given one...
virtual void SetMode(ETurretModes e_mode)=0
Sets the turret control mode Modes are: angular position control, rotation speed control, passive mode, off.
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.
void SetSpeedControlMode()
Sets the turret control mode to speed control.
static const CRange< SInt32 > SPEED_RANGE