10. WebAPP program use

10.1. Set Default Program to Load Automatically on Startup

1/**
2* @brief  Set default program to load automatically on startup
3* @param  [in] flag  0-Do not load default program on startup, 1-Load default program on startup
4* @param  [in] program_name Program name and path, e.g. "/fruser/movej.lua", where "/fruser/" is the fixed path for QX, and "/usr/local/etc/controller/lua/" is the fixed path for LA.
5* @return  Error code
6*/
7errno_t  LoadDefaultProgConfig(uint8_t flag, char program_name[64]);

10.2. Load Specified Program

1/**
2* @brief  Load specified program
3* @param  [in] program_name Program name and path, e.g. "/fruser/movej.lua", where "/fruser/" is the fixed path for QX, and "/usr/local/etc/controller/lua/" is the fixed path for LA.
4* @return  Error code
5*/
6errno_t  ProgramLoad(char program_name[64]);

10.3. Get Loaded Program Name

1/**
2* @brief  Get loaded program name
3* @param  [out] program_name Program name and path, e.g. "/fruser/movej.lua", where "/fruser/" is the fixed path for QX, and "/usr/local/etc/controller/lua/" is the fixed path for LA.
4* @return  Error code
5*/
6errno_t  GetLoadedProgram(char program_name[64]);

10.4. Get Current Program Execution Line Number

1/**
2* @brief  Get current program execution line number
3* @param  [out] line  Line number
4* @return  Error code
5*/
6errno_t  GetCurrentLine(int *line);

10.5. Run Currently Loaded Program

1/**
2* @brief  Run currently loaded program
3* @return  Error code
4*/
5errno_t  ProgramRun();

10.6. Pause Currently Running Program

1/**
2* @brief  Pause currently running program
3* @return  Error code
4*/
5errno_t  ProgramPause();

10.7. Resume Currently Paused Program

1/**
2* @brief  Resume currently paused program
3* @return  Error code
4*/
5errno_t  ProgramResume();

10.8. Stop Currently Running Program

1/**
2* @brief  Stop currently running program
3* @return  Error code
4*/
5errno_t  ProgramStop();

10.9. Get Program Execution State

1/**
2* @brief  Get program execution state
3* @param  [out]  state 1-Program stopped or no program running, 2-Program running, 3-Program paused
4* @return  Error code
5*/
6errno_t  GetProgramState(uint8_t *state);

10.10. Robot LUA Program Operation Code Example

 1int TestLuaOp(void)
 2{
 3  ROBOT_STATE_PKG pkg = {};
 4  FRRobot robot;
 5  robot.LoggerInit();
 6  robot.SetLoggerLevel(1);
 7  int rtn = robot.RPC("192.168.58.2");
 8  if (rtn != 0)
 9  {
10    return -1;
11  }
12  robot.SetReConnectParam(true, 30000, 500);
13  char program_name[64] = "/fruser/test.lua";
14  char loaded_name[64] = "";
15  uint8_t state;
16  int line;
17  robot.Mode(0);
18  robot.LoadDefaultProgConfig(0, program_name);
19  robot.ProgramLoad(program_name);
20  robot.ProgramRun();
21  robot.Sleep(1000);
22  robot.ProgramPause();
23  robot.GetProgramState(&state);
24  printf("program state:%u\n", state);
25  robot.GetCurrentLine(&line);
26  printf("current line:%d\n", line);
27  robot.GetLoadedProgram(loaded_name);
28  printf("program name:%s\n", loaded_name);
29  robot.Sleep(1000);
30  robot.ProgramResume();
31  robot.Sleep(1000);
32  robot.ProgramStop();
33  robot.Sleep(1000);
34  robot.CloseRPC();
35  return 0;
36}

10.11. Download Lua File

New in version C++SDK-v2.1.2.0.

1/**
2* @brief Download Lua file
3* @param [in] fileName Lua file name to download, e.g. "test.lua"
4* @param [in] savePath Local path to save file, e.g. "D://Down/"
5* @return Error code
6*/
7errno_t LuaDownLoad(std::string fileName, std::string savePath);

10.12. Delete Lua File

New in version C++SDK-v2.1.2.0.

1/**
2* @brief Delete Lua file
3* @param [in] fileName Lua file name to delete, e.g. "test.lua"
4* @return Error code
5*/
6errno_t LuaDelete(std::string fileName);

10.13. Get All Current Lua File Names

New in version C++SDK-v2.1.2.0.

1/**
2* @brief Get all current Lua file names
3* @param [out] luaNames List of Lua file names
4* @return Error code
5*/
6errno_t GetLuaList(std::list<std::string>* luaNames);

10.14. Upload Lua File

New in version C++SDK-v2.1.2.0.

1/**
2* @brief Upload Lua file
3* @param [in] filePath Local Lua file path name
4* @return Error code
5*/
6errno_t LuaUpload(std::string filePath);

10.15. Robot LUA File Upload/Download Code Example

 1int TestLUAUpDownLoad(void)
 2{
 3  ROBOT_STATE_PKG pkg = {};
 4  FRRobot robot;
 5  robot.LoggerInit();
 6  robot.SetLoggerLevel(1);
 7  int rtn = robot.RPC("192.168.58.2");
 8  if (rtn != 0)
 9  {
10    return -1;
11  }
12  robot.SetReConnectParam(true, 30000, 500);
13  list<std::string> luaNames;
14  rtn = robot.GetLuaList(&luaNames);
15  std::cout << "res is: " << rtn << std::endl;
16  std::cout << "size is: " << luaNames.size() << std::endl;
17  for (auto it = luaNames.begin(); it != luaNames.end(); it++)
18  {
19    std::cout << it->c_str() << std::endl;
20  }
21  rtn = robot.LuaDownLoad("test.lua", "D://zDOWN/");
22  printf("LuaDownLoad rtn is %d\n", rtn);
23  rtn = robot.LuaUpload("D://zUP/airlab.lua");
24  printf("LuaUpload rtn is %d\n", rtn);
25  rtn = robot.LuaDelete("test.lua");
26  printf("LuaDelete rtn is %d\n", rtn);
27  robot.CloseRPC();
28  return 0;
29}