Compare commits

...

2 Commits

Author SHA1 Message Date
zhaohe aca47889c7 update 11 months ago
zhaohe fbefb0e3d1 moveToEndTestVersion 11 months ago
  1. 2
      stm32components
  2. 23
      usrc/module/tmc_motor_group.cpp

2
stm32components

@ -1 +1 @@
Subproject commit 29c41362b35e5097f8b52751098aede52133aed5
Subproject commit 16ccc17d6d41154562af9294f49c5545cedaea00

23
usrc/module/tmc_motor_group.cpp

@ -8,7 +8,8 @@ using namespace transmit_disfection_protocol;
/*********************************************************************************************************************** /***********************************************************************************************************************
* * * *
***********************************************************************************************************************/ ***********************************************************************************************************************/
static osTimerId MotorMonitorTimerId; // 压力传感器数值上报
static osTimerId MotorMonitorTimerId; //
static osTimerId MoveToEndUpdateTimer; //
static bool motorErrorFlagCache[10]; // 电机异常状态上报标志位 static bool motorErrorFlagCache[10]; // 电机异常状态上报标志位
static zmutex motorErrorFlagCacheLock = {"motorErrorFlagCacheLock"}; static zmutex motorErrorFlagCacheLock = {"motorErrorFlagCacheLock"};
static TmcMotorGroup* tmcgroup_p; static TmcMotorGroup* tmcgroup_p;
@ -28,6 +29,16 @@ static void motorErrorFlag_set(int subindex, bool val) {
motorErrorFlagCache[subindex] = val; motorErrorFlagCache[subindex] = val;
} }
} }
static void onMoveToEndUpdateTimer(void const* argument) {
TmcMotorGroup* DEVICE = (TmcMotorGroup*)tmcgroup_p;
report_exeception_data_t data = {0};
for (size_t i = 0; i < DEVICE->motorNum(); i++) {
if (DEVICE->motor(i)->isMoveToEnd()) {
ZLOGI(TAG, "refreshMoveToEnd %d", i);
DEVICE->motor(i)->refreshMoveToEnd();
}
}
}
static void onMotorMonitorTimer(void const* argument) { static void onMotorMonitorTimer(void const* argument) {
// ZLOGI(TAG, "x MotorMonitorTimerId: %p", argument); // ZLOGI(TAG, "x MotorMonitorTimerId: %p", argument);
@ -143,10 +154,15 @@ void TmcMotorGroup::initialize(Pin_t tmcPowerPin, TMC51X0Cfg cfg0, TMC51X0Cfg cf
motorErrorFlagCacheLock.init(); motorErrorFlagCacheLock.init();
tmcgroup_p = this; tmcgroup_p = this;
osTimerDef(MotorMonitorTimer, onMotorMonitorTimer); osTimerDef(MotorMonitorTimer, onMotorMonitorTimer);
MotorMonitorTimerId = osTimerCreate(osTimer(MotorMonitorTimer), osTimerPeriodic, this); MotorMonitorTimerId = osTimerCreate(osTimer(MotorMonitorTimer), osTimerPeriodic, this);
ZLOGI(TAG, "MotorMonitorTimerId: %p", this);
osTimerStart(MotorMonitorTimerId, 1000); osTimerStart(MotorMonitorTimerId, 1000);
osTimerDef(MoveToEndUpdateTimer, onMoveToEndUpdateTimer);
MoveToEndUpdateTimer = osTimerCreate(osTimer(MoveToEndUpdateTimer), osTimerPeriodic, this);
osTimerStart(MoveToEndUpdateTimer, 10000);
m_isInitialized = true; m_isInitialized = true;
BIND_FN(TmcMotorGroup, this, fn_pump_rotate); BIND_FN(TmcMotorGroup, this, fn_pump_rotate);
@ -182,7 +198,8 @@ void TmcMotorGroup::fn_pump_rotate(ProcessContext* cxt) {
motor(GET_PARAM(0))->enable(false); motor(GET_PARAM(0))->enable(false);
motor(GET_PARAM(0))->refreshcfg(); motor(GET_PARAM(0))->refreshcfg();
motor(GET_PARAM(0))->enable(true); motor(GET_PARAM(0))->enable(true);
motor(GET_PARAM(0))->rotate(velocity);
// motor(GET_PARAM(0))->rotate(velocity);
motor(GET_PARAM(0))->moveToEnd(velocity, abs(velocity));
zcanbus_send_ack(cxt->packet, NULL, 0); zcanbus_send_ack(cxt->packet, NULL, 0);
motorErrorFlag_set(GET_PARAM(0), false); motorErrorFlag_set(GET_PARAM(0), false);

Loading…
Cancel
Save