rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
StepperMotorBase Class Reference

#include <stepper.h>

Inheritance diagram for StepperMotorBase:
Inheritance graph
[legend]
Collaboration diagram for StepperMotorBase:
Collaboration graph
[legend]

Public Member Functions

virtual void initialize (StepperHw *hardware, int totalSteps)
 
void doIteration ()
 
void setTargetPosition (float targetPositionSteps)
 
float getTargetPosition () const
 
bool isBusy () const
 

Data Fields

int m_currentPosition = 0
 
int m_totalSteps = 0
 

Protected Member Functions

void setInitialPosition (void)
 
void saveStepperPos (int pos)
 
int loadStepperPos ()
 
void changeCurrentPosition (bool positive)
 
void postCurrentPosition (void)
 

Protected Attributes

StepperHwm_hw = nullptr
 
float m_targetPosition = 0
 
bool initialPositionSet = false
 
bool m_isBusy = false
 

Detailed Description

Definition at line 66 of file stepper.h.

Member Function Documentation

◆ changeCurrentPosition()

void StepperMotorBase::changeCurrentPosition ( bool  positive)
protected

Definition at line 51 of file stepper.cpp.

51 {
52 if (positive) {
54 } else {
56 }
58}
void postCurrentPosition(void)
Definition stepper.cpp:60
int m_currentPosition
Definition stepper.h:76

Referenced by doIteration(), and setInitialPosition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doIteration()

void StepperMotorBase::doIteration ( )

Definition at line 125 of file stepper.cpp.

125 {
126 int targetPosition = efiRound(getTargetPosition(), 1);
127 int currentPosition = m_currentPosition;
128
129 // stepper requires +12V
130 if (!isIgnVoltage()) {
131 initialPositionSet = false;
132 m_hw->pause();
133 return;
134 }
135
136 if (!initialPositionSet) {
138 return;
139 }
140
141 if (targetPosition == currentPosition) {
142 m_hw->sleep();
143 m_isBusy = false;
144 return;
145 }
146
147 m_isBusy = true;
148
149 bool isIncrementing = targetPosition > currentPosition;
150
151 if (m_hw->step(isIncrementing)) {
152 changeCurrentPosition(isIncrementing);
153 }
154
155 // save position to backup RTC register
156#if EFI_PROD_CODE
158#endif
159}
virtual void sleep()
Definition stepper.cpp:193
virtual bool step(bool positive)=0
void pause(int divisor=1) const
Definition stepper.cpp:197
float getTargetPosition() const
Definition stepper.cpp:14
StepperHw * m_hw
Definition stepper.h:88
bool initialPositionSet
Definition stepper.h:91
void saveStepperPos(int pos)
Definition stepper.cpp:35
void setInitialPosition(void)
Definition stepper.cpp:68
void changeCurrentPosition(bool positive)
Definition stepper.cpp:51
float efiRound(float value, float precision)
Definition efilib.cpp:34
bool isIgnVoltage()

Referenced by StepperMotor::ThreadTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTargetPosition()

float StepperMotorBase::getTargetPosition ( ) const

Definition at line 14 of file stepper.cpp.

14 {
15 return m_targetPosition;
16}
float m_targetPosition
Definition stepper.h:90

Referenced by doIteration(), and IdleController::getIdlePosition().

Here is the caller graph for this function:

◆ initialize()

void StepperMotorBase::initialize ( StepperHw hardware,
int  totalSteps 
)
virtual

Reimplemented in StepperMotor.

Definition at line 26 of file stepper.cpp.

26 {
27 m_totalSteps = maxI(3, totalSteps);
28
29 m_hw = hardware;
30}

Referenced by StepperMotor::initialize().

Here is the caller graph for this function:

◆ isBusy()

bool StepperMotorBase::isBusy ( ) const

Definition at line 161 of file stepper.cpp.

161 {
162 return m_isBusy;
163}

◆ loadStepperPos()

int StepperMotorBase::loadStepperPos ( )
protected

Definition at line 43 of file stepper.cpp.

43 {
44#if EFI_PROD_CODE && EFI_BACKUP_SRAM
46#else
47 return 0;
48#endif
49}
uint32_t backupRamLoad(backup_ram_e idx)

Referenced by setInitialPosition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ postCurrentPosition()

void StepperMotorBase::postCurrentPosition ( void  )
protected

Definition at line 60 of file stepper.cpp.

60 {
61 if (engineConfiguration->debugMode == DBG_STEPPER_IDLE_CONTROL) {
62#if EFI_TUNER_STUDIO
64#endif /* EFI_TUNER_STUDIO */
65 }
66}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration

Referenced by changeCurrentPosition(), and saveStepperPos().

Here is the caller graph for this function:

◆ saveStepperPos()

void StepperMotorBase::saveStepperPos ( int  pos)
protected

Definition at line 35 of file stepper.cpp.

35 {
36 // use backup-power RTC registers to store the data
37#if EFI_PROD_CODE && EFI_BACKUP_SRAM
39#endif
41}
void backupRamSave(backup_ram_e idx, uint32_t value)

Referenced by doIteration(), and setInitialPosition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInitialPosition()

void StepperMotorBase::setInitialPosition ( void  )
protected

let's park the motor in a known position to begin with

I believe it's safer to retract the valve for parking - at least on a bench I've seen valves disassembling themselves while pushing too far out.

Add extra steps to compensate step skipping by some old motors.

Definition at line 68 of file stepper.cpp.

68 {
69 // try to get saved stepper position (-1 for no data)
71
72#if HAL_USE_ADC
73 // first wait until at least 1 slowADC sampling is complete
75#endif
76
77#if EFI_SHAFT_POSITION_INPUT
79#else
80 bool isRunning = false;
81#endif /* EFI_SHAFT_POSITION_INPUT */
82 // now check if stepper motor re-initialization is requested - if the throttle pedal is pressed at startup
84 bool forceStepperParking = !isRunning && tpsPos > STEPPER_PARKING_TPS;
86 forceStepperParking = true;
87 efiPrintf("Stepper: savedStepperPos=%d forceStepperParking=%d (tps=%.2f)", m_currentPosition, (forceStepperParking ? 1 : 0), tpsPos);
88
89 if (m_currentPosition < 0 || forceStepperParking) {
90 efiPrintf("Stepper: starting parking time=%lums", getTimeNowMs());
91 // reset saved value
93
94 /**
95 * let's park the motor in a known position to begin with
96 *
97 * I believe it's safer to retract the valve for parking - at least on a bench I've seen valves
98 * disassembling themselves while pushing too far out.
99 *
100 * Add extra steps to compensate step skipping by some old motors.
101 */
102 int numParkingSteps = (int)efiRound((1.0f + (float)engineConfiguration->stepperParkingExtraSteps / PERCENT_MULT) * m_totalSteps, 1.0f);
103 for (int i = 0; i < numParkingSteps; i++) {
104 if (!m_hw->step(false)) {
105 initialPositionSet = false;
106 return;
107 }
109 }
110
111 // set & save zero stepper position after the parking completion
114 // todo: is this a slow operation on the start-up path?
115 efiPrintf("Stepper: parking finished time=%lums", getTimeNowMs());
116 } else {
117 // The initial target position should correspond to the saved stepper position.
118 // Idle thread starts later and sets a new target position.
120 }
121
122 initialPositionSet = true;
123}
void waitForSlowAdc(uint32_t lastAdcCounter=1)
RpmCalculator rpmCalculator
Definition engine.h:306
bool isRunning() const
static float getOrZero(SensorType type)
Definition sensor.h:83
void setTargetPosition(float targetPositionSteps)
Definition stepper.cpp:18
int loadStepperPos()
Definition stepper.cpp:43
efitimems_t getTimeNowMs()
Returns the 32 bit number of milliseconds since the board initialization.
Definition efitime.cpp:34
@ DriverThrottleIntent
static bool isRunning

Referenced by doIteration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setTargetPosition()

void StepperMotorBase::setTargetPosition ( float  targetPositionSteps)

Definition at line 18 of file stepper.cpp.

18 {
19 // When the IAC position value change is insignificant (lower than this threshold), leave the poor valve alone
20 // When we get a larger change, actually update the target stepper position
21 if (std::abs(m_targetPosition - targetPositionSteps) >= 1) {
22 m_targetPosition = targetPositionSteps;
23 }
24}

Referenced by setInitialPosition().

Here is the caller graph for this function:

Field Documentation

◆ initialPositionSet

bool StepperMotorBase::initialPositionSet = false
protected

Definition at line 91 of file stepper.h.

Referenced by doIteration(), and setInitialPosition().

◆ m_currentPosition

int StepperMotorBase::m_currentPosition = 0

◆ m_hw

StepperHw* StepperMotorBase::m_hw = nullptr
protected

Definition at line 88 of file stepper.h.

Referenced by doIteration(), initialize(), setInitialPosition(), and StepperMotor::ThreadTask().

◆ m_isBusy

bool StepperMotorBase::m_isBusy = false
protected

Definition at line 92 of file stepper.h.

Referenced by doIteration(), and isBusy().

◆ m_targetPosition

float StepperMotorBase::m_targetPosition = 0
protected

Definition at line 90 of file stepper.h.

Referenced by getTargetPosition(), and setTargetPosition().

◆ m_totalSteps

int StepperMotorBase::m_totalSteps = 0

Definition at line 77 of file stepper.h.

Referenced by initialize(), and setInitialPosition().


The documentation for this class was generated from the following files: