tmcstepper

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package tmcstepper implements a TMC stepper motor.

Index

Constants

View Source
const (
	Command = "command"
	Home    = "home"
	Jog     = "jog"
	RPMVal  = "rpm"
)

Do() related constants.

Variables

This section is empty.

Functions

func NewMotor

NewMotor returns a TMC5072 driven motor.

Types

type Motor

type Motor struct {
	// contains filtered or unexported fields
}

A Motor represents a brushless motor connected via a TMC controller chip (ex: TMC5072).

func (*Motor) AtVelocity

func (m *Motor) AtVelocity(ctx context.Context) (bool, error)

AtVelocity returns true if the motor has reached the requested velocity.

func (*Motor) Do

func (m *Motor) Do(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error)

Do executes additional commands beyond the Motor{} interface.

func (*Motor) Enable

func (m *Motor) Enable(ctx context.Context, turnOn bool) error

Enable pulls down the hardware enable pin, activating the power stage of the chip.

func (*Motor) GetPosition

func (m *Motor) GetPosition(ctx context.Context, extra map[string]interface{}) (float64, error)

GetPosition gives the current motor position.

func (*Motor) GetProperties added in v0.0.9

func (m *Motor) GetProperties(ctx context.Context, extra map[string]interface{}) (map[motor.Feature]bool, error)

GetProperties returns the status of optional features on the motor.

func (*Motor) GetSG

func (m *Motor) GetSG(ctx context.Context) (int32, error)

GetSG returns the current StallGuard reading (effectively an indication of motor load.)

func (*Motor) GoFor

func (m *Motor) GoFor(ctx context.Context, rpm, rotations float64, extra map[string]interface{}) error

GoFor turns in the given direction the given number of times at the given speed. Both the RPM and the revolutions can be assigned negative values to move in a backwards direction. Note: if both are negative the motor will spin in the forward direction.

func (*Motor) GoTillStop

func (m *Motor) GoTillStop(ctx context.Context, rpm float64, stopFunc func(ctx context.Context) bool) error

GoTillStop enables StallGuard detection, then moves in the direction/speed given until resistance (endstop) is detected.

func (*Motor) GoTo

func (m *Motor) GoTo(ctx context.Context, rpm, positionRevolutions float64, extra map[string]interface{}) error

GoTo moves to the specified position in terms of (provided in revolutions from home/zero), at a specific speed. Regardless of the directionality of the RPM this function will move the motor towards the specified target.

func (*Motor) Home

func (m *Motor) Home(ctx context.Context) error

Home homes the motor using stallguard.

func (*Motor) IsMoving

func (m *Motor) IsMoving(ctx context.Context) (bool, error)

IsMoving returns true if the motor is currently moving.

func (*Motor) IsPowered

func (m *Motor) IsPowered(ctx context.Context, extra map[string]interface{}) (bool, error)

IsPowered returns true if the motor is currently moving.

func (*Motor) IsStopped

func (m *Motor) IsStopped(ctx context.Context) (bool, error)

IsStopped returns true if the motor is NOT moving.

func (*Motor) Jog

func (m *Motor) Jog(ctx context.Context, rpm float64) error

Jog sets a fixed RPM.

func (*Motor) ResetZeroPosition

func (m *Motor) ResetZeroPosition(ctx context.Context, offset float64, extra map[string]interface{}) error

ResetZeroPosition sets the current position of the motor specified by the request (adjusted by a given offset) to be its new zero position.

func (*Motor) SetPower

func (m *Motor) SetPower(ctx context.Context, powerPct float64, extra map[string]interface{}) error

SetPower sets the motor at a particular rpm based on the percent of maxRPM supplied by powerPct (between -1 and 1).

func (*Motor) Stop

func (m *Motor) Stop(ctx context.Context, extra map[string]interface{}) error

Stop stops the motor.

type TMC5072Config

type TMC5072Config struct {
	motor.Config
	SPIBus      string  `json:"spi_bus"`
	ChipSelect  string  `json:"chip_select"`
	Index       int     `json:"index"`
	SGThresh    int32   `json:"sg_thresh"`
	HomeRPM     float64 `json:"home_rpm"`
	CalFactor   float64 `json:"cal_factor"`
	RunCurrent  int32   `json:"run_current"`  // 1-32 as a percentage of rsense voltage, 15 default
	HoldCurrent int32   `json:"hold_current"` // 1-32 as a percentage of rsense voltage, 8 default
	HoldDelay   int32   `json:"hold_delay"`   // 0=instant powerdown, 1-15=delay * 2^18 clocks, 6 default
}

TMC5072Config extends motor.Config, mainly for RegisterComponentAttributeMapConverter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL