-
Notifications
You must be signed in to change notification settings - Fork 0
/
DescisionThread.cs
52 lines (44 loc) · 1.39 KB
/
DescisionThread.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
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Samples.Kinect.DepthBasics.Properties;
namespace Microsoft.Samples.Kinect.DepthBasics
{
class DescisionThread
{
private ArduinoCommunictor arduinoCom;
private VectorAngleEngine vectorEngine;
private readonly int threshold = 5;
public DescisionThread()
{
//arduinoCom = new ArduinoCommunictor();
vectorEngine = new VectorAngleEngine();
}
public void Decide()
{
while (true)
{
System.Threading.Thread.Sleep(1); // must be less than the arduino delay() value
double[] ranges = MainWindow.ranges;
if (IsEmergency(ranges, threshold))
{
int rotation = vectorEngine.VectorAngle(ranges);
//arduinoCom.SendRotation(rotation); // value -70 to 70
}
}
}
// Will change according to velocity ideally
private bool IsEmergency(double[] ranges, int threshold)
{
if (ranges == null)
return false;
for (int i = 0; i < ranges.Length; i++)
{
if (ranges[i] <= threshold && ranges[i] != 0)
return true;
}
return false;
}
}
}