Cache TMC error flags inside movable_base class

pull/112/head
D.R.racer 2021-08-31 09:19:37 +02:00 committed by DRracer
parent 309d4704b7
commit ac78619b5b
4 changed files with 17 additions and 10 deletions

View File

@ -39,7 +39,7 @@ struct __attribute__((packed)) ErrorFlags {
uint8_t s2g : 1; ///< short to ground
uint8_t otpw : 1; ///< over temperature pre-warning
uint8_t ot : 1; ///< over temperature hard
inline ErrorFlags()
inline constexpr ErrorFlags()
: reset_flag(0)
, uv_cp(0)
, s2g(0)

View File

@ -10,22 +10,22 @@ inline ErrorCode &operator|=(ErrorCode &a, ErrorCode b) {
return a = (ErrorCode)((uint16_t)a | (uint16_t)b);
}
static ErrorCode TMC2130ToErrorCode(const hal::tmc2130::TMC2130 &tmc, uint8_t tmcIndex) {
static ErrorCode TMC2130ToErrorCode(const hal::tmc2130::ErrorFlags &ef, uint8_t tmcIndex) {
ErrorCode e = ErrorCode::RUNNING;
if (tmc.GetErrorFlags().reset_flag) {
if (ef.reset_flag) {
e |= ErrorCode::TMC_RESET;
}
if (tmc.GetErrorFlags().uv_cp) {
if (ef.uv_cp) {
e |= ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP;
}
if (tmc.GetErrorFlags().s2g) {
if (ef.s2g) {
e |= ErrorCode::TMC_SHORT_TO_GROUND;
}
if (tmc.GetErrorFlags().otpw) {
if (ef.otpw) {
e |= ErrorCode::TMC_OVER_TEMPERATURE_WARN;
}
if (tmc.GetErrorFlags().ot) {
if (ef.ot) {
e |= ErrorCode::TMC_OVER_TEMPERATURE_ERROR;
}
@ -53,11 +53,11 @@ bool CommandBase::Step() {
// check the global HW errors - may be we should avoid the modules layer and check for the HAL layer errors directly
if (mi::idler.State() == mi::Idler::Failed) {
state = ProgressCode::ERRTMCFailed;
tmcErr |= TMC2130ToErrorCode(mm::motion.DriverForAxis(mm::Axis::Idler), mm::Axis::Idler);
tmcErr |= TMC2130ToErrorCode(mi::idler.TMCErrorFlags(), mm::Axis::Idler);
}
if (ms::selector.State() == ms::Selector::Failed) {
state = ProgressCode::ERRTMCFailed;
tmcErr |= TMC2130ToErrorCode(mm::motion.DriverForAxis(mm::Axis::Selector), mm::Axis::Selector);
tmcErr |= TMC2130ToErrorCode(ms::selector.TMCErrorFlags(), mm::Axis::Selector);
}
// may be we should model the Pulley as well...
// if (ms::selector.State() == ms::Selector::Failed) {

View File

@ -16,8 +16,9 @@ MovableBase::OperationResult MovableBase::InitMovement(config::Axis axis) {
}
void MovableBase::PerformMove(config::Axis axis) {
if (!mm::motion.DriverForAxis(axis).GetErrorFlags().Good()) {
if (!mm::motion.DriverForAxis(axis).GetErrorFlags().Good()) { // @@TODO check occasionally, i.e. not every time?
// TMC2130 entered some error state, the planned move couldn't have been finished - result of operation is Failed
tmcErrorFlags = mm::motion.DriverForAxis(axis).GetErrorFlags(); // save the failed state
state = Failed;
} else if (mm::motion.QueueEmpty(axis)) {
// move finished

View File

@ -1,6 +1,7 @@
#pragma once
#include <stdint.h>
#include "../config/axis.h"
#include "../hal/tmc2130.h"
namespace modules {
namespace motion {
@ -37,6 +38,8 @@ public:
/// @returns internal state of the state machine
inline uint8_t State() const { return state; }
inline hal::tmc2130::ErrorFlags TMCErrorFlags() const { return tmcErrorFlags; }
protected:
/// internal state of the automaton
uint8_t state;
@ -47,6 +50,9 @@ protected:
/// current slot
uint8_t currentSlot;
/// cached TMC2130 error flags - being read only if the axis is enabled and doing something (moving)
hal::tmc2130::ErrorFlags tmcErrorFlags;
virtual void PrepareMoveToPlannedSlot() = 0;
OperationResult InitMovement(config::Axis axis);