Browse Source

修复部分电机初始化失败的BUG

master
zhaohe 4 months ago
parent
commit
21932f7c97
  1. 71
      sdk/chip/zgpio.cpp
  2. 5
      sdk/chip/zgpio.hpp
  3. 2
      sdk/components/tmc/ic/ztmc5130.cpp
  4. 3
      usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.cpp
  5. 3
      usrc/subboards/subboard20_plate_clamp_case/subboard20_plate_clamp_case.cpp
  6. 5
      usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp
  7. 4
      usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.cpp
  8. 27
      usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.cpp
  9. 2
      usrc/subboards/subboard90_optical_module/subboard90_optical_module.cpp
  10. 2
      usrc/version.h

71
sdk/chip/zgpio.cpp

@ -49,69 +49,69 @@ void ZGPIO::regListener(onirq_t listener) { m_onirq = listener; }
/*******************************************************************************
* BASE_FUNC *
*******************************************************************************/
bool ZGPIO::enableClock() {
bool ZGPIO::enableClock(GPIO_TypeDef *port) {
#ifdef GPIOA
if (m_gpio == GPIOA) {
if (port == GPIOA) {
__HAL_RCC_GPIOA_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOB
if (m_gpio == GPIOB) {
if (port == GPIOB) {
__HAL_RCC_GPIOB_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOC
if (m_gpio == GPIOC) {
if (port == GPIOC) {
__HAL_RCC_GPIOC_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOD
if (m_gpio == GPIOD) {
if (port == GPIOD) {
__HAL_RCC_GPIOD_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOE
if (m_gpio == GPIOE) {
if (port == GPIOE) {
__HAL_RCC_GPIOE_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOF
if (m_gpio == GPIOF) {
if (port == GPIOF) {
__HAL_RCC_GPIOF_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOG
if (m_gpio == GPIOG) {
if (port == GPIOG) {
__HAL_RCC_GPIOG_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOH
if (m_gpio == GPIOH) {
if (port == GPIOH) {
__HAL_RCC_GPIOH_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOI
if (m_gpio == GPIOI) {
if (port == GPIOI) {
__HAL_RCC_GPIOI_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOJ
if (m_gpio == GPIOJ) {
if (port == GPIOJ) {
__HAL_RCC_GPIOJ_CLK_ENABLE();
return true;
}
#endif
#ifdef GPIOK
if (m_gpio == GPIOK) {
if (port == GPIOK) {
__HAL_RCC_GPIOK_CLK_ENABLE();
return true;
}
@ -119,6 +119,8 @@ bool ZGPIO::enableClock() {
return false;
}
bool ZGPIO::enableClock() { enableClock(m_gpio); }
void regIRQGPIO(ZGPIO *gpio) {
for (int i = 0; i < s_irqGPIO_num; i++) {
if (s_irqGPIO[i] == gpio) {
@ -188,6 +190,45 @@ void ZGPIO::initAsInput(Pin_t pin, GPIOMode_t mode, GPIOIrqType_t irqtype, bool
m_initflag = true;
return;
}
void ZGPIO::initAsOutputStatic(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel) {
if (pin == PinNull) return;
GPIO_TypeDef *m_gpio = chip_get_gpio(pin);
uint16_t m_pinoff = chip_get_pinoff(pin);
enableClock(m_gpio);
GPIO_InitTypeDef m_GPIO_InitStruct = {0};
initLevel = mirror ? !initLevel : initLevel;
GPIO_PinState pinState = initLevel ? GPIO_PIN_SET : GPIO_PIN_RESET;
HAL_GPIO_WritePin(m_gpio, m_pinoff, pinState);
if (mode == kMode_nopull) {
m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
m_GPIO_InitStruct.Pull = GPIO_NOPULL;
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
} else if (mode == kMode_pullup) {
m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
m_GPIO_InitStruct.Pull = GPIO_PULLUP;
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
} else if (mode == kMode_pulldown) {
m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
m_GPIO_InitStruct.Pull = GPIO_PULLDOWN;
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
} else if (mode == kMode_od) {
m_GPIO_InitStruct.Pin = m_pinoff;
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
m_GPIO_InitStruct.Pull = 0;
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
}
HAL_GPIO_Init(m_gpio, &m_GPIO_InitStruct);
return;
}
void ZGPIO::initAsOutput(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel) {
if (pin == PinNull) return;
@ -195,9 +236,9 @@ void ZGPIO::initAsOutput(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel
m_mode = mode;
m_irqtype = kIRQ_noIrq;
m_gpiotype = kType_Output;
m_pin = pin;
m_gpio = chip_get_gpio(pin);
m_pinoff = chip_get_pinoff(pin);
m_pin = pin;
m_gpio = chip_get_gpio(pin);
m_pinoff = chip_get_pinoff(pin);
enableClock();

5
sdk/chip/zgpio.hpp

@ -63,7 +63,9 @@ class ZGPIO {
bool m_initflag;
public:
ZGPIO(){};
ZGPIO() {};
static void initAsOutputStatic(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel);
void initAsInput(Pin_t pin, GPIOMode_t mode, GPIOIrqType_t irqtype, bool mirror);
void initAsOutput(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel);
@ -99,5 +101,6 @@ class ZGPIO {
private:
bool enableClock();
static bool enableClock(GPIO_TypeDef *port);
};
} // namespace iflytop

2
sdk/components/tmc/ic/ztmc5130.cpp

@ -115,7 +115,7 @@ uint8_t TMC51X0::reset() {
if (!motorICInitOk) {
ZLOGE("TMC5130", "MOTOR INIT FAIL, DRIVER_IC_IS_OFFLINE");
return;
return 1;
}
stop();

3
usrc/subboards/subboard10_hbot_v2/subboard10_hbot_v2.cpp

@ -9,7 +9,6 @@ extern "C" {
#include "sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp"
#include "sdk/components/sensors/m3078/m3078_code_scaner.hpp"
#include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
#include "sdk\components\xy_robot_ctrl_module\xy_robot_ctrl_module.hpp"
#define TAG "Subboard10HbotV2"
@ -39,6 +38,8 @@ void Subboard10HbotV2::initialize() {
TMC51X0_1_SD_MODE.initAsOutput(PB4, iflytop::ZGPIO::kMode_nopull, false, false);
TMC51X0_2_SPI_MODE.initAsOutput(PE11, iflytop::ZGPIO::kMode_nopull, false, true);
TMC51X0_2_SD_MODE.initAsOutput(PE12, iflytop::ZGPIO::kMode_nopull, false, false);
ZGPIO::initAsOutputStatic(MOTOR1_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR2_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
osDelay(10);
motorPowerEnPin.initAsOutput(PB12, iflytop::ZGPIO::kMode_nopull, true, true);

3
usrc/subboards/subboard20_plate_clamp_case/subboard20_plate_clamp_case.cpp

@ -24,7 +24,8 @@ void Subboard20PlateClampCase::initialize() {
GService::inst()->getZCanProtocolParser()->registerModule(this);
static StepMotorCtrlModule* push_rod_motor = nullptr;
ZGPIO::initAsOutputStatic(MOTOR1_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR2_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
#if 1
/***********************************************************************************************************************
* ID1 *

5
usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp

@ -20,6 +20,10 @@ void Subboard30ShakeModule::initialize() {
osDelay(1000); // 等待舵机上电
#if 1
ZGPIO::initAsOutputStatic(MOTOR1_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR2_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR3_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
TMC5130_MOTOR_INITER(/*motorid:*/ 1, /*moduleid:*/ 1);
TMC5130_MOTOR_INITER(/*motorid:*/ 2, /*moduleid:*/ 2);
TMC5130_MOTOR_INITER(/*motorid:*/ 3, /*moduleid:*/ 3);
@ -84,7 +88,6 @@ void Subboard30ShakeModule::initialize() {
GService::inst()->getZCanProtocolParser()->registerModule(&module);
}
{
static MiniServoCtrlModule::config_t cfg = {0};
static MiniServoCtrlModule module;

4
usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.cpp

@ -17,7 +17,9 @@ void Subboard60InjectAndOutletModule::initialize() {
GService::inst()->getZCanProtocolParser()->registerModule(this);
ZGPIO::initAsOutputStatic(MOTOR1_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR2_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR3_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
#if 1
TMC5130_MOTOR_INITER(/*motorid:*/ 1, /*moduleid:*/ 1);
TMC5130_MOTOR_INITER(/*motorid:*/ 2, /*moduleid:*/ 2);

27
usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.cpp

@ -8,7 +8,6 @@ extern "C" {
#include "sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp"
#include "sdk/components/sensors/m3078/m3078_code_scaner.hpp"
#include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
using namespace iflytop;
#define TAG "Subboard70IncubationTurntable"
@ -18,26 +17,20 @@ void Subboard70IncubationTurntable::initialize() {
GService::inst()->getZCanProtocolParser()->registerModule(this);
static ZGPIO motorPowerEnPin;
static ZGPIO motor1ENNPin;
static ZGPIO motor2ENNPin;
static ZGPIO TMC51X0_1_SPI_MODE;
static ZGPIO TMC51X0_1_SD_MODE;
static ZGPIO TMC51X0_2_SPI_MODE;
static ZGPIO TMC51X0_2_SD_MODE;
ZGPIO::initAsOutputStatic(MOTOR1_ENN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR2_ENN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(PB3, iflytop::ZGPIO::kMode_nopull, false, true); // TMC51X0_1_SPI_MODE
ZGPIO::initAsOutputStatic(PB4, iflytop::ZGPIO::kMode_nopull, false, false); // TMC51X0_1_SD_MODE
ZGPIO::initAsOutputStatic(PE11, iflytop::ZGPIO::kMode_nopull, false, true); // TMC51X0_2_SPI_MODE
ZGPIO::initAsOutputStatic(PE12, iflytop::ZGPIO::kMode_nopull, false, false); // TMC51X0_2_SD_MODE
motor1ENNPin.initAsOutput(MOTOR1_ENN, iflytop::ZGPIO::kMode_nopull, false, true);
motor2ENNPin.initAsOutput(MOTOR2_ENN, iflytop::ZGPIO::kMode_nopull, false, true);
TMC51X0_1_SPI_MODE.initAsOutput(PB3, iflytop::ZGPIO::kMode_nopull, false, true);
TMC51X0_1_SD_MODE.initAsOutput(PB4, iflytop::ZGPIO::kMode_nopull, false, false);
TMC51X0_2_SPI_MODE.initAsOutput(PE11, iflytop::ZGPIO::kMode_nopull, false, true);
TMC51X0_2_SD_MODE.initAsOutput(PE12, iflytop::ZGPIO::kMode_nopull, false, false);
ZGPIO::initAsOutputStatic(MOTOR1_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR2_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
osDelay(10);
motorPowerEnPin.initAsOutput(PB12, iflytop::ZGPIO::kMode_nopull, true, true);
ZGPIO::initAsOutputStatic(PB12, iflytop::ZGPIO::kMode_nopull, true, true); // motorPowerEnPin
#if 1
TMC5130_MOTOR_INITER(/*motorid*/ 1, /*moduleid*/ 1);
TMC5130_MOTOR_INITER(/*motorid*/ 2, /*moduleid*/ 2);
TMC5130_MOTOR_INITER(/*motorid*/ 1, /*moduleid*/ 1);
#endif
}

2
usrc/subboards/subboard90_optical_module/subboard90_optical_module.cpp

@ -30,6 +30,8 @@ void Subboard90OpticalModule::initialize() {
/***********************************************************************************************************************
* ID1 *
***********************************************************************************************************************/
ZGPIO::initAsOutputStatic(MOTOR1_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
ZGPIO::initAsOutputStatic(MOTOR2_CSN, iflytop::ZGPIO::kMode_nopull, false, true);
{ TMC5130_MOTOR_INITER(1, 1); }
{ TMC5130_MOTOR_INITER(2, 2); }
opt_scan_motor = dynamic_cast<StepMotorCtrlModule*>(GService::inst()->getZCanProtocolParser()->getModule(getmoduleId(1)));

2
usrc/version.h

@ -1,2 +1,2 @@
#pragma once
#define APP_VERSION 1023
#define APP_VERSION 1024
Loading…
Cancel
Save