Browse Source

1. 注释急停按钮

2. 增加模拟温控
3. 适配 基质喷涂 V2
develop
HSZ_HeSongZhen 3 weeks ago
parent
commit
2ba2d420c7
  1. 2
      CMakeLists.txt
  2. 2
      User/BSP/LED/exti_key_manager.cpp
  3. 23
      User/BSP/LED/temp_control.cpp
  4. 31
      User/BSP/LED/temp_control.h
  5. 11
      User/BSP/base/apphardware.cpp
  6. 3
      User/BSP/base/apphardware.hpp
  7. 8
      User/BSP/can_control/can_config.h
  8. 8
      User/BSP/status/elc_motor.cpp
  9. 2
      User/BSP/status/elc_motor_helper.cpp
  10. 57
      User/BSP/uart_cmd/cmd_process_service_process.cpp

2
CMakeLists.txt

@ -119,6 +119,8 @@ add_executable(${CMAKE_PROJECT_NAME}
User/BSP/uart_cmd/cmd_process_service_process.cpp
User/BSP/uart_cmd/cmd_process_service_process.h
User/project_config.h
User/BSP/LED/temp_control.cpp
User/BSP/LED/temp_control.h
)
# Add STM32CubeMX generated sources

2
User/BSP/LED/exti_key_manager.cpp

@ -303,7 +303,7 @@ extern "C" void EXTI15_10_IRQHandler(void) {
HAL_GPIO_EXTI_IRQHandler(Y_LIMIT_PIN);
HAL_GPIO_EXTI_IRQHandler(Z_ORIGIN_PIN);
HAL_GPIO_EXTI_IRQHandler(Z_LIMIT_PIN);
HAL_GPIO_EXTI_IRQHandler(E_STOP_PIN);
// HAL_GPIO_EXTI_IRQHandler(E_STOP_PIN);
}
extern "C" uint16_t getORIGINPin(uint32_t motor_index) {

23
User/BSP/LED/temp_control.cpp

@ -0,0 +1,23 @@
//
// Created by iflyt on 2025/7/13.
//
#include "temp_control.h"
void TempControl::init() {
}
int32_t TempControl::setTemp(double temp) {
target_temp_ = temp;
current_temp_ = temp;
return 0;
}
int32_t TempControl::close() {
return 0;
}
double TempControl::getCurrentTemp() const {
return current_temp_;
}

31
User/BSP/LED/temp_control.h

@ -0,0 +1,31 @@
//
// Created by iflyt on 2025/7/13.
//
#ifndef TEMP_CONTROL_H
#define TEMP_CONTROL_H
#include <stdint.h>
class TempControl {
public:
TempControl() = default;
~TempControl() = default;
void init();
int32_t setTemp(double temp);
int32_t close();
double getCurrentTemp() const;
private:
double target_temp_{0};
double current_temp_{0};
};
#endif //TEMP_CONTROL_H

11
User/BSP/base/apphardware.cpp

@ -55,7 +55,7 @@ void AppHardware::initialize() {
#if 0
MOTO1.setIHOLD_IRUN(0, 7, 100);
#else
MOTO1.setIHOLD_IRUN(0, 5, 100);
MOTO1.setIHOLD_IRUN(0, 8, 100);
#endif
MOTO1.setScale(1000);
MOTO1.setEncResolution(-1000);
@ -68,7 +68,7 @@ void AppHardware::initialize() {
#if 0
MOTO2.setIHOLD_IRUN(0, 10, 100);
#else
MOTO2.setIHOLD_IRUN(0, 5, 100);
MOTO2.setIHOLD_IRUN(0, 8, 100);
#endif
MOTO2.setScale(1000);
MOTO2.setEncResolution(-1000);
@ -78,7 +78,7 @@ void AppHardware::initialize() {
MOTO3.initialize(2, tmc5130cfg3);
MOTO3.enable(false);
MOTO3.setIHOLD_IRUN(0, 5, 100);
MOTO3.setIHOLD_IRUN(0, 8, 100);
MOTO3.setScale(1000);
MOTO3.setEncResolution(-1000);
@ -103,6 +103,8 @@ void AppHardware::initialize() {
pump_controller.init();
high_voltage_pack.init(true);
laser_control.init(true);
temp_control_nozzle.init();
temp_control_slide.init();
// 初始化电机索引
MotorManager::ins()->motors[0].setMotorIndex(0);
MotorManager::ins()->motors[1].setMotorIndex(1);
@ -177,7 +179,8 @@ void AppHardware::setE_Stop(bool isE_Stop) {
}
bool AppHardware::isE_Stop() {
return isE_Stop_;
// return isE_Stop_;
return false;
}
void AppHardware::toggleLaunched() {

3
User/BSP/base/apphardware.hpp

@ -10,6 +10,7 @@
#include "zgpio.hpp"
#include "appcfg.h"
#include "stm32components.hpp"
#include "LED/temp_control.h"
#include "uart_control/uart_control.h"
namespace iflytop {
@ -74,6 +75,8 @@ class AppHardware {
PumpController pump_controller; // 电机泵
HighVoltagePack high_voltage_pack; // 注射泵
LaserControl laser_control; // 激光
TempControl temp_control_nozzle; // 喷嘴温度控制
TempControl temp_control_slide; // 拨片温度控制
bool hardwareInitedOK = false;

8
User/BSP/can_control/can_config.h

@ -62,7 +62,6 @@
#define THREE_VALVE_ADDRESS_VT 0x28 // 三通阀 VT
#define THREE_VALVE_ADDRESS_POWER 0x29 // 三通阀 POWER
#define MOVE_FINISHED_READ_ADDRESS 0x10
#define AT_ORIGIN_READ_ADDRESS 0x11
#define AT_LIMIT_READ_ADDRESS 0x12
@ -96,6 +95,13 @@
#define PUMP_DRIVER_SPEED_ADDRESS 0x21 // 注射泵速度 ML
#define LASER_POWER_ADDRESS 0x22 // 激光控制
#define PUMP_DRIVER_SET_SPEED_ADDRESS 0x23 // 设置注射泵速度 ML
#define TMEP_CONTROL_NOZZLE_SET_TEMP_ADDRESS 0x24 // 设置温度
#define TMEP_CONTROL_NOZZLE_CLOSE_TEMP_ADDRESS 0x25 // 关闭温度
#define TMEP_CONTROL_NOZZLE_READ_TEMP_ADDRESS 0x26 // 读取温度
#define TMEP_CONTROL_SLIDE_SET_TEMP_ADDRESS 0x27 // 设置温度
#define TMEP_CONTROL_SLIDE_CLOSE_TEMP_ADDRESS 0x28 // 关闭温度
#define TMEP_CONTROL_SLIDE_READ_TEMP_ADDRESS 0x29 // 读取温度
//
#define UPLOAD_FUN_CODE_MOTOR_X 0x5A

8
User/BSP/status/elc_motor.cpp

@ -156,9 +156,10 @@ ECLMotor::~ECLMotor() {
// 读取电机的位置
int32_t ECLMotor::getPosition() {
osMutexAcquire(mutex_, osWaitForever);
int32_t pos = x_actual_;
const int32_t pos = x_actual_;
osMutexRelease(mutex_);
return pos;
const int32_t py_pos = ELCMotorHelper::isFlip(index_) ? -pos : pos;
return py_pos;
}
// 设置电机的目标位置
@ -247,7 +248,8 @@ int32_t ECLMotor::getEncoderPosition() {
osMutexAcquire(mutex_, osWaitForever);
int32_t encPos = enc_val_;
osMutexRelease(mutex_);
return encPos;
const int32_t py_pos = ELCMotorHelper::isFlip(index_) ? -encPos : encPos;
return py_pos;
}
// 设置编码器位置

2
User/BSP/status/elc_motor_helper.cpp

@ -41,7 +41,7 @@ const int32_t ELCMotorHelper::encLockRotorTH[MOTOR_NUM] = {500, 500, 500}; //
#if SUB_SPRAY_VERVION == SUB_SPRAY_VERVION_V1
const bool ELCMotorHelper::isFlip_[MOTOR_NUM] = {true, false, true};
#elif SUB_SPRAY_VERVION == SUB_SPRAY_VERVION_V2
const bool ELCMotorHelper::isFlip_[MOTOR_NUM] = {false, true, false};
const bool ELCMotorHelper::isFlip_[MOTOR_NUM] = {true, true, false};
#else
#endif

57
User/BSP/uart_cmd/cmd_process_service_process.cpp

@ -353,6 +353,31 @@ std::vector<uint8_t> handle_write_regsiter(uint16_t cmdId, uint16_t slaveId, uin
ZLOGI(TAG, "SET LASER POWER ADDRESS %d", power);
break;
}
case TMEP_CONTROL_NOZZLE_SET_TEMP_ADDRESS: {
const int32_t i_temp = value;
const double temp = abs(i_temp) * 0.1;
AppHardware::ins()->temp_control_nozzle.setTemp(temp);
ZLOGI(TAG, "SET NOZZLE TEMP %f", temp);
break;
}
case TMEP_CONTROL_NOZZLE_CLOSE_TEMP_ADDRESS: {
AppHardware::ins()->temp_control_nozzle.close();
ZLOGI(TAG, "CLOSE NOZZLE TEMP");
break;
}
case TMEP_CONTROL_SLIDE_SET_TEMP_ADDRESS: {
const int32_t i_temp = value;
const double temp = abs(i_temp) * 0.1;
AppHardware::ins()->temp_control_slide.setTemp(temp);
ZLOGI(TAG, "SET SLIDE TEMP %f", temp);
break;
}
case TMEP_CONTROL_SLIDE_CLOSE_TEMP_ADDRESS: {
AppHardware::ins()->temp_control_slide.close();
ZLOGI(TAG, "CLOSE SLIDE TEMP");
break;
}
default: {
break;
@ -467,7 +492,8 @@ std::vector<uint8_t> handle_read_coils(uint16_t cmdId, uint16_t slaveId, uint16_
if(count != 4) {
break;
}
const bool isE_Stop = ExtiKeyManager::ins()->isPinTriggered(E_STOP_PIN);
// const bool isE_Stop = ExtiKeyManager::ins()->isPinTriggered(E_STOP_PIN);
const bool isE_Stop = false;
const bool isPause = ExtiKeyManager::ins()->isPinTriggered(SYSTEM_POWER_PIN);
const uint8_t twvStatus = AppHardware::ins()->three_way_valve.getMode();
bool pumpIsNormal = AppHardware::ins()->pump_controller.isNoraml();
@ -528,7 +554,8 @@ std::vector<uint8_t> handle_read_coils(uint16_t cmdId, uint16_t slaveId, uint16_
break;
}
bool coils[count] = {0};
coils[0] = ExtiKeyManager::ins()->isPinTriggered(E_STOP_PIN);
// coils[0] = ExtiKeyManager::ins()->isPinTriggered(E_STOP_PIN);
coils[0] = false;
coils[1] = AppHardware::ins()->isLaunched();
coils[2] = !MotorManager::ins()->motors[0].isMoveFinished();
@ -603,7 +630,7 @@ std::vector<uint8_t> handle_read_registers(uint16_t cmdId, uint16_t slaveId, uin
}
bool is_flip = ELCMotorHelper::isFlip(motor_index);
int32_t motor_pos = MotorManager::ins()->motors[motor_index].getEncoderPosition();
int32_t motor_pos = MotorManager::ins()->motors[motor_index].getPosition();
#if defined TEST
motor_pos = (400 + motor_index) * 1000;
#else
@ -637,13 +664,33 @@ std::vector<uint8_t> handle_read_registers(uint16_t cmdId, uint16_t slaveId, uin
ZLOGI(TAG, "READ MOTOR [%d] RT_SPEED_READ_ADDRESS", motor_index);
break;
}
case TMEP_CONTROL_NOZZLE_READ_TEMP_ADDRESS: {
if(count != 1) {
break;
}
const double d_temp = AppHardware::ins()->temp_control_nozzle.getCurrentTemp();
const int16_t i_temp = int16_t(d_temp * 10);
data[0] = i_temp;
ack_msg = ModbusRtuProtocolFactory::createReadHoldingRegistersResponse(cmdId, slaveId, address, count, data);
break;
}
case TMEP_CONTROL_SLIDE_READ_TEMP_ADDRESS: {
if(count != 1) {
break;
}
const double d_temp = AppHardware::ins()->temp_control_slide.getCurrentTemp();
const int16_t i_temp = int16_t(d_temp * 10);
data[0] = i_temp;
ack_msg = ModbusRtuProtocolFactory::createReadHoldingRegistersResponse(cmdId, slaveId, address, count, data);
break;
}
case MOTOR_XYZ_ADDRESS: {
if(count != 6) {
break;
}
for(int motor_index = 0; motor_index < 3; motor_index++) {
const int32_t motor_pos = MotorManager::ins()->motors[motor_index].getEncoderPosition();
const int32_t motor_pos = MotorManager::ins()->motors[motor_index].getPosition();
intToShortArray(motor_pos, data + 2 * motor_index);
}
ack_msg = ModbusRtuProtocolFactory::createReadHoldingRegistersResponse(cmdId, slaveId, address, count, data);
@ -655,7 +702,7 @@ std::vector<uint8_t> handle_read_registers(uint16_t cmdId, uint16_t slaveId, uin
}
for(int motor_index = 0; motor_index < 3; motor_index++) {
int32_t motor_pos = MotorManager::ins()->motors[motor_index].getEncoderPosition();
int32_t motor_pos = MotorManager::ins()->motors[motor_index].getPosition();
intToShortArray(motor_pos, data + 4 * motor_index);
int32_t motor_speed = MotorManager::ins()->motors[motor_index].getRTSpeed();

Loading…
Cancel
Save