ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
00001 00007 #include "ci_gripper_actuator.h" 00008 #include <argos3/core/utility/math/range.h> 00009 00010 #ifdef ARGOS_WITH_LUA 00011 #include <argos3/core/wrappers/lua/lua_utility.h> 00012 #endif 00013 00014 namespace argos { 00015 00016 /****************************************/ 00017 /****************************************/ 00018 00019 CRange<Real> UNIT(0.0f, 1.0f); 00020 00021 /****************************************/ 00022 /****************************************/ 00023 00024 #ifdef ARGOS_WITH_LUA 00025 /* 00026 * The stack must have no values 00027 */ 00028 int LuaGripperLock(lua_State* pt_lua_state) { 00029 /* Get wheel speed from stack */ 00030 if(lua_gettop(pt_lua_state) != 0) { 00031 return luaL_error(pt_lua_state, "robot.gripper.lock() expects no arguments"); 00032 } 00033 /* Perform action */ 00034 CLuaUtility::GetDeviceInstance<CCI_GripperActuator>(pt_lua_state, "gripper")->Lock(); 00035 return 0; 00036 } 00037 00038 /* 00039 * The stack must have no values 00040 */ 00041 int LuaGripperUnlock(lua_State* pt_lua_state) { 00042 /* Get wheel speed from stack */ 00043 if(lua_gettop(pt_lua_state) != 0) { 00044 return luaL_error(pt_lua_state, "robot.gripper.unlock() expects no arguments"); 00045 } 00046 /* Perform action */ 00047 CLuaUtility::GetDeviceInstance<CCI_GripperActuator>(pt_lua_state, "gripper")->Unlock(); 00048 return 0; 00049 } 00050 #endif 00051 00052 /****************************************/ 00053 /****************************************/ 00054 00055 CCI_GripperActuator::CCI_GripperActuator() : 00056 m_fLockState(0.0f) {} 00057 00058 /****************************************/ 00059 /****************************************/ 00060 00061 void CCI_GripperActuator::SetLockState(Real f_lock_state) { 00062 UNIT.TruncValue(f_lock_state); 00063 m_fLockState = f_lock_state; 00064 } 00065 00066 /****************************************/ 00067 /****************************************/ 00068 00069 #ifdef ARGOS_WITH_LUA 00070 void CCI_GripperActuator::CreateLuaState(lua_State* pt_lua_state) { 00071 CLuaUtility::StartTable(pt_lua_state, "gripper"); 00072 CLuaUtility::AddToTable(pt_lua_state, "_instance", this); 00073 CLuaUtility::AddToTable(pt_lua_state, "lock", &LuaGripperLock); 00074 CLuaUtility::AddToTable(pt_lua_state, "unlock", &LuaGripperUnlock); 00075 CLuaUtility::EndTable(pt_lua_state); 00076 } 00077 #endif 00078 00079 /****************************************/ 00080 /****************************************/ 00081 00082 }