gopigo3

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

README

GoPiGo3

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

How to Install

go get -d -u gobot.io/x/gobot/...

How to Use

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

package main

import (
	"fmt"
	"time"

	"gobot.io/x/gobot"
	g "gobot.io/x/gobot/platforms/dexter/gopigo3"
	"gobot.io/x/gobot/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

Based on https://github.com/DexterInd/GoPiGo3/blob/master/Software/Python/gopigo3.py You will need to run the following script if using a stock raspbian image before this library will work: https://www.dexterindustries.com/GoPiGo/get-started-with-the-gopigo3-raspberry-pi-robot/3-program-your-raspberry-pi-robot/python-programming-language/

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 (
	WHEEL_BASE_WIDTH           = 117                                                       // distance (mm) from left wheel to right wheel. This works with the initial GPG3 prototype. Will need to be adjusted.
	WHEEL_DIAMETER             = 66.5                                                      // wheel diameter (mm)
	WHEEL_BASE_CIRCUMFERENCE   = WHEEL_BASE_WIDTH * math.Pi                                // circumference of the circle the wheels will trace while turning (mm)
	WHEEL_CIRCUMFERENCE        = WHEEL_DIAMETER * math.Pi                                  // circumference of the wheels (mm)
	MOTOR_GEAR_RATIO           = 120                                                       // motor gear ratio
	ENCODER_TICKS_PER_ROTATION = 6                                                         // encoder ticks per motor rotation (number of magnet positions)
	MOTOR_TICKS_PER_DEGREE     = ((MOTOR_GEAR_RATIO * ENCODER_TICKS_PER_ROTATION) / 360.0) // encoder ticks per output shaft rotation degree
	GROVE_I2C_LENGTH_LIMIT     = 16
	MOTOR_FLOAT                = -128
)
View Source
const (
	CUSTOM        GroveType = 1
	IR_DI_REMOTE            = 2
	IR_EV3_REMOTE           = 3
	US                      = 4
	I2C                     = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

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

Driver is a Gobot Driver for the GoPiGo3 board.

func NewDriver

func NewDriver(a spi.Connector) *Driver

NewDriver creates a new Gobot Driver for the GoPiGo3 board.

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*Driver) AnalogRead

func (g *Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns the analog value of the given pin.

func (*Driver) Connection

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

Connection returns the Connection of the device.

func (*Driver) DigitalRead

func (g *Driver) DigitalRead(pin string) (value int, err error)

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

func (*Driver) DigitalWrite

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

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

func (*Driver) Get5vVoltage

func (g *Driver) Get5vVoltage() (voltage float32, err error)

Get5vVoltage returns the current voltage on the 5v line.

func (*Driver) GetBatteryVoltage

func (g *Driver) GetBatteryVoltage() (voltage float32, err error)

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

func (*Driver) GetBoardName

func (g *Driver) GetBoardName() (bName string, err error)

GetBoardName returns the board name from the firmware.

func (*Driver) GetFirmwareVersion

func (g *Driver) GetFirmwareVersion() (fVer string, err error)

GetFirmwareVersion returns the current firmware version.

func (*Driver) GetHardwareVersion

func (g *Driver) GetHardwareVersion() (hVer string, err error)

GetHardwareVersion returns the hardware version from the firmware.

func (*Driver) GetManufacturerName

func (g *Driver) GetManufacturerName() (mName string, err error)

GetManufacturerName returns the manufacturer from the firmware.

func (*Driver) GetMotorEncoder

func (g *Driver) GetMotorEncoder(motor Motor) (encoder int64, err error)

GetMotorEncoder reads a motor's encoder in degrees.

func (*Driver) GetMotorStatus

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

GetMotorStatus returns the status for the given motor.

func (*Driver) GetSerialNumber

func (g *Driver) GetSerialNumber() (sNum string, err error)

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

func (*Driver) Halt

func (g *Driver) Halt() (err error)

Halt stops the driver.

func (*Driver) Name

func (g *Driver) Name() string

Name returns the name of the device.

func (*Driver) OffsetMotorEncoder

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

OffsetMotorEncoder offsets a motor's encoder for calibration purposes.

func (*Driver) PwmWrite

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

PwmWrite implents the pwm interface for the gopigo3.

func (*Driver) ServoWrite

func (g *Driver) ServoWrite(pin string, angle byte) error

func (*Driver) SetGroveMode

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

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

func (*Driver) SetGroveType

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

SetGroveType sets the given port to a grove device type.

func (*Driver) SetLED

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

SetLED sets rgb values from 0 to 255.

func (*Driver) SetMotorDps

func (g *Driver) SetMotorDps(motor Motor, dps float64) error

SetMotorDps sets the motor target speed in degrees per second.

func (*Driver) SetMotorLimits

func (g *Driver) SetMotorLimits(motor Motor, power int8, dps float64) error

SetMotorLimits sets the speed limits for a motor.

func (*Driver) SetMotorPosition

func (g *Driver) SetMotorPosition(motor Motor, position float64) error

SetMotorPosition sets the motor's position in degrees.

func (*Driver) SetMotorPower

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

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

func (*Driver) SetName

func (g *Driver) SetName(n string)

SetName sets the name of the device.

func (*Driver) SetPWMDuty

func (g *Driver) SetPWMDuty(port Grove, duty uint8) (err error)

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

func (*Driver) SetPWMFreq

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

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

func (*Driver) SetServo

func (g *Driver) SetServo(servo Servo, us uint16) error

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

func (*Driver) Start

func (g *Driver) Start() (err error)

Start initializes the GoPiGo3

type Grove

type Grove byte

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

const (
)

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.

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