Documentation ¶
Overview ¶
Package gpio implements a GPIO based motor.
Index ¶
- func NewEncodedMotor(conf resource.Config, motorConfig Config, realMotor motor.Motor, ...) (motor.Motor, error)
- func NewMotor(b board.Board, mc Config, name resource.Name, logger golog.Logger) (motor.Motor, error)
- func WrapMotorWithEncoder(ctx context.Context, e encoder.Encoder, c resource.Config, mc Config, ...) (motor.Motor, error)
- type Config
- type EncodedMotor
- func (m *EncodedMotor) Close(ctx context.Context) error
- func (m *EncodedMotor) DirectionMoving() int64
- func (m *EncodedMotor) GoFor(ctx context.Context, rpm, revolutions float64, extra map[string]interface{}) error
- func (m *EncodedMotor) GoTo(ctx context.Context, rpm, targetPosition float64, extra map[string]interface{}) error
- func (m *EncodedMotor) IsMoving(ctx context.Context) (bool, error)
- func (m *EncodedMotor) IsPowered(ctx context.Context, extra map[string]interface{}) (bool, float64, error)
- func (m *EncodedMotor) Position(ctx context.Context, extra map[string]interface{}) (float64, error)
- func (m *EncodedMotor) Properties(ctx context.Context, extra map[string]interface{}) (motor.Properties, error)
- func (m *EncodedMotor) RPMMonitorCalls() int64
- func (m *EncodedMotor) RPMMonitorStart()
- func (m *EncodedMotor) ResetZeroPosition(ctx context.Context, offset float64, extra map[string]interface{}) error
- func (m *EncodedMotor) SetPower(ctx context.Context, powerPct float64, extra map[string]interface{}) error
- func (m *EncodedMotor) Stop(ctx context.Context, extra map[string]interface{}) error
- type EncodedMotorState
- type Motor
- func (m *Motor) GoFor(ctx context.Context, rpm, revolutions float64, extra map[string]interface{}) error
- func (m *Motor) GoTo(ctx context.Context, rpm, positionRevolutions float64, ...) error
- func (m *Motor) IsMoving(ctx context.Context) (bool, error)
- func (m *Motor) IsPowered(ctx context.Context, extra map[string]interface{}) (bool, float64, error)
- func (m *Motor) Position(ctx context.Context, extra map[string]interface{}) (float64, error)
- func (m *Motor) Properties(ctx context.Context, extra map[string]interface{}) (motor.Properties, error)
- func (m *Motor) ResetZeroPosition(ctx context.Context, offset float64, extra map[string]interface{}) error
- func (m *Motor) SetPower(ctx context.Context, powerPct float64, extra map[string]interface{}) error
- func (m *Motor) Stop(ctx context.Context, extra map[string]interface{}) error
- type PinConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEncodedMotor ¶
func NewEncodedMotor( conf resource.Config, motorConfig Config, realMotor motor.Motor, encoder encoder.Encoder, logger golog.Logger, ) (motor.Motor, error)
NewEncodedMotor creates a new motor that supports an arbitrary source of encoder information.
Types ¶
type Config ¶
type Config struct { Pins PinConfig `json:"pins"` BoardName string `json:"board"` MinPowerPct float64 `json:"min_power_pct,omitempty"` // min power percentage to allow for this motor default is 0.0 MaxPowerPct float64 `json:"max_power_pct,omitempty"` // max power percentage to allow for this motor (0.06 - 1.0) PWMFreq uint `json:"pwm_freq,omitempty"` DirectionFlip bool `json:"dir_flip,omitempty"` // Flip the direction of the signal sent if there is a Dir pin ControlLoop control.Config `json:"control_config,omitempty"` // Optional control loop Encoder string `json:"encoder,omitempty"` // name of encoder RampRate float64 `json:"ramp_rate_rpm_per_sec,omitempty"` // how fast to ramp power to motor when using rpm control MaxRPM float64 `json:"max_rpm,omitempty"` TicksPerRotation int `json:"ticks_per_rotation,omitempty"` Debug bool `json:"rpm_debug,omitempty"` }
Config describes the configuration of a motor.
type EncodedMotor ¶
type EncodedMotor struct { resource.Named resource.AlwaysRebuild // contains filtered or unexported fields }
EncodedMotor is a motor that utilizes an encoder to track its position.
func (*EncodedMotor) Close ¶
func (m *EncodedMotor) Close(ctx context.Context) error
Close cleanly shuts down the motor.
func (*EncodedMotor) DirectionMoving ¶
func (m *EncodedMotor) DirectionMoving() int64
DirectionMoving returns the direction we are currently moving in, with 1 representing forward and -1 representing backwards.
func (*EncodedMotor) GoFor ¶
func (m *EncodedMotor) GoFor(ctx context.Context, rpm, revolutions float64, extra map[string]interface{}) error
GoFor instructs the motor to go in a specific direction for a specific amount of revolutions at a given speed in revolutions per minute. 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. If revolutions is 0, this will run the motor at rpm indefinitely If revolutions != 0, this will block until the number of revolutions has been completed or another operation comes in.
func (*EncodedMotor) GoTo ¶
func (m *EncodedMotor) GoTo(ctx context.Context, rpm, targetPosition 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 This will block until the position has been reached.
func (*EncodedMotor) IsMoving ¶
func (m *EncodedMotor) IsMoving(ctx context.Context) (bool, error)
IsMoving returns if the motor is moving or not.
func (*EncodedMotor) IsPowered ¶
func (m *EncodedMotor) IsPowered(ctx context.Context, extra map[string]interface{}) (bool, float64, error)
IsPowered returns whether or not the motor is currently on, and the percent power (between 0 and 1, if the motor is off then the percent power will be 0).
func (*EncodedMotor) Position ¶
Position reports the position of the motor based on its encoder. If it's not supported, the returned data is undefined. The unit returned is the number of revolutions which is intended to be fed back into calls of GoFor.
func (*EncodedMotor) Properties ¶
func (m *EncodedMotor) Properties(ctx context.Context, extra map[string]interface{}) (motor.Properties, error)
Properties returns whether or not the motor supports certain optional properties.
func (*EncodedMotor) RPMMonitorCalls ¶
func (m *EncodedMotor) RPMMonitorCalls() int64
RPMMonitorCalls returns the number of calls RPM monitor has made.
func (*EncodedMotor) RPMMonitorStart ¶
func (m *EncodedMotor) RPMMonitorStart()
RPMMonitorStart starts the RPM monitor.
func (*EncodedMotor) ResetZeroPosition ¶
func (m *EncodedMotor) ResetZeroPosition(ctx context.Context, offset float64, extra map[string]interface{}) error
ResetZeroPosition sets the current position (+/- offset) to be the new zero (home) position.
type EncodedMotorState ¶
type EncodedMotorState struct {
// contains filtered or unexported fields
}
EncodedMotorState is the core, non-statistical state for the motor. Multiple values should be updated atomically at the same time.
type Motor ¶
type Motor struct { resource.Named resource.AlwaysRebuild resource.TriviallyCloseable // config Board board.Board A, B, Direction, PWM, En board.GPIOPin EnablePinLow board.GPIOPin EnablePinHigh board.GPIOPin // contains filtered or unexported fields }
A Motor is a GPIO based Motor that resides on a GPIO Board.
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) GoTo ¶
func (m *Motor) GoTo(ctx context.Context, rpm, positionRevolutions float64, extra map[string]interface{}) error
GoTo is not supported.
func (*Motor) Properties ¶
func (m *Motor) Properties(ctx context.Context, extra map[string]interface{}) (motor.Properties, error)
Properties returns the status of whether the motor supports certain optional properties.
func (*Motor) ResetZeroPosition ¶
func (m *Motor) ResetZeroPosition(ctx context.Context, offset float64, extra map[string]interface{}) error
ResetZeroPosition is not supported.