You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
6.7 KiB
204 lines
6.7 KiB
#include "main.hpp"
|
|
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
#include "main.h"
|
|
#include "project.hpp"
|
|
//
|
|
#include "one_dimensional_code_laser_scanner.hpp"
|
|
// #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
|
|
#include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
|
|
#include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
|
|
#include "sdk/hal/zhal.hpp"
|
|
#include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
|
|
#include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
|
|
#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 {
|
|
Main gmain;
|
|
};
|
|
|
|
using namespace iflytop;
|
|
|
|
IflytopCanProtocolStackProcesser m_protocolStack;
|
|
|
|
TMC5130 m_motor1;
|
|
TMC5130 m_motor2;
|
|
|
|
ZGPIO debuglight;
|
|
|
|
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);
|
|
for (size_t i = 0; i < len; i++) {
|
|
printf("%02X ", packet[i]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
void Main::run() {
|
|
ZHALCORE::cfg_t oscfg = {
|
|
.delayhtim = &DELAY_US_TIMER,
|
|
.debuguart = &DEBUG_UART,
|
|
};
|
|
ZHALCORE::getInstance()->initialize(oscfg);
|
|
|
|
ZLOGI(TAG, "zapp:%s", VERSION);
|
|
printf("int32_t %d int %d longint %d\n", sizeof(int32_t), sizeof(int), sizeof(long int));
|
|
|
|
debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false);
|
|
ZHAL_CORE_REG(200, { debuglight.toggleState(); });
|
|
|
|
ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID);
|
|
m_canReceiver.init(cfg);
|
|
m_canReceiver.registerListener(this);
|
|
|
|
/**
|
|
* @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) {
|
|
ZHALCORE::getInstance()->loop();
|
|
}
|
|
}
|