Browse Source

update

master
zhaohe 2 years ago
parent
commit
a10c26be6e
  1. 78
      app/MDK-ARM/app.uvguix.h_zha
  2. 2
      dep/libtrinamic
  3. 5
      src/board/device_io_service.cpp
  4. 1
      src/board/device_io_service.hpp
  5. 23
      src/board/hardware.cpp
  6. 1
      src/board/hardware.hpp
  7. 14
      src/board/libtmcimpl.cpp
  8. 16
      src/board/libtmcimpl.hpp
  9. 38
      src/lncubator_rotating_control_service.cpp
  10. 22
      src/lncubator_rotating_control_service.hpp

78
app/MDK-ARM/app.uvguix.h_zha
File diff suppressed because it is too large
View File

2
dep/libtrinamic

@ -1 +1 @@
Subproject commit cab741ca3a6c542ebf25e6ef3a1d46766d035f55
Subproject commit 02807418568c7fdb1bee192424af3ad274b06269

5
src/board/device_io_service.cpp

@ -169,8 +169,9 @@ void DeviceIoService::tmc_nFREEZE_pin_set_state(uint8_t channel, bool state) {
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_12, state ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
}
void DeviceIoService::tmc_ENN_pin_set_state(uint8_t channel, bool state) {
if (channel == MOTOR_1_TMC2160_CHANNEL) {
void DeviceIoService::tmc_ENN_pin_set_state(uint8_t channel, bool state) {}
void DeviceIoService::tmc_subic_ENN_pin_set_state(uint8_t channel, bool state) {
if (channel == MOTOR_1_TMC4361A_CHANNEL) {
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_11, state ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
}

1
src/board/device_io_service.hpp

@ -53,6 +53,7 @@ class DeviceIoService : public IflytopMicroOS {
void tmc_extern_clk_enable();
void tmc_nFREEZE_pin_set_state(uint8_t channel, bool state);
void tmc_ENN_pin_set_state(uint8_t channel, bool state);
void tmc_subic_ENN_pin_set_state(uint8_t channel, bool state);
void tmc_nRESET_pin_set_state(uint8_t channel, bool state);
/*******************************************************************************

23
src/board/hardware.cpp

@ -3,7 +3,7 @@
#include "i2c.h"
using namespace iflytop;
#define TAG "hardware"
#define ENABLE_CAN 1
#define ENABLE_CAN 0
int32_t Hardware::port_tmc4361_get_version(uint8_t channel) {
int value;
@ -56,6 +56,7 @@ void Hardware::hardwareinit() {
// 4361初始化
TMC4361AImpl::TMC4361AConfig_t *tmc4361aconfig = TMC4361AImpl::createDeafultTMC4361AConfig();
tmc4361aconfig->encoder_config.diff_enc_in_disable = false;
tmc4361aconfig->encoder_config.invert_enc_dir = true; // 如果编码器方向和期望方向相反,设置为true
tmc4361aconfig->encoder_config.enc_in_res = 4000;
tmc4361aconfig->close_loop_config.enable_closed_loop = false;
@ -63,27 +64,29 @@ void Hardware::hardwareinit() {
tmc4361motor1.setMaximumAcceleration(300000);
tmc4361motor1.setMaximumDeceleration(300000);
// 2160初始化
tmc2160motor1.initialize(&m_deviceIoService, &tmc4361motor1, MOTOR_1_TMC2160_CHANNEL);
tmc2160motor1.setMaximumCurrent(3);
HAL_Delay(100);
// 使能电机
tmc2160motor1.enableIC(true);
tmc4361motor1.enableIC(true);
/**
* @brief Version寄存器来判断芯片是否正常
*/
int32_t ic4361Version = tmc4361motor1.readICVersion();
int32_t ic2160Version = tmc2160motor1.readICVersion();
int32_t ic2160Version = tmc4361motor1.read2160ICVersion();
ZLOGI(TAG, "TMC4361Version:%x TMC2160VERSION:%x", ic4361Version, ic2160Version);
if (ic4361Version != 2 || ic2160Version != 30) {
if (ic4361Version != 2) {
ZLOGE(TAG, "TMC4361 or TMC2160 is not normal");
}
// 期望 4361Version:2 ic2160Version:30
// tmc4361motor1.stop();
#if 1
// 测试编码器方向
tmc4361motor1.rotate(-300000);
while (true) {
HAL_Delay(100);
ZLOGI(TAG, "TMC4361A: XACTUAL:%d ENC_POS:%d DIFF:%d", tmc4361motor1.getXACTUAL(), tmc4361motor1.getENC_POS(), tmc4361motor1.getENC_POS_DEV());
}
#endif
tmc4361motor1.rotate(300000);
#endif
/*******************************************************************************
* *

1
src/board/hardware.hpp

@ -13,7 +13,6 @@ class Hardware {
public:
TMC4361AImpl tmc4361motor1;
TMC2160Impl tmc2160motor1;
TMP117 tmp117[4];
FanStateMonitor m_fanStateMonitor[6];
IflytopCanSlave canSlaveService;

14
src/board/libtmcimpl.cpp

@ -10,26 +10,14 @@ using namespace std;
void TMC4361AImpl::setResetPinState(bool state) { m_deviceIoService->tmc_nRESET_pin_set_state(m_channel, state); };
void TMC4361AImpl::setFREEZEPinState(bool state) { m_deviceIoService->tmc_nFREEZE_pin_set_state(m_channel, state); };
void TMC4361AImpl::setENNPinState(bool state) { m_deviceIoService->tmc_ENN_pin_set_state(m_channel, state); };
void TMC4361AImpl::setSubICENNPinState(bool state) { m_deviceIoService->tmc_subic_ENN_pin_set_state(m_channel, state); }
bool TMC4361AImpl::getTargetReachedPinState() { return false; };
void TMC4361AImpl::sleepus(int32_t us) { m_deviceIoService->sleepus(us); };
void TMC4361AImpl::readWriteArray(uint8_t *data, size_t length) { //
m_deviceIoService->tmc_motor_spi_write_and_read(m_channel, data, length);
};
void TMC4361AImpl::initialize(DeviceIoService *deviceIoService, uint8_t channel, driver_ic_type_t driver_ic_type, TMC4361AConfig_t *config) {
m_deviceIoService = deviceIoService;
TMC4361A::initialize(channel, driver_ic_type, config);
}
/*******************************************************************************
* TMC2160Impl *
*******************************************************************************/
void TMC2160Impl::initialize(DeviceIoService *deviceIoService, TMC4361A *tmc4361, uint8_t channelId) {
m_tmc4361 = tmc4361;
m_deviceIoService = deviceIoService;
TMC2160::initialize(channelId);
}
void TMC2160Impl::setENNPinState(bool state) { m_deviceIoService->tmc_ENN_pin_set_state(m_channel, state); };
void TMC2160Impl::sleepus(int32_t us) { m_deviceIoService->sleepus(us); };
void TMC2160Impl::readWriteArray(uint8_t *data, size_t length) { m_tmc4361->readWriteCover(data, length); };
} // namespace iflytop

16
src/board/libtmcimpl.hpp

@ -19,23 +19,9 @@ class TMC4361AImpl : public TMC4361A {
virtual bool getTargetReachedPinState();
virtual void sleepus(int32_t us);
virtual void readWriteArray(uint8_t *data, size_t length);
virtual void setSubICENNPinState(bool state);
public:
void initialize(DeviceIoService *deviceIoService, uint8_t channel, driver_ic_type_t driver_ic_type, TMC4361AConfig_t *config);
};
/**
* @brief TMC2160和硬件的接口
*/
class TMC2160Impl : public TMC2160 {
TMC4361A *m_tmc4361;
DeviceIoService *m_deviceIoService;
public:
void initialize(DeviceIoService *deviceIoService, TMC4361A *tmc4361, uint8_t channelId);
protected:
virtual void setENNPinState(bool state);
virtual void sleepus(int32_t us);
virtual void readWriteArray(uint8_t *data, size_t length);
};
} // namespace iflytop

38
src/lncubator_rotating_control_service.cpp

@ -2,23 +2,43 @@
using namespace iflytop;
const uint32_t LncubatorRotatingControlService::mc_onecircle_ustep_num = (256 * 200 * 50);
const uint32_t LncubatorRotatingControlService::mc_default_velocity = 500000; // 500k
LncubatorRotatingControlService::LncubatorRotatingControlService() {}
LncubatorRotatingControlService::~LncubatorRotatingControlService() {}
/**
* @brief
*
*
* 1.
* 2.
* 3.
*
*/
void LncubatorRotatingControlService::initialize(Hardware* hardware) { //
m_hardware = hardware;
m_motor = &m_hardware->tmc4361motor1;
m_os = &m_hardware->m_deviceIoService;
m_hardware = hardware;
m_motor = &m_hardware->tmc4361motor1;
m_os = &m_hardware->m_deviceIoService;
m_workfinished = false;
m_dowhat = kidle;
m_maxVelocity = mc_default_velocity;
/**
* @brief
*/
m_motor->setMotorInPositionMode();
}
void LncubatorRotatingControlService::setVelocity(uint32_t velocityMax) { m_maxVelocity = velocityMax; }
void LncubatorRotatingControlService::rotate(uint32_t count) {
m_motor->moveBy(count, m_maxVelocity);
void LncubatorRotatingControlService::moveToHome() {
m_dowhat = krotateToHome;
m_motor->moveTo(mc_onecircle_ustep_num * 2, m_maxVelocity);
}
}
void LncubatorRotatingControlService::setVelocity(uint32_t velocityMax) { m_maxVelocity = velocityMax; }
void LncubatorRotatingControlService::rotate(uint32_t count) { m_motor->moveBy(count, m_maxVelocity); }
void LncubatorRotatingControlService::periodicJob() {
if (krotateToHome) {
}
}

22
src/lncubator_rotating_control_service.hpp

@ -27,19 +27,32 @@ class LncubatorRotatingControlService {
REFPOINT_TYPE_ZERO, // 零点
} refpoint_t;
static const uint32_t mc_onecircle_ustep_num;
static const uint32_t mc_default_velocity;
private:
typedef enum {
kidle,
krotateToTarget,
krotateToHome,
} dowhat_t;
/* data */
Hardware* m_hardware;
IflytopMicroOS* m_os;
TMC4361AImpl* m_motor;
dowhat_t m_dowhat;
// 零点位置
uint32_t m_zeroPosition;
uint32_t m_homePosition;
// 便宜修正,第一个仓位中心距离零点的距离
uint32_t m_ZeroOffsetCorrection;
uint32_t m_homeOffsetCorrection;
uint32_t m_maxVelocity = 0;
bool m_workfinished;
bool homeKeyTriggered;
public:
LncubatorRotatingControlService();
~LncubatorRotatingControlService();
@ -48,8 +61,9 @@ class LncubatorRotatingControlService {
void setVelocity(uint32_t velocityMax);
void rotate(uint32_t count);
void moveToZero();
void moveToHome();
void moveTo(refpoint_t refpoint, uint32_t positionIndex);
void stop();
/**
* @brief
@ -58,5 +72,7 @@ class LncubatorRotatingControlService {
* @param positionIndex
*/
void calibrationPosition(refpoint_t refpoint, uint32_t positionIndex);
void periodicJob();
};
} // namespace iflytop
Loading…
Cancel
Save