packages feed

MBot 0.1.2.0 → 0.2.0.0

raw patch · 2 files changed

+21/−43 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- MBot: goAhead :: Device -> IO ()
- MBot: goBackwards :: Device -> IO ()
- MBot: goLeft :: Device -> IO ()
- MBot: goRight :: Device -> IO ()
- MBot: stop :: Device -> IO ()
- MBot: setMotor :: Int -> Int -> Int -> Command
+ MBot: setMotor :: Int -> Int -> Command

Files

MBot.cabal view
@@ -10,7 +10,7 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.2.0+version:             0.2.0.0  -- A short (one-line) description of the package. synopsis:            Haskell interface for controlling the mBot educational robot
src/MBot.hs view
@@ -60,13 +60,8 @@              sendCommand,              readUltraSonic,              readLineFollower,-             goAhead,-             goBackwards,-             goLeft,-             goRight,-             stop,-             setRGB,              setMotor,+             setRGB,              playTone,              Line(LEFTB, RIGHTB, BOTHB, BOTHW),              Command() ) where@@ -324,12 +319,21 @@ -} setRGB  index red green blue = MBotCommand idx RUN  RGBLED rgbp  [2,index,red,green,blue] +setJoystick a b c d            = MBotCommand  idx RUN  JOYSTICK  a     [b,c,d] -setMotor port speed sp       = MBotCommand  idx RUN  MOTOR  port  [speed,sp]-getLineFollower              = MBotCommand  lineIdx   GET LINEFOLLOWER      linp  []-getUltrasonicSensor          = MBotCommand  ultraIdx  GET ULTRASONIC_SENSOR sonp  []+{-|+   Create an mBot command for moving the motors+-}+setMotor vl vr                 =  let (hspeed,lspeed) = shortToBytes vr+                                      (hnegsp,lnegsp) = shortToBytes (-vl)+                                  in        +                                      setJoystick lnegsp hnegsp lspeed hspeed   +getLineFollower                = MBotCommand  lineIdx   GET LINEFOLLOWER      linp  []+getUltrasonicSensor            = MBotCommand  ultraIdx  GET ULTRASONIC_SENSOR sonp  []++ {-|    Read out the status of the ultrasonic line follower -}@@ -339,41 +343,17 @@ -} readLineFollower d = convertToReading <$> readSensor d getLineFollower  lineIdx --- Example code to show how the motor commands work -{-|-   Start both motors so that the robot moves fowards--}-goAhead d = do  sendCommand d $ setMotor rightMotor speed  stops-                sendCommand d $ setMotor leftMotor   (complement speed)  (complement stops)----{-|-   Start both motors so that the robot moves backwards--}-goBackwards d = do  sendCommand d $ setMotor rightMotor (complement speed) (complement stops)-                    sendCommand d $ setMotor leftMotor  speed stops----{-|-  Start the motors let the mBot turn left--}-goLeft d  = do   sendCommand d $ setMotor leftMotor  stops stops-                 sendCommand d $ setMotor rightMotor speed stops--{-|-  Start the motors so that the robots turns right--}-goRight d = do  sendCommand d $ setMotor rightMotor  stops               stops-                sendCommand d $ setMotor leftMotor   (complement speed)  (complement stops)+-- Split a short into a tuple of two bytes+shortToBytes i = (shiftR i 8, i)  {-|-   Stop both motors+   Set the speed of the motors -}-stop d   = do   sendCommand d $ setMotor rightMotor  stops stops-                sendCommand d $ setMotor leftMotor   stops stops+drive d vl vr =  let (hspeed,lspeed) = shortToBytes vr+                     (hnegsp,lnegsp) = shortToBytes (-vl)+                    in    +                       do sendCommand d $ setJoystick lnegsp hnegsp lspeed hspeed    {-|@@ -387,5 +367,3 @@                           -- there. Something something little-endian?                           in MBotCommand idx RUN TONE                              lowFreq [highFreq, lowTime, highTime]-                      where -- Split a short into a tuple of two bytes-                             shortToBytes i = (shiftR i 8, i)