megapi

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2017 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 gobot.io/x/gobot/...

How to Use

package main

import (
	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/megapi"
	"time"
)

func main() {
	// use "/dev/ttyUSB0" if connecting with USB cable
	// use "/dev/ttyAMA0" on devices older than Raspberry Pi 3 Model B
	megaPiAdaptor := megapi.NewAdaptor("/dev/ttyS0")
	motor := megapi.NewMotorDriver(megaPiAdaptor, 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,
	)

	robot.Start()
}

Documentation

Overview

Package megapi provides the Gobot adaptor for MegaPi.

For more information refer to the README: https://github.com/hybridgroup/gobot/blob/master/platforms/megapi/README.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adaptor added in v1.0.0

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

Adaptor is the Gobot adaptor for the MakeBlock MegaPi board

func NewAdaptor added in v1.0.0

func NewAdaptor(device string) *Adaptor

NewAdaptor returns a new MegaPi Adaptor with specified serial port used to talk to the MegaPi with a baud rate of 115200

func (*Adaptor) Connect added in v1.0.0

func (megaPi *Adaptor) Connect() error

Connect starts a connection to the board

func (*Adaptor) Finalize added in v1.0.0

func (megaPi *Adaptor) Finalize() error

Finalize terminates the connection to the board

func (*Adaptor) Name added in v1.0.0

func (megaPi *Adaptor) Name() string

Name returns the name of this adaptor

func (*Adaptor) SetName added in v1.0.0

func (megaPi *Adaptor) SetName(n string)

SetName sets the name of this adaptor

type MotorDriver

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

MotorDriver represents a motor

func NewMotorDriver

func NewMotorDriver(megaPi *Adaptor, port byte) *MotorDriver

NewMotorDriver creates a new MotorDriver 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) SetName added in v1.0.0

func (m *MotorDriver) SetName(n string)

SetName sets 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