diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index c61406d..536a5f7 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/Core/Src/usart.c b/Core/Src/usart.c index e0f643e..635107c 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -70,7 +70,7 @@ void MX_USART2_UART_Init(void) /* USER CODE END USART2_Init 1 */ huart2.Instance = USART2; - huart2.Init.BaudRate = 115200; + huart2.Init.BaudRate = 9600; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; diff --git a/README.md b/README.md new file mode 100644 index 0000000..583c218 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +``` +1. CAN测试通过 OK +2. 测试驱动器 OK +3. 三色报警灯 +4. 测试IO输入 +5. 测试ADC读值 (电流) + + + +``` \ No newline at end of file diff --git a/usrc/main.cpp b/usrc/main.cpp index 38d5724..3cfc14e 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -16,6 +16,12 @@ #include "sdk\components\m3078\m3078_code_scaner.hpp" #include "sdk\components\tmc\ic\ztmc4361A.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" namespace iflytop { @@ -26,57 +32,24 @@ using namespace iflytop; IflytopCanProtocolStackProcesser m_protocolStack; -TMC5130 m_tj_motor; -TMC5130 m_py_motor; +TMC5130 m_motor1; +TMC5130 m_motor2; 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) { ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len); @@ -103,11 +76,126 @@ void Main::run() { m_canReceiver.init(cfg); 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"); while (1) { diff --git a/usrc/project.hpp b/usrc/project.hpp index 3c85f9a..e2dfad5 100644 --- a/usrc/project.hpp +++ b/usrc/project.hpp @@ -12,71 +12,13 @@ #define DELAY_US_TIMER htim6 #define MICROSWITCH_NUM 6 // -/******************************************************************************* - * 主从485通讯 * - *******************************************************************************/ -#define MASTER_SLAVE_485_UART huart2 -/******************************************************************************* - * 反应盒扫码传感器 * - *******************************************************************************/ -#define REACTION_BOX_SWEEP_SENSOR_UART huart3 -/******************************************************************************* - * MOTOR * - *******************************************************************************/ -/** - * - * - */ #define MOTOR_SPI hspi1 #define TMC5130_MOTOR_NUM 2 #define MOTOR_CH(n) (n) // FYBJ_PY -#define MOTOR0_CSN PA4 // 平移电机片选信号 -#define MOTOR0_ENN PE14 +#define MOTOR2_CSN PA4 // +#define MOTOR2_ENN PE11 // FYBJ_TJ_DRV -#define MOTOR1_CSN PC4 // 添加电机片选信号 -#define MOTOR1_ENN PE13 - -/******************************************************************************* - * REG LIST * - *******************************************************************************/ - -#define DEVICE_BASIC_CONTROLLER_ADD_BASE 0 - -#define GPIO_INPUT_ADD_BASE 1000 // GPIO输入 - -#define REG_PY_MOTOR_CTRL_ADD_BASE 10000 // 控制 入料电机控制 -#define REG_TJ_MOTOR_CTRL_ADD_BASE 10100 // 控制 转移电机控制 -#define REG_ID_CARD_READER_CTRL_ADD_BASE 20000 // 控制 串口扫码器 -#define REG_LARSER_SCANNER_CTRL_ADD_BASE 30000 // 控制 单点激光扫码器 - - -/******************************************************************************* - * GPIO * - *******************************************************************************/ -#define BEEP PA1 // 蜂鸣器 -#define FAN1_FB_INT PA15 // 帕尔贴风机反馈 - -#define HOT_CTR PB1 - -#define FAN0_POWER PC8 // 外部风机电源 -#define FAN1_POWER PC9 // 帕尔贴风机 - -#define FYBH_READ1 PD0 -#define FYBH_READ2 PD1 -#define FYBH_READ3 PD2 -#define FYBH_READ4 PD3 -#define FYBH_READ5 PD4 -#define FYBH_READ6 PD5 -#define FYBJL_SENSOR8 PD7 // 开门霍尔 -#define FYBJL_SENSOR7 PD8 // 卡板光电1 -#define FYBJL_SENSOR6 PD9 // 预留光电 -#define FYBJL_SENSOR5 PD10 // 推杆限位光电 -#define FYBJL_SENSOR4 PD11 // 推杆原点光电 -#define FYBJL_SENSOR3 PD12 // 平移计步光电(预留) -#define FYBJL_SENSOR2 PD13 // 平移限位光电 -#define FYBJL_SENSOR1 PD14 // 平移原点光电 -#define FYBJL_SENSOR0 PD15 // 黑白扫码 - -#define COLD_CTR PE10 \ No newline at end of file +#define MOTOR1_CSN PC4 // +#define MOTOR1_ENN PE12 \ No newline at end of file