|
@@ -200,7 +200,7 @@ namespace KinectCar
|
|
|
new Tuple<JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft),
|
|
|
new Tuple<JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
// 设置状态文本
|
|
|
StatusText = _kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText;
|
|
|
// 在这个简单的例子中使用window对象作为视图模型
|
|
@@ -347,49 +347,77 @@ namespace KinectCar
|
|
|
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)
|
|
|
+ if (body.HandRightState == HandState.Open && body.HandLeftState == HandState.Open)
|
|
|
{
|
|
|
- TipText = "前进";
|
|
|
- _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("8"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
- // 角度计算
|
|
|
- var value = Math.Atan2((yHandRight - yHandLeft), (xHandRight - xHandLeft)) * 180 / Math.PI;
|
|
|
- // 20 < value < 80
|
|
|
- if (20 < value && value < 90)
|
|
|
- {
|
|
|
- TipText = "左前方行驶";
|
|
|
- _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("4"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
- }
|
|
|
- // < value < 170
|
|
|
- if (-90 < value && value < -20)
|
|
|
- {
|
|
|
- TipText = "右前方行驶";
|
|
|
- _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("6"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
- }
|
|
|
+ TipText = "停止";
|
|
|
+ //Console.WriteLine("stop");
|
|
|
+ _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("0"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
}
|
|
|
- // 双手进入控制区域
|
|
|
- if (body.HandRightState == HandState.Lasso && body.HandLeftState == HandState.Lasso && yHandRight > ySpineMid && yHandLeft > xSpineMid)
|
|
|
+ //前进逻辑
|
|
|
+ if (Count % 2 == 1)
|
|
|
{
|
|
|
- // 角度计算
|
|
|
- _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("Reversing"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
- var value = Math.Atan2((yHandRight - yHandLeft), (xHandRight - xHandLeft)) * 180 / Math.PI;
|
|
|
- // 20 < value < 80
|
|
|
- if (20 < value && value < 90)
|
|
|
+ // 控制汽车逻辑
|
|
|
+ if (body.HandRightState == HandState.Closed && body.HandLeftState == HandState.Closed)
|
|
|
{
|
|
|
- TipText = "右后方行驶";
|
|
|
- _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("Reversing right"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+ // 角度计算
|
|
|
+ var value = Math.Atan2((yHandRight - yHandLeft), (xHandRight - xHandLeft)) * 180 / Math.PI;
|
|
|
+
|
|
|
+ if (20 > value && value > -20)
|
|
|
+ {
|
|
|
+ TipText = "前进";
|
|
|
+ Console.WriteLine("go");
|
|
|
+ _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("8"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 右高左低
|
|
|
+ if (20 < value && value < 90)
|
|
|
+ {
|
|
|
+ TipText = "左前方行驶";
|
|
|
+ Console.WriteLine("left");
|
|
|
+ _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("4"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 左高右低
|
|
|
+ if (-90 < value && value < -20)
|
|
|
+ {
|
|
|
+ TipText = "右前方行驶";
|
|
|
+ Console.WriteLine("rightt");
|
|
|
+ _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("6"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+ }
|
|
|
}
|
|
|
- // < value < 170
|
|
|
- if (-90 < value && value < -20)
|
|
|
+
|
|
|
+ }
|
|
|
+ //后退逻辑
|
|
|
+ if (Count % 2 == 0)
|
|
|
+ {
|
|
|
+ // 控制汽车逻辑
|
|
|
+ if (body.HandRightState == HandState.Closed && body.HandLeftState == HandState.Closed)
|
|
|
{
|
|
|
- TipText = "左后方行驶";
|
|
|
- _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("Reversing left"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+
|
|
|
+ var value = Math.Atan2((yHandRight - yHandLeft), (xHandRight - xHandLeft)) * 180 / Math.PI;
|
|
|
+
|
|
|
+ if (20 > value && value > -20)
|
|
|
+ {
|
|
|
+ TipText = "后退";
|
|
|
+ Console.WriteLine("brak");
|
|
|
+ _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("2"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 右高左低
|
|
|
+ if (20 < value && value < 90)
|
|
|
+ {
|
|
|
+ TipText = "左方行驶";
|
|
|
+ _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("4"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+
|
|
|
+ }
|
|
|
+ // 左高右低
|
|
|
+ if (-90 < value && value < -20)
|
|
|
+ {
|
|
|
+ TipText = "右方行驶";
|
|
|
+ _client.Publish(Const.MQTT_TOPIC_CAR_CTRL, Encoding.UTF8.GetBytes("6"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 麦克风管理
|
|
|
if (jointHead.TrackingState == TrackingState.Tracked
|
|
|
&& jointHandRight.TrackingState == TrackingState.Tracked
|
|
@@ -417,7 +445,7 @@ namespace KinectCar
|
|
|
{
|
|
|
if (positionHandRight.Y < positionHead.Y)
|
|
|
{
|
|
|
- Console.WriteLine("手势合格,麦克风打开.键盘输入 下键");
|
|
|
+ Console.WriteLine("手势合格 ,麦克风打开.键盘输入 下键");
|
|
|
open1 = false;
|
|
|
open2 = false;
|
|
|
}
|
|
@@ -457,8 +485,7 @@ namespace KinectCar
|
|
|
open4 = false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- ////未使用功能 执行一次开启,再次重复关闭
|
|
|
+ //未使用功能 执行一次开启,再次重复关闭
|
|
|
if (open4 && open1)
|
|
|
{
|
|
|
if (positionHandLeft.Y < positionHead.Y && positionHandRight.Y < positionHead.Y)
|