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.
207 lines
8.3 KiB
207 lines
8.3 KiB
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
#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\modbus\modbus_client.hpp"
|
|
#include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp"
|
|
#include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
|
|
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
|
|
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|
//
|
|
#include "sdk\components\hardware\uart\zuart_dma_receiver.hpp"
|
|
#include "serial485_to_analog.hpp"
|
|
#include "temperature_sensor.hpp"
|
|
#define TAG "main"
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
|
|
static ZCancmderSubboardIniter initer;
|
|
static Serial485ToAnalog serial485_to_analog;
|
|
|
|
extern void umain();
|
|
extern "C" {
|
|
void StartDefaultTask(void const* argument) { umain(); }
|
|
|
|
class UARTSender : public ZIUartSender {
|
|
UART_HandleTypeDef* m_huart;
|
|
|
|
public:
|
|
void init(UART_HandleTypeDef* huart) { m_huart = huart; }
|
|
virtual void send(const uint8_t* data, size_t len) { HAL_UART_Transmit(m_huart, (uint8_t*)data, len, 1000); }
|
|
};
|
|
|
|
extern DMA_HandleTypeDef hdma_usart3_rx;
|
|
extern DMA_HandleTypeDef hdma_usart3_tx;
|
|
}
|
|
/*******************************************************************************
|
|
* GET_DEVICE_ID *
|
|
*******************************************************************************/
|
|
static int32_t getDeviceId() {
|
|
static bool init = false;
|
|
static ZGPIO ID0;
|
|
static ZGPIO ID1;
|
|
static ZGPIO ID2;
|
|
static ZGPIO ID3;
|
|
static ZGPIO ID4;
|
|
if (!init) {
|
|
ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true);
|
|
init = true;
|
|
}
|
|
uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16;
|
|
return id;
|
|
}
|
|
/*******************************************************************************
|
|
* INIT_SUBMODULE *
|
|
*******************************************************************************/
|
|
void nvs_init_cb() {}
|
|
TemperatureSensor m_temperature_sensor[8];
|
|
|
|
static void initsubmodule() {
|
|
osDelay(1000);
|
|
{
|
|
m_temperature_sensor[0].initialize(&hadc1, ADC_CHANNEL_10);
|
|
m_temperature_sensor[1].initialize(&hadc1, ADC_CHANNEL_11);
|
|
m_temperature_sensor[2].initialize(&hadc1, ADC_CHANNEL_12);
|
|
m_temperature_sensor[3].initialize(&hadc1, ADC_CHANNEL_13);
|
|
m_temperature_sensor[4].initialize(&hadc1, ADC_CHANNEL_14);
|
|
}
|
|
{
|
|
/*******************************************************************************
|
|
* 温度4->20MA转485 *
|
|
*******************************************************************************/
|
|
/**
|
|
* @brief
|
|
* 串口参数:
|
|
* 115200
|
|
* 奇偶校验位:无校验
|
|
* 停止位:一个停止位
|
|
*/
|
|
ZASSERT(PC_MODBUS_UART.Init.BaudRate == 115200);
|
|
ZASSERT(PC_MODBUS_UART.Init.Parity == UART_PARITY_NONE);
|
|
ZASSERT(PC_MODBUS_UART.Init.StopBits == UART_STOPBITS_1);
|
|
serial485_to_analog.initialize(&PC_MODBUS_UART, NULL, NULL);
|
|
serial485_to_analog.reg(&m_temperature_sensor[0]);
|
|
serial485_to_analog.reg(&m_temperature_sensor[1]);
|
|
serial485_to_analog.reg(&m_temperature_sensor[2]);
|
|
serial485_to_analog.reg(&m_temperature_sensor[3]);
|
|
serial485_to_analog.reg(&m_temperature_sensor[4]);
|
|
serial485_to_analog.start();
|
|
|
|
// static ZUARTDmaReceiver dmaUartReceiver;
|
|
// static ZUARTDmaReceiver::hardware_config_t cfg = {
|
|
// .huart = &PC_MODBUS_UART,
|
|
// .dma_rx = &PC_MODBUS_UART_DMA_HANDLER,
|
|
// .rxbuffersize = PC_MODBUS_UART_RX_BUF_SIZE,
|
|
// .rxovertime_ms = 1,
|
|
// };
|
|
// dmaUartReceiver.initialize(&cfg);
|
|
|
|
// static UARTSender uartSender;
|
|
// uartSender.init(&PC_MODBUS_UART);
|
|
|
|
// ModulebusClient::Inst()->init(
|
|
// &dmaUartReceiver, &uartSender, 1, //
|
|
// [](uint16_t regadd, uint16_t& val) {
|
|
// int32_t sendval = 0;
|
|
// if (regadd == 11) {
|
|
// m_temperature_sensor[0].getTemperature(sendval);
|
|
// val = sendval;
|
|
// } else if (regadd == 12) {
|
|
// m_temperature_sensor[1].getTemperature(sendval);
|
|
// val = sendval;
|
|
// } else if (regadd == 13) {
|
|
// m_temperature_sensor[2].getTemperature(sendval);
|
|
// val = sendval;
|
|
// } else if (regadd == 14) {
|
|
// m_temperature_sensor[3].getTemperature(sendval);
|
|
// val = sendval;
|
|
// } else if (regadd == 15) {
|
|
// m_temperature_sensor[4].getTemperature(sendval);
|
|
// val = sendval;
|
|
// }
|
|
// }, //
|
|
// [](uint16_t regadd, uint16_t val) {});
|
|
// OSDefaultSchduler::getInstance()->regPeriodJob([](OSDefaultSchduler::Context& context) { ModulebusClient::Inst()->loop(); }, 1);
|
|
}
|
|
{
|
|
// 115200
|
|
/*******************************************************************************
|
|
* 试管帽夹舵机 *
|
|
*******************************************************************************/
|
|
static FeiTeServoMotor feiteservomotor_bus; // 飞特舵机总线
|
|
|
|
// 飞特舵机总线
|
|
ZASSERT(huart3.Init.BaudRate == 115200);
|
|
feiteservomotor_bus.initialize(&huart3, &hdma_usart3_rx, &hdma_usart3_tx);
|
|
|
|
{
|
|
static MiniRobotCtrlModule mini_servo;
|
|
static MiniRobotCtrlModule::flash_config_t cfg = {0};
|
|
cfg.default_torque = 330;
|
|
mini_servo.initialize(initer.get_module_id(1), &feiteservomotor_bus, 1, &cfg);
|
|
initer.register_module(&mini_servo);
|
|
}
|
|
{
|
|
static MiniRobotCtrlModule mini_servo;
|
|
static MiniRobotCtrlModule::flash_config_t cfg = {0};
|
|
cfg.default_torque = 330;
|
|
mini_servo.initialize(initer.get_module_id(2), &feiteservomotor_bus, 2, &cfg);
|
|
initer.register_module(&mini_servo);
|
|
}
|
|
{
|
|
static MiniRobotCtrlModule mini_servo;
|
|
static MiniRobotCtrlModule::flash_config_t cfg = {0};
|
|
cfg.default_torque = 330;
|
|
mini_servo.initialize(initer.get_module_id(3), &feiteservomotor_bus, 3, &cfg);
|
|
initer.register_module(&mini_servo);
|
|
}
|
|
{
|
|
static MiniRobotCtrlModule mini_servo;
|
|
static MiniRobotCtrlModule::flash_config_t cfg = {0};
|
|
cfg.default_torque = 330;
|
|
mini_servo.initialize(initer.get_module_id(4), &feiteservomotor_bus, 4, &cfg);
|
|
initer.register_module(&mini_servo);
|
|
}
|
|
{
|
|
static MiniRobotCtrlModule mini_servo;
|
|
static MiniRobotCtrlModule::flash_config_t cfg = {0};
|
|
cfg.default_torque = 330;
|
|
mini_servo.initialize(initer.get_module_id(5), &feiteservomotor_bus, 5, &cfg);
|
|
initer.register_module(&mini_servo);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* MAIN *
|
|
*******************************************************************************/
|
|
void umain() {
|
|
ZCancmderSubboardIniter::cfg_t cfg = //
|
|
{
|
|
.deviceId = getDeviceId(),
|
|
.input_gpio = {},
|
|
.output_gpio = {},
|
|
.temperature_sensor =
|
|
{
|
|
&m_temperature_sensor[0],
|
|
&m_temperature_sensor[1],
|
|
&m_temperature_sensor[2],
|
|
&m_temperature_sensor[3],
|
|
&m_temperature_sensor[4],
|
|
},
|
|
};
|
|
initer.init(&cfg);
|
|
initsubmodule();
|
|
initer.loop();
|
|
}
|