minidrone

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: Apache-2.0, Apache-2.0, Apache-2.0 Imports: 8 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
- Parrot Mambo

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

How to Install

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

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 or name 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.

If you connect by name, then you do not need to worry about the Bluetooth LE ID. However, if you want to connect by ID, OS X 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.

For example:

GODEBUG=cgocheck=0 go run examples/minidrone.go RS_1234
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"

	// LightFixed mode for LightControl
	LightFixed = 0

	// LightBlinked mode for LightControl
	LightBlinked = 1

	// LightOscillated mode for LightControl
	LightOscillated = 3

	// ClawOpen mode for ClawControl
	ClawOpen = 0

	// ClawClosed mode for ClawControl
	ClawClosed = 1
)

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.BLEConnector) *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. Pass in an int from 0-100.

func (*Driver) ClawControl added in v1.6.0

func (b *Driver) ClawControl(id uint8, mode uint8) (err error)

ClawControl controls the claw on the Parrot Mambo Params:

id - always 0
mode - either ClawOpen or ClawClosed

func (*Driver) Clockwise

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

Clockwise tells drone to rotate in a clockwise direction. Pass in an int from 0-100.

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. Pass in an int from 0-100.

func (*Driver) Down

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

Down tells the drone to descend. Pass in an int from 0-100.

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. Pass in an int from 0-100.

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) GunControl added in v1.6.0

func (b *Driver) GunControl(id uint8) (err error)

GunControl fires the gun on the Parrot Mambo Params:

id - always 0

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. Pass in an int from 0-100.

func (*Driver) LeftFlip

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

LeftFlip tells the drone to perform a flip to the left

func (*Driver) LightControl added in v1.6.0

func (b *Driver) LightControl(id uint8, mode uint8, intensity uint8) (err error)

LightControl controls lights on those Minidrone models which have the correct hardware, such as the Maclane, Blaze, & Swat. Params:

id - always 0
mode - either LightFixed, LightBlinked, or LightOscillated
intensity - Light intensity from 0 (OFF) to 100 (Max intensity).
			Only used in LightFixed mode.

func (*Driver) Name

func (b *Driver) Name() string

Name returns the Driver Name

func (*Driver) Outdoor

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

Outdoor mode is not supported by the Parrot Minidrone

func (*Driver) Right

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

Right tells drone to go right. Pass in an int from 0-100.

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. Pass in an int from 0-100.

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