|
|
@ -6,6 +6,8 @@ |
|
|
|
#include "libtrinamic/src/ic/tmc2160.hpp"
|
|
|
|
#include "libtrinamic\src\ic\tmc4361A.hpp"
|
|
|
|
//
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "board/hardware.hpp"
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "libiflytop_micro\stm32\basic\zsignal.hpp"
|
|
|
@ -15,14 +17,14 @@ |
|
|
|
#include "lncubator_temperature_control_service.hpp"
|
|
|
|
#define TAG "main"
|
|
|
|
|
|
|
|
#define ACTIVE_REG(reg, mask, initval) IflytopCanProtocolStackProcesser::activeReg(&IflytopCanStackConfig, reg, mask, initval)
|
|
|
|
#define UPDATE_REG(reg, value, periodms) \
|
|
|
|
{ \ |
|
|
|
static uint32_t lastReportTicket = 0; \ |
|
|
|
if (m_hardware.hasPassedMS(lastReportTicket) > periodms) { \ |
|
|
|
lastReportTicket = m_hardware.getTicket(); \ |
|
|
|
m_protocolStack.writeRegValue(reg, value, false); \ |
|
|
|
} \ |
|
|
|
#define ACTIVE_REG(reg, mask, initval) IflytopCanProtocolStackProcesser::activeReg(&IflytopCanStackConfig, reg, mask, (initval))
|
|
|
|
#define UPDATE_REG(reg, value, periodms) \
|
|
|
|
{ \ |
|
|
|
static uint32_t lastReportTicket = 0; \ |
|
|
|
if (m_hardware.hasPassedMS(lastReportTicket) > (periodms + random(3))) { \ |
|
|
|
lastReportTicket = m_hardware.getTicket(); \ |
|
|
|
m_protocolStack.writeRegValue(reg, value, false); \ |
|
|
|
} \ |
|
|
|
} |
|
|
|
|
|
|
|
using namespace iflytop; |
|
|
@ -51,6 +53,7 @@ class Main : public HardwareListener, // |
|
|
|
virtual void LncubatorRotatingControlService_onMoveToHomeJobFinished(); |
|
|
|
virtual void LncubatorRotatingControlService_onMoveSubPositionJobFinished(); |
|
|
|
virtual void LncubatorRotatingControlService_onMoveByJobFinished(); |
|
|
|
virtual void LncubatorRotatingControlService_startWorking(int32_t dowhat); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* override HardwareListener * |
|
|
@ -67,9 +70,14 @@ class Main : public HardwareListener, // |
|
|
|
|
|
|
|
virtual icps::error_t IflytopCanProtocolStack_onHostRegisterReadEvent( //
|
|
|
|
icps::Reg_t *reg, int32_t &value); |
|
|
|
virtual void IflytopCanProtocolStack_onRegisterValueAutoReportEvent(icps::Reg_t *reg, int32_t &value); |
|
|
|
virtual void IflytopCanProtocolStack_onRegisterValueAutoReportEvent(icps::Reg_t *reg, int32_t &value); |
|
|
|
}; |
|
|
|
|
|
|
|
int random(int max) { |
|
|
|
// TODO:使用STM32的随机数功能生成随机数
|
|
|
|
return 0 % max; |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* CODE IMPL * |
|
|
|
*******************************************************************************/ |
|
|
@ -139,6 +147,53 @@ icps::error_t Main::IflytopCanProtocolStack_onHostRegisterWriteEvent( // |
|
|
|
} else if (reg->add == REG_TEMPERATURE_CTRL_DUMPVALUE) { |
|
|
|
m_tempCtrl.setDumpValue((bool)newvalue); |
|
|
|
} |
|
|
|
// 赋予转盘控制
|
|
|
|
else if (reg->add == REG_MOTOR_CTRL_TARGET_POSITION1) { |
|
|
|
if (m_rotatingCtrl.isWorkFinished()) { |
|
|
|
m_rotatingCtrl.moveToSubPosition(m_rotatingCtrl.REFPOINT_TYPE_INLET, newvalue); |
|
|
|
} else { |
|
|
|
return icps::kDeviceBusy; |
|
|
|
} |
|
|
|
newvalue = 0; |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_TARGET_POSITION2) { |
|
|
|
if (m_rotatingCtrl.isWorkFinished()) { |
|
|
|
m_rotatingCtrl.moveToSubPosition(m_rotatingCtrl.REFPOINT_TYPE_INLET, newvalue); |
|
|
|
} else { |
|
|
|
return icps::kDeviceBusy; |
|
|
|
} |
|
|
|
newvalue = 0; |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_BACK_TO_HOME) { |
|
|
|
if (m_rotatingCtrl.isWorkFinished()) { |
|
|
|
m_rotatingCtrl.moveToHome(); |
|
|
|
} else { |
|
|
|
return icps::kDeviceBusy; |
|
|
|
} |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_ROATE_PULSE) { |
|
|
|
if (m_rotatingCtrl.getDoWhat() == m_rotatingCtrl.kmoveByJob || //
|
|
|
|
m_rotatingCtrl.getDoWhat() == m_rotatingCtrl.kidle) { |
|
|
|
m_rotatingCtrl.moveBy(newvalue); |
|
|
|
} else { |
|
|
|
return icps::kDeviceBusy; |
|
|
|
} |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_STOP) { |
|
|
|
m_rotatingCtrl.stop(); |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_CALIBRATE_POSITION) { |
|
|
|
if (newvalue == 0) { |
|
|
|
m_rotatingCtrl.calibrationPosition(m_rotatingCtrl.REFPOINT_TYPE_INLET); |
|
|
|
} else if (newvalue == 1) { |
|
|
|
m_rotatingCtrl.calibrationPosition(m_rotatingCtrl.REFPOINT_TYPE_OUTLET); |
|
|
|
} |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_MAX_SPEED) { |
|
|
|
m_rotatingCtrl.setVelocity(newvalue); |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_ENTRY_POSITION) { |
|
|
|
m_rotatingCtrl.setInletPosition(newvalue); |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_EXIT_POSITION) { |
|
|
|
m_rotatingCtrl.setoutletPosition(newvalue); |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_ACCELERATION) { |
|
|
|
m_hardware.tmc_get_motor1()->setMaximumAcceleration(newvalue); |
|
|
|
} else if (reg->add == REG_MOTOR_CTRL_DECELERATION) { |
|
|
|
m_hardware.tmc_get_motor1()->setMaximumDeceleration(newvalue); |
|
|
|
} |
|
|
|
return icps::kSuccess; |
|
|
|
} |
|
|
|
|
|
|
@ -183,14 +238,47 @@ void Main::initializeIflytopCanProtocolStackProcesser() { |
|
|
|
ACTIVE_REG(REG_TEMPERATURE_CTRL_SENSOR2_TEMPERATURE /* */, icps::kr, 0); |
|
|
|
ACTIVE_REG(REG_TEMPERATURE_CTRL_SENSOR3_TEMPERATURE /* */, icps::kr, 0); |
|
|
|
ACTIVE_REG(REG_TEMPERATURE_CTRL_SENSOR4_TEMPERATURE /* */, icps::kr, 0); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 孵育区转盘控制 * |
|
|
|
*******************************************************************************/ |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_TARGET_POSITION1 /* */, icps::kw, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_TARGET_POSITION2 /* */, icps::kw, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_BACK_TO_HOME /* */, icps::kw, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_ROATE_PULSE /* */, icps::kw, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_CALIBRATE_POSITION /* */, icps::kw, 0); |
|
|
|
|
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_MAX_SPEED /* */, icps::kwr, REG_MOTOR_CTRL_MAX_SPEED_DEFAULT); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_ENTRY_POSITION /* */, icps::kwr, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_EXIT_POSITION /* */, icps::kwr, ONECIRCLE_USTEP_NUM / 2); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_ACCELERATION /* */, icps::kwr, REG_MOTOR_CTRL_ACCELERATION_DEFAULT); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_DECELERATION /* */, icps::kwr, REG_MOTOR_CTRL_DECELERATION_DEFAULT); |
|
|
|
|
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_CURRENT_POSITION1 /* */, icps::kr, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_CURRENT_POSITION2 /* */, icps::kr, SUB_POSITION_NUM / 2); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_CURRENT_POSITION3 /* */, icps::kr, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_CURRENT_POSITION4 /* */, icps::kr, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_CURRENT_ACTION /* */, icps::kr, 0); |
|
|
|
ACTIVE_REG(REG_MOTOR_CTRL_CURRENT_STATE /* */, icps::kr, 0); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::LncubatorRotatingControlService_onException(exception_id_t exception) {} |
|
|
|
void Main::LncubatorRotatingControlService_onMoveToHomeJobFinished() {} |
|
|
|
void Main::LncubatorRotatingControlService_onMoveSubPositionJobFinished() {} |
|
|
|
void Main::LncubatorRotatingControlService_onMoveByJobFinished() {} |
|
|
|
void Main::LncubatorRotatingControlService_onMoveToHomeJobFinished() { //
|
|
|
|
m_protocolStack.writeRegValue(REG_MOTOR_CTRL_CURRENT_STATE, 1, false); |
|
|
|
} |
|
|
|
void Main::LncubatorRotatingControlService_onMoveSubPositionJobFinished() { //
|
|
|
|
m_protocolStack.writeRegValue(REG_MOTOR_CTRL_CURRENT_STATE, 1, false); |
|
|
|
} |
|
|
|
void Main::LncubatorRotatingControlService_onMoveByJobFinished() { //
|
|
|
|
m_protocolStack.writeRegValue(REG_MOTOR_CTRL_CURRENT_STATE, 1, false); |
|
|
|
} |
|
|
|
void Main::LncubatorRotatingControlService_startWorking(int32_t dowhat) { //
|
|
|
|
m_protocolStack.writeRegValue(REG_MOTOR_CTRL_CURRENT_STATE, 0, false); |
|
|
|
m_protocolStack.writeRegValue(REG_MOTOR_CTRL_CURRENT_ACTION, dowhat, false); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::updateRegList() { //
|
|
|
|
|
|
|
|
UPDATE_REG(REG_TEMPERATURE_CTRL_MAIN_FAN_SPEED, m_hardware.fanReadState4(), 1000); |
|
|
|
UPDATE_REG(REG_TEMPERATURE_CTRL_SUB_FAN_SPEED, m_hardware.fanReadState0to3(), 1000); |
|
|
|
UPDATE_REG(REG_TEMPERATURE_CTRL_HEAT_TEMPERATURE, 0, 1000); |
|
|
@ -200,6 +288,13 @@ void Main::updateRegList() { // |
|
|
|
UPDATE_REG(REG_TEMPERATURE_CTRL_SENSOR2_TEMPERATURE, m_hardware.temperature_get_temp(1) * 100, 1000); |
|
|
|
UPDATE_REG(REG_TEMPERATURE_CTRL_SENSOR3_TEMPERATURE, m_hardware.temperature_get_temp(2) * 100, 1000); |
|
|
|
UPDATE_REG(REG_TEMPERATURE_CTRL_SENSOR4_TEMPERATURE, m_hardware.temperature_get_temp(3) * 100, 1000); |
|
|
|
|
|
|
|
UPDATE_REG(REG_MOTOR_CTRL_CURRENT_POSITION1, m_rotatingCtrl.getPositionIndex(m_rotatingCtrl.REFPOINT_TYPE_INLET), 100); |
|
|
|
UPDATE_REG(REG_MOTOR_CTRL_CURRENT_POSITION2, m_rotatingCtrl.getPositionIndex(m_rotatingCtrl.REFPOINT_TYPE_OUTLET), 100); |
|
|
|
// UPDATE_REG(REG_MOTOR_CTRL_CURRENT_POSITION3, m_rotatingCtrl.getPositionIndex(m_rotatingCtrl.REFPOINT_TYPE_HOME), 100);
|
|
|
|
UPDATE_REG(REG_MOTOR_CTRL_CURRENT_POSITION4, m_rotatingCtrl.getPositionPulse(), 100); |
|
|
|
UPDATE_REG(REG_MOTOR_CTRL_CURRENT_ACTION, m_rotatingCtrl.getDoWhat(), 33); |
|
|
|
UPDATE_REG(REG_MOTOR_CTRL_CURRENT_STATE, m_rotatingCtrl.isWorkFinished(), 33); |
|
|
|
} |
|
|
|
|
|
|
|
void Main::main(int argc, char const *argv[]) { |
|
|
@ -223,6 +318,8 @@ void Main::main(int argc, char const *argv[]) { |
|
|
|
// 初始化转盘控制器
|
|
|
|
m_rotatingCtrl.initialize(&m_hardware); |
|
|
|
m_rotatingCtrl.registerListener(this); |
|
|
|
m_rotatingCtrl.setVelocity(m_protocolStack.readRegValue(REG_MOTOR_CTRL_MAX_SPEED)); |
|
|
|
m_rotatingCtrl.setInletPosition(m_protocolStack.readRegValue(REG_MOTOR_CTRL_ENTRY_POSITION)); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
m_hardware.periodicJob(); |
|
|
|