|
@@ -131,9 +131,9 @@
|
|
|
string clientId = Guid.NewGuid().ToString();
|
|
|
_client.Connect(clientId, "yumin", "minbb.cn");
|
|
|
// 订阅主题"" 消息质量为 2
|
|
|
- _client.Subscribe(new string[] { "iot.time" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
|
|
|
+ _client.Subscribe(new string[] { "wifi/car" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
|
|
|
// 发布消息到主题 "wifi/car" 消息质量为 2,不保留
|
|
|
- _client.Publish("iot.all", Encoding.UTF8.GetBytes("I'm C#"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+ _client.Publish("wifi/car", Encoding.UTF8.GetBytes("I'm C#"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
}
|
|
|
|
|
|
private void Window_Closing(object sender, CancelEventArgs e)
|
|
@@ -176,117 +176,150 @@
|
|
|
dataReceived = true;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //所有工作
|
|
|
if (dataReceived)
|
|
|
{
|
|
|
+
|
|
|
+ //Console.WriteLine("进入程序");
|
|
|
+
|
|
|
foreach (Body body in _bodies)
|
|
|
{
|
|
|
if (body.IsTracked)
|
|
|
{
|
|
|
Status.Content = "追踪到Body.";
|
|
|
+ //Console.WriteLine(body.HandRightConfidence);
|
|
|
IReadOnlyDictionary<JointType, Joint> joints = body.Joints;
|
|
|
|
|
|
- Joint jointHandRight = joints[JointType.HandRight], jointShoulderRight = joints[JointType.ShoulderRight];
|
|
|
- CameraSpacePoint positionHandRight = jointHandRight.Position, positionShoulderRight = jointShoulderRight.Position;
|
|
|
- if (jointHandRight.TrackingState == TrackingState.Tracked &&
|
|
|
- jointShoulderRight.TrackingState == TrackingState.Tracked)
|
|
|
+ //Console.WriteLine("追踪到body");
|
|
|
+ //右手
|
|
|
+ Joint jointHandRight = joints[JointType.HandRight];
|
|
|
+ //右肩膀
|
|
|
+ Joint jointShoulderRight = joints[JointType.ShoulderRight];
|
|
|
+ //左手
|
|
|
+ Joint jointHandLeft = joints[JointType.HandLeft];
|
|
|
+ //左肩
|
|
|
+ Joint jointShoulderLeft = joints[JointType.ShoulderLeft];
|
|
|
+ // 脊柱中
|
|
|
+ Joint jointSpineMid = joints[JointType.SpineBase];
|
|
|
+
|
|
|
+
|
|
|
+ //右手空间坐标
|
|
|
+ CameraSpacePoint positionHandRight = jointHandRight.Position;
|
|
|
+ //左手空间坐标
|
|
|
+ CameraSpacePoint positionHandLeft = jointHandLeft.Position;
|
|
|
+ //脊椎中空间坐标
|
|
|
+ CameraSpacePoint positionSpineMid = jointSpineMid.Position;
|
|
|
+
|
|
|
+ //右手坐标集
|
|
|
+ float xHandRight = positionHandRight.X;
|
|
|
+ float yHandRight = positionHandRight.Y;
|
|
|
+ float zHandRight = positionHandRight.Z;
|
|
|
+
|
|
|
+ //左手坐标集
|
|
|
+ float xHandLeft = positionHandLeft.X;
|
|
|
+ float yHandLeft = positionHandLeft.Y;
|
|
|
+ float ZHandLeft = positionHandLeft.Z;
|
|
|
+
|
|
|
+ //脊椎中坐标集
|
|
|
+ float xSpineMid = positionSpineMid.X;
|
|
|
+ float ySpineMid = positionSpineMid.Y;
|
|
|
+ float ZSpineMid = positionSpineMid.Z;
|
|
|
+ //追踪到所需目标。
|
|
|
+
|
|
|
+
|
|
|
+ Console.WriteLine(body.HandRightState);
|
|
|
+ Console.WriteLine(body.HandLeftState);
|
|
|
+ //双手进入控制区域
|
|
|
+ if (body.HandRightState == HandState.Closed && body.HandLeftState == HandState.Closed && yHandRight > ySpineMid && yHandLeft > xSpineMid)
|
|
|
{
|
|
|
- float xHandRight = positionHandRight.X, yHandRight = positionHandRight.Y;
|
|
|
- float xShoulderRight = positionShoulderRight.X, yShoulderRight = positionShoulderRight.Y;
|
|
|
- // 右手位置判定(基于右肩为原点且无深度检测)
|
|
|
- if (xHandRight >= 2 * xShoulderRight - Threshold && xHandRight <= 2 * xShoulderRight + Threshold &&
|
|
|
- yHandRight >= 2 * yShoulderRight - Threshold && yHandRight <= 2 * yShoulderRight + Threshold)
|
|
|
- {
|
|
|
- // 中 - 5
|
|
|
- if(_gesture != 5)
|
|
|
- {
|
|
|
- _gesture = 5;
|
|
|
- Console.WriteLine("中");
|
|
|
- }
|
|
|
- }
|
|
|
- else if(xHandRight > 2 * xShoulderRight - Threshold && xHandRight < 2 * xShoulderRight + Threshold && yHandRight > 2 * yShoulderRight + Threshold)
|
|
|
- {
|
|
|
- // 上 - 2
|
|
|
- if (_gesture != 2)
|
|
|
- {
|
|
|
- _gesture = 2;
|
|
|
- Console.WriteLine("上");
|
|
|
- }
|
|
|
- }
|
|
|
- else if (xHandRight > 2 * xShoulderRight - Threshold && xHandRight < 2 * xShoulderRight + Threshold && yHandRight < 2 * yShoulderRight + Threshold)
|
|
|
- {
|
|
|
- // 下 - 8
|
|
|
- if (_gesture != 8)
|
|
|
- {
|
|
|
- _gesture = 8;
|
|
|
- Console.WriteLine("下");
|
|
|
- }
|
|
|
- }
|
|
|
- else if (xHandRight < 2 * xShoulderRight - Threshold && yHandRight > 2 * yShoulderRight - Threshold && yHandRight < 2 * yShoulderRight + Threshold)
|
|
|
- {
|
|
|
- // 左 - 4
|
|
|
- if (_gesture != 4)
|
|
|
- {
|
|
|
- _gesture = 4;
|
|
|
- Console.WriteLine("左");
|
|
|
- }
|
|
|
- }
|
|
|
- else if (xHandRight > 2 * xShoulderRight + Threshold && yHandRight > 2 * yShoulderRight - Threshold && yHandRight < 2 * yShoulderRight + Threshold)
|
|
|
- {
|
|
|
- // 右 - 6
|
|
|
- if (_gesture != 6)
|
|
|
- {
|
|
|
- _gesture = 6;
|
|
|
- Console.WriteLine("右");
|
|
|
- }
|
|
|
- }
|
|
|
- else if (xHandRight > 2 * xShoulderRight + Threshold && yHandRight > 2 * yShoulderRight + Threshold)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Console.WriteLine("前进");
|
|
|
+ _client.Publish("wifi/car", Encoding.UTF8.GetBytes("go"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+
|
|
|
+ //角度计算
|
|
|
+
|
|
|
+ double value = Math.Atan2((yHandRight - yHandLeft), (xHandRight - xHandLeft)) * 180 / Math.PI;
|
|
|
+
|
|
|
+ Console.WriteLine("执行到这里了 {0}", value);
|
|
|
+ // 20 < value < 80
|
|
|
+ if (20 < value && value < 90)
|
|
|
{
|
|
|
- // 右上 - 3
|
|
|
- if (_gesture != 3)
|
|
|
- {
|
|
|
- _gesture = 3;
|
|
|
- Console.WriteLine("右上");
|
|
|
- }
|
|
|
+ Console.WriteLine("左前方行驶");
|
|
|
+ _client.Publish("wifi/car", Encoding.UTF8.GetBytes("lef go"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
}
|
|
|
- else if (xHandRight > 2 * xShoulderRight + Threshold && yHandRight < 2 * yShoulderRight - Threshold)
|
|
|
+
|
|
|
+ // < value < 170
|
|
|
+ if (-90 < value && value < -20)
|
|
|
{
|
|
|
- // 右下 - 9
|
|
|
- if (_gesture != 9)
|
|
|
- {
|
|
|
- _gesture = 9;
|
|
|
- Console.WriteLine("右下");
|
|
|
- }
|
|
|
+ Console.WriteLine("右前方行驶");
|
|
|
+ _client.Publish("wifi/car", Encoding.UTF8.GetBytes("right go"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
}
|
|
|
- else if (xHandRight < 2 * xShoulderRight - Threshold && yHandRight > 2 * yShoulderRight + Threshold)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (body.HandRightState == HandState.Lasso && body.HandLeftState == HandState.Lasso && yHandRight > ySpineMid && yHandLeft > xSpineMid)
|
|
|
+ {
|
|
|
+
|
|
|
+ //角度计算
|
|
|
+ _client.Publish("wifi/car", Encoding.UTF8.GetBytes("Reversing"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+ double value = Math.Atan2((yHandRight - yHandLeft), (xHandRight - xHandLeft)) * 180 / Math.PI;
|
|
|
+
|
|
|
+ Console.WriteLine("执行到这里了 {0}", value);
|
|
|
+ // 20 < value < 80
|
|
|
+ if (20 < value && value < 90)
|
|
|
{
|
|
|
- // 左上 - 1
|
|
|
- if (_gesture != 1)
|
|
|
- {
|
|
|
- _gesture = 1;
|
|
|
- Console.WriteLine("左上");
|
|
|
- }
|
|
|
+ Console.WriteLine("右后方行驶");
|
|
|
+ _client.Publish("wifi/car", Encoding.UTF8.GetBytes("Reversing right"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+
|
|
|
}
|
|
|
- else if (xHandRight < 2 * xShoulderRight - Threshold && yHandRight < 2 * yShoulderRight - Threshold)
|
|
|
+
|
|
|
+ // < value < 170
|
|
|
+ if (-90 < value && value < -20)
|
|
|
{
|
|
|
- // 左下 - 7
|
|
|
- if (_gesture != 7)
|
|
|
- {
|
|
|
- _gesture = 7;
|
|
|
- Console.WriteLine("左下");
|
|
|
- }
|
|
|
+ Console.WriteLine("左后方行驶");
|
|
|
+ _client.Publish("wifi/car", Encoding.UTF8.GetBytes("Reversing left"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
}
|
|
|
- //Console.WriteLine("X = " + positionHead.X + ", Y = " + positionHead.Y + ", Z = " + positionHead.Z);
|
|
|
- //Console.WriteLine("X = " + positionHandRight.X + ", Y = " + positionHandRight.Y + ", Z = " + positionHandRight.Z);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- // 将关节点转换为深度(显示)空间
|
|
|
- //Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>();
|
|
|
- //foreach (JointType jointType in joints.Keys)
|
|
|
- //{
|
|
|
- // DepthSpacePoint depthSpacePoint = coordinateMapper.MapCameraPointToDepthSpace(positionHead);
|
|
|
- // jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
|
|
|
- //}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|