|
|
@ -8,10 +8,12 @@ |
|
|
|
//
|
|
|
|
#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"
|
|
|
|
|
|
|
@ -46,11 +48,14 @@ 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; |
|
|
|
|
|
|
|
void input_sensors_init() { |
|
|
|
io_fybh_read1.initAsInput(FYBH_READ1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/); |
|
|
@ -71,7 +76,6 @@ void input_sensors_init() { |
|
|
|
io_fybjl_sensor0.initAsInput(FYBJL_SENSOR0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_risingAndFallingIrq, true /*mirror*/); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
icps::error_t Main::onHostRegisterWriteEvent(IflytopCanProtocolStackProcesser *processer, icps::WriteEvent *event) { return icps::kSuccess; } |
|
|
|
icps::error_t Main::onHostRegisterReadEvent(IflytopCanProtocolStackProcesser *processer, icps::ReadEvent *event) { return icps::kSuccess; } |
|
|
|
void Main::onHostRegisterReportEvent(IflytopCanProtocolStackProcesser *processer, icps::ReportEvent *event) {} |
|
|
@ -90,53 +94,6 @@ void Main::run() { |
|
|
|
ZHAL_CORE_REG(200, { debuglight.toggleState(); }); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* GPIO输入初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
input_sensors_init(); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 电机初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR0_ENN, .csn_pin = MOTOR0_CSN}; |
|
|
|
|
|
|
|
m_py_motor.initialize(&cfg); |
|
|
|
int32_t chipv = m_py_motor.readChipVERSION(); |
|
|
|
ZLOGI(TAG, "m_py_motor:%lx", chipv); |
|
|
|
m_py_motor.setIHOLD_IRUN(1, 31, 0); |
|
|
|
// m_py_motor.rotate(500000);
|
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR1_ENN, .csn_pin = MOTOR1_CSN}; |
|
|
|
|
|
|
|
m_tj_motor.initialize(&cfg); |
|
|
|
int32_t chipv = m_tj_motor.readChipVERSION(); |
|
|
|
ZLOGI(TAG, "m_tj_motor:%lx", chipv); |
|
|
|
m_tj_motor.setIHOLD_IRUN(1, 31, 0); |
|
|
|
// m_tj_motor.rotate(500000);
|
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 扫码枪初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
// static ZUART uart;
|
|
|
|
// PB6.initAsOutput(STM32_GPIO::kOutput_nopull, true, false);
|
|
|
|
// ZUART::cfg_t cfg = {
|
|
|
|
// .name = "CODE_SCANER_UART",
|
|
|
|
// .huart = &CODE_SCANER_UART,
|
|
|
|
// .rxbuffersize = 300,
|
|
|
|
// .rxovertime_ms = 10,
|
|
|
|
// };
|
|
|
|
// uart.initialize(&cfg,[](){})
|
|
|
|
// uart.initialize_basic("CODE_SCANER_UART", &m_hardware, &CODE_SCANER_UART);
|
|
|
|
// uart.initialize_setRxBuffer(300);
|
|
|
|
// uart.initialize_setRxOvertime(33);
|
|
|
|
// uart.initialize_finished();
|
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 协议栈初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ //
|
|
|
@ -155,7 +112,14 @@ void Main::run() { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
m_ioControlService.initialize(&m_protocolStack, GPIO_INPUT_ADD_BASE, nullptr, [this](int io_off) { |
|
|
|
/*******************************************************************************
|
|
|
|
* GPIO输入初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
input_sensors_init(); |
|
|
|
{ |
|
|
|
m_ioControlService.initialize(&m_protocolStack, GPIO_INPUT_ADD_BASE, nullptr, //
|
|
|
|
//
|
|
|
|
[this](int io_off) { |
|
|
|
if (io_off == 0) return io_fybjl_sensor0.getState(); |
|
|
|
if (io_off == 1) return io_fybjl_sensor1.getState(); |
|
|
|
if (io_off == 2) return io_fybjl_sensor2.getState(); |
|
|
@ -175,10 +139,20 @@ void Main::run() { |
|
|
|
|
|
|
|
return false; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 横移电机 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR0_ENN, .csn_pin = MOTOR0_CSN}; |
|
|
|
|
|
|
|
m_py_motor.initialize(&cfg); |
|
|
|
int32_t chipv = m_py_motor.readChipVERSION(); |
|
|
|
ZLOGI(TAG, "m_py_motor:%lx", chipv); |
|
|
|
m_py_motor.setIHOLD_IRUN(1, 31, 0); |
|
|
|
// m_py_motor.rotate(500000);
|
|
|
|
|
|
|
|
m_py_motor.setIHOLD_IRUN(2, 12, 0); |
|
|
|
m_py_motor.setMotorShaft(false); |
|
|
|
|
|
|
@ -200,10 +174,19 @@ void Main::run() { |
|
|
|
m_pyMotorControlService.cfg_max_pos->setVal(1144028); |
|
|
|
m_pyMotorControlService.cfg_runtohome_max_distance->setVal(INT32_MAX); |
|
|
|
m_pyMotorControlService.cfg_runtohome_leave_zero_point_distance->setVal(256 * 200 * 1); |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 推杆电机 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR1_ENN, .csn_pin = MOTOR1_CSN}; |
|
|
|
|
|
|
|
m_tj_motor.initialize(&cfg); |
|
|
|
int32_t chipv = m_tj_motor.readChipVERSION(); |
|
|
|
ZLOGI(TAG, "m_tj_motor:%lx", chipv); |
|
|
|
m_tj_motor.setIHOLD_IRUN(1, 31, 0); |
|
|
|
// m_tj_motor.rotate(500000);
|
|
|
|
|
|
|
|
m_tj_motor.setIHOLD_IRUN(2, 12, 0); |
|
|
|
m_tj_motor.setMotorShaft(true); |
|
|
@ -225,15 +208,19 @@ void Main::run() { |
|
|
|
m_tjMotorControlService.cfg_max_pos->setVal(1130108); |
|
|
|
m_tjMotorControlService.cfg_runtohome_max_distance->setVal(INT32_MAX); |
|
|
|
m_tjMotorControlService.cfg_runtohome_leave_zero_point_distance->setVal(256 * 200 * 1); |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 扫码枪初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
#if 0
|
|
|
|
|
|
|
|
扫描开始位置:518400 |
|
|
|
扫描结束位置:659200 |
|
|
|
|
|
|
|
#endif
|
|
|
|
m_m3078CodeScanner.initialize(&REACTION_BOX_SWEEP_SENSOR_UART, PC11, false /*trigger pin mirror*/); |
|
|
|
m_idCardReaderService.initialize("idCardReaderService", &m_protocolStack, REG_ID_CARD_READER_CTRL_ADD_BASE, &m_m3078CodeScanner); |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
// 扫描开始位置:518400
|
|
|
|
// 扫描结束位置:659200
|
|
|
|
OneDimensionalCodeLaserScanner::cfg_t cfg; |
|
|
|
cfg.triggerPin = FYBJL_SENSOR0; |
|
|
|
cfg.codestartpos = 518500; |
|
|
|