PowerShell/SMA/WAP: Controlling LEGO Mindstorms EV3 from PowerShell/SMA Runbook – Part 1 – The Runbook

A few weeks ago i posted the video about my demo of the LEGO Mindstorms robot, controlled by a Runbook inside the Service Management Automation section of Windows Azure Pack

The video has been seen by many people and i have gotten so much great feedback!

Multiple people have asked me of “How did you do that?”

I have decided to do a multi part post, first posting the details, then more guides to how to do the different setup tasks

Part 1 – SMA Runbook, Overview + Setup

Part 2 – How to setup a variable asset in SMA (Robot Com port value)

Part 3 – How to setup a connection asset in SMA (Robot Server conneciton)

First the Video:

URL: http://youtu.be/1Al-dY-DHlw

Blog post: http://blog.coretech.dk/?p=7308

and here is how to do it!

Setup Robot connection and asssemblies

  1. Build the LEGO Robot using the build manual!
  2. Pair the robot to a computer which has PowerShell Remoting enabled.
  3. Open Bluetooth settings and check the com port number of which is the outgoing port to EV3. (COM10 in this example)


  1. Download the LEGO Mindstorms EV3 .net library from CodePlex here
  2. Place the Desktop assembly, Lego.Ev3.Desktop.dll, on the computer. Note the location for use later.

Setup Service Management Automation Runbook

  1. Logon to Windows Azure Pack administration site
  2. Create a mgmt server connection asset called RobotServer (How to, will be explained in Part 3)
  3. Create a setting asset, called RobotPort. This is a string asset with the value of the COM port of which the robot is connected via bluetooth (COM10 etc.) (will be explained in Part 2)
  4. Edit the New-Robotnotification workflow to make sure the Path to the Lego.Ev3.Desktop.dll assembly is correct.
  5. Import the New-RobotNotification runbook/workflow to SMA.
  6. Publish the runbook.
  7. Start the runbook and provide directory (Left/Right)
  8. Wait for the magic to happen!

Download the workflow here:

zip New-RobotNotification.zip 1.2 kB
Downloaded 70 times

or copy paste the code from below:

workflow New-RobotNotification
        A workflow developed for demo'ing a LEGO Mindsstorms EV3 robot via Windows Azure Pack - Service Management Automation

        This workflow was originally developed by Jakob Gottlieb Svendsen, Datacenter MVP, Coretech, Denmark

    # Specify input parameters here
	param (
    $comPort = Get-AutomationVariable -Name 'RobotComPort'
    $Connection = Get-AutomationConnection -Name 'RobotServer'

    $Password = ConvertTo-SecureString -AsPlainText `
    -String $Connection.Password -Force
    $Cred = New-Object -TypeName System.Management.Automation.PSCredential `
    -ArgumentList $Connection.Username, $Password
   $result = InlineScript

 $ErrorActionPreference = "stop"
[System.Reflection.Assembly]::LoadFrom("E:\Data\System Center\WAP\SMA\Workflows\LEGO Mindstorms\Lego.Ev3.1.0.0\Desktop\Lego.Ev3.Desktop.dll")

$com = new-object Lego.Ev3.Desktop.BluetoothCommunication -ArgumentList $Using:comPort
$brick = new-object Lego.Ev3.Core.Brick -ArgumentList $com, $true
$result = $brick.ConnectAsync()

Start-Sleep -Seconds 1

if($result.Status -eq "Faulted")
    throw "cannot connect to robot $($result.Exception)"
#$brick.DirectCommand | gm
#Go Forward
$brick.DirectCommand.TurnMotorAtPowerForTimeAsync("B",100, 0, 5 * 1000, 0, $false)
$brick.DirectCommand.TurnMotorAtPowerForTimeAsync("C",100, 0, 5 * 1000, 0, $false)
Start-Sleep -Seconds 5

if ($Using:Direction -eq "Left")
    #Turn 90 degrees Left
    $brick.DirectCommand.StepMotorAtPowerAsync("B", -100, 0, 400, 0, $false); 
    $brick.DirectCommand.StepMotorAtPowerAsync("C", 100, 0, 400, 0, $false); 
    #Turn 90 degrees Right
    $brick.DirectCommand.StepMotorAtPowerAsync("B", 100, 0, 400, 0, $false); 
    $brick.DirectCommand.StepMotorAtPowerAsync("C", -100, 0, 400, 0, $false); 
Start-Sleep -Seconds 1

#wave flag    
for($i=0;$i -lt 5;$i++)
    $brick.DirectCommand.TurnMotorAtPowerForTimeAsync("B",-100, 0, 0.5 * 1000, 0, $false)
    $brick.DirectCommand.TurnMotorAtPowerForTimeAsync("C",100, 0, 0.5 * 1000, 0, $false)
    Start-Sleep -Milliseconds 500
    $brick.DirectCommand.TurnMotorAtPowerForTimeAsync("B",100, 0, 0.5 * 1000, 0, $false)
    $brick.DirectCommand.TurnMotorAtPowerForTimeAsync("C",-100, 0, 0.5 * 1000, 0, $false)
    Start-Sleep -Milliseconds 500

    } –PSComputer $Connection.ComputerName –PSCredential $Cred
write-debug ($result | Out-String)

Have fun!

and please dont hesistate to comment or contact me about ideas/fixes/anything related to system center or Windows Azure Pack

Comments (2):

  1. Viswanatha Swamy says:


    How will Azure Automation knows that from where it should pickup the .dll. I have to load CloudStorageClient.dll. Please advice. Many thanks!

    Viswanatha Swamy

Leave a Reply