added line sensor in RobotLib and UI

main
Jonas Arnold 4 years ago
parent a3a2d14328
commit aa391305f5
  1. 12
      ADIS_Csharp/RobotClientWpf/Views/ConfigView.xaml
  2. 15
      ADIS_Csharp/RobotClientWpf/Views/ConfigView.xaml.cs
  3. 4
      ADIS_Csharp/RobotClientWpf/Views/MainView.xaml.cs
  4. 27
      ADIS_Csharp/RobotLib/Movement/DevLineSensor.cs
  5. 2
      ADIS_Csharp/RobotLib/Robot.cs

@ -8,10 +8,10 @@
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="120"/>
<RowDefinition Height="120"/> <RowDefinition Height="120"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -30,5 +30,15 @@
<Button x:Name="btnApplyConfiguration" Content="Apply" HorizontalAlignment="Right" Height="30" Width="100" Margin="10" Click="btnApplyConfiguration_Click"/> <Button x:Name="btnApplyConfiguration" Content="Apply" HorizontalAlignment="Right" Height="30" Width="100" Margin="10" Click="btnApplyConfiguration_Click"/>
</DockPanel> </DockPanel>
</GroupBox> </GroupBox>
<GroupBox Grid.Row="1" Grid.Column="0" Header="Line Sensor calibration">
<DockPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Vertical">
<Button x:Name="btnStartCalibration" Content="Start Calibration" Margin="5" Width="200" Height="30" Click="btnStartCalibration_Click" />
<Button x:Name="btnEndCalibration" Content="End Calibration" Margin="5" Width="200" Height="30" Click="btnEndCalibration_Click" />
</StackPanel>
<Button DockPanel.Dock="Top" x:Name="btnGetCalibrationData" Content="Get Calibration Data" Margin="5" Width="200" Height="30" Click="btnGetCalibrationData_Click"/>
</DockPanel>
</GroupBox>
</Grid> </Grid>
</UserControl> </UserControl>

@ -61,5 +61,20 @@ namespace RobotClientWpf.Views
log.Error("challenge object is null"); log.Error("challenge object is null");
} }
} }
private void btnStartCalibration_Click(object sender, RoutedEventArgs e)
{
this.challenge?.RobotMobile.LineSensor.StartCalibration(true);
}
private void btnEndCalibration_Click(object sender, RoutedEventArgs e)
{
this.challenge?.RobotMobile.LineSensor.StartCalibration(false);
}
private void btnGetCalibrationData_Click(object sender, RoutedEventArgs e)
{
this.challenge?.RobotMobile.LineSensor.GetCalibrationData();
}
} }
} }

@ -12,8 +12,8 @@ namespace RobotClientWpf.Views
{ {
private static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger(); private static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
private ChallengeFactory? challenge; private ChallengeFactory? challenge;
private const int AMOUNT_SPEED_ADDED_PER_CLICK = 10; private const int AMOUNT_SPEED_ADDED_PER_CLICK = 500;
private const int TURN_ANGLE_PER_CLICK = 25; private const int TURN_ANGLE_PER_CLICK = 30;
public MainView() public MainView()
{ {

@ -0,0 +1,27 @@
using RobotLib.Communication;
using System;
using System.Collections.Generic;
using System.Text.Json;
namespace RobotLib.Movement
{
public class DevLineSensor : DevBase
{
private const string TOPIC_ROBO_CALIB_CMD = "/mobile/cmd/line_sens/calib";
private const string TOPIC_ROBO_GET_CALIB = "/mobile/cmd/line_sens/get_calib";
private const string TOPIC_ROBO_CALIB_STATE = "/mobile/state/line_sens/calib_data";
public DevLineSensor(IPublisherSubscriber com) : base(com, new List<string>() { }) { }
public void GetCalibrationData()
{
base.SendMessage(TOPIC_ROBO_GET_CALIB, true.ToString());
}
public void StartCalibration(bool start)
{
string payload = JsonSerializer.Serialize(new Dictionary<string, bool>() { { "start", start } });
base.SendMessage(TOPIC_ROBO_CALIB_CMD, payload);
}
}
}

@ -13,6 +13,7 @@ namespace RobotLib
//Buzzer = new DevBuzzer(Com); //Buzzer = new DevBuzzer(Com);
//Battery = new DevBattery(Com); //Battery = new DevBattery(Com);
SplitFlap = new DevSplitFlap(com); SplitFlap = new DevSplitFlap(com);
LineSensor = new DevLineSensor(com);
Movement = new DevMovement(com); Movement = new DevMovement(com);
Timer timer = new Timer(TimerCallback); Timer timer = new Timer(TimerCallback);
@ -25,6 +26,7 @@ namespace RobotLib
//public DevBattery Battery { get; } //public DevBattery Battery { get; }
public DevSplitFlap SplitFlap { get; } public DevSplitFlap SplitFlap { get; }
public DevMovement Movement { get; } public DevMovement Movement { get; }
public DevLineSensor LineSensor { get; }
public void Connect(string host, int port) public void Connect(string host, int port)
{ {

Loading…
Cancel
Save