megapi

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

README

MegaPi

The MegaPi is a motor controller by MakeBlock that is compatible with the Raspberry Pi.

The code is based on a python implementation that can be found here.

How to Install

go get -d -u github.com/hybridgroup/gobot/... && go install github.com/hybridgroup/gobot/platforms/megapi

How to Use

package main

import (
	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/gobot/platforms/megapi"
	"time"
)

func main() {
	gbot := gobot.NewGobot()

	// use "/dev/ttyUSB0" if connecting with USB cable
	// use "/dev/ttyAMA0" on devices older than Raspberry Pi 3 Model B
	megaPiAdaptor := megapi.NewMegaPiAdaptor("megapi", "/dev/ttyS0")
	motor := megapi.NewMotorDriver(megaPiAdaptor, "motor1", 1)

	work := func() {
		speed := int16(0)
		fadeAmount := int16(30)

		gobot.Every(100*time.Millisecond, func() {
			motor.Speed(speed)
			speed = speed + fadeAmount
			if speed == 0 || speed == 300 {
				fadeAmount = -fadeAmount
			}
		})
	}

	robot := gobot.NewRobot("megaPiBot",
		[]gobot.Connection{megaPiAdaptor},
		[]gobot.Device{motor},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MegaPiAdaptor

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

MegaPiAdaptor is the Gobot adaptor for the MakeBlock MegaPi board

func NewMegaPiAdaptor

func NewMegaPiAdaptor(name string, device string) *MegaPiAdaptor

NewMegaPiAdaptor returns a new MegaPiAdaptor with specified name and specified serial port used to talk to the MegaPi with a baud rate of 115200

func (*MegaPiAdaptor) Connect

func (megaPi *MegaPiAdaptor) Connect() (errs []error)

Connect starts a connection to the board

func (*MegaPiAdaptor) Finalize

func (megaPi *MegaPiAdaptor) Finalize() (errs []error)

Finalize terminates the connection to the board

func (*MegaPiAdaptor) Name

func (megaPi *MegaPiAdaptor) Name() string

Name returns the name of this adaptor

type MotorDriver

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

MotorDriver represents a motor

func NewMotorDriver

func NewMotorDriver(megaPi *MegaPiAdaptor, name string, port byte) *MotorDriver

NewMotorDriver creates a new MotorDriver using the provided name, and at the given port

func (*MotorDriver) Connection

func (m *MotorDriver) Connection() gobot.Connection

Connection returns the Connection associated with the Driver

func (*MotorDriver) Halt

func (m *MotorDriver) Halt() []error

Halt terminates the Driver interface

func (*MotorDriver) Name

func (m *MotorDriver) Name() string

Name returns the name of this motor

func (*MotorDriver) Speed

func (m *MotorDriver) Speed(speed int16) error

Speed sets the motors speed to the specified value

func (*MotorDriver) Start

func (m *MotorDriver) Start() []error

Start implements the Driver interface

Jump to

Keyboard shortcuts

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