ci_gripper_actuator.cpp
Go to the documentation of this file.
1 
7 #include "ci_gripper_actuator.h"
8 #include <argos3/core/utility/math/range.h>
9 
10 #ifdef ARGOS_WITH_LUA
11 #include <argos3/core/wrappers/lua/lua_utility.h>
12 #endif
13 
14 namespace argos {
15 
16  /****************************************/
17  /****************************************/
18 
19  CRange<Real> UNIT(0.0f, 1.0f);
20 
21  /****************************************/
22  /****************************************/
23 
24 #ifdef ARGOS_WITH_LUA
25  /*
26  * The stack must have no values
27  */
28  int LuaGripperLock(lua_State* pt_lua_state) {
29  /* Get wheel speed from stack */
30  if(lua_gettop(pt_lua_state) != 0) {
31  return luaL_error(pt_lua_state, "robot.gripper.lock() expects no arguments");
32  }
33  /* Perform action */
34  CLuaUtility::GetDeviceInstance<CCI_GripperActuator>(pt_lua_state, "gripper")->Lock();
35  return 0;
36  }
37 
38  /*
39  * The stack must have no values
40  */
41  int LuaGripperUnlock(lua_State* pt_lua_state) {
42  /* Get wheel speed from stack */
43  if(lua_gettop(pt_lua_state) != 0) {
44  return luaL_error(pt_lua_state, "robot.gripper.unlock() expects no arguments");
45  }
46  /* Perform action */
47  CLuaUtility::GetDeviceInstance<CCI_GripperActuator>(pt_lua_state, "gripper")->Unlock();
48  return 0;
49  }
50 #endif
51 
52  /****************************************/
53  /****************************************/
54 
56  m_fLockState(0.0f) {}
57 
58  /****************************************/
59  /****************************************/
60 
62  UNIT.TruncValue(f_lock_state);
63  m_fLockState = f_lock_state;
64  }
65 
66  /****************************************/
67  /****************************************/
68 
70  SetLockState(1.0f);
71  }
72 
73  /****************************************/
74  /****************************************/
75 
77  SetLockState(0.0f);
78  }
79 
80  /****************************************/
81  /****************************************/
82 
83 #ifdef ARGOS_WITH_LUA
84  void CCI_GripperActuator::CreateLuaState(lua_State* pt_lua_state) {
85  CLuaUtility::StartTable(pt_lua_state, "gripper");
86  CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
87  CLuaUtility::AddToTable(pt_lua_state, "lock", &LuaGripperLock);
88  CLuaUtility::AddToTable(pt_lua_state, "unlock", &LuaGripperUnlock);
89  CLuaUtility::EndTable(pt_lua_state);
90  }
91 #endif
92 
93  /****************************************/
94  /****************************************/
95 
96 }
static void EndTable(lua_State *pt_state)
Adds a table to the Lua stack.
void Lock()
Locks the gripper.
static void StartTable(lua_State *pt_state, const std::string &str_key)
Adds a table with the given string key to the table located at the top of the stack.
void TruncValue(T &t_value) const
Definition: range.h:97
void Unlock()
Unlocks the gripper.
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...
CRange< Real > UNIT(0.0f, 1.0f)
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
CCI_GripperActuator()
Class constructor.
void SetLockState(Real f_lock_state)
Sets the gripper lock state.
float Real
Collects all ARGoS code.
Definition: datatypes.h:39