Browse Source

update

master
zhaohe 1 year ago
parent
commit
64b9d7331e
  1. 2
      a8000_protocol
  2. 4
      libzqt/zui/z_function_list_box.cpp
  3. 256
      src/tab/step_motor_ctrl_tab.cpp

2
a8000_protocol

@ -1 +1 @@
Subproject commit 4f4db2708e7503d5369c7b5f9bdc7781fcca1be9
Subproject commit e4a80570d108c0a711401236f95bbc95b4ae7ecf

4
libzqt/zui/z_function_list_box.cpp

@ -54,6 +54,10 @@ void ZQFunctionListBox::newSubButton(QString zh_name, std::function<void(int arg
if (!workQ.isWorking()) {
workQ.startSchedule();
}
if (subbotton_column_off >= m_column) {
newSubButtonEnd();
}
}
void ZQFunctionListBox::newSubButtonEnd() {
subbotton_column_off = 0;

256
src/tab/step_motor_ctrl_tab.cpp

@ -28,46 +28,29 @@ void StepMotorCtrlTab::construct(QTabWidget *fathertab) {
/***********************************************************************************************************************
* *
***********************************************************************************************************************/
// kstep_motor_enable = NEW_CMDID(101, 1), // para:{1}, ack:{}
// kstep_motor_read_pos = NEW_CMDID(101, 2), // para:{}, ack:{4}
// kstep_motor_easy_rotate = NEW_CMDID(101, 3), // para:{4}, ack:{}
// kstep_motor_easy_move_by = NEW_CMDID(101, 4), // para:{4}, ack:{}
// kstep_motor_easy_move_to = NEW_CMDID(101, 5), // para:{4}, ack:{}
// kstep_motor_easy_move_to_zero = NEW_CMDID(101, 6), // para:{1}, ack:{}
// kstep_motor_easy_set_current_pos = NEW_CMDID(101, 7), // para:{4}, ack:{}
// kstep_motor_easy_move_to_io = NEW_CMDID(101, 8), // para:{4,4}, ack:{}
// kstep_motor_active_cfg = NEW_CMDID(101, 9), // para:{4,4}, ack:{}
// kstep_motor_stop = NEW_CMDID(101, 10), // para:{4}, ack:{}
// kstep_motor_read_io_state = NEW_CMDID(101, 11), // para:{4}, ack:{4}
ZQVTabPage *tab = new ZQVTabPage(fathertab, "步进电机");
{
ZQFunctionListBox *box = new ZQFunctionListBox(tab, "方法组1", 4);
box->newFunc("使能", {"enable"}, [this](int argn, const char **args) { ICM->step_motor_enable(getDeviceId(), atoi(args[0])); });
box->newFunc("停止", {}, [this](int argn, const char **args) { ICM->step_motor_stop(getDeviceId(), 0); });
box->newFunc("激活配置", {}, [this](int argn, const char **args) { ICM->step_motor_active_cfg(getDeviceId()); });
}
{
ZQFunctionListBox *box = new ZQFunctionListBox(tab, "方法组2", 4);
box->newFunc("旋转", {"direction"}, [this](int argn, const char **args) { ICM->step_motor_easy_rotate(getDeviceId(), atoi(args[0])); });
box->newFunc("相对移动", {"distance"}, [this](int argn, const char **args) { ICM->step_motor_easy_move_by(getDeviceId(), atoi(args[0])); });
box->newFunc("移动到", {"position"}, [this](int argn, const char **args) { ICM->step_motor_easy_move_to(getDeviceId(), atoi(args[0])); });
box->newFunc("归零", {}, [this](int argn, const char **args) { ICM->step_motor_easy_move_to_zero(getDeviceId()); });
box->newFunc("移动到终点", {}, [this](int argn, const char **args) { ICM->callcmd0(getDeviceId(), kstep_motor_easy_move_to_end_point); });
box->newFunc("移动到IO", {"ioindex", "direction"}, [this](int argn, const char **args) { ICM->step_motor_easy_move_to_io(getDeviceId(), atoi(args[0]), atoi(args[1])); });
}
box->newSubButton("使能", [this](int argn, const char **args) { ICM->step_motor_enable(getDeviceId(), 1); });
box->newSubButton("失能", [this](int argn, const char **args) { ICM->step_motor_enable(getDeviceId(), 0); });
box->newSubButton("停止", [this](int argn, const char **args) { ICM->step_motor_stop(getDeviceId(), 0); });
box->newSubButton("激活配置", [this](int argn, const char **args) { ICM->step_motor_active_cfg(getDeviceId()); });
{
ZQFunctionListBox *box = new ZQFunctionListBox(tab, "方法组3", 4);
box->newFunc("设置当前位置", {"position"}, [this](int argn, const char **args) { ICM->step_motor_easy_set_current_pos(getDeviceId(), atoi(args[0])); });
box->newFunc("读取位置", {}, [this](int argn, const char **args) {
box->newSubButton("读取位置1", [this](int argn, const char **args) {
int32_t pos = 0;
ICM->step_motor_read_pos(getDeviceId(), &pos);
ZQUI::ins()->ishow("Pos:%d", pos);
});
box->newFunc("读取IO状态", {"ioindex"}, [this](int argn, const char **args) {
box->newSubButton("读取位置2", [this](int argn, const char **args) {
int32_t pos = 0;
ICM->callcmd0(getDeviceId(), kstep_motor_read_pos_and_enc_pos);
ZQUI::ins()->ishow("Pos :%d", ICM->getAck(0));
ZQUI::ins()->ishow("EncPos:%d", ICM->getAck(1));
});
box->newSubButton("读取IO状态", [this](int argn, const char **args) {
int32_t portState = 0;
int32_t indexInStm32 = 0;
for (int i = 0; i < 10; i++) {
@ -77,14 +60,14 @@ void StepMotorCtrlTab::construct(QTabWidget *fathertab) {
ICM->callcmd1(getDeviceId(), kstep_motor_read_io_state, i);
portState = ICM->getAck(0);
if (indexInStm32 == 0) continue;
ZQUI::ins()->ishow("io%d(%s):%d", i, stm32pin2str((Pin_t)indexInStm32).c_str(), portState);
} catch (const std::exception &e) {
break;
}
}
});
box->newFunc("读取5130电机详细状态", {"ioindex"}, [this](int argn, const char **args) {
box->newSubButton("读取5130电机详细状态", [this](int argn, const char **args) {
ICM->callcmd0(getDeviceId(), kstep_motor_read_tmc5130_status);
TMC5130MotorStatus_t status;
@ -106,168 +89,69 @@ void StepMotorCtrlTab::construct(QTabWidget *fathertab) {
ZQUI::ins()->ishow("olb :%d", status.olb);
ZQUI::ins()->ishow("stst :%d", status.stst);
});
box->newFunc("设置当前位置", {"position"}, [this](int argn, const char **args) { ICM->step_motor_easy_set_current_pos(getDeviceId(), atoi(args[0])); });
}
box->newFunc("读取TMC2160状态", {}, [this](int argn, const char **args) {
ICM->callcmd0(getDeviceId(), kstep_motor_read_tmc2160_status);
TMC2160MotorDriverStatus_t status;
static_assert(sizeof(status) == 4, "sizeof(TMC2160MotorDriverStatus_t) != 4");
memcpy(&status, ICM->getAckBuf(), 4);
ZQUI::ins()->ishow("sg_result :%d", status.sg_result);
ZQUI::ins()->ishow("reserved0 :%d", status.reserved0);
ZQUI::ins()->ishow("reserved1 :%d", status.reserved1);
ZQUI::ins()->ishow("s2vsa :%d", status.s2vsa);
ZQUI::ins()->ishow("s2vsb :%d", status.s2vsb);
ZQUI::ins()->ishow("stealth :%d", status.stealth);
ZQUI::ins()->ishow("fsactive :%d", status.fsactive);
ZQUI::ins()->ishow("cs_actual :%d", status.cs_actual);
ZQUI::ins()->ishow("reserved2 :%d", status.reserved2);
ZQUI::ins()->ishow("stallguard :%d", status.stallguard);
ZQUI::ins()->ishow("ot :%d", status.ot);
ZQUI::ins()->ishow("otpw :%d", status.otpw);
ZQUI::ins()->ishow("s2ga :%d", status.s2ga);
ZQUI::ins()->ishow("s2gb :%d", status.s2gb);
ZQUI::ins()->ishow("ola :%d", status.ola);
ZQUI::ins()->ishow("olb :%d", status.olb);
ZQUI::ins()->ishow("stst :%d", status.stst);
});
box->newFunc("读取TMC2160_GState", {}, [this](int argn, const char **args) {
ICM->callcmd0(getDeviceId(), kstep_motor_read_tmc2160_state);
TMC2160MotorGstate_t status;
static_assert(sizeof(status) == 4, "sizeof(TMC2160MotorGstate_t) != 4");
memcpy(&status, ICM->getAckBuf(), 4);
ZQUI::ins()->ishow("reset :%d", status.reset);
ZQUI::ins()->ishow("drv_err :%d", status.drv_err);
ZQUI::ins()->ishow("uv_cp :%d", status.uv_cp);
});
box->newFunc("读取TMC4361A状态", {}, [this](int argn, const char **args) {
ICM->callcmd0(getDeviceId(), kstep_motor_read_tmc4361a_status);
TMC4361AMotorStatus_t status;
static_assert(sizeof(status) == 4, "sizeof(TMC4361AMotorStatus_t) != 4");
memcpy(&status, ICM->getAckBuf(), 4);
ZQUI::ins()->ishow("TARGET_REACHED_F :%d", status.TARGET_REACHED_F);
ZQUI::ins()->ishow("POS_COMP_REACHED_F :%d", status.POS_COMP_REACHED_F);
ZQUI::ins()->ishow("VEL_REACHED_F :%d", status.VEL_REACHED_F);
ZQUI::ins()->ishow("VEL_STATE_F :%d", status.VEL_STATE_F);
ZQUI::ins()->ishow("RAMP_STATE_F :%d", status.RAMP_STATE_F);
ZQUI::ins()->ishow("STOPL_ACTIVE_F :%d", status.STOPL_ACTIVE_F);
ZQUI::ins()->ishow("STOPR_ACTIVE_F :%d", status.STOPR_ACTIVE_F);
ZQUI::ins()->ishow("VSTOPL_ACTIVE_F :%d", status.VSTOPL_ACTIVE_F);
ZQUI::ins()->ishow("VSTOPR_ACTIVE_F :%d", status.VSTOPR_ACTIVE_F);
ZQUI::ins()->ishow("ACTIVE_STALL_F :%d", status.ACTIVE_STALL_F);
ZQUI::ins()->ishow("HOME_ERROR_F :%d", status.HOME_ERROR_F);
ZQUI::ins()->ishow("FS_ACTIVE_F :%d", status.FS_ACTIVE_F);
ZQUI::ins()->ishow("ENC_FAIL_F :%d", status.ENC_FAIL_F);
ZQUI::ins()->ishow("N_ACTIVE_F :%d", status.N_ACTIVE_F);
ZQUI::ins()->ishow("ENC_LATCH_F :%d", status.ENC_LATCH_F);
ZQUI::ins()->ishow("MULTI_CYCLE_FAIL_F :%d", status.MULTI_CYCLE_FAIL_F);
ZQUI::ins()->ishow("___ :%d", status.___);
ZQUI::ins()->ishow("CL_FIT_F :%d", status.CL_FIT_F);
ZQUI::ins()->ishow("SERIAL_ENC_FLAGS :%d", status.SERIAL_ENC_FLAGS);
ZQUI::ins()->ishow("SG :%d", status.SG);
ZQUI::ins()->ishow("OT :%d", status.OT);
ZQUI::ins()->ishow("OTPW :%d", status.OTPW);
ZQUI::ins()->ishow("S2GA :%d", status.S2GA);
ZQUI::ins()->ishow("S2GB :%d", status.S2GB);
ZQUI::ins()->ishow("OLA :%d", status.OLA);
ZQUI::ins()->ishow("OLB :%d", status.OLB);
ZQUI::ins()->ishow("STST :%d", status.STST);
});
box->newFunc("读取TMC4361A事件状态", {}, [this](int argn, const char **args) {
ICM->callcmd0(getDeviceId(), kstep_motor_read_tmc4361a_state);
{
ZQFunctionListBox *box = new ZQFunctionListBox(tab, "方法组2", 4);
TMC4361AMotorEventState_t status;
static_assert(sizeof(status) == 4, "sizeof(TMC4361AMotorEventState_t) != 4");
box->newSubButton("归零", [this](int argn, const char **args) { ICM->step_motor_easy_move_to_zero(getDeviceId()); });
box->newSubButton("移动到终点", [this](int argn, const char **args) { ICM->callcmd0(getDeviceId(), kstep_motor_easy_move_to_end_point); });
box->newFunc("旋转", {"direction"}, [this](int argn, const char **args) { ICM->step_motor_easy_rotate(getDeviceId(), atoi(args[0])); });
box->newFunc("相对移动", {"distance"}, [this](int argn, const char **args) { ICM->step_motor_easy_move_by(getDeviceId(), atoi(args[0])); });
box->newFunc("移动到", {"position"}, [this](int argn, const char **args) { ICM->step_motor_easy_move_to(getDeviceId(), atoi(args[0])); });
box->newFunc("移动到IO", {"ioindex", "direction"}, [this](int argn, const char **args) { ICM->step_motor_easy_move_to_io(getDeviceId(), atoi(args[0]), atoi(args[1])); });
}
memcpy(&status, ICM->getAckBuf(), 4);
ZQUI::ins()->ishow("%20s: %d", "TARGET_REACHED", status.TARGET_REACHED);
ZQUI::ins()->ishow("%20s: %d", "POS_COMP_REACHED", status.POS_COMP_REACHED);
ZQUI::ins()->ishow("%20s: %d", "VEL_REACHED", status.VEL_REACHED);
ZQUI::ins()->ishow("%20s: %d", "VEL_STATE_EQ_0", status.VEL_STATE_EQ_0);
ZQUI::ins()->ishow("%20s: %d", "VEL_STATE_EQ_1", status.VEL_STATE_EQ_1);
ZQUI::ins()->ishow("%20s: %d", "VEL_STATE_EQ_2", status.VEL_STATE_EQ_2);
ZQUI::ins()->ishow("%20s: %d", "RAMP_STATE_EQ_0", status.RAMP_STATE_EQ_0);
ZQUI::ins()->ishow("%20s: %d", "RAMP_STATE_EQ_1", status.RAMP_STATE_EQ_1);
ZQUI::ins()->ishow("%20s: %d", "RAMP_STATE_EQ_2", status.RAMP_STATE_EQ_2);
ZQUI::ins()->ishow("%20s: %d", "MAX_PHASE_TRAP", status.MAX_PHASE_TRAP);
ZQUI::ins()->ishow("%20s: %d", "FROZEN", status.FROZEN);
ZQUI::ins()->ishow("%20s: %d", "STOPL", status.STOPL);
ZQUI::ins()->ishow("%20s: %d", "STOPR", status.STOPR);
ZQUI::ins()->ishow("%20s: %d", "VSTOPL_ACTIVE", status.VSTOPL_ACTIVE);
ZQUI::ins()->ishow("%20s: %d", "VSTOPR_ACTIVE", status.VSTOPR_ACTIVE);
ZQUI::ins()->ishow("%20s: %d", "HOME_ERROR", status.HOME_ERROR);
ZQUI::ins()->ishow("%20s: %d", "XLATCH_DONE", status.XLATCH_DONE);
ZQUI::ins()->ishow("%20s: %d", "FS_ACTIVE", status.FS_ACTIVE);
ZQUI::ins()->ishow("%20s: %d", "ENC_FAIL", status.ENC_FAIL);
ZQUI::ins()->ishow("%20s: %d", "N_ACTIVE", status.N_ACTIVE);
ZQUI::ins()->ishow("%20s: %d", "ENC_DONE", status.ENC_DONE);
ZQUI::ins()->ishow("%20s: %d", "SER_ENC_DATA_FAIL", status.SER_ENC_DATA_FAIL);
ZQUI::ins()->ishow("%20s: %d", "___", status.___);
ZQUI::ins()->ishow("%20s: %d", "SER_DATA_DONE", status.SER_DATA_DONE);
ZQUI::ins()->ishow("%20s: %d", "SERIAL_ENC_Flags", status.SERIAL_ENC_Flags);
ZQUI::ins()->ishow("%20s: %d", "COVER_DONE", status.COVER_DONE);
ZQUI::ins()->ishow("%20s: %d", "ENC_VEL0", status.ENC_VEL0);
ZQUI::ins()->ishow("%20s: %d", "CL_MAX", status.CL_MAX);
ZQUI::ins()->ishow("%20s: %d", "CL_FIT", status.CL_FIT);
ZQUI::ins()->ishow("%20s: %d", "STOP_ON_STALL", status.STOP_ON_STALL);
ZQUI::ins()->ishow("%20s: %d", "MOTOR_EV", status.MOTOR_EV);
ZQUI::ins()->ishow("%20s: %d", "RST_EV", status.RST_EV);
});
{
ZRegTableList *tableBox = new ZRegTableList(tab, "寄存器操作");
tableBox->initializeRegOperation(
[this](int32_t add, int32_t val) { //
ICM->writereg(getDeviceId(), add, val);
return true;
},
[this](int32_t add, int32_t *val) { //
ICM->readreg(getDeviceId(), add, val);
return true;
});
tableBox->addReg("pos", kreg_step_motor_pos, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("dpos", kreg_step_motor_dpos, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("enc_val", kreg_step_motor_enc_val, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("denc_val", kreg_step_motor_denc_val, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("shift", kreg_step_motor_shift, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("shaft", kreg_step_motor_shaft, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("one_circle_pulse", kreg_step_motor_one_circle_pulse, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("one_circle_pulse_denominator", kreg_step_motor_one_circle_pulse_denominator, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("default_velocity", kreg_step_motor_default_velocity, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("ihold", kreg_step_motor_ihold, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("irun", kreg_step_motor_irun, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("iholddelay", kreg_step_motor_iholddelay, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("iglobalscaler", kreg_step_motor_iglobalscaler, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("run_to_zero_speed", kreg_step_motor_run_to_zero_speed, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("look_zero_edge_speed", kreg_step_motor_look_zero_edge_speed, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("max_d", kreg_step_motor_max_d, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("min_d", kreg_step_motor_min_d, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("in_debug_mode", kreg_step_motor_in_debug_mode, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("vstart", kreg_step_motor_vstart, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("a1", kreg_step_motor_a1, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("amax", kreg_step_motor_amax, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("v1", kreg_step_motor_v1, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("dmax", kreg_step_motor_dmax, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("d1", kreg_step_motor_d1, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("vstop", kreg_step_motor_vstop, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("tzerowait", kreg_step_motor_tzerowait, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("enc_resolution", kreg_step_motor_enc_resolution, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("enable_enc", kreg_step_motor_enable_enc, ZRegItem::krw | ZRegItem::kdec);
}
tab->addSpacer();
}
void StepMotorCtrlTab::constructRegTab(QTabWidget *fathertab) {
ZQVTabPage *tab = new ZQVTabPage(fathertab, "步进电机-寄存器");
ZRegTableList *tableBox = new ZRegTableList(tab, "寄存器操作");
tableBox->initializeRegOperation(
[this](int32_t add, int32_t val) { //
ICM->writereg(getDeviceId(), add, val);
return true;
},
[this](int32_t add, int32_t *val) { //
ICM->readreg(getDeviceId(), add, val);
return true;
});
// ZQVTabPage *tab = new ZQVTabPage(fathertab, "步进电机-寄存器");
tableBox->addReg("motor_pos", kreg_step_motor_pos, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("motor_dpos", kreg_step_motor_dpos, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_shaft", kreg_step_motor_shaft, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_one_circle_pulse", kreg_step_motor_one_circle_pulse, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_one_circle_pulse_denominator", kreg_step_motor_one_circle_pulse_denominator, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_default_velocity", kreg_step_motor_default_velocity, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_ihold", kreg_step_motor_ihold, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_irun", kreg_step_motor_irun, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_iholddelay", kreg_step_motor_iholddelay, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_iglobalscaler", kreg_step_motor_iglobalscaler, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_run_to_zero_speed", kreg_step_motor_run_to_zero_speed, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_look_zero_edge_speed", kreg_step_motor_look_zero_edge_speed, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_max_d", kreg_step_motor_max_d, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_min_d", kreg_step_motor_min_d, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_in_debug_mode", kreg_step_motor_in_debug_mode, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_vstart", kreg_step_motor_vstart, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_a1", kreg_step_motor_a1, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_amax", kreg_step_motor_amax, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_v1", kreg_step_motor_v1, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_dmax", kreg_step_motor_dmax, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_d1", kreg_step_motor_d1, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_vstop", kreg_step_motor_vstop, ZRegItem::krw | ZRegItem::kdec);
tableBox->addReg("reg_step_motor_tzerowait", kreg_step_motor_tzerowait, ZRegItem::krw | ZRegItem::kdec);
tableBox->addSpacer();
tab->addSpacer();
// tableBox->addSpacer();
// tab->addSpacer();
}
Loading…
Cancel
Save