/
Program.cs
48 lines (43 loc) · 1.2 KB
/
Program.cs
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
48
using RoboticArm535Library;
using System;
using System.Threading;
using System.Threading.Tasks;
UsbComms usb = new();
CancellationTokenSource tokenSource = new();
if (usb.Connect() != UsbConnErrorCode.NoError)
{
Console.WriteLine("Unable to connect to USB device.");
Console.ReadKey();
return;
}
Console.CancelKeyPress += (sender, e) => { tokenSource.Cancel(); e.Cancel = true; };
Console.WriteLine("Press Ctrl-C to abort");
// demonstrates a simple script
try
{
await sendCommandsByTimedOpCodeMasks();
}
catch (OperationCanceledException)
{
Console.WriteLine("Script aborted.");
}
finally
{
tokenSource.Dispose();
}
async Task sendCommandsByTimedOpCodeMasks()
{
await Task.Run(() =>
{
usb.Cmd(OpCode.WristUp, 1.0f);
usb.Cmd(OpCode.ElbowUp, 1.0f);
for (int i = 0; i < 5; i++)
{
if (tokenSource.IsCancellationRequested)
tokenSource.Token.ThrowIfCancellationRequested();
usb.Cmd(OpCode.GripOpen | OpCode.WristUp | OpCode.LedOn, 0.8f);
usb.Cmd(OpCode.GripClose | OpCode.WristDown | OpCode.LedOff, 0.8f);
}
usb.Cmd(OpCode.WristDown | OpCode.ElbowDown, 1.0f);
}, tokenSource.Token);
}