-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathExampleRampUp.cs
More file actions
48 lines (34 loc) · 1.59 KB
/
Copy pathExampleRampUp.cs
File metadata and controls
48 lines (34 loc) · 1.59 KB
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 System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SharpBrick.PoweredUp;
using SharpBrick.PoweredUp.Functions;
namespace Example;
public class ExampleRampUp : BaseExample
{
public override async Task ExecuteAsync()
{
using var technicMediumHub = Host.FindByType<TechnicMediumHub>();
var stopWatch = new Stopwatch();
var motor = technicMediumHub.A.GetDevice<TechnicLargeLinearMotor>();
// ramp up with linear speed
var rampUp = ServiceProvider.GetRequiredService<LinearSpeedChange>();
await technicMediumHub.RgbLight.SetRgbColorNoAsync(PoweredUpColor.Red);
stopWatch.Start();
await rampUp.ExecuteAsync(motor, 20, 100, 40, 10_000);
var redPhase = stopWatch.ElapsedMilliseconds;
await technicMediumHub.RgbLight.SetRgbColorNoAsync(PoweredUpColor.Green);
await Task.Delay(2_000);
await technicMediumHub.RgbLight.SetRgbColorNoAsync(PoweredUpColor.Orange);
// ramp down with linear speed
var rampDown = ServiceProvider.GetRequiredService<LinearSpeedChange>();
var beforeOrangePhase = stopWatch.ElapsedMilliseconds;
await rampDown.ExecuteAsync(motor, 100, 0, 100, 20_000);
var orangePhase = stopWatch.ElapsedMilliseconds - beforeOrangePhase;
stopWatch.Stop();
await technicMediumHub.SwitchOffAsync();
// time delays (parameter) + 100s of BLE messages async/await ops
Log.LogInformation($"Red Phase: {redPhase}ms; Orange Phase: {orangePhase}ms");
}
}