gobrickpi

package module
v0.0.0-...-f4ffabe Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

README

gobrickpi

Go library to control brick pi robot

Using Go SPI and Raspberry Pi

TODO: There is a lot to do :)

The following functionailty has been implmented.

  1. Read/Write from the BrickPi using SPI
  2. Read BrickPi voltages
  3. Set BrickPi LED
  4. Set Sensor type (basic version)
  5. Get Sensor value (basic version)
  6. Read NXT Touch Sensor

Example Usage

Below is a very basic example that shows how to use a Lego Touch Sensor in your program

/*Simple example to show how to use Lego Touch Sensor connected to port 1
 */
package main

import (
	"fmt"
	"github.com/r3d-dy3-n0-2/gobrickpi"
	"time"
)

func main() {
	//Create connection to BrickPi
	gobrickpi.Start()
	//Set Sensor Port 1 to be a lego touch sensor
	gobrickpi.SetSensorType(gobrickpi.PORT_1, gobrickpi.SENSOR_TYPE_TOUCH)
	//Wait for 50 seconds to ensure sensor is setup correctly
	time.Sleep(50 * time.Millisecond)

	//Loop forever reading the value of the touch sensor on port 1.
	//If pressed will return 1 from sensor if not pressed the sensor will read 0
	for {
		touch_state := gobrickpi.GetSensorValue(gobrickpi.PORT_1)
		if touch_state == 1 {

			fmt.Println("Touch Sensor: HIT")
		} else {
			fmt.Println("Touch Sensor: NOT HIT!")
		}
		time.Sleep(40 * time.Millisecond) //Sleep to stop swamping the CPU
	}

}

Documentation

Index

Constants

View Source
const (
	SENSOR_TYPE_NONE   = iota
	SENSOR_TYPE_I2C    = iota
	SENSOR_TYPE_CUSTOM = iota

	SENSOR_TYPE_TOUCH     = iota
	SENSOR_TYPE_TOUCH_NXT = iota
	SENSOR_TYPE_TOUCH_EV3 = iota

	SENSOR_TYPE_NXT_LIGHT_ON  = iota
	SENSOR_TYPE_NXT_LIGHT_OFF = iota

	SENSOR_TYPE_NXT_COLOR_RED   = iota
	SENSOR_TYPE_NXT_COLOR_GREEN = iota
	SENSOR_TYPE_NXT_COLOR_BLUE  = iota
	SENSOR_TYPE_NXT_COLOR_FULL  = iota
	SENSOR_TYPE_NXT_COLOR_OFF   = iota

	SENSOR_TYPE_NXT_ULTRASONIC = iota

	SENSOR_TYPE_EV3_GYRO_ABS = iota
	SENSOR_TYPE_EV3_GYRO_DPS = iota
	SENSOR_TYPE_EV3_ABS_DPS  = iota

	SENSOR_TYPE_EV3_COLOR_REFLECTED        = iota
	SENSOR_TYPE_EV3_COLOR_AMBIENT          = iota
	SENSOR_TYPE_EV3_COLOR_COLOR            = iota
	SENSOR_TYPE_EV3_COLOR_RAW_REFLECTED_   = iota
	SENSOR_TYPE_EV3_COLOR_COLOR_COMPONENTS = iota

	SENSOR_TYPE_EV3_ULTRASONIC_CM     = iota
	SENSOR_TYPE_EV3_ULTRASONIC_INCHES = iota
	SENSOR_TYPE_EV3_ULTRASONIC_LISTEN = iota

	SENSOR_TYPE_EV3_INFRARED_PROXIMITY = iota
	SENSOR_TYPE_EV3_INFRARED_SEEK      = iota
	SENSOR_TYPE_EV3_INFRARED_REMOTE    = iota
)
View Source
const (
	SENSOR_STATE_VALID_DATA     = iota
	SENSOR_STATE_NOT_CONFIGURED = iota
	SENSOR_STATE_CONFIGURING    = iota
	SENSOR_STATE_NO_DATA        = iota
	SENSOR_STATE_I2C_ERROR      = iota
)
View Source
const (
	PORT_1 = 1
	PORT_2 = 2
	PORT_3 = 4
	PORT_4 = 8
)
View Source
const (
	PORT_A = 1
	PORT_B = 2
	PORT_C = 4
	PORT_D = 8
)
View Source
const MOTOR_FLOAT = -128

Variables

Functions

func Close

func Close()

func GetBoard

func GetBoard() (boardName string)

func GetFirmwareVersion

func GetFirmwareVersion() (firmware string)

func GetHardwareVersion

func GetHardwareVersion() (hardwareVersion string)

func GetID

func GetID() (id string)

func GetManufacturer

func GetManufacturer() (manufactor string)

func GetMotorEncoder

func GetMotorEncoder(port byte) (encoder int32)

func GetMotorStatus

func GetMotorStatus(port byte) (state uint8, power int8, position int32, dps int16)

func GetSensorValue

func GetSensorValue(port uint) (sensorValue int)

func OffsetMotorEncoder

func OffsetMotorEncoder(port byte, position int32)

func ReadVoltage3V3

func ReadVoltage3V3() (voltage float32)

func ReadVoltage5V

func ReadVoltage5V() (voltage float32)

func ReadVoltage9V

func ReadVoltage9V() (voltage float32)

func ReadVoltageBattery

func ReadVoltageBattery() (voltage float32)

func ResetAll

func ResetAll()

func ResetMotorEncoder

func ResetMotorEncoder(port byte)

func SetLed

func SetLed(ledValue byte)

func SetMotorDPS

func SetMotorDPS(port byte, dps int)

func SetMotorLimits

func SetMotorLimits(port byte, power byte, dps int)

func SetMotorPosition

func SetMotorPosition(port byte, position int32)

func SetMotorPositionKD

func SetMotorPositionKD(port byte, kd byte)

func SetMotorPositionKP

func SetMotorPositionKP(port byte, kp byte)

func SetMotorPositionRelative

func SetMotorPositionRelative(port byte, degrees int32)

func SetMotorPower

func SetMotorPower(port byte, power int8)

func SetSensorType

func SetSensorType(port byte, sensorType byte)

func Start

func Start()

Types

This section is empty.

Jump to

Keyboard shortcuts

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