From a3a2d143283889abf8ea4620b211e6be38f8c092 Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Thu, 15 Dec 2022 18:54:29 +0100 Subject: [PATCH] implemented steering and added robot control to UI --- .../RobotClientWpf/Assets/arrow-down-bold.png | Bin 0 -> 368 bytes ADIS_Csharp/RobotClientWpf/MainWindow.xaml | 2 +- .../RobotClientWpf/RobotClientWpf.csproj | 4 ++ .../RobotClientWpf/Views/MainView.xaml | 58 +++++++++++++++- .../RobotClientWpf/Views/MainView.xaml.cs | 62 ++++++++++++++++++ ADIS_Csharp/RobotConsoleClient/Program.cs | 4 +- ADIS_Csharp/RobotLib/Movement/DevMovement.cs | 2 +- 7 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 ADIS_Csharp/RobotClientWpf/Assets/arrow-down-bold.png diff --git a/ADIS_Csharp/RobotClientWpf/Assets/arrow-down-bold.png b/ADIS_Csharp/RobotClientWpf/Assets/arrow-down-bold.png new file mode 100644 index 0000000000000000000000000000000000000000..e2c20c7a53cb267e1f5fbf6f7fab7cd1a1ab3ae6 GIT binary patch literal 368 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbBSkfJR9T^xl_H+M9WCijSl0AZa z85pY67#JE_7#My5g&JNkFq9fFFuY1&V6Xz}5igjtE6@fg!ItFh?gFHN;HUHMdLYGF z;1O92q!YmSL$=d-Afw3B#W5t}@Y}1_Tnz>St{1y!3$uKm65Bo1>=wtQ`zppqcYnB5 zu#8J%Y0|U??afy{eRxzm(}9UoWrDeb!s)OF3jfouzGL~Ou|luM^b|{StI^Rfi`o*R z0-X)FuF#wjbS1=x?`hLd=bcIWRtU`4{&r@NR*iXn+@y!j*90a4ZC5REjVMV;EJ?LW zE=mPb3`PbWooExU|?lnP`-2vs)pSBl+3hB+#1+^@aO_--> - + diff --git a/ADIS_Csharp/RobotClientWpf/RobotClientWpf.csproj b/ADIS_Csharp/RobotClientWpf/RobotClientWpf.csproj index 02c5250..b651ea2 100644 --- a/ADIS_Csharp/RobotClientWpf/RobotClientWpf.csproj +++ b/ADIS_Csharp/RobotClientWpf/RobotClientWpf.csproj @@ -8,6 +8,7 @@ + @@ -21,6 +22,9 @@ + + Always + Always diff --git a/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml b/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml index 8377738..d3c0402 100644 --- a/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml +++ b/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml @@ -5,20 +5,72 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:RobotClientWpf.Views" mc:Ignorable="d" - d:DesignHeight="450" d:DesignWidth="800"> + d:DesignHeight="450" d:DesignWidth="800" KeyDown="UserControl_KeyDown"> - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml.cs b/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml.cs index e7d91f6..44f7ffd 100644 --- a/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml.cs +++ b/ADIS_Csharp/RobotClientWpf/Views/MainView.xaml.cs @@ -1,5 +1,7 @@ using RobotClientWpf.Utilities; +using System.DirectoryServices.ActiveDirectory; using System.Windows.Controls; +using System.Windows.Input; namespace RobotClientWpf.Views { @@ -10,6 +12,8 @@ namespace RobotClientWpf.Views { private static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger(); private ChallengeFactory? challenge; + private const int AMOUNT_SPEED_ADDED_PER_CLICK = 10; + private const int TURN_ANGLE_PER_CLICK = 25; public MainView() { @@ -27,5 +31,63 @@ namespace RobotClientWpf.Views { UIAccessHelpers.SetTextboxText(this.tbSplitflapText, e.DisplayMessage); } + + private void btnModeAuto_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.challenge?.RobotMobile.Movement.SetMobilityMode(true); + } + + private void btnModeManual_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.challenge?.RobotMobile.Movement.SetMobilityMode(false); + } + + private void btnRoboFwd_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.challenge?.RobotMobile.Movement.AddSpeed(AMOUNT_SPEED_ADDED_PER_CLICK); + } + private void btnRoboBwd_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.challenge?.RobotMobile.Movement.AddSpeed(-AMOUNT_SPEED_ADDED_PER_CLICK); + } + + private void btnRoboRight_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.challenge?.RobotMobile.Movement.Turn(TURN_ANGLE_PER_CLICK); + } + + private void btnRoboLeft_Click(object sender, System.Windows.RoutedEventArgs e) + { + this.challenge?.RobotMobile.Movement.Turn(-TURN_ANGLE_PER_CLICK); + } + + private void UserControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) + { + if (e.Key == Key.Up) + { + this.challenge?.RobotMobile.Movement.AddSpeed(AMOUNT_SPEED_ADDED_PER_CLICK); + e.Handled = true; + } + else if (e.Key == Key.Down) + { + this.challenge?.RobotMobile.Movement.AddSpeed(-AMOUNT_SPEED_ADDED_PER_CLICK); + e.Handled = true; + } + else if (e.Key == Key.Left) + { + this.challenge?.RobotMobile.Movement.Turn(-TURN_ANGLE_PER_CLICK); + e.Handled = true; + } + else if (e.Key == Key.Right) + { + this.challenge?.RobotMobile.Movement.Turn(TURN_ANGLE_PER_CLICK); + e.Handled = true; + } + else if(e.Key == Key.End) + { + this.challenge?.RobotMobile.Movement.Stop(); + e.Handled = true; + } + } } } diff --git a/ADIS_Csharp/RobotConsoleClient/Program.cs b/ADIS_Csharp/RobotConsoleClient/Program.cs index d2d83d8..3720897 100644 --- a/ADIS_Csharp/RobotConsoleClient/Program.cs +++ b/ADIS_Csharp/RobotConsoleClient/Program.cs @@ -19,9 +19,9 @@ namespace RobotConsoleClient robotStationary.SplitFlap.InitializeAllSplitflaps(); Thread.Sleep(1000); - robotMobile.Movement.SetSpeed(1000); + robotMobile.Movement.AddSpeed(1000); robotMobile.Movement.Turn(-10); - robotMobile.Movement.SetSpeed(-500); + robotMobile.Movement.AddSpeed(-500); robotMobile.Movement.Stop(); robotMobile.Movement.SetMobilityMode(automatic: true); diff --git a/ADIS_Csharp/RobotLib/Movement/DevMovement.cs b/ADIS_Csharp/RobotLib/Movement/DevMovement.cs index f58638a..8648400 100644 --- a/ADIS_Csharp/RobotLib/Movement/DevMovement.cs +++ b/ADIS_Csharp/RobotLib/Movement/DevMovement.cs @@ -24,7 +24,7 @@ namespace RobotLib.Movement base.SendMessage(TOPIC_MOBILE_NAV_TURN, angle.ToString()); } - public void SetSpeed(int speed) + public void AddSpeed(int speed) { base.SendMessage(TOPIC_MOBILE_NAV_MOVE, speed.ToString()); }