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.
319 lines
13 KiB
319 lines
13 KiB
#include "main.hpp"
|
|
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
//
|
|
#include "feite_servo_motor.hpp"
|
|
#include "sdk/os/zos.hpp"
|
|
//
|
|
// #include "sdk\components\cmdscheduler\cmd_scheduler.hpp"
|
|
#include "sdk\components\eq_20_asb_motor\eq20_servomotor.hpp"
|
|
#include "sdk\components\iflytop_can_slave_module_master_end\stepmotor.hpp"
|
|
#include "sdk\components\iflytop_can_slave_v1\iflytop_can_master.hpp"
|
|
#include "sdk\components\step_motor_45\step_motor_45.hpp"
|
|
#include "sdk\components\step_motor_45\step_motor_45_scheduler.hpp"
|
|
#include "sdk\components\zcancmder\zcanreceiver_master.hpp"
|
|
//
|
|
#include "sdk\components/step_motor_ctrl_module/step_motor_ctrl_script_cmder_module.hpp"
|
|
#include "sdk\components/xy_robot_ctrl_module/xy_robot_script_cmder_module.hpp"
|
|
#include "sdk\components\cmdscheduler\cmd_scheduler_v2.hpp"
|
|
#include "sdk\components\eq_20_asb_motor\script_cmder_eq20_servomotor.hpp"
|
|
#include "sdk\components\mini_servo_motor\mini_servo_motor_ctrl_module.hpp"
|
|
#include "sdk\components\mini_servo_motor\scirpt_cmder_mini_servo_motor_ctrl_module.hpp"
|
|
#include "sdk\components\step_motor_45\script_cmder_step_motor_45.hpp"
|
|
// #include "sdk\components\scriptcmder_module\xy_robot_script_cmder_module.hpp"
|
|
// #include "sdk\components\zcancmder_master_module/zcan_master_step_motor_ctrl_module.hpp"
|
|
// #include "sdk\components\zcancmder_master_module\zcan_xy_robot_master_module.hpp"
|
|
|
|
#include "intelligent_winding_robot_ctrl.hpp"
|
|
#include "sdk\components\taojingchi_screen\taojingchi_screen_service.hpp"
|
|
#include "sdk\components\zprotocol_helper\micro_computer_module_device_script_cmder_paser.hpp"
|
|
#include "sdk\components\zprotocols\zcancmder_v2\protocol_proxy.hpp"
|
|
#include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_manager.hpp"
|
|
#include "sdk\components\zprotocols\zcancmder_v2\zmodule_device_script_cmder_paser.hpp"
|
|
//
|
|
#include "app_zmodule_device_manager.hpp"
|
|
#define TAG "main"
|
|
namespace iflytop {
|
|
Main gmain;
|
|
};
|
|
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
#define CHECK_ARGC(n) \
|
|
if (argc != (n + 1)) { \
|
|
ZLOGE(TAG, "argc != %d", n); \
|
|
context->breakflag = true; \
|
|
return; \
|
|
}
|
|
extern "C" {
|
|
void StartDefaultTask(void const* argument) { iflytop::gmain.run(); }
|
|
}
|
|
/*******************************************************************************
|
|
* 配置 *
|
|
*******************************************************************************/
|
|
static chip_cfg_t chipcfg = {
|
|
.us_dleay_tim = &DELAY_US_TIMER,
|
|
.tim_irq_scheduler_tim = &TIM_IRQ_SCHEDULER_TIMER,
|
|
.huart = &DEBUG_UART,
|
|
.debuglight = DEBUG_LIGHT_GPIO,
|
|
};
|
|
|
|
static StepMotor45::cfg_t cfg1 = {
|
|
.max_pos = -1,
|
|
.enable_zero_limit = true,
|
|
.enable_max_pos_limit = false,
|
|
.mirror = true,
|
|
|
|
.zeroPin = PB12,
|
|
.ioPollType = ZGPIO::kMode_pullup,
|
|
.zeroPinMirror = true,
|
|
|
|
.driverPin = {PB15, PD11, PD12, PD13},
|
|
.driverPinMirror = true,
|
|
};
|
|
static StepMotor45::cfg_t cfg2 = {
|
|
.max_pos = -1,
|
|
.enable_zero_limit = false,
|
|
.enable_max_pos_limit = false,
|
|
.mirror = true,
|
|
|
|
.zeroPin = PG1,
|
|
.ioPollType = ZGPIO::kMode_pullup,
|
|
.zeroPinMirror = true,
|
|
|
|
.driverPin = {PG2, PG3, PG4, PG5},
|
|
.driverPinMirror = true,
|
|
};
|
|
// PB13
|
|
#if 0
|
|
static StepMotor45::cfg_t cfg3 = {
|
|
.max_pos = -1,
|
|
.enable_zero_limit = true,
|
|
.enable_max_pos_limit = false,
|
|
.mirror = true,
|
|
|
|
.zeroPin = PB12,
|
|
.ioPollType = ZGPIO::kMode_pullup,
|
|
.zeroPinMirror = true,
|
|
|
|
.driverPin = {PG6, PG7, PG8, PC6},
|
|
.driverPinMirror = true,
|
|
};
|
|
static StepMotor45::cfg_t cfg4 = {
|
|
.max_pos = -1,
|
|
.enable_zero_limit = false,
|
|
.enable_max_pos_limit = false,
|
|
.mirror = true,
|
|
|
|
.zeroPin = PinNull,
|
|
.zeroPinMirror = false,
|
|
|
|
.driverPin = {PE0, PE2, PE4, PE6},
|
|
.driverPinMirror = true,
|
|
};
|
|
|
|
static StepMotor45::cfg_t cfg5 = {
|
|
.max_pos = -1,
|
|
.enable_zero_limit = false,
|
|
.enable_max_pos_limit = false,
|
|
.mirror = true,
|
|
|
|
.zeroPin = PinNull,
|
|
.zeroPinMirror = false,
|
|
|
|
.driverPin = {PC13, PE5, PE3, PE1},
|
|
.driverPinMirror = true,
|
|
};
|
|
static StepMotor45::cfg_t cfg6 = {
|
|
.max_pos = -1,
|
|
.enable_zero_limit = false,
|
|
.enable_max_pos_limit = false,
|
|
.mirror = true,
|
|
|
|
.zeroPin = PinNull,
|
|
.zeroPinMirror = false,
|
|
|
|
.driverPin = {PC12, PD3, PD5, PD7},
|
|
.driverPinMirror = true,
|
|
};
|
|
#endif
|
|
|
|
namespace iflytop {
|
|
/*******************************************************************************
|
|
* 基础组件 *
|
|
*******************************************************************************/
|
|
ZCanCommnaderMaster m_zcanCommnaderMaster; // can总线
|
|
ModbusBlockHost g_modbusblockhost; // modbus总线
|
|
FeiTeServoMotor g_feiteservomotor_bus; // 飞特舵机总线
|
|
APPDM g_zmodule_device_manager; // 用于管理所有的设备
|
|
StepMotor45Scheduler step_motor45_scheduler; // 45步进电机调度器
|
|
|
|
CmdSchedulerV2 g_cmdScheduler; // 串口字符串指令总线
|
|
TaoJingChiScreenService g_taojingchi_screen_service; // 淘精驰屏幕服务
|
|
MicroComputerModuleDeviceScriptCmderPaser g_zmodule_device_script_cmder_paser; // 用于解析所有的设备指令
|
|
ScriptCmderEq20Servomotor g_eq20_servomotor_script_cmder; // eq20
|
|
ScriptCmderStepMotor45 g_step_motor45_script_cmder; // 45步进电机
|
|
ScirptCmderMiniServoMotorCtrlModule g_mini_servo_motor_script_cmder; // 小舵机
|
|
|
|
/*******************************************************************************
|
|
* 本地设备 *
|
|
*******************************************************************************/
|
|
Eq20ServoMotor g_main_servo_motor;
|
|
StepMotor45 g_step_motor45[7];
|
|
MiniRobotCtrlModule g_mini_servo[10];
|
|
/*******************************************************************************
|
|
* CAN设备 *
|
|
*******************************************************************************/
|
|
ZIProtocolProxy g_xyrobotctrlmodule;
|
|
ZIProtocolProxy g_z_step_motor;
|
|
|
|
IntelligentWindingRobotCtrl g_intelligent_winding_robot_ctrl;
|
|
|
|
} // namespace iflytop
|
|
|
|
extern "C" {
|
|
extern DMA_HandleTypeDef hdma_usart3_rx;
|
|
extern DMA_HandleTypeDef hdma_usart3_tx;
|
|
}
|
|
|
|
extern "C" {}
|
|
extern DMA_HandleTypeDef hdma_usart2_rx;
|
|
extern DMA_HandleTypeDef hdma_usart2_tx;
|
|
|
|
extern void script_reg_fn();
|
|
void regfn() { script_reg_fn(); }
|
|
|
|
extern void step_motor_cmd_reg();
|
|
void Main::run() {
|
|
// PB13
|
|
/*******************************************************************************
|
|
* 系统初始化 *
|
|
*******************************************************************************/
|
|
|
|
chip_init(&chipcfg);
|
|
zos_cfg_t zoscfg;
|
|
zos_init(&zoscfg);
|
|
|
|
/*******************************************************************************
|
|
* 总线初始化 *
|
|
*******************************************************************************/
|
|
auto* cfg = m_zcanCommnaderMaster.createCFG(); // can总线配置
|
|
m_zcanCommnaderMaster.init(cfg); // can总线
|
|
g_modbusblockhost.initialize(&huart2, &hdma_usart2_tx, &hdma_usart2_rx); // modbus总线
|
|
g_feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx); // 飞特舵机总线
|
|
step_motor45_scheduler.initialize(&htim10);
|
|
// 设备管理器初始化
|
|
g_zmodule_device_manager.initialize(&m_zcanCommnaderMaster);
|
|
// 设备指令解析器初始化
|
|
|
|
/*******************************************************************************
|
|
* 设备构造和初始化 *
|
|
*******************************************************************************/
|
|
g_main_servo_motor.init(2, &g_modbusblockhost, 1);
|
|
g_xyrobotctrlmodule.initialize(3, &m_zcanCommnaderMaster);
|
|
g_z_step_motor.initialize(4, &m_zcanCommnaderMaster);
|
|
|
|
g_mini_servo[0].initialize(11, &g_feiteservomotor_bus, 1);
|
|
g_mini_servo[1].initialize(12, &g_feiteservomotor_bus, 2);
|
|
g_mini_servo[2].initialize(13, &g_feiteservomotor_bus, 3);
|
|
g_mini_servo[3].initialize(14, &g_feiteservomotor_bus, 4);
|
|
g_mini_servo[4].initialize(15, &g_feiteservomotor_bus, 5);
|
|
g_mini_servo[5].initialize(16, &g_feiteservomotor_bus, 6);
|
|
g_mini_servo[6].initialize(23, &g_feiteservomotor_bus, 23);
|
|
|
|
g_step_motor45[0].initialize(21, &step_motor45_scheduler, cfg1);
|
|
g_step_motor45[1].initialize(22, &step_motor45_scheduler, cfg2);
|
|
// g_step_motor45[2].initialize(23, &step_motor45_scheduler, cfg3);
|
|
|
|
step_motor45_scheduler.start();
|
|
|
|
g_zmodule_device_manager.registerModule(&g_main_servo_motor);
|
|
g_zmodule_device_manager.registerModule(&g_xyrobotctrlmodule);
|
|
g_zmodule_device_manager.registerModule(&g_z_step_motor);
|
|
g_zmodule_device_manager.registerModule(&g_mini_servo[0]);
|
|
g_zmodule_device_manager.registerModule(&g_mini_servo[1]);
|
|
g_zmodule_device_manager.registerModule(&g_mini_servo[2]);
|
|
g_zmodule_device_manager.registerModule(&g_mini_servo[3]);
|
|
g_zmodule_device_manager.registerModule(&g_mini_servo[4]);
|
|
g_zmodule_device_manager.registerModule(&g_mini_servo[5]);
|
|
g_zmodule_device_manager.registerModule(&g_mini_servo[6]);
|
|
g_zmodule_device_manager.registerModule(&g_step_motor45[0]);
|
|
g_zmodule_device_manager.registerModule(&g_step_motor45[1]);
|
|
g_zmodule_device_manager.registerModule(&g_step_motor45[2]);
|
|
|
|
int32_t status;
|
|
g_zmodule_device_manager.module_get_status(21, &status);
|
|
|
|
// status *= 2;
|
|
// status
|
|
|
|
g_intelligent_winding_robot_ctrl.initialize(&g_zmodule_device_manager, &g_cmdScheduler);
|
|
|
|
/*******************************************************************************
|
|
* g_xyrobotctrlmodule *
|
|
*******************************************************************************/
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_x_shift, 0);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_y_shift, 0);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_x_one_circle_pulse, 7344);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_y_one_circle_pulse, 7344);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_run_to_zero_speed, 80);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_run_to_zero_dec, 1600);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_look_zero_edge_speed, 10);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_look_zero_edge_dec, 1600);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_default_velocity, 600);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_default_acc, 1000);
|
|
g_xyrobotctrlmodule.module_set_param(kcfg_motor_default_dec, 1000);
|
|
g_xyrobotctrlmodule.module_set_param(k_cfg_stepmotor_irun, 4);
|
|
|
|
g_xyrobotctrlmodule.module_active_cfg();
|
|
|
|
g_z_step_motor.module_set_param(kcfg_motor_x_shift, 0);
|
|
g_z_step_motor.module_set_param(kcfg_motor_x_one_circle_pulse, 800);
|
|
g_z_step_motor.module_active_cfg();
|
|
|
|
/*******************************************************************************
|
|
* 串口字符串指令总线 *
|
|
*******************************************************************************/
|
|
g_cmdScheduler.initialize(&DEBUG_UART, 1000); //
|
|
g_zmodule_device_script_cmder_paser.initialize(&g_cmdScheduler, &g_zmodule_device_manager);
|
|
g_eq20_servomotor_script_cmder.initialize(&g_cmdScheduler);
|
|
g_eq20_servomotor_script_cmder.regmodule(1, &g_main_servo_motor);
|
|
|
|
g_step_motor45_script_cmder.initialize(&g_cmdScheduler);
|
|
g_step_motor45_script_cmder.regmodule(1, &g_step_motor45[0]);
|
|
g_step_motor45_script_cmder.regmodule(2, &g_step_motor45[1]);
|
|
g_step_motor45_script_cmder.regmodule(3, &g_step_motor45[2]);
|
|
|
|
g_mini_servo_motor_script_cmder.initialize(&g_cmdScheduler);
|
|
g_mini_servo_motor_script_cmder.regmodule(1, &g_mini_servo[0]);
|
|
g_mini_servo_motor_script_cmder.regmodule(2, &g_mini_servo[1]);
|
|
g_mini_servo_motor_script_cmder.regmodule(3, &g_mini_servo[2]);
|
|
g_mini_servo_motor_script_cmder.regmodule(4, &g_mini_servo[3]);
|
|
g_mini_servo_motor_script_cmder.regmodule(5, &g_mini_servo[4]);
|
|
g_mini_servo_motor_script_cmder.regmodule(6, &g_mini_servo[5]);
|
|
|
|
g_taojingchi_screen_service.initialize(
|
|
&huart5, 1,
|
|
/**
|
|
* @brief 私有协议解析
|
|
*/
|
|
[this](const char* cmd, int32_t paramN, const char** paraV) { //
|
|
ZLOGI(TAG, "process cmd:%s", cmd);
|
|
|
|
},
|
|
/**
|
|
* @brief 陶晶驰消息解析
|
|
*/
|
|
[this](uint8_t* data, size_t len) {});
|
|
regfn();
|
|
#if 0
|
|
step_motor_cmd_reg();
|
|
#endif
|
|
while (true) {
|
|
OSDefaultSchduler::getInstance()->loop();
|
|
g_cmdScheduler.schedule();
|
|
osDelay(1);
|
|
}
|
|
}
|