Browse Source

修复死锁的BUG

master
zhaohe 2 years ago
parent
commit
b3dbb159e8
  1. 22
      components/step_motor_ctrl_module/step_motor_ctrl_module.cpp
  2. 0
      components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.cpp
  3. 0
      components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.hpp
  4. 2
      components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.cpp
  5. 0
      components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.hpp
  6. 5
      components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.cpp
  7. 2
      components/step_motor_ctrl_module/zcan_step_motor_ctrl_module.hpp
  8. 0
      components/xy_robot_ctrl_module/xy_robot_script_cmder_module.cpp
  9. 0
      components/xy_robot_ctrl_module/xy_robot_script_cmder_module.hpp
  10. 0
      components/xy_robot_ctrl_module/zcan_xy_robot_master_module.cpp
  11. 0
      components/xy_robot_ctrl_module/zcan_xy_robot_master_module.hpp
  12. 0
      components/xy_robot_ctrl_module/zcan_xy_robot_module.cpp
  13. 0
      components/xy_robot_ctrl_module/zcan_xy_robot_module.hpp
  14. 11
      components/zcancmder/zcanreceiver.cpp
  15. 5
      components/zcancmder/zcanreceiver.hpp
  16. 2
      components/zcancmder_module/zcan_eeprom_module.cpp
  17. 1
      components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp
  18. 1
      components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp
  19. 1
      components/zcancmder_module/zcan_pipette_module.cpp
  20. 2
      components/zprotocols/zcancmder

22
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;

0
components/scriptcmder_module/step_motor_ctrl_script_cmder_module.cpp → components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.cpp

0
components/scriptcmder_module/step_motor_ctrl_script_cmder_module.hpp → components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.hpp

2
components/zcancmder_master_module/zcan_master_step_motor_ctrl_module.cpp → 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;

0
components/zcancmder_master_module/zcan_master_step_motor_ctrl_module.hpp → components/step_motor_ctrl_module/zcan_master_step_motor_ctrl_module.hpp

5
components/zcancmder_module/zcan_step_motor_ctrl_module.cpp → 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();

2
components/zcancmder_module/zcan_step_motor_ctrl_module.hpp → 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);

0
components/scriptcmder_module/xy_robot_script_cmder_module.cpp → components/xy_robot_ctrl_module/xy_robot_script_cmder_module.cpp

0
components/scriptcmder_module/xy_robot_script_cmder_module.hpp → components/xy_robot_ctrl_module/xy_robot_script_cmder_module.hpp

0
components/zcancmder_master_module/zcan_xy_robot_master_module.cpp → components/xy_robot_ctrl_module/zcan_xy_robot_master_module.cpp

0
components/zcancmder_master_module/zcan_xy_robot_master_module.hpp → components/xy_robot_ctrl_module/zcan_xy_robot_master_module.hpp

0
components/zcancmder_module/zcan_xy_robot_module.cpp → components/xy_robot_ctrl_module/zcan_xy_robot_module.cpp

0
components/zcancmder_module/zcan_xy_robot_module.hpp → components/xy_robot_ctrl_module/zcan_xy_robot_module.hpp

11
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*/;

5
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<zcan_cmder_listener_t> m_listenerList2;
CanPacketRxBuffer m_canPacketRxBuffer[1];
int txPacketInterval_ms = 0;
int txPacketInterval_ms = 0;
zmutex m_lock;
public:
ZCanCmder() {}

2
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");

1
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();

1
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( //

1
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();

2
components/zprotocols/zcancmder

@ -1 +1 @@
Subproject commit 1a22209b189847bee8761a2f773c3dea084c2e96
Subproject commit a160247f4b19096115532301b61a81f133ab9b67
Loading…
Cancel
Save