implemented steering and added robot control to UI

main
Jonas Arnold 4 years ago
parent a526c7f01f
commit a3a2d14328
  1. BIN
      ADIS_Csharp/RobotClientWpf/Assets/arrow-down-bold.png
  2. 2
      ADIS_Csharp/RobotClientWpf/MainWindow.xaml
  3. 4
      ADIS_Csharp/RobotClientWpf/RobotClientWpf.csproj
  4. 58
      ADIS_Csharp/RobotClientWpf/Views/MainView.xaml
  5. 62
      ADIS_Csharp/RobotClientWpf/Views/MainView.xaml.cs
  6. 4
      ADIS_Csharp/RobotConsoleClient/Program.cs
  7. 2
      ADIS_Csharp/RobotLib/Movement/DevMovement.cs

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

@ -72,7 +72,7 @@
</RichTextBox>-->
<StackPanel Grid.Row="3" Orientation="Horizontal" Grid.ColumnSpan="2" Margin="0,150,0,0" Grid.RowSpan="2">
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,150,0,0">
<TextBlock x:Name="tbBottomMessage" FontSize="15" Margin="10 5"/>
</StackPanel>
</Grid>

@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<None Remove="Assets\arrow-down-bold.png" />
<None Remove="Assets\cog.png" />
<None Remove="Assets\robot-industrial.png" />
</ItemGroup>
@ -21,6 +22,9 @@
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\arrow-down-bold.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Assets\cog.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>

@ -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">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="150"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Grid.Column="1" Header="Splitflap Display" Margin="10" HorizontalAlignment="Right">
<TextBox x:Name="tbSplitflapText" Height="70" Width="150" FontSize="30" IsReadOnly="True" TextWrapping="NoWrap"/>
</GroupBox>
<DockPanel>
<GroupBox DockPanel.Dock="Left" Grid.Column="0" Header="Robot Control" Width="200">
<StackPanel Orientation="Vertical" Margin="5">
<Button x:Name="btnModeAuto" Height="25" Margin="0 5" Click="btnModeAuto_Click">Set Automatic Mode</Button>
<Button x:Name="btnModeManual" Height="25" Margin="0 5" Click="btnModeManual_Click">Set Manual Mode</Button>
</StackPanel>
</GroupBox>
<GroupBox DockPanel.Dock="Left" Grid.Column="0" Header="Robot Steering" Width="200">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="25"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<Button Grid.Column="1" Grid.Row="0" Height="30" Width="30" x:Name="btnRoboFwd" Click="btnRoboFwd_Click">
<Image>
<Image.Source>
<BitmapImage UriSource="/Assets/arrow-down-bold.png" Rotation="Rotate180"/>
</Image.Source>
</Image>
</Button>
<Button Grid.Column="1" Grid.Row="1" Height="30" Width="30" x:Name="btnRoboBwd" Click="btnRoboBwd_Click">
<Image>
<Image.Source>
<BitmapImage UriSource="/Assets/arrow-down-bold.png"/>
</Image.Source>
</Image>
</Button>
<Button Grid.Column="0" Grid.Row="1" Height="30" Width="30" x:Name="btnRoboLeft" Click="btnRoboLeft_Click">
<Image>
<Image.Source>
<BitmapImage UriSource="/Assets/arrow-down-bold.png" Rotation="Rotate90"/>
</Image.Source>
</Image>
</Button>
<Button Grid.Column="2" Grid.Row="1" Height="30" Width="30" x:Name="btnRoboRight" Click="btnRoboRight_Click">
<Image>
<Image.Source>
<BitmapImage UriSource="/Assets/arrow-down-bold.png" Rotation="Rotate270"/>
</Image.Source>
</Image>
</Button>
<Label Grid.Row="2" Grid.ColumnSpan="3" FontWeight="Bold" FontSize="12" Margin="5 0">Control with Arrow keys</Label>
<Label Grid.Row="3" Grid.ColumnSpan="3" FontWeight="Bold" FontSize="12" Margin="5 0">Stop with End key</Label>
</Grid>
</GroupBox>
</DockPanel>
</Grid>
</UserControl>

@ -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;
}
}
}
}

@ -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);

@ -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());
}

Loading…
Cancel
Save