|
|
@ -14,30 +14,6 @@ using namespace std; |
|
|
|
#define TAG "umain"
|
|
|
|
int random(int max) { return SysTick->VAL % max; } |
|
|
|
|
|
|
|
#if CONFIG_ENABLE_IFLYTOP_CAN_SLAVE_MODULE
|
|
|
|
/*******************************************************************************
|
|
|
|
* IflytopCanProtocolStackProcesser * |
|
|
|
*******************************************************************************/ |
|
|
|
icps::error_t Main::onHostRegisterWriteEvent(IflytopCanProtocolStackProcesser *processer, icps::WriteEvent *writeEvent) { |
|
|
|
if (m_deviceBaseControlService.isThisRegOwnToMe(writeEvent->reg)) { |
|
|
|
return m_deviceBaseControlService.processIflytopCanRegisterWriteEvent(writeEvent); |
|
|
|
} else if (writeEvent->reg->add == REG_GPIO_OUTPUT0_WRITE) { |
|
|
|
uint32_t mask = (writeEvent->newvalue & 0xFFFF0000) >> 16; |
|
|
|
uint32_t value = writeEvent->newvalue & 0xFFFF; |
|
|
|
m_hardware.output_switch_set(0, (uint16_t)mask, value); |
|
|
|
return icps::kSuccess; |
|
|
|
} |
|
|
|
return icps::kSuccess; |
|
|
|
} |
|
|
|
icps::error_t Main::onHostRegisterReadEvent(IflytopCanProtocolStackProcesser *processer, icps::ReadEvent *event) { return icps::kSuccess; } |
|
|
|
void Main::onHostRegisterReportEvent(IflytopCanProtocolStackProcesser *processer, icps::ReportEvent *event) {} |
|
|
|
|
|
|
|
icps::error_t Main::onSetEngineerMode(DeviceBaseControlService *service, int32_t engineer_mode) { |
|
|
|
ZLOGI(TAG, "onSetEngineerMode %d", engineer_mode); |
|
|
|
return icps::kSuccess; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* MAIN * |
|
|
|
*******************************************************************************/ |
|
|
@ -57,67 +33,6 @@ void Main::main(int argc, char const *argv[]) { |
|
|
|
m_hardware.input_sensors_init(); |
|
|
|
m_hardware.output_switch_init(); |
|
|
|
|
|
|
|
#if CONFIG_ENABLE_TMC_MOTOR
|
|
|
|
m_motor5130_1.initialize("motor1", &m_hardware, &MOTOR_SPI, &MOTOR0_CSN, &MOTOR0_ENN); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_ENABLE_IFLYTOP_CAN_SLAVE_MODULE
|
|
|
|
/*******************************************************************************
|
|
|
|
* m_protocolStack * |
|
|
|
*******************************************************************************/ |
|
|
|
IflytopCanProtocolStackProcesser::createDefaultConfig(&m_iflytopCanStackConfig, m_hardware.getDeviceId(), m_regList, ZARRAY_SIZE(m_regList)); |
|
|
|
m_protocolStack.initialize(&m_hardware, &m_iflytopCanStackConfig); |
|
|
|
m_protocolStack.setDumpPacketFlag(false); |
|
|
|
m_protocolStack.registerListener(this); |
|
|
|
m_protocolStack.activeReg(REG_GPIO_INPUT0, icps::kr, 0); |
|
|
|
m_protocolStack.activeReg(REG_GPIO_OUTPUT0_WRITE, icps::kw, 0); |
|
|
|
m_protocolStack.activeReg(REG_GPIO_OUTPUT0_STATE, icps::kr, 0); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* m_deviceBaseControlService * |
|
|
|
*******************************************************************************/ |
|
|
|
m_deviceBaseControlService.initialize(&m_hardware, &m_protocolStack, m_hardware.getDeviceId()); |
|
|
|
m_deviceBaseControlService.setListener(this); |
|
|
|
|
|
|
|
#if CONFIG_ENABLE_TMC_MOTOR
|
|
|
|
/*******************************************************************************
|
|
|
|
* 电机服务 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
TMC5130 *tmc_motor = m_motor5130_1.getTMC5130(); |
|
|
|
SingleAxisMotorControlerV2 *service = &m_motorService; |
|
|
|
MOTOR_L_SENSOR.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true /*mirror*/); |
|
|
|
STM32_GPIO *homeGpio = &MOTOR_L_SENSOR; |
|
|
|
|
|
|
|
tmc_motor->setMotorShaft(false); |
|
|
|
tmc_motor->setIHOLD_IRUN(2, 3, 0); |
|
|
|
|
|
|
|
service->initialize( //
|
|
|
|
"motorService", &m_protocolStack, REG_MOTOR1_CTRL_ADD_BASE, |
|
|
|
homeGpio, // ZERO_GPIO
|
|
|
|
NULL, // LGPIO
|
|
|
|
NULL, // RGPIO
|
|
|
|
tmc_motor, // motor
|
|
|
|
&m_hardware // os
|
|
|
|
); |
|
|
|
|
|
|
|
// service->disableMoveHomeCheck();
|
|
|
|
service->cfg_acc->setVal(30000); // 加速度
|
|
|
|
service->cfg_dec->setVal(30000); // 减速度
|
|
|
|
service->cfg_velocity->setVal(300000); // 位置模式时运行的速度
|
|
|
|
service->cfg_zero_shift->setVal(0); // 回零时的偏移量
|
|
|
|
service->cfg_runhome_velocity->setVal(50000); // 回零速度
|
|
|
|
service->cfg_runtohome_dec->setVal(100000); // 回零减速度
|
|
|
|
service->cfg_min_pos->setVal(INT32_MIN); // 最小位置
|
|
|
|
service->cfg_max_pos->setVal(INT32_MAX); // 最大位置
|
|
|
|
service->cfg_runtohome_max_distance->setVal(256 * 200 * 5); // 回零时移动的最大位移
|
|
|
|
service->cfg_runtohome_leave_zero_point_distance->setVal(256 * 200 * 5); // 回零时离开零点的距离
|
|
|
|
service->cfg_runtohome_keep_move_distance->setVal(256 * 25 * 1); // 回零时保持运动的距离
|
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
m_hardware.periodicJob(); |
|
|
|
m_hardware.debug_light_periodicJob(); |
|
|
@ -126,18 +41,6 @@ void Main::main(int argc, char const *argv[]) { |
|
|
|
m_hardware.input_sensors_table_dump(0); |
|
|
|
} |
|
|
|
|
|
|
|
#if CONFIG_ENABLE_IFLYTOP_CAN_SLAVE_MODULE
|
|
|
|
if (m_ticket % 20 == 0) { |
|
|
|
m_protocolStack.writeRegValue(REG_GPIO_INPUT0, m_hardware.input_sensors_get_table(0), false); |
|
|
|
m_protocolStack.writeRegValue(REG_GPIO_OUTPUT0_STATE, m_hardware.output_switch_get(0), false); |
|
|
|
} |
|
|
|
m_protocolStack.periodicJob(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_ENABLE_TMC_MOTOR
|
|
|
|
m_motor5130_1.periodicJob(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
HAL_IWDG_Refresh(&hiwdg); |
|
|
|
} |
|
|
|
} |