From 52ceab199527bc01dfdb35b4c3c023a971959717 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 11 Oct 2023 17:45:00 +0800 Subject: [PATCH] update --- .../xy_robot_script_cmder_module.cpp | 102 +++++++++++++-------- 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/components/scriptcmder_module/xy_robot_script_cmder_module.cpp b/components/scriptcmder_module/xy_robot_script_cmder_module.cpp index 8210e3a..66e7aea 100644 --- a/components/scriptcmder_module/xy_robot_script_cmder_module.cpp +++ b/components/scriptcmder_module/xy_robot_script_cmder_module.cpp @@ -1,5 +1,7 @@ #include "xy_robot_script_cmder_module.hpp" +#include + #include "sdk\components\zprotocols\zcancmder\zcancmder_protocol.hpp" using namespace iflytop; #define TAG "XYRobotScriptCmderModule" @@ -32,6 +34,8 @@ I_XYRobotCtrlModule* XYRobotScriptCmderModule::findXYRobot(int id) { return it->second; } +static bool streq(const char* a, const char* b) { return strcmp(a, b) == 0; } + void XYRobotScriptCmderModule::regXYRobot(int id, I_XYRobotCtrlModule* robot) { ZASSERT(moduler.find(id) == moduler.end()); ZASSERT(robot != nullptr); @@ -190,49 +194,73 @@ void XYRobotScriptCmderModule::regcmd() { // }); m_cmdScheduler->registerCmd("xy_robot_ctrl_set_base_param", [this](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { - SCRIPT_CMDER_CHECK(argc == 2); - -#if 0 - s32 robot_type; - s32 x_shaft; - s32 y_shaft; - s32 ihold; - s32 irun; - s32 iholddelay; - s32 distance_scale; // 0.001 - s32 shift_x; - s32 shift_y; - - // limit - s32 acc; - s32 dec; - s32 breakdec; - s32 maxspeed; - s32 min_x; - s32 max_x; - s32 min_y; - s32 max_y; - - s32 run_to_zero_max_d; - s32 leave_from_zero_max_d; - s32 run_to_zero_speed; - s32 run_to_zero_dec; - - int32_t id = atoi(argv[1]); + SCRIPT_CMDER_CHECK(argc == 4); + int32_t id = atoi(argv[1]); + const char* paramName = argv[2]; + int32_t paramVal = atoi(argv[3]); I_XYRobotCtrlModule* module = findXYRobot(id); SCRIPT_CMDER_CHECK(module != nullptr); I_XYRobotCtrlModule::base_param_t status; - int32_t ack = module->read_detailed_status(status); - ZLOGI(TAG, "ack:%d:%s", ack,err::error2str(ack)); - if (ack == 0) { - ZLOGI(TAG, " status:%d", status.status); - ZLOGI(TAG, " x:%d", status.x); - ZLOGI(TAG, " y:%d", status.y); - ZLOGI(TAG, " iostate:%d", status.iostate); + int32_t ack = module->get_base_param(status); + if (ack != 0) { + ZLOGE(TAG, "get_base_param failed:%d", ack); + return; + } + + if (streq(paramName, "robot_type")) { + status.robot_type = paramVal; + } else if (streq(paramName, "x_shaft")) { + status.x_shaft = paramVal; + } else if (streq(paramName, "y_shaft")) { + status.y_shaft = paramVal; + } else if (streq(paramName, "ihold")) { + status.ihold = paramVal; + } else if (streq(paramName, "irun")) { + status.irun = paramVal; + } else if (streq(paramName, "iholddelay")) { + status.iholddelay = paramVal; + } else if (streq(paramName, "distance_scale")) { + status.distance_scale = paramVal; + } else if (streq(paramName, "shift_x")) { + status.shift_x = paramVal; + } else if (streq(paramName, "shift_y")) { + status.shift_y = paramVal; + } else if (streq(paramName, "acc")) { + status.acc = paramVal; + } else if (streq(paramName, "dec")) { + status.dec = paramVal; + } else if (streq(paramName, "breakdec")) { + status.breakdec = paramVal; + } else if (streq(paramName, "maxspeed")) { + status.maxspeed = paramVal; + } else if (streq(paramName, "min_x")) { + status.min_x = paramVal; + } else if (streq(paramName, "max_x")) { + status.max_x = paramVal; + } else if (streq(paramName, "min_y")) { + status.min_y = paramVal; + } else if (streq(paramName, "max_y")) { + status.max_y = paramVal; + } else if (streq(paramName, "run_to_zero_max_d")) { + status.run_to_zero_max_d = paramVal; + } else if (streq(paramName, "leave_from_zero_max_d")) { + status.leave_from_zero_max_d = paramVal; + } else if (streq(paramName, "run_to_zero_speed")) { + status.run_to_zero_speed = paramVal; + } else if (streq(paramName, "run_to_zero_dec")) { + status.run_to_zero_dec = paramVal; + } else { + ZLOGE(TAG, "invalid param name:%s", paramName); + return; + } + ack = module->set_base_param(status); + if (ack != 0) { + ZLOGE(TAG, "set_base_param failed:%d,%s", ack, err::error2str(ack)); + return; } -#endif + return; }); m_cmdScheduler->registerCmd("xy_robot_ctrl_get_base_param", [this](int argc, char** argv, CmdScheduler::CmdProcessContext* context) { SCRIPT_CMDER_CHECK(argc == 2);