Skip to main content

Command Registration

This section introduces how to register a command. Register Command Flowchart: Register Command Flowchart

Usage Example:

/**
* @brief Command construction and registration
*/
void RegPrintq() {
// 1. Command configuration, such as name, trigger method, task limits, etc.
RLCmdConfigAPI cfg;
cfg.SetFuncName("printq");
// Set command look-ahead method, default is WAIT_MOVE_PAUSE
cfg.SetLookAhead(CmdLookAheadImplAPI::WAIT_MOVE_PAUSE) ;
// Set task limit type
cfg.SetTaskLimit(TaskLimitAPI::TASK_NO_LIMIT);
// Set step-back type
cfg.SetStepBack(StepBackAPI::STEP_BACK_SKIP);

// 2. Create command according to configuration
BEGIN_COMMAND_API(cfg)

// 3. Configure parameter checker for the command
PARAMS_API(
ArgTypeAPI(ValueTypeAPI::VALUE_ROBTARGET),
ArgTypeAPI(ValueTypeAPI::VALUE_WOBJ),
ArgTypeAPI(ValueTypeAPI::VALUE_STRING)
)

// 4. Command forward execution body
RLCmdActionAPI cmd_func = [=](std::shared_ptr<RLCallFrameAPI> frame,
std::vector<std::shared_ptr<SymbolVarBaseAPI>> args) -> CommandExecuteAPI {
// Get nested data
auto cart_pos = args[0]->GetSubUnit("ROT");
std::vector<double> robs_q = {
cart_pos.GetSubUnit("Q1").GetDoubleVal(), cart_pos.GetSubUnit("Q2").GetDoubleVal(),
cart_pos.GetSubUnit("Q3").GetDoubleVal(), cart_pos.GetSubUnit("Q4").GetDoubleVal()};

CommandExecuteAPI cmd_exec = [=]()
{
LOG_INFO << "printq:" << frame->GetCmdTask() << " " << frame->GetCmdFile() << " " << frame->GetCmdLine();

LOG_INFO << "printq Q1=" << robs_q[0] << " Q2=" << robs_q[1] << " Q3=" << robs_q[2] << " Q4=" << robs_q[3] << " ";
LOG_INFO << "printq str=" << args[2]->GetStringVal();
return CommandProcessResultAPI::CMD_PROCESS_SUCCESS;
};
return cmd_exec;
};
EXECUTE_API(cmd_func)

// 5. Command step-back execution body (add as needed)
RLCmdActionAPI cmd_func_stb = [=](std::shared_ptr<RLCallFrameAPI> frame,
std::vector<std::shared_ptr<SymbolVarBaseAPI>> args) -> CommandExecuteAPI {
// Get nested data
auto cart_pos = args[0]->GetSubUnit("ROT");

std::vector<double> robs_q = {
cart_pos.GetSubUnit("Q1").GetDoubleVal(), cart_pos.GetSubUnit("Q2").GetDoubleVal(),
cart_pos.GetSubUnit("Q3").GetDoubleVal(), cart_pos.GetSubUnit("Q4").GetDoubleVal()};

CommandExecuteAPI cmd_exec = [=]()
{
LOG_INFO << "printq:" << frame->GetCmdTask() << " " << frame->GetCmdFile() << " " << frame->GetCmdLine();

LOG_INFO << "printq Q1=" << robs_q[0] << " Q2=" << robs_q[1] << " Q3=" << robs_q[2] << " Q4=" << robs_q[3] << " ";
LOG_INFO << "printq str=" << args[2]->GetStringVal();
return CommandProcessResultAPI::CMD_PROCESS_SUCCESS;
};
return cmd_exec;
};
EXECUTE_STB_API(cmd_func_stb)

// 6. Register command to Controller
REGISTER_COMMAND_API
}

When using the printq command in HMI, executing this command will print the quaternion in the log. Users can use the Client Plugin to inject this command into the auxiliary programming, making it convenient to use the newly registered command.

hmi Usage Command

Command Result

For specific usage examples, please refer to examples/rl_cmd.hpp This command implements printing the quaternion of a Cartesian variable.