MBot-0.1.0.1: Haskell interface for controlling the mBot educational robot

Safe HaskellNone
LanguageHaskell2010

MBot

Description

Programming the mBot

With this library it is possible to control the mBot robot from within Haskell over 2.4ghz wireless. The mBot itself needs to contain the standard firmware otherwise the library will not behave as expected. There is support for steering the motors and leds and for reading the linesensor and the ultrasonic sensor. An small example program is shown below, for more information about the individual functions take a look at the api documentation below.

import MBot

main =  do
  putStrLn "My first mBot program in Haskell !"
  -- Open the connection with the mMbot
  d <- openMBot
  putStrLn "Opened a connection with the mBot"
  -- Turn on led 1 of the mBot and set the RGB value to (0,100,0)
  sendCommand d $ setRGB 1 0 100 0
  putStrLn "Look at all the pretty colors !"
  -- Turn on led 2 of the mBot and set the RGB value to (100,0,0)
  sendCommand d $ setRGB 2 100 0 0
  -- close the connection with the mBot 
  closeMBot d

Synopsis

Documentation

openMBot Source #

Arguments

:: IO Device

gives back the connection with the mBot

Opens a connection with the mBot

closeMBot :: Device -> IO () Source #

Close the connection with the mBot

sendCommand Source #

Arguments

:: Device

An open Device connection

-> Command

The command to send

-> IO ()

There is no return value

Sends a mBot command over the HID device

readUltraSonic :: Device -> IO Float Source #

Read out the status of the ultrasonic line follower

readLineFollower :: Device -> IO Line Source #

Read out the status of line follower sensor

goAhead :: Device -> IO () Source #

Start both motors so that the robot moves forward

goLeft :: Device -> IO () Source #

Start the motors so that the robots turns left

goRight :: Device -> IO () Source #

Start the motors let the mBot turn right

stop :: Device -> IO () Source #

Stop both motors

setRGB :: Int -> Int -> Int -> Int -> Command Source #

Create an mBot command to turn on the led on a particular rgb value

data Line Source #

The line sensor consists of two sensors which are able to detect either a black or a white surface. Therefore there are four different states to represent the state of the line sensor

Constructors

LEFTB

Left sensor reads black right sensor reads white

RIGHTB

Right sensor reads black left sensor reads white

BOTHB

Both the left and right sensor observe a black surface

BOTHW

Both the left and right sensor observe a white surface

Instances

Eq Line Source # 

Methods

(==) :: Line -> Line -> Bool #

(/=) :: Line -> Line -> Bool #

Show Line Source # 

Methods

showsPrec :: Int -> Line -> ShowS #

show :: Line -> String #

showList :: [Line] -> ShowS #

data Command Source #

Type of mBot commands the constructor is not exported.