diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp index 0960f05..1aa0737 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -231,12 +231,14 @@ int32_t StepMotorCtrlModule::rotate(int32_t speed, int32_t lastforms, action_cb_ return err::kce_param_out_of_range; } - if (abs(speed) > m_param.maxspeed) { + if (m_param.maxspeed != 0 && abs(speed) > m_param.maxspeed) { ZLOGW(TAG, "speed:%d > m_cfg_max_speed:%d", speed, m_param.maxspeed); speed = m_param.maxspeed; } m_thread.stop(); m_thread.start([this, lastforms, speed, status_cb]() { + ZLOGI(TAG, "(in work thread)rotate speed:%d lastforms:%d acc:%d dec:%d", speed, lastforms, m_param.acc, m_param.dec); + m_stepM1->setAcceleration(m_param.acc); m_stepM1->setDeceleration(m_param.dec); m_stepM1->rotate(speed); @@ -245,12 +247,13 @@ int32_t StepMotorCtrlModule::rotate(int32_t speed, int32_t lastforms, action_cb_ bool reachtime = false; while (!m_thread.getExitFlag()) { - if (zos_haspassedms(startticket) > lastforms || lastforms == 0) { + if (zos_haspassedms(startticket) > lastforms && lastforms != 0) { reachtime = true; m_stepM1->stop(); break; } - osDelay(1); + // ZLOGI(TAG,"..... state %d",m_thread.getExitFlag()); + osDelay(100); } call_exec_status_cb(0, status_cb); m_stepM1->stop(); @@ -513,12 +516,13 @@ void StepMotorCtrlModule::call_exec_status_cb(int32_t status, action_cb_status_t } void StepMotorCtrlModule::create_default_cfg(flash_config_t& cfg) { memset(&cfg, 0, sizeof(cfg)); - cfg.base_param.ihold = 0; - cfg.base_param.irun = 8; - cfg.base_param.iholddelay = 100; - cfg.base_param.acc = 3000000; - cfg.base_param.dec = 3000000; - cfg.base_param.maxspeed = 300000; + cfg.base_param.distance_scale = 1000; + cfg.base_param.ihold = 0; + cfg.base_param.irun = 8; + cfg.base_param.iholddelay = 100; + cfg.base_param.acc = 3000000; + cfg.base_param.dec = 3000000; + cfg.base_param.maxspeed = 300000; cfg.base_param.run_to_zero_move_to_zero_max_d = INT32_MAX; cfg.base_param.run_to_zero_leave_from_zero_max_d = 51200 * 3; diff --git a/components/scriptcmder_module/step_motor_ctrl_script_cmder_module.cpp b/components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.cpp similarity index 100% rename from components/scriptcmder_module/step_motor_ctrl_script_cmder_module.cpp rename to components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.cpp diff --git a/components/scriptcmder_module/step_motor_ctrl_script_cmder_module.hpp b/components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.hpp similarity index 100% rename from components/scriptcmder_module/step_motor_ctrl_script_cmder_module.hpp rename to components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.hpp diff --git a/components/zcancmder_master_module/zcan_master_step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.cpp similarity index 99% rename from components/zcancmder_master_module/zcan_master_step_motor_ctrl_module.cpp rename to components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.cpp index af46241..ff1a0ee 100644 --- a/components/zcancmder_master_module/zcan_master_step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.cpp @@ -1,5 +1,5 @@ #include "sdk\components\zprotocols\errorcode\errorcode.hpp" -#include "zcan_xy_robot_master_module.hpp" +#include "zcan_master_step_motor_ctrl_module.hpp" using namespace iflytop; diff --git a/components/zcancmder_master_module/zcan_master_step_motor_ctrl_module.hpp b/components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.hpp similarity index 100% rename from components/zcancmder_master_module/zcan_master_step_motor_ctrl_module.hpp rename to components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.hpp diff --git a/components/zcancmder_module/zcan_step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.cpp similarity index 95% rename from components/zcancmder_module/zcan_step_motor_ctrl_module.cpp rename to components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.cpp index 3622587..50b49b6 100644 --- a/components/zcancmder_module/zcan_step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.cpp @@ -7,11 +7,12 @@ void ZCanStepMotorCtrlModule::initialize(ZCanCmder* cancmder, int id, I_StepMoto m_cancmder = cancmder; m_id = id; m_module = module; - m_lock.init(); + // m_lock.init(); cancmder->registerListener(this); } void ZCanStepMotorCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { - zlock_guard l(m_lock); + // zlock_guard l(m_lock); + ZLOGI(TAG, "onRceivePacket %d %d", rxcmd->get_cmdheader()->cmdid, rxcmd->get_cmdheader()->subcmdid); PROCESS_PACKET(kcmd_step_motor_ctrl_enable, m_id) { errorcode = m_module->enable(cmd->enable); } END_PP(); diff --git a/components/zcancmder_module/zcan_step_motor_ctrl_module.hpp b/components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.hpp similarity index 96% rename from components/zcancmder_module/zcan_step_motor_ctrl_module.hpp rename to components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.hpp index f85882d..09a39f3 100644 --- a/components/zcancmder_module/zcan_step_motor_ctrl_module.hpp +++ b/components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.hpp @@ -8,7 +8,7 @@ class ZCanStepMotorCtrlModule : public ZCanCmderListener { I_StepMotorCtrlModule* m_module; uint8_t m_txbuf[128] = {0}; - zmutex m_lock; + // zmutex m_lock; public: void initialize(ZCanCmder* cancmder, int id, I_StepMotorCtrlModule* m_module); diff --git a/components/scriptcmder_module/xy_robot_script_cmder_module.cpp b/components/xy_robot_ctrl_module/xy_robot_script_cmder_module.cpp similarity index 100% rename from components/scriptcmder_module/xy_robot_script_cmder_module.cpp rename to components/xy_robot_ctrl_module/xy_robot_script_cmder_module.cpp diff --git a/components/scriptcmder_module/xy_robot_script_cmder_module.hpp b/components/xy_robot_ctrl_module/xy_robot_script_cmder_module.hpp similarity index 100% rename from components/scriptcmder_module/xy_robot_script_cmder_module.hpp rename to components/xy_robot_ctrl_module/xy_robot_script_cmder_module.hpp diff --git a/components/zcancmder_master_module/zcan_xy_robot_master_module.cpp b/components/xy_robot_ctrl_module/zcan_xy_robot_master_module.cpp similarity index 100% rename from components/zcancmder_master_module/zcan_xy_robot_master_module.cpp rename to components/xy_robot_ctrl_module/zcan_xy_robot_master_module.cpp diff --git a/components/zcancmder_master_module/zcan_xy_robot_master_module.hpp b/components/xy_robot_ctrl_module/zcan_xy_robot_master_module.hpp similarity index 100% rename from components/zcancmder_master_module/zcan_xy_robot_master_module.hpp rename to components/xy_robot_ctrl_module/zcan_xy_robot_master_module.hpp diff --git a/components/zcancmder_module/zcan_xy_robot_module.cpp b/components/xy_robot_ctrl_module/zcan_xy_robot_module.cpp similarity index 100% rename from components/zcancmder_module/zcan_xy_robot_module.cpp rename to components/xy_robot_ctrl_module/zcan_xy_robot_module.cpp diff --git a/components/zcancmder_module/zcan_xy_robot_module.hpp b/components/xy_robot_ctrl_module/zcan_xy_robot_module.hpp similarity index 100% rename from components/zcancmder_module/zcan_xy_robot_module.hpp rename to components/xy_robot_ctrl_module/zcan_xy_robot_module.hpp diff --git a/components/zcancmder/zcanreceiver.cpp b/components/zcancmder/zcanreceiver.cpp index 1856651..771671d 100644 --- a/components/zcancmder/zcanreceiver.cpp +++ b/components/zcancmder/zcanreceiver.cpp @@ -11,7 +11,6 @@ using namespace zcr; #define OVER_TIME_MS 5 - ZCanCmder::CFG *ZCanCmder::createCFG(uint8_t deviceId) { CFG *cfg = new CFG(); ZASSERT(cfg != NULL); @@ -29,6 +28,7 @@ ZCanCmder::CFG *ZCanCmder::createCFG(uint8_t deviceId) { void ZCanCmder::init(CFG *cfg) { HAL_StatusTypeDef hal_status; m_config = cfg; + m_lock.init(); /** * @brief ³õʼ»¯CAN @@ -136,6 +136,7 @@ void ZCanCmder::sendPacket(uint8_t *packet, size_t len) { } void ZCanCmder::sendAck(Cmdheader_t *cmdheader, uint8_t *data, size_t len) { + zlock_guard l(m_lock); Cmdheader_t *txheader = (Cmdheader_t *)txbuff; memcpy(txheader, cmdheader, sizeof(Cmdheader_t)); txheader->packetType = kpt_ack; @@ -143,6 +144,8 @@ void ZCanCmder::sendAck(Cmdheader_t *cmdheader, uint8_t *data, size_t len) { sendPacket(txbuff, sizeof(Cmdheader_t) + len); } void ZCanCmder::sendExecStatusReport(Cmdheader_t *rxcmdheader, uint8_t *data, size_t len) { + zlock_guard l(m_lock); + Cmdheader_t *txheader = (Cmdheader_t *)txbuff; memcpy(txheader, rxcmdheader, sizeof(Cmdheader_t)); txheader->packetType = kpt_cmd_exec_status_report; @@ -150,6 +153,8 @@ void ZCanCmder::sendExecStatusReport(Cmdheader_t *rxcmdheader, uint8_t *data, si sendPacket(txbuff, sizeof(Cmdheader_t) + len); } void ZCanCmder::sendStatusReport(Cmdheader_t *rxcmdheader, uint8_t *data, size_t len) { + zlock_guard l(m_lock); + Cmdheader_t *txheader = (Cmdheader_t *)txbuff; memcpy(txheader, rxcmdheader, sizeof(Cmdheader_t)); txheader->packetType = kpt_report; @@ -158,6 +163,8 @@ void ZCanCmder::sendStatusReport(Cmdheader_t *rxcmdheader, uint8_t *data, size_t } void ZCanCmder::sendErrorAck(Cmdheader_t *cmdheader, uint16_t id, uint32_t errcode) { + zlock_guard l(m_lock); + Cmdheader_t *txheader = (Cmdheader_t *)txbuff; memcpy(txheader, cmdheader, sizeof(Cmdheader_t)); txheader->packetType = kpt_error_ack; @@ -168,6 +175,8 @@ void ZCanCmder::sendErrorAck(Cmdheader_t *cmdheader, uint16_t id, uint32_t errco } bool ZCanCmder::sendPacketSub(int npacket, int packetIndex, uint8_t *packet, size_t len, int overtimems) { + zlock_guard l(m_lock); + // ZLOGI(TAG, "sendPacketSub(%d:%d)", npacket, packetIndex); CAN_TxHeaderTypeDef pHeader; uint8_t aData[8] /*8byte table*/; diff --git a/components/zcancmder/zcanreceiver.hpp b/components/zcancmder/zcanreceiver.hpp index e5f1be7..28bd6c5 100644 --- a/components/zcancmder/zcanreceiver.hpp +++ b/components/zcancmder/zcanreceiver.hpp @@ -3,9 +3,9 @@ // #pragma once +#include "basic.hpp" #include "sdk/os/zos.hpp" #include "sdk\components\zprotocols\zcancmder\zcancmder_protocol.hpp" -#include "basic.hpp" namespace iflytop { using namespace zcr; @@ -50,7 +50,8 @@ class ZCanCmder : public ZCanIRQListener { list m_listenerList2; CanPacketRxBuffer m_canPacketRxBuffer[1]; - int txPacketInterval_ms = 0; + int txPacketInterval_ms = 0; + zmutex m_lock; public: ZCanCmder() {} diff --git a/components/zcancmder_module/zcan_eeprom_module.cpp b/components/zcancmder_module/zcan_eeprom_module.cpp index 58b8043..6243da6 100644 --- a/components/zcancmder_module/zcan_eeprom_module.cpp +++ b/components/zcancmder_module/zcan_eeprom_module.cpp @@ -11,11 +11,9 @@ void ZCanEepromModule::initialize(ZCanCmder* cancmder, int id, I_EEPROMModule* m cancmder->registerListener(this); } void ZCanEepromModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { // - zlock_guard l(m_lock); PROCESS_PACKET(kcmd_eeprom_start_monitor_status, m_id) { errorcode = m_module->start_monitor_status([this, cmdheader](I_EEPROMModule::eeprom_status_t& status) { // - zlock_guard l(m_lock); auto* report = (kcmd_eeprom_start_monitor_status_report_t*)m_txbuf; static_assert(sizeof(*report) < sizeof(m_txbuf), "report size too large"); diff --git a/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp b/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp index 6e9fb69..e546270 100644 --- a/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp +++ b/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp @@ -11,7 +11,6 @@ void ZCanMiniServoCtrlModule::initialize(ZCanCmder* cancmder, int id, I_MiniServ } void ZCanMiniServoCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { - zlock_guard l(m_lock); PROCESS_PACKET(kcmd_mini_servo_ctrl_enable, m_id) { errorcode = m_module->enable(cmd->enable); } END_PP(); diff --git a/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp b/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp index 7135719..a8dc959 100644 --- a/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp +++ b/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp @@ -13,7 +13,6 @@ void ZcanMotorLaserCodeScannerScanModule::initialize(ZCanCmder* cancmder, int id cancmder->registerListener(this); } void ZcanMotorLaserCodeScannerScanModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { - zlock_guard l(m_lock); PROCESS_PACKET(kcmd_motor_laser_code_scanner_scan, m_id) { errorcode = m_module->start_scan( // diff --git a/components/zcancmder_module/zcan_pipette_module.cpp b/components/zcancmder_module/zcan_pipette_module.cpp index 9677f5d..92b818e 100644 --- a/components/zcancmder_module/zcan_pipette_module.cpp +++ b/components/zcancmder_module/zcan_pipette_module.cpp @@ -11,7 +11,6 @@ void ZcanPipetteModule::initialize(ZCanCmder* cancmder, int id, I_PipetteModule* cancmder->registerListener(this); } void ZcanPipetteModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { - zlock_guard l(m_lock); PROCESS_PACKET(kcmd_pipette_module_enable, m_id) { errorcode = m_module->enable(cmd->enable); } END_PP(); diff --git a/components/zprotocols/zcancmder b/components/zprotocols/zcancmder index 1a22209..a160247 160000 --- a/components/zprotocols/zcancmder +++ b/components/zprotocols/zcancmder @@ -1 +1 @@ -Subproject commit 1a22209b189847bee8761a2f773c3dea084c2e96 +Subproject commit a160247f4b19096115532301b61a81f133ab9b67