dimensionengineering

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package dimensionengineering contains implementations of the dimensionengineering motor controls

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMotor

func NewMotor(ctx context.Context, c *Config, logger golog.Logger) (motor.LocalMotor, error)

NewMotor returns a Sabertooth driven motor.

Types

type Config

type Config struct {
	// path to /dev/ttyXXXX file
	SerialPath string `json:"serial_path"`

	// The baud rate of the controller
	BaudRate int `json:"serial_baud_rate,omitempty"`

	// Valid values are 128-135
	SerialAddress int `json:"serial_address"`

	// Valid values are 1/2
	MotorChannel int `json:"motor_channel"`

	// Flip the direction of the signal sent to the controller.
	// Due to wiring/motor orientation, "forward" on the controller may not represent "forward" on the robot
	DirectionFlip bool `json:"dir_flip,omitempty"`

	// A value to control how quickly the controller ramps to a particular setpoint
	RampValue int `json:"controller_ramp_value,omitempty"`

	// The maximum freewheel rotational velocity of the motor after the final drive (maximum effective wheel speed)
	MaxRPM float64 `json:"max_rpm,omitempty"`

	// The name of the encoder used for this motor
	Encoder string `json:"encoder,omitempty"`

	// The lowest power percentage to allow for this motor. This is used to prevent motor stalls and overheating. Default is 0.0
	MinPowerPct float64 `json:"min_power_pct,omitempty"`

	// The max power percentage to allow for this motor. Default is 0.0
	MaxPowerPct float64 `json:"max_power_pct,omitempty"`

	// The number of ticks per rotation of this motor from the encoder
	TicksPerRotation int `json:"ticks_per_rotation,omitempty"`

	// TestChan is a fake "serial" path for test use only
	TestChan chan []byte `json:"-,omitempty"`
}

Config adds DimensionEngineering-specific config options.

func (*Config) Validate

func (cfg *Config) Validate(path string) error

Validate ensures all parts of the config are valid.

type Motor

type Motor struct {

	// which channel the motor is connected to on the controller
	Channel int
	// contains filtered or unexported fields
}

Motor is a single axis/motor/component instance.

func (*Motor) Close

func (m *Motor) Close()

Close stops the motor and marks the axis inactive.

func (*Motor) DoCommand

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

DoCommand executes additional commands beyond the Motor{} interface.

func (*Motor) GoFor

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

GoFor moves an inputted number of revolutions at the given rpm, no encoder is present for this so power is determined via a linear relationship with the maxRPM and the distance traveled is a time based estimation based on desired RPM.

func (*Motor) GoTillStop

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

GoTillStop moves a motor until stopped by the controller (due to switch or function) or stopFunc.

func (*Motor) GoTo

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

GoTo instructs the motor to go to a specific position (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/position.

func (*Motor) IsMoving

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

IsMoving returns whether the motor is currently moving.

func (*Motor) IsPowered

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

IsPowered returns if the motor is currently on or off.

func (*Motor) Position

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

Position reports the position in revolutions.

func (*Motor) Properties

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

Properties returns the additional features supported by this motor.

func (*Motor) ResetZeroPosition

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

ResetZeroPosition defines the current position to be zero (+/- offset).

func (*Motor) SetPower

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

SetPower instructs the motor to go in a specific direction at a percentage of power between -1 and 1.

func (*Motor) Stop

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

Stop turns the power to the motor off immediately, without any gradual step down.

Jump to

Keyboard shortcuts

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