lift

package module
v0.0.0-...-14c8b33 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2017 License: MIT Imports: 11 Imported by: 0

README

lift

GoDoc Go Report Card

Package lift provide an united interface for connection to either physical lifts or simulated lifts for use in the course TTK4145 at The Norwegian University of Science and Technology. This package is based on work done by Martin Korsgaard, Morten Fyhn and klasbo.

Installation

go get -u github.com/hdhauk/lift

This package have not been tested with physical hardware, but the simulator part are tested on Ubuntu 17.04. To be able to compile you must have the Comedi drivers which can be downloaded by:

wget http://www.comedi.org/download/comedilib-0.10.2.tar.gz
tar -xvzf comedilib-0.10.2.tar.gz
cd comedilib-0.10.2 && ./configure && make && sudo make install

Furthermore is the simulator by github.com/klasbo statically embedded in the project using the gobuffalo/packr tool. This mean that to generate standalone binaries first do

go get -u github.com/gobuffalo/packr/... 	# Installation, only needed once
packr 						# Generate static files that contain binaries and config.

Example

package main

import "github.com/hdhauk/lift"

func main(){
  // The order to which options or how many options you supply doesn't matter.
  // Here we configure the simulator to have 6 floors, and to listen on port 9999.
  // If neither is supplied the defaults will be used (4 floors and a random port).
  sim, err := lift.NewSim(lift.NumFloors(6), lift.ComPort(9999))
  if err != nil {
      panic(err)
  }

  if err := sim.Init(); err != nil {
      panic(err)
  }

  // The simulator can then be controlled by using the methods defined by Lifter.
  // Example: Sending the lift upward.
  sim.SetMotorDirection(1)
}

Documentation

Please see: GoDoc

Documentation

Overview

Package lift provide an united interface for connection to either physical lifts or simulated lifts for use in the course TTK4145 at The Norwegian University of Science and Technology. This package is based on work done by Martin Korsgaard, Morten Fyhn and github.com/klasbo.

This package have not been tested with physical hardware, but the simulator part are tested on Ubuntu 17.04. To be able to compile you must have the Comedi drivers which can be downloaded by:

wget http://www.comedi.org/download/comedilib-0.10.2.tar.gz
tar -xvzf comedilib-0.10.2.tar.gz
cd comedilib-0.10.2 && ./configure && make && sudo make install

Furthermore is the simulator by github.com/klasbo statically embedded in the project using the http://github.com/gobuffalo/packr tool. This mean that to generate standalone binaries first do

go get -u github.com/gobuffalo/packr/... 	# Installation, only needed once
packr 						# Generate static files that contain binaries and config.
Example

Basic usage.

package main

import (
	"github.com/hdhauk/lift"
)

func main() {
	// The order to which options or how many options you supply doesn't matter.
	// Here we configure the simulator to have 6 floors, and to listen on port 9999.
	// If neither is supplied the defaults will be used (4 floors and a random port).
	sim, err := lift.NewSim(lift.NumFloors(6), lift.ComPort(9999))
	if err != nil {
		panic(err)
	}

	if err := sim.Init(); err != nil {
		panic(err)
	}

	// The simulator can then be controlled by using the methods defined by Lifter.
	// Example:
	sim.SetMotorDirection(1)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lifter

type Lifter interface {
	Init() error

	SetMotorDirection(direction int)
	OrderButtonLight(button int, floor int, on bool)
	FloorIndicator(floor int)
	DoorLight(on bool)
	StopLight(on bool)

	OrderButton(button int, floor int) (pressed bool)
	FloorSensor() (inFloor bool, floor int)
	StopButton() (pressed bool)
	Obstruction() (active bool)
}

Lifter is the interface for what the lifts can do. It offers few guarantees and will generally simply do nothing if used wrong. The following conventions are used:

Direction:	-1 = down, 0 = stop, 1 = up
Buttons:	0 = hall up, 1 = hall down, 2 = inside lift

func New

func New() (Lifter, error)

New returns a new physical lift. It is assumed to only be one physical lift.

func NewSim

func NewSim(options ...SimOption) (Lifter, error)

NewSim returns a new simulated lift.

type SimOption

type SimOption func(*liftSim) error

SimOption are option functions for simulated lifts.

func BtnDepressedTime

func BtnDepressedTime(d time.Duration) SimOption

BtnDepressedTime sets the duration a button will be considered pressed after the actual key event happens.

func ComPort

func ComPort(port int) SimOption

ComPort sets what port the simulator should listen on. This must be unique per instance of simulators. Must be in the range 1024 - 65535.

func NumFloors

func NumFloors(floors int) SimOption

NumFloors sets the number of floors in simulated lift.

func TravelTimeBetweenFloors

func TravelTimeBetweenFloors(d time.Duration) SimOption

TravelTimeBetweenFloors sets the travel time between each floor.

func TravelTimePassingFloors

func TravelTimePassingFloors(d time.Duration) SimOption

TravelTimePassingFloors sets the time spent within the sensors range when passing a floor.

Jump to

Keyboard shortcuts

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