-
Notifications
You must be signed in to change notification settings - Fork 2
/
New-RobotFlow.org.ps1
47 lines (40 loc) · 1.26 KB
/
New-RobotFlow.org.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
param(
[Parameter(Mandatory=$true)]
[String]$IPAddress,
[Parameter(Mandatory=$true)]
[Int]$LengthInCm,
[Parameter(Mandatory=$true)]
[ValidateSet("grab", "release")]
[String]$Action
)
$ErrorActionPreference = "stop"
#Init Robot
[System.Reflection.Assembly]::LoadFrom("C:\DLLs\Lego.Ev3.Desktop.dll")
$com = new-object Lego.Ev3.Desktop.NetworkCommunication -ArgumentList $IPAddress
$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)"
}
#$LengthInCm = 30
$lengthInSteps = $LengthInCm * 35
#Go forward
$brick.DirectCommand.StepMotorAtPowerAsync("B", 100, 0, $lengthInSteps, 0, $true);
$brick.DirectCommand.StepMotorAtPowerAsync("C", 100, 0, $lengthInSteps, 0, $true);
start-sleep -Seconds 1
switch($Action) {
"grab" {
#Release grab
$brick.DirectCommand.StepMotorAtPowerAsync("A",50, 0, 700, 0, $true)
start-sleep -Seconds 2
$brick.DirectCommand.StopMotorAsync("A",$false)
}
"release" {
#Release grab
$brick.DirectCommand.StepMotorAtPowerAsync("A",-50, 0, 700, 0, $true)
start-sleep -Seconds 2
$brick.DirectCommand.StopMotorAsync("A",$false)
}
}