ci_differential_steering_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 two values in this order:
21  * 1. left wheel speed (a number)
22  * 2. right wheel speed (a number)
23  */
24  int LuaSetDiffSteeringLinearVelocity(lua_State* pt_lua_state) {
25  /* Check parameters */
26  if(lua_gettop(pt_lua_state) != 2) {
27  return luaL_error(pt_lua_state, "robot.wheels.set_velocity() expects 2 arguments");
28  }
29  luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
30  luaL_checktype(pt_lua_state, 2, LUA_TNUMBER);
31  /* Perform action */
32  CLuaUtility::GetDeviceInstance<CCI_DifferentialSteeringActuator>(pt_lua_state, "wheels")->
33  SetLinearVelocity(lua_tonumber(pt_lua_state, 1),
34  lua_tonumber(pt_lua_state, 2));
35  return 0;
36  }
37 #endif
38 
39  /****************************************/
40  /****************************************/
41 
42 #ifdef ARGOS_WITH_LUA
43  void CCI_DifferentialSteeringActuator::CreateLuaState(lua_State* pt_lua_state) {
44  CLuaUtility::OpenRobotStateTable(pt_lua_state, "wheels");
45  CLuaUtility::AddToTable(pt_lua_state, "_instance", this);
46  CLuaUtility::AddToTable(pt_lua_state, "set_velocity", &LuaSetDiffSteeringLinearVelocity);
48  }
49 #endif
50 
51  /****************************************/
52  /****************************************/
53 
54 }
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.