minidrone

package
Version: v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2017 License: Apache-2.0, Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

README

Parrot Minidrone

The Parrot Minidrones are very inexpensive drones that are controlled using Bluetooth LE aka Bluetooth 4.0.

Models that are known to work with this package include:

- Parrot Rolling Spider
- Parrot Airborne Cargo Mars
- Parrot Airborne Cargo Travis

Models that should work now, but have not been tested by us:

- Parrot Airborne Night Swat
- Parrot Airborne Night Maclane
- Parrot Airborne Night Blaze
- Parrot HYDROFOIL Orak
- Parrot HYDROFOIL NewZ

Models that will require additional work for compatibility:

- Parrot Swing
- Parrot Mambo

How to Install

go get -d -u gobot.io/x/gobot/... && go install gobot.io/x/gobot/platforms/ble

How to Use

package main

import (
	"fmt"
	"os"
	"time"

	"gobot.io/x/gobot"
	"gobot.io/x/gobot/platforms/ble"
	"gobot.io/x/gobot/platforms/parrot/minidrone"
)

func main() {
	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
	drone := minidrone.NewDriver(bleAdaptor)

	work := func() {
		drone.On(minidrone.Battery, func(data interface{}) {
			fmt.Printf("battery: %d\n", data)
		})

		drone.On(minidrone.FlightStatus, func(data interface{}) {
			fmt.Printf("flight status: %d\n", data)
		})

		drone.On(minidrone.Takeoff, func(data interface{}) {
			fmt.Println("taking off...")
		})

		drone.On(minidrone.Hovering, func(data interface{}) {
			fmt.Println("hovering!")
			gobot.After(5*time.Second, func() {
				drone.Land()
			})
		})

		drone.On(minidrone.Landing, func(data interface{}) {
			fmt.Println("landing...")
		})

		drone.On(minidrone.Landed, func(data interface{}) {
			fmt.Println("landed.")
		})

		time.Sleep(1000 * time.Millisecond)
		drone.TakeOff()
	}

	robot := gobot.NewRobot("minidrone",
		[]gobot.Connection{bleAdaptor},
		[]gobot.Device{drone},
		work,
	)

	robot.Start()
}

How to Connect

The Parrot Minidrones are Bluetooth LE devices.

You need to know the BLE ID of the Minidrone you want to connect to. The Gobot BLE client adaptor also lets you connect by friendly name, aka "RS_1234".

OSX

To run any of the Gobot BLE code you must use the GODEBUG=cgocheck=0 flag in order to get around some of the issues in the CGo-based implementation.

For example:

GODEBUG=cgocheck=0 go run examples/minidrone.go RS_1234

OSX uses its own Bluetooth ID system which is different from the IDs used on Linux. The code calls thru the XPC interfaces provided by OSX, so as a result does not need to run under sudo.

Ubuntu

On Linux the BLE code will need to run as a root user account. The easiest way to accomplish this is probably to use go build to build your program, and then to run the requesting executable using sudo.

For example:

go build examples/minidrone.go
sudo ./minidrone RS_1234
Windows

Hopefully coming soon...

Documentation

Overview

Package minidrone contains the Gobot driver for the Parrot Minidrone.

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

Index

Constants

View Source
const (

	// Battery event
	Battery = "battery"

	// FlightStatus event
	FlightStatus = "flightstatus"

	// Takeoff event
	Takeoff = "takeoff"

	// Hovering event
	Hovering = "hovering"

	// Flying event
	Flying = "flying"

	// Landing event
	Landing = "landing"

	// Landed event
	Landed = "landed"

	// Emergency event
	Emergency = "emergency"

	// Rolling event
	Rolling = "rolling"

	// FlatTrimChange event
	FlatTrimChange = "flattrimchange"
)

Variables

This section is empty.

Functions

func ValidatePitch added in v1.2.0

func ValidatePitch(data float64, offset float64) int

ValidatePitch helps validate pitch values such as those created by a joystick to values between 0-100 that are required as params to Parrot Minidrone PCMDs

Types

type Driver

type Driver struct {
	Pcmd Pcmd
	gobot.Eventer
	// contains filtered or unexported fields
}

Driver is the Gobot interface to the Parrot Minidrone

func NewDriver

func NewDriver(a *ble.ClientAdaptor) *Driver

NewDriver creates a Parrot Minidrone Driver

func (*Driver) BackFlip

func (b *Driver) BackFlip() (err error)

BackFlip tells the drone to perform a backflip

func (*Driver) Backward

func (b *Driver) Backward(val int) error

Backward tells drone to go in reverse

func (*Driver) Clockwise

func (b *Driver) Clockwise(val int) error

Clockwise tells drone to rotate in a clockwise direction

func (*Driver) Connection

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

Connection returns the BLE connection

func (*Driver) CounterClockwise

func (b *Driver) CounterClockwise(val int) error

CounterClockwise tells drone to rotate in a counter-clockwise direction

func (*Driver) Down

func (b *Driver) Down(val int) error

Down tells the drone to descend

func (*Driver) Emergency added in v1.1.0

func (b *Driver) Emergency() (err error)

Emergency sets the Minidrone into emergency mode

func (*Driver) FlatTrim

func (b *Driver) FlatTrim() (err error)

FlatTrim calibrates the Minidrone to use its current position as being level

func (*Driver) Forward

func (b *Driver) Forward(val int) error

Forward tells the drone to go forward

func (*Driver) FrontFlip

func (b *Driver) FrontFlip() (err error)

FrontFlip tells the drone to perform a front flip

func (*Driver) GenerateAllStates

func (b *Driver) GenerateAllStates() (err error)

GenerateAllStates sets up all the default states aka settings on the drone

func (*Driver) Halt

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

Halt stops minidrone driver (void)

func (*Driver) HullProtection

func (b *Driver) HullProtection(protect bool) error

HullProtection is not supported by the Parrot Minidrone

func (*Driver) Init

func (b *Driver) Init() (err error)

Init initializes the BLE insterfaces used by the Minidrone

func (*Driver) Land

func (b *Driver) Land() (err error)

Land tells the Minidrone to land

func (*Driver) Left

func (b *Driver) Left(val int) error

Left tells drone to go left

func (*Driver) LeftFlip

func (b *Driver) LeftFlip() (err error)

LeftFlip tells the drone to perform a flip to the left

func (*Driver) Name

func (b *Driver) Name() string

Name returns the Driver Name

func (*Driver) Outdoor

func (b *Driver) Outdoor(outdoor bool) error

Outdoor mdoe is not supported by the Parrot Minidrone

func (*Driver) Right

func (b *Driver) Right(val int) error

Right tells drone to go right

func (*Driver) RightFlip

func (b *Driver) RightFlip() (err error)

RightFlip tells the drone to perform a flip to the right

func (*Driver) SetName

func (b *Driver) SetName(n string)

SetName sets the Driver Name

func (*Driver) Start

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

Start tells driver to get ready to do work

func (*Driver) StartPcmd

func (b *Driver) StartPcmd()

StartPcmd starts the continuous Pcmd communication with the Minidrone

func (*Driver) StartRecording

func (b *Driver) StartRecording() error

StartRecording is not supported by the Parrot Minidrone

func (*Driver) Stop

func (b *Driver) Stop() error

Stop tells the drone to stop moving in any direction and simply hover in place

func (*Driver) StopRecording

func (b *Driver) StopRecording() error

StopRecording is not supported by the Parrot Minidrone

func (*Driver) TakeOff

func (b *Driver) TakeOff() (err error)

TakeOff tells the Minidrone to takeoff

func (*Driver) TakePicture added in v1.1.0

func (b *Driver) TakePicture() (err error)

TakePicture tells the Minidrone to take a picture

func (*Driver) Up

func (b *Driver) Up(val int) error

Up tells the drone to ascend

type Pcmd

type Pcmd struct {
	Flag  int
	Roll  int
	Pitch int
	Yaw   int
	Gaz   int
	Psi   float32
}

Pcmd is the Parrot Command structure for flight control

Jump to

Keyboard shortcuts

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