forked from sharpbrick/powered-up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleMotorControl.cs
42 lines (33 loc) · 1.65 KB
/
ExampleMotorControl.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
using System;
using System.Threading.Tasks;
using SharpBrick.PoweredUp;
namespace Example
{
public static class ExampleMotorControl
{
public static async Task ExecuteAsync(PoweredUpHost host, IServiceProvider serviceProvider, Hub selectedHub)
{
using (var technicMediumHub = host.FindByType<TechnicMediumHub>())
{
var motor = technicMediumHub.A.GetDevice<TechnicXLargeLinearMotor>();
await motor.SetAccelerationTimeAsync(3000);
await motor.SetDecelerationTimeAsync(1000);
await motor.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile);
await Task.Delay(10_000);
await motor.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await Task.Delay(10_000);
await motor.StartSpeedAsync(100, 90, SpeedProfiles.None);
await Task.Delay(2000);
await motor.StartSpeedAsync(127, 90, SpeedProfiles.None);
await motor.StartSpeedAsync(-100, 90, SpeedProfiles.None);
await Task.Delay(2000);
await motor.StartSpeedAsync(0, 90, SpeedProfiles.None);
await Task.Delay(10_000);
await motor.GotoAbsolutePositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await Task.Delay(2000);
await motor.GotoAbsolutePositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await technicMediumHub.SwitchOffAsync();
}
}
}
}