|
|
@ -1,137 +1,138 @@ |
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "sdk/os/zos.hpp"
|
|
|
|
#include "sdk\components\flash\zsimple_flash.hpp"
|
|
|
|
#include "sdk\components\zcancmder\zcanreceiver.hpp"
|
|
|
|
#include "sdk\components\zcancmder_module\zcan_basic_order_module.hpp"
|
|
|
|
#include "sdk\components\zprotocols\zcancmder_v2\protocol_parser.hpp"
|
|
|
|
//
|
|
|
|
#include "sdk\components\flash\znvs.hpp"
|
|
|
|
//
|
|
|
|
#include "board.h"
|
|
|
|
#include "sdk\components\subcanmodule\zcancmder_subboard_initer.hpp"
|
|
|
|
/*******************************************************************************
|
|
|
|
* PROJECT_INCLUDE * |
|
|
|
*******************************************************************************/ |
|
|
|
#include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
|
|
|
|
#include "sdk\components\mini_servo_motor\feite_servo_motor.hpp"
|
|
|
|
#include "sdk\components\mini_servo_motor\mini_servo_motor_ctrl_module.hpp"
|
|
|
|
#include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp"
|
|
|
|
#include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
|
|
|
|
#include "sdk\components\sensors\tmp117\tmp117.hpp"
|
|
|
|
#include "sdk\components\ti\drv8710.hpp"
|
|
|
|
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.cpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.hpp"
|
|
|
|
#include "sdk\components\zcancmder\zcan_board_module.hpp"
|
|
|
|
// #include "M3078CodeScanner"
|
|
|
|
|
|
|
|
#define TAG "main"
|
|
|
|
using namespace iflytop; |
|
|
|
using namespace std; |
|
|
|
|
|
|
|
static ZCancmderSubboardIniter initer; |
|
|
|
|
|
|
|
extern void umain(); |
|
|
|
extern "C" { |
|
|
|
void StartDefaultTask(void const* argument) { umain(); } |
|
|
|
} |
|
|
|
extern "C" { |
|
|
|
extern DMA_HandleTypeDef hdma_usart2_rx; |
|
|
|
extern DMA_HandleTypeDef hdma_usart2_tx; |
|
|
|
} |
|
|
|
static ZCanCmder g_zcanCmder; |
|
|
|
static ZIProtocolParser g_ziProtocolParser; |
|
|
|
//
|
|
|
|
static TMC5130 g_motor[3]; |
|
|
|
//
|
|
|
|
static PipetteModule g_pipetteModule; |
|
|
|
// USART4_TX
|
|
|
|
|
|
|
|
void initmodule() { |
|
|
|
osDelay(1000); |
|
|
|
|
|
|
|
{ |
|
|
|
static ZCanBoardModule::hardware_config_t cfg = { |
|
|
|
.input = |
|
|
|
{ |
|
|
|
{PD0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD5, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
{PD8, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
static ZCanBoardModule boardmodule; |
|
|
|
boardmodule.initialize(BOARD_ID * 10 + 0, &cfg); |
|
|
|
g_ziProtocolParser.registerModule(&boardmodule); |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* GET_DEVICE_ID * |
|
|
|
*******************************************************************************/ |
|
|
|
static int32_t getDeviceId() { return BOARD_ID; } |
|
|
|
/*******************************************************************************
|
|
|
|
* INIT_SUBMODULE * |
|
|
|
*******************************************************************************/ |
|
|
|
void nvs_init_cb() {} |
|
|
|
static void initsubmodule() { |
|
|
|
/**
|
|
|
|
* @brief 入料 |
|
|
|
*/ |
|
|
|
{ |
|
|
|
static TMC5130 motor; |
|
|
|
static StepMotorCtrlModule stepMotorCtrlModule; |
|
|
|
|
|
|
|
TMC5130::cfg_t cfg = { |
|
|
|
.spi = &TMC_MOTOR_SPI, //
|
|
|
|
.csgpio = MOTOR0_CSN, //
|
|
|
|
.ennPin = MOTOR0_ENN, //
|
|
|
|
.spi_mode_select = MOTOR0_SPI_MODE_SELECT, //
|
|
|
|
.csgpio = MOTOR1_CSN, //
|
|
|
|
.ennPin = MOTOR1_ENN, //
|
|
|
|
.spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
|
|
|
|
}; |
|
|
|
motor.initialize(&cfg); |
|
|
|
motor.setMotorShaft(false); |
|
|
|
ZLOGI(TAG, "motora initialize 5160:%x ", motor.readICVersion()); |
|
|
|
ZLOGI(TAG, "motor1 initialize 5160:%x ", motor.readICVersion()); |
|
|
|
|
|
|
|
static ZGPIO input[2]; |
|
|
|
input[0].initAsInput(MOTOR0_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[1].initAsInput(MOTOR0_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[0].initAsInput(MOTOR1_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
|
|
|
|
stepMotorCtrlModule.initialize(BOARD_ID * 10 + 1, &motor, input, ZARRAY_SIZE(input), nullptr); |
|
|
|
g_ziProtocolParser.registerModule(&stepMotorCtrlModule); |
|
|
|
I_StepMotorCtrlModule::flash_config_t smcm_cfg = {0}; |
|
|
|
StepMotorCtrlModule::create_default_cfg(smcm_cfg); |
|
|
|
smcm_cfg.base_param.distance_scale = 200; |
|
|
|
smcm_cfg.base_param.distance_scale_denominator = 1; |
|
|
|
smcm_cfg.base_param.irun = 24; |
|
|
|
smcm_cfg.base_param.ihold = 1; |
|
|
|
smcm_cfg.base_param.x_shaft = false; |
|
|
|
smcm_cfg.base_param.maxspeed = 150; |
|
|
|
|
|
|
|
stepMotorCtrlModule.initialize(initer.get_module_id(1), &motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg); |
|
|
|
initer.register_module(&stepMotorCtrlModule); |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 平移 |
|
|
|
*/ |
|
|
|
{ |
|
|
|
static TMC5130 motor; |
|
|
|
static StepMotorCtrlModule stepMotorCtrlModule; |
|
|
|
|
|
|
|
TMC5130::cfg_t cfg = { |
|
|
|
.spi = &TMC_MOTOR_SPI, //
|
|
|
|
.csgpio = MOTOR1_CSN, //
|
|
|
|
.ennPin = MOTOR1_ENN, //
|
|
|
|
.spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
|
|
|
|
.csgpio = MOTOR2_CSN, //
|
|
|
|
.ennPin = MOTOR2_ENN, //
|
|
|
|
.spi_mode_select = MOTOR2_SPI_MODE_SELECT, //
|
|
|
|
}; |
|
|
|
motor.initialize(&cfg); |
|
|
|
motor.setMotorShaft(false); |
|
|
|
ZLOGI(TAG, "motora initialize 5160:%x ", motor.readICVersion()); |
|
|
|
ZLOGI(TAG, "motor2 initialize 5160:%x ", motor.readICVersion()); |
|
|
|
|
|
|
|
static ZGPIO input[2]; |
|
|
|
input[0].initAsInput(MOTOR1_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[0].initAsInput(MOTOR2_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[1].initAsInput(MOTOR2_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
|
|
|
|
stepMotorCtrlModule.initialize(BOARD_ID * 10 + 2, &motor, input, ZARRAY_SIZE(input), nullptr); |
|
|
|
g_ziProtocolParser.registerModule(&stepMotorCtrlModule); |
|
|
|
I_StepMotorCtrlModule::flash_config_t smcm_cfg = {0}; |
|
|
|
StepMotorCtrlModule::create_default_cfg(smcm_cfg); |
|
|
|
smcm_cfg.base_param.distance_scale = 100; |
|
|
|
smcm_cfg.base_param.distance_scale_denominator = 1; |
|
|
|
smcm_cfg.base_param.irun = 24; |
|
|
|
smcm_cfg.base_param.ihold = 1; |
|
|
|
smcm_cfg.base_param.x_shaft = true; |
|
|
|
smcm_cfg.base_param.maxspeed = 50; |
|
|
|
smcm_cfg.base_param.run_to_zero_speed = 50; |
|
|
|
|
|
|
|
stepMotorCtrlModule.initialize(initer.get_module_id(2), &motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg); |
|
|
|
initer.register_module(&stepMotorCtrlModule); |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 出料 |
|
|
|
*/ |
|
|
|
{ |
|
|
|
static TMC5130 motor; |
|
|
|
static StepMotorCtrlModule stepMotorCtrlModule; |
|
|
|
|
|
|
|
TMC5130::cfg_t cfg = { |
|
|
|
.spi = &TMC_MOTOR_SPI, //
|
|
|
|
.csgpio = MOTOR2_CSN, //
|
|
|
|
.ennPin = MOTOR2_ENN, //
|
|
|
|
.spi_mode_select = MOTOR2_SPI_MODE_SELECT, //
|
|
|
|
.csgpio = MOTOR3_CSN, //
|
|
|
|
.ennPin = MOTOR3_ENN, //
|
|
|
|
.spi_mode_select = MOTOR3_SPI_MODE_SELECT, //
|
|
|
|
}; |
|
|
|
motor.initialize(&cfg); |
|
|
|
motor.setMotorShaft(false); |
|
|
|
ZLOGI(TAG, "motora initialize 5160:%x ", motor.readICVersion()); |
|
|
|
ZLOGI(TAG, "motor3 initialize 5160:%x ", motor.readICVersion()); |
|
|
|
|
|
|
|
static ZGPIO input[2]; |
|
|
|
input[0].initAsInput(MOTOR2_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[1].initAsInput(MOTOR2_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
|
|
|
|
stepMotorCtrlModule.initialize(BOARD_ID * 10 + 3, &motor, input, ZARRAY_SIZE(input), nullptr); |
|
|
|
g_ziProtocolParser.registerModule(&stepMotorCtrlModule); |
|
|
|
input[0].initAsInput(MOTOR3_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[1].initAsInput(MOTOR3_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
|
|
|
|
I_StepMotorCtrlModule::flash_config_t smcm_cfg = {0}; |
|
|
|
StepMotorCtrlModule::create_default_cfg(smcm_cfg); |
|
|
|
smcm_cfg.base_param.distance_scale = 100; |
|
|
|
smcm_cfg.base_param.distance_scale_denominator = 1; |
|
|
|
smcm_cfg.base_param.irun = 24; |
|
|
|
smcm_cfg.base_param.ihold = 1; |
|
|
|
smcm_cfg.base_param.x_shaft = true; |
|
|
|
smcm_cfg.base_param.maxspeed = 50; |
|
|
|
smcm_cfg.base_param.run_to_zero_speed = 50; |
|
|
|
|
|
|
|
stepMotorCtrlModule.initialize(initer.get_module_id(3), &motor, input, ZARRAY_SIZE(input), nullptr, &smcm_cfg); |
|
|
|
initer.register_module(&stepMotorCtrlModule); |
|
|
|
} |
|
|
|
|
|
|
|
#if 0
|
|
|
|
{ |
|
|
|
static M3078CodeScanner codescanner; |
|
|
|
static M3078CodeScanner::hardware_config_t cfg = { |
|
|
@ -146,58 +147,27 @@ void initmodule() { |
|
|
|
codescanner.initialize(BOARD_ID * 10 + 4, &cfg); |
|
|
|
g_ziProtocolParser.registerModule(&codescanner); |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
// 115200
|
|
|
|
static FeiTeServoMotor feiteservomotor_bus; // 飞特舵机总线
|
|
|
|
static MiniRobotCtrlModule mini_servo[4]; |
|
|
|
|
|
|
|
ZASSERT(huart2.Init.BaudRate == 115200); // 飞特舵机总线
|
|
|
|
feiteservomotor_bus.initialize(&huart2, &hdma_usart2_rx, &hdma_usart2_tx); // 飞特舵机总线
|
|
|
|
|
|
|
|
mini_servo[0].initialize(BOARD_ID * 10 + 5, &feiteservomotor_bus, 1); |
|
|
|
mini_servo[1].initialize(BOARD_ID * 10 + 6, &feiteservomotor_bus, 2); |
|
|
|
mini_servo[2].initialize(BOARD_ID * 10 + 7, &feiteservomotor_bus, 3); |
|
|
|
mini_servo[3].initialize(BOARD_ID * 10 + 8, &feiteservomotor_bus, 4); |
|
|
|
|
|
|
|
g_ziProtocolParser.registerModule(&mini_servo[0]); |
|
|
|
g_ziProtocolParser.registerModule(&mini_servo[1]); |
|
|
|
g_ziProtocolParser.registerModule(&mini_servo[2]); |
|
|
|
g_ziProtocolParser.registerModule(&mini_servo[3]); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* MAIN * |
|
|
|
*******************************************************************************/ |
|
|
|
void umain() { |
|
|
|
chip_cfg_t chipcfg; |
|
|
|
chipcfg.us_dleay_tim = &DELAY_US_TIMER; |
|
|
|
chipcfg.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER; |
|
|
|
chipcfg.huart = &DEBUG_UART; |
|
|
|
chipcfg.debuglight = DEBUG_LIGHT_GPIO; |
|
|
|
|
|
|
|
chip_init(&chipcfg); |
|
|
|
|
|
|
|
zos_cfg_t zoscfg; |
|
|
|
zos_init(&zoscfg); |
|
|
|
|
|
|
|
ZLOGI(TAG, "boardId:%d", BOARD_ID); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* NVSINIT * |
|
|
|
*******************************************************************************/ |
|
|
|
ZNVS::ins().initialize(IFLYTOP_NVS_CONFIG_FLASH_SECTOR); |
|
|
|
{ |
|
|
|
static I_StepMotorCtrlModule::flash_config_t cfg; |
|
|
|
StepMotorCtrlModule::create_default_cfg(cfg); |
|
|
|
ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg)); |
|
|
|
} |
|
|
|
ZNVS::ins().init_config(); |
|
|
|
auto zcanCmder_cfg = g_zcanCmder.createCFG(BOARD_ID); |
|
|
|
g_zcanCmder.init(zcanCmder_cfg); |
|
|
|
g_ziProtocolParser.initialize(&g_zcanCmder); |
|
|
|
|
|
|
|
initmodule(); |
|
|
|
while (true) { |
|
|
|
OSDefaultSchduler::getInstance()->loop(); |
|
|
|
g_zcanCmder.loop(); |
|
|
|
} |
|
|
|
}; |
|
|
|
ZCancmderSubboardIniter::cfg_t cfg = //
|
|
|
|
{ |
|
|
|
.deviceId = getDeviceId(), |
|
|
|
.input_gpio = |
|
|
|
{ |
|
|
|
{.pin = PD0, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true}, |
|
|
|
{.pin = PD1, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true}, |
|
|
|
{.pin = PD2, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true}, |
|
|
|
{.pin = PD3, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true}, |
|
|
|
{.pin = PD4, .mode = ZGPIO::kMode_nopull, .irqtype = ZGPIO::kIRQ_noIrq, .mirror = true}, |
|
|
|
}, |
|
|
|
.output_gpio = {}, |
|
|
|
}; |
|
|
|
initer.init(&cfg); |
|
|
|
initsubmodule(); |
|
|
|
initer.loop(); |
|
|
|
} |