mks42d

package module
v0.0.0-...-313f337 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 8 Imported by: 0

README

MKS-SERVO42D-golang

Warning! Your mileage may vary with this project code as is, its primarily being shared as an example of how to use the documentation for this particular stepper motor controller.

This is a simple module for communicating serially with a MKS-SERVO42D_RS485 stepper motor controller board. We used the documentation and examples from the following repository.

Documentation

Index

Constants

View Source
const DEFAULT_ACCELERATION uint8 = 0
View Source
const DOWNLINK_HEAD byte = 0xFA
View Source
const MAX_MOTOR_ACCELERATION = 255
View Source
const MAX_MOTOR_SPEED = 3000
View Source
const MOTOR_TOTAL_STEPS = 200 // 200 for 1.8
View Source
const SLAVE_ADDRESS byte = 0x01
View Source
const UPLINK_HEAD byte = 0xFB

Variables

View Source
var S42DDriverConfig = serial.Config{
	Name:        "/dev/ttyUSB1",
	Baud:        115200,
	ReadTimeout: 3 * time.Millisecond,
}

Functions

func ByteArrayToString

func ByteArrayToString(array []byte) string

Types

type Direction

type Direction int
const (
	COUNTERCLOCKWISE Direction = iota // COUNTERCLOCKWISE is assigned 0 (DOWN)
	CLOCKWISE                         // CLOCKWISE is assigned 1 (UP)
)

type DriverCommand

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

type S42DDriver

type S42DDriver struct {
	SerialConfig *serial.Config

	EncoderAddition  uint // encoder value +/- for a full rotation
	ScrewPitch       uint // mm
	StepsPerRotation uint // usually 200 without microsteps
	StepsPerMm       uint // steps_per_rotation / screw_pitch
	// contains filtered or unexported fields
}

func (*S42DDriver) Close

func (driver *S42DDriver) Close() error

func (*S42DDriver) Connect

func (driver *S42DDriver) Connect() error

func (*S42DDriver) FindMaxBottom

func (driver *S42DDriver) FindMaxBottom() (int, error)

func (*S42DDriver) GoHome

func (driver *S42DDriver) GoHome() error

go to top of system. Note this resets all pulse counting

func (*S42DDriver) MoveOneRotation

func (driver *S42DDriver) MoveOneRotation(dir Direction, speed uint16) error

func (*S42DDriver) ReadDistance

func (driver *S42DDriver) ReadDistance() (float64, error)

this assumes we traveled in one direction from a 0 axis

func (*S42DDriver) ResetCounters

func (driver *S42DDriver) ResetCounters() error

func (*S42DDriver) StartGoingDown

func (driver *S42DDriver) StartGoingDown(speed uint16) error

func (*S42DDriver) StartGoingUp

func (driver *S42DDriver) StartGoingUp(speed uint16) error

type ServoMessage

type ServoMessage struct {
	Type    ServoMessageType
	Data    any
	Message string
}

type ServoMessageType

type ServoMessageType int
const (
	ServoError ServoMessageType = iota // 0 ...
	ServoTravelMessage
	ServoEncoderMessage
	ServoPulseCountMessage
)

type StepperDriver

type StepperDriver interface {
	Connect() error                  // initialize serial connection
	GetCurrentDistanceTraveled() int // get distance traveled since counter started in mm
	ResetCounters() error            // resets pulse and distance counters
	StartGoingDown() error           // start motor going forward
	StartGoingUp(speed uint16) error // start motor going in reverse
	Stop() error                     // stop all movement
	FindMaxBottom() (int, error)     // find the maximum encoder value to the bottom of the system
	GoHome(speed uint16) error       // go to the very top of the system
}

This module contains the abstraction for interacting with a stepper motor and its driver board. Each concrete implementation of this interface for different driver boards should be in their own files.

Jump to

Keyboard shortcuts

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