|
@ -16,6 +16,12 @@ |
|
|
#include "sdk\components\m3078\m3078_code_scaner.hpp"
|
|
|
#include "sdk\components\m3078\m3078_code_scaner.hpp"
|
|
|
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
|
|
|
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
|
|
|
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|
|
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|
|
|
|
|
//
|
|
|
|
|
|
#include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
|
|
|
|
|
|
#include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
|
|
|
|
|
|
#include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
|
|
|
|
|
|
#include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
|
|
|
|
|
|
#include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
|
|
|
|
|
|
|
|
|
#define TAG "main"
|
|
|
#define TAG "main"
|
|
|
namespace iflytop { |
|
|
namespace iflytop { |
|
@ -26,57 +32,24 @@ using namespace iflytop; |
|
|
|
|
|
|
|
|
IflytopCanProtocolStackProcesser m_protocolStack; |
|
|
IflytopCanProtocolStackProcesser m_protocolStack; |
|
|
|
|
|
|
|
|
TMC5130 m_tj_motor; |
|
|
|
|
|
TMC5130 m_py_motor; |
|
|
|
|
|
|
|
|
TMC5130 m_motor1; |
|
|
|
|
|
TMC5130 m_motor2; |
|
|
|
|
|
|
|
|
ZGPIO debuglight; |
|
|
ZGPIO debuglight; |
|
|
|
|
|
|
|
|
ZGPIO io_fybh_read1; |
|
|
|
|
|
ZGPIO io_fybh_read2; |
|
|
|
|
|
ZGPIO io_fybh_read3; |
|
|
|
|
|
ZGPIO io_fybh_read4; |
|
|
|
|
|
ZGPIO io_fybh_read5; |
|
|
|
|
|
ZGPIO io_fybh_read6; |
|
|
|
|
|
|
|
|
|
|
|
ZGPIO io_fybjl_sensor8; |
|
|
|
|
|
ZGPIO io_fybjl_sensor7; |
|
|
|
|
|
ZGPIO io_fybjl_sensor6; |
|
|
|
|
|
ZGPIO io_fybjl_sensor5; |
|
|
|
|
|
ZGPIO io_fybjl_sensor4; |
|
|
|
|
|
ZGPIO io_fybjl_sensor3; |
|
|
|
|
|
ZGPIO io_fybjl_sensor2; |
|
|
|
|
|
ZGPIO io_fybjl_sensor1; |
|
|
|
|
|
ZGPIO io_fybjl_sensor0; |
|
|
|
|
|
|
|
|
|
|
|
M3078CodeScanner m_m3078CodeScanner; |
|
|
|
|
|
|
|
|
|
|
|
DeviceBaseControlService m_deviceBaseControlService; |
|
|
|
|
|
IOControlService m_ioControlService; |
|
|
|
|
|
SingleAxisMotorControler m_pyMotorControlService; // 平移电机
|
|
|
|
|
|
SingleAxisMotorControler m_tjMotorControlService; // 推进电机
|
|
|
|
|
|
OneDimensionalCodeLaserScanner m_oneDimensionalCodeLaserScanner; |
|
|
|
|
|
IDCardReaderService m_idCardReaderService; |
|
|
|
|
|
|
|
|
|
|
|
ZCanReceiver m_canReceiver; |
|
|
|
|
|
|
|
|
|
|
|
void input_sensors_init() { |
|
|
|
|
|
io_fybh_read1.initAsInput(FYBH_READ1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/); |
|
|
|
|
|
io_fybh_read2.initAsInput(FYBH_READ2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/); |
|
|
|
|
|
io_fybh_read3.initAsInput(FYBH_READ3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/); |
|
|
|
|
|
io_fybh_read4.initAsInput(FYBH_READ4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/); |
|
|
|
|
|
io_fybh_read5.initAsInput(FYBH_READ5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/); |
|
|
|
|
|
io_fybh_read6.initAsInput(FYBH_READ6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/); |
|
|
|
|
|
|
|
|
|
|
|
io_fybjl_sensor8.initAsInput(FYBJL_SENSOR8, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor7.initAsInput(FYBJL_SENSOR7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor6.initAsInput(FYBJL_SENSOR6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor5.initAsInput(FYBJL_SENSOR5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor4.initAsInput(FYBJL_SENSOR4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor3.initAsInput(FYBJL_SENSOR3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor2.initAsInput(FYBJL_SENSOR2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor1.initAsInput(FYBJL_SENSOR1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/); |
|
|
|
|
|
io_fybjl_sensor0.initAsInput(FYBJL_SENSOR0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ZGPIO triLight_R; |
|
|
|
|
|
ZGPIO triLight_G; |
|
|
|
|
|
ZGPIO triLight_B; |
|
|
|
|
|
ZGPIO triLight_BEEP; |
|
|
|
|
|
|
|
|
|
|
|
ZGPIO m_input1; |
|
|
|
|
|
ZGPIO m_input2; |
|
|
|
|
|
|
|
|
|
|
|
ZCanReceiver m_canReceiver; |
|
|
|
|
|
ZCanBasicOrderModule m_basicOrderModule; |
|
|
|
|
|
ZCanPumpCtrlModule m_pumpCtrlModule; |
|
|
|
|
|
ZCanTrigleWarningLightCtlModule m_warningLightCtlModule; |
|
|
|
|
|
HuachengPressureSensor m_huachengPressureSensor; |
|
|
|
|
|
|
|
|
void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) { |
|
|
void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) { |
|
|
ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len); |
|
|
ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len); |
|
@ -103,11 +76,126 @@ void Main::run() { |
|
|
m_canReceiver.init(cfg); |
|
|
m_canReceiver.init(cfg); |
|
|
m_canReceiver.registerListener(this); |
|
|
m_canReceiver.registerListener(this); |
|
|
|
|
|
|
|
|
// uint8_t packet[255];
|
|
|
|
|
|
// for (int i = 0; i < 255; i++) {
|
|
|
|
|
|
// packet[i] = i;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// ZHAL_CORE_REG(200, { m_canReceiver.sendPacket(packet, 255); });
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 基础模块 |
|
|
|
|
|
*/ |
|
|
|
|
|
m_input1.initAsInput(PD11, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/); |
|
|
|
|
|
m_input2.initAsInput(PC5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true /*mirror*/); |
|
|
|
|
|
m_basicOrderModule.initialize(&m_canReceiver); |
|
|
|
|
|
m_basicOrderModule.regInputCtl([this](uint8_t id, bool &val) { |
|
|
|
|
|
if (id == 1) { |
|
|
|
|
|
val = m_input1.getState(); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
if (id == 2) { |
|
|
|
|
|
val = m_input2.getState(); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
}); |
|
|
|
|
|
ZHAL_CORE_REG(1000, { ZLOGI(TAG, "IO1:%d IO2:%d", m_input1.getState(), m_input2.getState()); }); |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 蠕动泵驱动 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR1_ENN, .csn_pin = MOTOR1_CSN}; |
|
|
|
|
|
|
|
|
|
|
|
m_motor1.initialize(&cfg); |
|
|
|
|
|
int32_t chipv = m_motor1.readChipVERSION(); |
|
|
|
|
|
ZLOGI(TAG, "m_motor1:%lx", chipv); |
|
|
|
|
|
m_motor1.setIHOLD_IRUN(1, 31, 0); |
|
|
|
|
|
m_motor1.setMotorShaft(true); |
|
|
|
|
|
|
|
|
|
|
|
m_motor1.setAcceleration(300000); |
|
|
|
|
|
m_motor1.setDeceleration(300000); |
|
|
|
|
|
m_motor1.rotate(1000000); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR2_ENN, .csn_pin = MOTOR2_CSN}; |
|
|
|
|
|
|
|
|
|
|
|
m_motor2.initialize(&cfg); |
|
|
|
|
|
int32_t chipv = m_motor2.readChipVERSION(); |
|
|
|
|
|
ZLOGI(TAG, "m_motor2:%lx", chipv); |
|
|
|
|
|
m_motor2.setIHOLD_IRUN(1, 31, 0); |
|
|
|
|
|
m_motor2.setMotorShaft(true); |
|
|
|
|
|
|
|
|
|
|
|
m_motor2.setAcceleration(300000); |
|
|
|
|
|
m_motor2.setDeceleration(300000); |
|
|
|
|
|
// m_motor1.rotate(1000000);
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
m_pumpCtrlModule.initialize(&m_canReceiver); |
|
|
|
|
|
m_pumpCtrlModule.regSubmodule(1, [&](int16_t acc_rpm2, int16_t rpm) { |
|
|
|
|
|
ZLOGI(TAG, "pump1 acc_rpm2:%d rpm:%d", acc_rpm2, rpm); |
|
|
|
|
|
int32_t ppm = rpm / 60.0 * 51200; |
|
|
|
|
|
int32_t acc = acc_rpm2 / 60.0 * 51200; |
|
|
|
|
|
m_motor1.setAcceleration(acc); |
|
|
|
|
|
m_motor1.setDeceleration(acc); |
|
|
|
|
|
m_motor1.rotate(ppm); |
|
|
|
|
|
}); |
|
|
|
|
|
m_pumpCtrlModule.regSubmodule(2, [&](int16_t acc, int16_t rpm) { |
|
|
|
|
|
ZLOGI(TAG, "pump2 acc:%d rpm:%d", acc, rpm); |
|
|
|
|
|
int32_t ppm = rpm / 60.0 * 51200; |
|
|
|
|
|
m_motor2.setAcceleration(acc); |
|
|
|
|
|
m_motor2.setDeceleration(acc); |
|
|
|
|
|
m_motor2.rotate(ppm); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 三色指示灯 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
triLight_R.initAsOutput(PD8, ZGPIO::kMode_nopull, false, false); |
|
|
|
|
|
triLight_G.initAsOutput(PD7, ZGPIO::kMode_nopull, false, false); |
|
|
|
|
|
triLight_B.initAsOutput(PD9, ZGPIO::kMode_nopull, false, false); |
|
|
|
|
|
triLight_BEEP.initAsOutput(PD10, ZGPIO::kMode_nopull, false, false); |
|
|
|
|
|
|
|
|
|
|
|
// while(true){
|
|
|
|
|
|
// triLight_R.setState(true);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
// triLight_R.setState(false);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
|
|
|
|
|
|
// triLight_G.setState(true);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
// triLight_G.setState(false);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
|
|
|
|
|
|
// triLight_B.setState(true);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
// triLight_B.setState(false);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
|
|
|
|
|
|
// triLight_BEEP.setState(true);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
// triLight_BEEP.setState(false);
|
|
|
|
|
|
// HAL_Delay(3000);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
m_warningLightCtlModule.initialize(&m_canReceiver); |
|
|
|
|
|
m_warningLightCtlModule.regSubmodule(1, [&](uint8_t r, uint8_t g, uint8_t b, uint8_t beep) { |
|
|
|
|
|
ZLOGI(TAG, "warningLightCtlModule r:%d g:%d b:%d beep:%d", r, g, b, beep); |
|
|
|
|
|
triLight_R.setState(r != 0); |
|
|
|
|
|
triLight_G.setState(g != 0); |
|
|
|
|
|
triLight_B.setState(b != 0); |
|
|
|
|
|
triLight_BEEP.setState(beep != 0); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 压力传感器 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
{ |
|
|
|
|
|
m_huachengPressureSensor.initialize(&m_canReceiver); |
|
|
|
|
|
m_huachengPressureSensor.regSubmodule(1, &huart2, 1); |
|
|
|
|
|
m_huachengPressureSensor.regSubmodule(2, &huart2, 2); |
|
|
|
|
|
m_huachengPressureSensor.regSubmodule(3, &huart2, 3); |
|
|
|
|
|
m_huachengPressureSensor.regSubmodule(4, &huart2, 4); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ZLOGI(TAG, "init done"); |
|
|
ZLOGI(TAG, "init done"); |
|
|
while (1) { |
|
|
while (1) { |
|
|