gopigo3

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

GoPiGo3

The GoPiGo3 is a robotics controller by Dexter Industries that is compatible with the Raspberry Pi.

How to Install

Please refer to the main README.md

How to Use

This example will blink the left and right leds red/blue.

package main

import (
  "fmt"
  "time"

  "gobot.io/x/gobot/v2"
  g "gobot.io/x/gobot/v2/platforms/dexter/gopigo3"
  "gobot.io/x/gobot/v2/platforms/raspi"
)

func main() {
  raspiAdaptor := raspi.NewAdaptor()
  gopigo3 := g.NewDriver(raspiAdaptor)

  work := func() {
    on := uint8(0xFF)
    gobot.Every(1000*time.Millisecond, func() {
      err := gopigo3.SetLED(g.LED_EYE_RIGHT, 0x00, 0x00, on)
      if err != nil {
        fmt.Println(err)
      }
      err = gopigo3.SetLED(g.LED_EYE_LEFT, ^on, 0x00, 0x00)
      if err != nil {
        fmt.Println(err)
      }
      on = ^on
    })
  }

  robot := gobot.NewRobot("gopigo3",
    []gobot.Connection{raspiAdaptor},
    []gobot.Device{gopigo3},
    work,
  )

  robot.Start()
}

Documentation

Overview

Package gopigo3 is based on https://github.com/DexterInd/GoPiGo3/blob/master/Software/Python/gopigo3.py You will need to run the following commands if using a stock raspbian image before this library will work: sudo curl -kL dexterindustries.com/update_gopigo3 | bash sudo reboot

Index

Constants

View Source
const (
	NONE byte = iota
	GET_MANUFACTURER
	GET_NAME
	GET_HARDWARE_VERSION
	GET_FIRMWARE_VERSION
	GET_ID
	SET_LED
	GET_VOLTAGE_5V
	GET_VOLTAGE_VCC
	SET_SERVO
	SET_MOTOR_PWM
	SET_MOTOR_POSITION
	SET_MOTOR_POSITION_KP
	SET_MOTOR_POSITION_KD
	SET_MOTOR_DPS
	SET_MOTOR_LIMITS
	OFFSET_MOTOR_ENCODER
	GET_MOTOR_ENCODER_LEFT
	GET_MOTOR_ENCODER_RIGHT
	GET_MOTOR_STATUS_LEFT
	GET_MOTOR_STATUS_RIGHT
	SET_GROVE_TYPE
	SET_GROVE_MODE
	SET_GROVE_STATE
	SET_GROVE_PWM_DUTY
	SET_GROVE_PWM_FREQUENCY
	GET_GROVE_VALUE_1
	GET_GROVE_VALUE_2
	GET_GROVE_STATE_1_1
	GET_GROVE_STATE_1_2
	GET_GROVE_STATE_2_1
	GET_GROVE_STATE_2_2
	GET_GROVE_VOLTAGE_1_1
	GET_GROVE_VOLTAGE_1_2
	GET_GROVE_VOLTAGE_2_1
	GET_GROVE_VOLTAGE_2_2
	GET_GROVE_ANALOG_1_1
	GET_GROVE_ANALOG_1_2
	GET_GROVE_ANALOG_2_1
	GET_GROVE_ANALOG_2_2
	START_GROVE_I2C_1
	START_GROVE_I2C_2
)

register addresses for gopigo3

View Source
const (
	// distance (mm) from left wheel to right wheel. This works with the initial GPG3 prototype. Will need to be adjusted.
	WHEEL_BASE_WIDTH = 117
	// wheel diameter (mm)
	WHEEL_DIAMETER = 66.5
	// circumference of the circle the wheels will trace while turning (mm)
	WHEEL_BASE_CIRCUMFERENCE = WHEEL_BASE_WIDTH * math.Pi
	// circumference of the wheels (mm)
	WHEEL_CIRCUMFERENCE = WHEEL_DIAMETER * math.Pi
	// motor gear ratio
	MOTOR_GEAR_RATIO = 120
	// encoder ticks per motor rotation (number of magnet positions)
	ENCODER_TICKS_PER_ROTATION = 6
	// encoder ticks per output shaft rotation degree
	MOTOR_TICKS_PER_DEGREE = ((MOTOR_GEAR_RATIO * ENCODER_TICKS_PER_ROTATION) / 360.0)
	GROVE_I2C_LENGTH_LIMIT = 16
	MOTOR_FLOAT            = -128
)
View Source
const (
	AD11     string = "AD_1_1"
	AD12     string = "AD_1_2"
	AD21     string = "AD_2_1"
	AD22     string = "AD_2_2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	spi.Config
	// contains filtered or unexported fields
}

Driver is a Gobot Driver for the GoPiGo3 board.

func NewDriver

func NewDriver(a spi.Connector, options ...func(spi.Config)) *Driver

NewDriver creates a new Gobot Driver for the GoPiGo3 board.

Params:

a *Adaptor - the Adaptor to use with this Driver

Optional params:

 spi.WithBusNumber(int):  bus to use with this driver
	spi.WithChipNumber(int): chip to use with this driver
 spi.WithMode(int):    	 mode to use with this driver
 spi.WithBitCount(int):   number of bits to use with this driver
 spi.WithSpeed(int64):    speed in Hz to use with this driver

func (*Driver) AnalogRead

func (d *Driver) AnalogRead(pin string) (int, error)

AnalogRead returns the analog value of the given pin.

func (*Driver) Connection

func (d *Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*Driver) DigitalRead

func (d *Driver) DigitalRead(pin string) (int, error)

DigitalRead reads the 0/1 value from the given pin.

func (*Driver) DigitalWrite

func (d *Driver) DigitalWrite(pin string, val byte) error

DigitalWrite writes a 0/1 value to the given pin.

func (*Driver) Get5vVoltage

func (d *Driver) Get5vVoltage() (float32, error)

Get5vVoltage returns the current voltage on the 5v line.

func (*Driver) GetBatteryVoltage

func (d *Driver) GetBatteryVoltage() (float32, error)

GetBatteryVoltage gets the battery voltage from the main battery pack (7v-12v).

func (*Driver) GetBoardName

func (d *Driver) GetBoardName() (string, error)

GetBoardName returns the board name from the firmware.

func (*Driver) GetFirmwareVersion

func (d *Driver) GetFirmwareVersion() (string, error)

GetFirmwareVersion returns the current firmware version.

func (*Driver) GetHardwareVersion

func (d *Driver) GetHardwareVersion() (string, error)

GetHardwareVersion returns the hardware version from the firmware.

func (*Driver) GetManufacturerName

func (d *Driver) GetManufacturerName() (string, error)

GetManufacturerName returns the manufacturer from the firmware.

func (*Driver) GetMotorEncoder

func (d *Driver) GetMotorEncoder(motor Motor) (int64, error)

GetMotorEncoder reads a motor's encoder in degrees.

func (*Driver) GetMotorStatus

func (d *Driver) GetMotorStatus(motor Motor) (flags uint8, power uint16, encoder, dps int, err error)

GetMotorStatus returns the status for the given motor.

func (*Driver) GetSerialNumber

func (d *Driver) GetSerialNumber() (string, error)

GetSerialNumber returns the 128-bit hardware serial number of the board.

func (*Driver) Halt

func (d *Driver) Halt() error

Halt stops the driver.

func (*Driver) Name

func (d *Driver) Name() string

Name returns the name of the device.

func (*Driver) OffsetMotorEncoder

func (d *Driver) OffsetMotorEncoder(motor Motor, offset float64) error

OffsetMotorEncoder offsets a motor's encoder for calibration purposes.

func (*Driver) PwmWrite

func (d *Driver) PwmWrite(pin string, val byte) error

PwmWrite implents the pwm interface for the gopigo3.

func (*Driver) ServoWrite

func (d *Driver) ServoWrite(port string, angle byte) error

ServoWrite writes an angle (0-180) to the given servo (servo 1 or servo 2). Must implement the ServoWriter interface of gpio package.

func (*Driver) SetGroveMode

func (d *Driver) SetGroveMode(port Grove, mode GroveMode) error

SetGroveMode sets the mode a given pin/port of the grove connector.

func (*Driver) SetGroveType

func (d *Driver) SetGroveType(port Grove, gType GroveType) error

SetGroveType sets the given port to a grove device type.

func (*Driver) SetLED

func (d *Driver) SetLED(led Led, red, green, blue uint8) error

SetLED sets rgb values from 0 to 255.

func (*Driver) SetMotorDps

func (d *Driver) SetMotorDps(motor Motor, dps int) error

SetMotorDps sets the motor target speed in degrees per second.

func (*Driver) SetMotorLimits

func (d *Driver) SetMotorLimits(motor Motor, power int8, dps int) error

SetMotorLimits sets the speed limits for a motor.

func (*Driver) SetMotorPosition

func (d *Driver) SetMotorPosition(motor Motor, position int) error

SetMotorPosition sets the motor's position in degrees.

func (*Driver) SetMotorPower

func (d *Driver) SetMotorPower(motor Motor, power int8) error

SetMotorPower sets a motor's power from -128 to 127.

func (*Driver) SetName

func (d *Driver) SetName(n string)

SetName sets the name of the device.

func (*Driver) SetPWMDuty

func (d *Driver) SetPWMDuty(port Grove, duty uint16) error

SetPWMDuty sets the pwm duty cycle for the given pin/port.

func (*Driver) SetPWMFreq

func (d *Driver) SetPWMFreq(port Grove, freq uint16) error

SetPWMFreq setst the pwm frequency for the given pin/port.

func (*Driver) SetServo

func (d *Driver) SetServo(srvo Servo, us uint16) error

SetServo sets a servo's position in microseconds (0-16666).

func (*Driver) Start

func (d *Driver) Start() error

Start initializes the GoPiGo3

type Grove

type Grove byte

Grove contains the addresses for pins/ports of the AD1/AD2 grove connector.

type GroveMode

type GroveMode byte

GroveMode sets the mode of AD pins on the gopigo3.

const (
	GROVE_INPUT_DIGITAL          GroveMode = 0
	GROVE_OUTPUT_DIGITAL         GroveMode = 1
	GROVE_INPUT_DIGITAL_PULLUP   GroveMode = 2
	GROVE_INPUT_DIGITAL_PULLDOWN GroveMode = 3
	GROVE_INPUT_ANALOG           GroveMode = 4
	GROVE_OUTPUT_PWM             GroveMode = 5
	GROVE_INPUT_ANALOG_PULLUP    GroveMode = 6
	GROVE_INPUT_ANALOG_PULLDOWN  GroveMode = 7
)

type GroveState

type GroveState int

GroveState contains the state of a grove device.

const (
	VALID_DATA GroveState = iota
	NOT_CONFIGURED
	CONFIGURING
	NO_DATA
	I2C_ERROR
)

type GroveType

type GroveType int

GroveType represents the type of a grove device.

const (
	CUSTOM        GroveType = 1
	IR_DI_REMOTE  GroveType = 2
	IR_EV3_REMOTE GroveType = 3
	US            GroveType = 4
	I2C           GroveType = 5
)

type Led

type Led byte

Led contains the addresses for all leds on the board.

const (
	LED_EYE_RIGHT     Led = 0x01
	LED_EYE_LEFT      Led = 0x02
	LED_BLINKER_LEFT  Led = 0x04
	LED_BLINKER_RIGHT Led = 0x08
	LED_WIFI          Led = 0x80
)

type Motor

type Motor byte

Motor contains the address for the left and right motors.

const (
	MOTOR_LEFT  Motor = 0x01
	MOTOR_RIGHT Motor = 0x02
)

type Servo

type Servo byte

Servo contains the address for the 2 servo ports.

const (
	SERVO_1 Servo = 0x01
	SERVO_2 Servo = 0x02
)

Jump to

Keyboard shortcuts

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