forked from sharpbrick/powered-up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleMotorControl.cs
44 lines (32 loc) · 1.54 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
43
44
using System.Threading.Tasks;
using SharpBrick.PoweredUp;
namespace Example;
public class ExampleMotorControl : BaseExample
{
public override async Task ExecuteAsync()
{
using var technicMediumHub = Host.FindByType<TechnicMediumHub>();
await technicMediumHub.VerifyDeploymentModelAsync(modelBuilder => modelBuilder
.AddHub<TechnicMediumHub>(hubBuilder => hubBuilder
.AddDevice<TechnicXLargeLinearMotor>(technicMediumHub.A)
)
);
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(-100, 90, SpeedProfiles.None);
await Task.Delay(2000);
await motor.StartSpeedAsync(0, 90, SpeedProfiles.None);
await Task.Delay(10_000);
await motor.GotoPositionAsync(45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await Task.Delay(2000);
await motor.GotoPositionAsync(-45, 10, 100, SpecialSpeed.Brake, SpeedProfiles.None);
await technicMediumHub.SwitchOffAsync();
}
}