Table of Contents

Class StepDir<TLine>

Namespace
Pamoja.Actuators
Assembly
Pamoja.Actuators.dll

A stepper behind a step and direction driver chip such as an A4988 or a DRV8825, as pamoja_actuators::stepper::StepDir drives one in Rust.

public sealed class StepDir<TLine> where TLine : IOutputLine

Type Parameters

TLine

The step and direction lines.

Inheritance
StepDir<TLine>
Inherited Members

Examples

var motor = new StepDir<PinScript>(new PinScript(), new PinScript(), delay: new DelayLog());
motor.Steps(-1);
// motor.Position is -1

Remarks

Each step sets the direction line, high for forward, and holds it for the pulse width, since the chip reads the direction on the step line's rising edge and needs it settled first. Then it pulses the step line high for the pulse width, brings it low, and waits the step interval. Microstepping, current limiting, and enable are the chip's own pins and settings, outside this driver.

Constructors

StepDir(TLine, TLine, uint, uint, IDelay?)

Wraps the step and direction lines, without driving them.

public StepDir(TLine step, TLine direction, uint pulseMicros = 10, uint stepMicros = 2000, IDelay? delay = null)

Parameters

step TLine

The line the chip counts rising edges on.

direction TLine

The line the chip reads the direction from; high is forward.

pulseMicros uint

How long the direction line is held before the step line rises, and the step line is then held high.

stepMicros uint

The pause after each step, which sets the speed.

delay IDelay

What waits: a SleepDelay unless given, or a DelayLog to run with nothing plugged in.

Properties

Position

The step count since the driver was built, forward positive.

public int Position { get; }

Property Value

int

PulseMicros

How long the direction is held before each step pulse, and the pulse itself, in microseconds.

public uint PulseMicros { get; }

Property Value

uint

StepMicros

The pause after each step, in microseconds.

public uint StepMicros { get; }

Property Value

uint

Methods

Release()

Hands the lines back.

public (TLine Step, TLine Direction) Release()

Returns

(TLine Step, TLine Direction)

The step line, then the direction line.

Step(StepDirection)

Takes one step and waits the step interval.

public void Step(StepDirection direction)

Parameters

direction StepDirection

Which way to step.

Exceptions

Exception

Whatever a line throws when it cannot be driven.

Steps(int)

Takes count steps, backward when negative.

public void Steps(int count)

Parameters

count int

The signed number of steps.

Exceptions

Exception

Whatever a line throws; the steps already taken stay counted.