From e56f25974e836995a280d831df22ba7e33e390cb Mon Sep 17 00:00:00 2001 From: Solomon Ritzow Date: Sat, 14 Jul 2018 15:01:00 -0700 Subject: [PATCH 1/6] Clean up file path manipulation and remove unused using directives in MapDisplay --- BaseStation/MainWindow/MainWindow.xaml.cs | 21 ++++++------- BaseStation/MainWindow/MapDisplay.xaml.cs | 36 ++++++++++------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/BaseStation/MainWindow/MainWindow.xaml.cs b/BaseStation/MainWindow/MainWindow.xaml.cs index 5ccb182..a5b3a85 100644 --- a/BaseStation/MainWindow/MainWindow.xaml.cs +++ b/BaseStation/MainWindow/MainWindow.xaml.cs @@ -35,6 +35,7 @@ public MainWindow() Gst.Application.Init(); Properties = new MockObservableMap(); InitializeComponent(); + Console.SetOut(((ConsoleView)FindName("console")).Writer); WindowState = WindowState.Maximized; this.Closing += OnCloseEvent; DataContext = this; @@ -50,11 +51,10 @@ public MainWindow() Settings.PropertyChanged += SettingChanged; SettingPanel.Settings = Settings; - if (!File.Exists(Directory.GetCurrentDirectory() + @"\Images\" + Settings.CurrentMapFile)) + if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Images", Settings.CurrentMapFile))) { - string[] mapFiles = Directory.GetFiles - (Directory.GetCurrentDirectory() + @"\Images", "*.map"); - if (mapFiles.Count() != 0) + string[] mapFiles = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Images"), "*.map"); + if (mapFiles.Count() > 0) { Settings.CurrentMapFile = Path.GetFileName(mapFiles[0]); } @@ -170,16 +170,13 @@ private void OnCloseEvent(object sender, CancelEventArgs e) for (int i = VideoWindows.Count - 1; i >= 0; i--) { VideoWindow window = VideoWindows[i]; - if(window is Window) + if(window is Window videoWindowAsWindow) { - Window videoWindowAsWindow = window as Window; - videoWindowAsWindow.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => - { - videoWindowAsWindow.Hide(); - videoWindowAsWindow.Close(); // Closing takes awhile so hide the window - })); + videoWindowAsWindow.Dispatcher.InvokeAsync(() => { + videoWindowAsWindow.Hide(); //Closing takes awhile so hide the window + videoWindowAsWindow.Close(); + }, System.Windows.Threading.DispatcherPriority.Normal); } - VideoWindows.RemoveAt(i); } } diff --git a/BaseStation/MainWindow/MapDisplay.xaml.cs b/BaseStation/MainWindow/MapDisplay.xaml.cs index 8a296ea..efa3f81 100644 --- a/BaseStation/MainWindow/MapDisplay.xaml.cs +++ b/BaseStation/MainWindow/MapDisplay.xaml.cs @@ -4,19 +4,11 @@ using System.Collections.Specialized; using HuskyRobotics.Utilities; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Text.RegularExpressions; using HuskyRobotics.BaseStation.Server; namespace HuskyRobotics.UI @@ -55,20 +47,26 @@ public MapDisplay() { InitializeComponent(); BaseServer.GPSUpdate += UpdateRoverPosition; - _roverIconBitmap = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + @"/Icons/RoverIcon.png", UriKind.Absolute)); - _waypointBitmap = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + @"/Icons/waypoint.png", UriKind.Absolute)); + _roverIconBitmap = LoadImageFromRelativeFile("Icons/RoverIcon.png"); + _waypointBitmap = LoadImageFromRelativeFile("Icons/waypoint.png"); RoverIcon = new Image { Source = _roverIconBitmap }; } + private static BitmapImage LoadImageFromRelativeFile(string file) + { + return new BitmapImage(new Uri(Path.Combine(Directory.GetCurrentDirectory(), file), UriKind.Absolute)); + } + public void DisplayMap(string mapSetFile) { ClearCanvas(); // load in individual images // TODO get the path from the settings - if (File.Exists(Directory.GetCurrentDirectory() + @"\Images\" + mapSetFile)) + string path = Path.Combine(Directory.GetCurrentDirectory(), "Images", mapSetFile); + if (File.Exists(path)) { String waypointsFile = (mapSetFile.Replace(".map", ".waypoints")); - using (StreamReader file = new StreamReader(Directory.GetCurrentDirectory() + @"\Images\" + mapSetFile)) + using (var file = new StreamReader(path)) { string line = file.ReadLine(); string[] config = line.Split('|'); @@ -101,11 +99,9 @@ public void DisplayMap(string mapSetFile) { string[] parts = line.Split('|'); string[] location = parts[0].Split(','); - int x = 0; - int y = 0; - Int32.TryParse(location[0], out x); - Int32.TryParse(location[1], out y); - AddImage(Directory.GetCurrentDirectory() + @"\Images\" + parts[1] + ".jpg", x, y, ImageWidth, ImageHeight); + Int32.TryParse(location[0], out int x); + Int32.TryParse(location[1], out int y); + AddImage(LoadImageFromRelativeFile(Path.Combine("Images", parts[1] + ".jpg")), x, y, ImageWidth, ImageHeight); } } @@ -117,10 +113,10 @@ public void DisplayMap(string mapSetFile) // adds an image to the canvas with the given file location and the coords of where // on the canvas it goes - private void AddImage(String location, int x, int y, int width, int height) + private void AddImage(BitmapImage bitmap, int x, int y, int width, int height) { - var uri = new Uri(location, UriKind.Absolute); - var bitmap = new BitmapImage(uri); + // var uri = new Uri(location, UriKind.Absolute); + //var bitmap = new BitmapImage(uri); var image = new Image { Source = bitmap, Width = width, Height = height }; Canvas.SetLeft(image, x * width - (width / 2)); Canvas.SetTop(image, y * height - (height / 2)); From 009b93eaf6e8c9175b0b8e3392c349eb623ea222 Mon Sep 17 00:00:00 2001 From: Solomon Ritzow Date: Sat, 14 Jul 2018 15:01:36 -0700 Subject: [PATCH 2/6] ConsoleView improvements Does not fix high performance cost --- BaseStation/MainWindow/ConsoleView.xaml.cs | 56 ++++++++++++---------- BaseStation/MainWindow/MainWindow.xaml | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/BaseStation/MainWindow/ConsoleView.xaml.cs b/BaseStation/MainWindow/ConsoleView.xaml.cs index b9bd5d9..9a9f182 100644 --- a/BaseStation/MainWindow/ConsoleView.xaml.cs +++ b/BaseStation/MainWindow/ConsoleView.xaml.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text; using System.Windows.Controls; +using System.Windows.Media; namespace HuskyRobotics.UI { @@ -9,46 +10,50 @@ namespace HuskyRobotics.UI /// Interaction logic for ConsoleView.xaml /// public partial class ConsoleView : ScrollViewer { - public ConsoleView() { - TextBlock child = new TextBlock(); - AddChild(child); - child.FontFamily = new System.Windows.Media.FontFamily("consolas"); - child.FontSize = 16; - Console.SetOut(new ConsoleWriter(child, this, Console.Out)); - InitializeComponent(); + private readonly ConsoleWriter writer; + + public TextWriter Writer => writer; + + public ConsoleView() { + TextBox box = new TextBox { + FontFamily = new FontFamily("consolas"), + FontSize = 16, + IsReadOnly = true, + IsReadOnlyCaretVisible = false, + BorderThickness = new System.Windows.Thickness(0), + TextWrapping = System.Windows.TextWrapping.Wrap + }; + + AddChild(box); + writer = new ConsoleWriter(box, this); + InitializeComponent(); } private class ConsoleWriter : TextWriter { - private readonly TextBlock view; + private readonly TextBox view; private readonly ScrollViewer scroll; - private readonly TextWriter oldOut; - public ConsoleWriter(TextBlock view, ScrollViewer scroll, TextWriter oldOut) { + public ConsoleWriter(TextBox view, ScrollViewer scroll) { this.view = view; this.scroll = scroll; - this.oldOut = oldOut; } - public override Encoding Encoding => Encoding.UTF8; + public override Encoding Encoding => Encoding.UTF8; public override void Write(char value) { - oldOut.Write(value); - view.Dispatcher.BeginInvoke(new Action(() => - { - view.Text += value; + view.Dispatcher.InvokeAsync(() => { + view.AppendText(value.ToString()); UpdateView(); - })); + }); } public override void Write(char[] buffer, int index, int count) { - oldOut.Write(buffer, index, count); - view.Dispatcher.BeginInvoke(new Action(() => - { - view.Text += new string(buffer, index, count); + view.Dispatcher.InvokeAsync(() => { + view.AppendText(new string(buffer, index, count)); UpdateView(); - })); + }); } //removes extra text (prevent memory leak) @@ -58,10 +63,9 @@ private void UpdateView() { double scrollHeight = scroll.ViewportHeight; double viewHeight = view.ActualHeight; int totalLines = CountLines(view.Text); - int lineHeight = (int)viewHeight/totalLines; - int possibleVisibleLines = (int)(scrollHeight/lineHeight); - if (viewHeight > scrollHeight * 2) //if stored text is partially offscreen, the 2 is there to buffer the text so there isn't so much garbage produced - { + int lineHeight = (int)viewHeight / totalLines; + int possibleVisibleLines = (int)(scrollHeight / lineHeight); + if (viewHeight > scrollHeight) { view.Text = GetFinalLines(view.Text, totalLines, Math.Min(totalLines, possibleVisibleLines)); } scroll.ScrollToEnd(); diff --git a/BaseStation/MainWindow/MainWindow.xaml b/BaseStation/MainWindow/MainWindow.xaml index d170561..6d7f2f7 100644 --- a/BaseStation/MainWindow/MainWindow.xaml +++ b/BaseStation/MainWindow/MainWindow.xaml @@ -102,7 +102,7 @@ - + From 833c6518345bd51a32f3bdd3a3ee74e0986143de Mon Sep 17 00:00:00 2001 From: Solomon Ritzow Date: Sat, 14 Jul 2018 15:02:15 -0700 Subject: [PATCH 3/6] Minor improvements to BaseServer Update --- BaseStation/BaseServer/BaseServer.cs | 202 ++++++++++++--------------- 1 file changed, 90 insertions(+), 112 deletions(-) diff --git a/BaseStation/BaseServer/BaseServer.cs b/BaseStation/BaseServer/BaseServer.cs index 53585b4..55f6471 100644 --- a/BaseStation/BaseServer/BaseServer.cs +++ b/BaseStation/BaseServer/BaseServer.cs @@ -47,106 +47,93 @@ private static void ClientConnected(object sender, EventArgs e) /// public static void Update(Controller driveController, Controller armController) { - if (driveController.IsConnected - && armController.IsConnected - && (TimeNanoseconds() - lastControlSend) > CONTROL_SEND_INTERVAL_NANOSECONDS) - { - Packet SteerPack; - Packet SpeedPack; - Packet WristPack; - Packet ElbowPack; - Packet ShoulderPack; - Packet BasePack; - - State driveState = driveController.GetState(); - State armState = armController.GetState(); - byte rightTrigger = driveState.Gamepad.RightTrigger; - byte leftTrigger = driveState.Gamepad.LeftTrigger; - short leftThumbX = PreventOverflow(driveState.Gamepad.LeftThumbX); - - if (rightTrigger < TriggerThreshold) { rightTrigger = 0; } - if (leftTrigger < TriggerThreshold) { leftTrigger = 0; } - if (Math.Abs(leftThumbX) < LeftThumbDeadzone) { leftThumbX = 0; } - - float speed = (float)UtilMain.LinearMap(rightTrigger - leftTrigger, -255, 255, -1, 1); - float steerPos = (float)UtilMain.LinearMap(leftThumbX, -32768, 32767, -1, 1); - - //Console.WriteLine("Speed: " + speed); - //Console.WriteLine("Steer Pos: " + steerPos); - - bool aPressedDrive = (driveState.Gamepad.Buttons & GamepadButtonFlags.A) != 0; - bool bPressedDrive = (driveState.Gamepad.Buttons & GamepadButtonFlags.B) != 0; - - bool aPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.A) != 0; - bool bPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.B) != 0; - bool xPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.X) != 0; - bool yPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.Y) != 0; - - bool upPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0; - bool downPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0; - bool leftPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0; - bool rightPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0; - - float steerSpeed = 0.0f; - if (aPressedDrive) - steerSpeed = 0.3f; - if (bPressedDrive) - steerSpeed = -0.3f; - - float wristArmSpeed = 0.0f; - if (xPressedArm) - wristArmSpeed = 0.5f; - if (yPressedArm) - wristArmSpeed = -0.5f; - - float elbowArmSpeed = 0.0f; - if (aPressedArm) - elbowArmSpeed = 0.5f; - if (bPressedArm) - elbowArmSpeed = -0.5f; - - float shoulderArmSpeed = 0.0f; - if (upPressedArm) - shoulderArmSpeed = 1.0f; - if (downPressedArm) - shoulderArmSpeed = -1.0f; - - float baseArmSpeed = 0.0f; - if (leftPressedArm) - baseArmSpeed = 0.5f; - if (rightPressedArm) - baseArmSpeed = -0.5f; - - SteerPack = new Packet(0x8F, true, "MainRover"); - SteerPack.AppendData(UtilData.ToBytes(steerSpeed)); - Scarlet.Communications.Server.Send(SteerPack); - - SpeedPack = new Packet(0x95, true, "MainRover"); - SpeedPack.AppendData(UtilData.ToBytes(speed)); - Scarlet.Communications.Server.Send(SpeedPack); - - WristPack = new Packet(0x9D, true, "ArmMaster"); - WristPack.AppendData(UtilData.ToBytes(wristArmSpeed)); - Scarlet.Communications.Server.Send(WristPack); - - ElbowPack = new Packet(0x9C, true, "ArmMaster"); - ElbowPack.AppendData(UtilData.ToBytes(elbowArmSpeed)); - Scarlet.Communications.Server.Send(ElbowPack); - - ShoulderPack = new Packet(0x9B, true, "ArmMaster"); - ShoulderPack.AppendData(UtilData.ToBytes(shoulderArmSpeed)); - Scarlet.Communications.Server.Send(ShoulderPack); - - BasePack = new Packet(0x9A, true, "ArmMaster"); - BasePack.AppendData(UtilData.ToBytes(baseArmSpeed)); - Scarlet.Communications.Server.Send(BasePack); - - lastControlSend = TimeNanoseconds(); //time in nanoseconds - } - else if ((TimeNanoseconds() - lastControlSend) > CONTROL_SEND_INTERVAL_NANOSECONDS) - { - Console.WriteLine("Gamepad not connected"); - HaltRoverMotion(); + if(SendIntervalElapsed()) { + if(driveController.IsConnected && armController.IsConnected) { + State driveState = driveController.GetState(); + State armState = armController.GetState(); + byte rightTrigger = driveState.Gamepad.RightTrigger; + byte leftTrigger = driveState.Gamepad.LeftTrigger; + short leftThumbX = PreventOverflow(driveState.Gamepad.LeftThumbX); + + if (rightTrigger < TriggerThreshold) { rightTrigger = 0; } + if (leftTrigger < TriggerThreshold) { leftTrigger = 0; } + if (Math.Abs(leftThumbX) < LeftThumbDeadzone) { leftThumbX = 0; } + + float speed = (float)UtilMain.LinearMap(rightTrigger - leftTrigger, -255, 255, -1, 1); + float steerPos = (float)UtilMain.LinearMap(leftThumbX, -32768, 32767, -1, 1); + + bool aPressedDrive = (driveState.Gamepad.Buttons & GamepadButtonFlags.A) != 0; + bool bPressedDrive = (driveState.Gamepad.Buttons & GamepadButtonFlags.B) != 0; + + bool aPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.A) != 0; + bool bPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.B) != 0; + bool xPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.X) != 0; + bool yPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.Y) != 0; + + bool upPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadUp) != 0; + bool downPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadDown) != 0; + bool leftPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadLeft) != 0; + bool rightPressedArm = (armState.Gamepad.Buttons & GamepadButtonFlags.DPadRight) != 0; + + float steerSpeed = 0.0f; + if (bPressedDrive) + steerSpeed = -0.3f; + else if (aPressedDrive) + steerSpeed = 0.3f; + + float wristArmSpeed = 0.0f; + if (yPressedArm) + wristArmSpeed = -0.5f; + else if (xPressedArm) + wristArmSpeed = 0.5f; + + float elbowArmSpeed = 0.0f; + if (bPressedArm) + elbowArmSpeed = -0.5f; + else if (aPressedArm) + elbowArmSpeed = 0.5f; + + float shoulderArmSpeed = 0.0f; + if (downPressedArm) + shoulderArmSpeed = -1.0f; + else if (upPressedArm) + shoulderArmSpeed = 1.0f; + + float baseArmSpeed = 0.0f; + if (rightPressedArm) + baseArmSpeed = -0.5f; + else if (leftPressedArm) + baseArmSpeed = 0.5f; + + Packet SteerPack = new Packet(0x8F, true, "MainRover"); + SteerPack.AppendData(UtilData.ToBytes(steerSpeed)); + Scarlet.Communications.Server.Send(SteerPack); + + Packet SpeedPack = new Packet(0x95, true, "MainRover"); + SpeedPack.AppendData(UtilData.ToBytes(speed)); + Scarlet.Communications.Server.Send(SpeedPack); + + Packet WristPack = new Packet(0x9D, true, "ArmMaster"); + WristPack.AppendData(UtilData.ToBytes(wristArmSpeed)); + Scarlet.Communications.Server.Send(WristPack); + + Packet ElbowPack = new Packet(0x9C, true, "ArmMaster"); + ElbowPack.AppendData(UtilData.ToBytes(elbowArmSpeed)); + Scarlet.Communications.Server.Send(ElbowPack); + + Packet ShoulderPack = new Packet(0x9B, true, "ArmMaster"); + ShoulderPack.AppendData(UtilData.ToBytes(shoulderArmSpeed)); + Scarlet.Communications.Server.Send(ShoulderPack); + + Packet BasePack = new Packet(0x9A, true, "ArmMaster"); + BasePack.AppendData(UtilData.ToBytes(baseArmSpeed)); + Scarlet.Communications.Server.Send(BasePack); + } else { + Console.WriteLine("Gamepad not connected!"); + HaltRoverMotion(); + } + + lastControlSend = TimeNanoseconds(); } } @@ -164,19 +151,10 @@ private static void HaltRoverMotion() Scarlet.Communications.Server.Send(ArmEmergencyStop); } - private static short PreventOverflow(short shortVal) - { - if (shortVal == -32768) - { - shortVal++; - } - return shortVal; - } + private static short PreventOverflow(short shortVal) => shortVal == -32768 ? (short)(shortVal + 1) : shortVal; - private static long TimeNanoseconds() - { - return DateTime.UtcNow.Ticks * 100; - } + private static bool SendIntervalElapsed() => (TimeNanoseconds() - lastControlSend) > CONTROL_SEND_INTERVAL_NANOSECONDS; + private static long TimeNanoseconds() => DateTime.UtcNow.Ticks * 100; private static List ConvertToFloatArray(Packet data) { From 882cfb993e8075a5f94fe88329f9999cb1ddf665 Mon Sep 17 00:00:00 2001 From: Solomon Ritzow Date: Mon, 16 Jul 2018 21:25:04 -0700 Subject: [PATCH 4/6] Rename method for clarity, reduce update interval bandaid --- BaseStation/BaseStation/StartBaseStation.cs | 2 +- BaseStation/MainWindow/ConsoleView.xaml.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/BaseStation/BaseStation/StartBaseStation.cs b/BaseStation/BaseStation/StartBaseStation.cs index 16a108e..f682124 100644 --- a/BaseStation/BaseStation/StartBaseStation.cs +++ b/BaseStation/BaseStation/StartBaseStation.cs @@ -34,7 +34,7 @@ private static void Update() { BaseServer.Update(DriveController, ArmController); CameraControl.Update(DriveController); - Thread.Sleep(150); + Thread.Sleep(100); } private static volatile bool exit; diff --git a/BaseStation/MainWindow/ConsoleView.xaml.cs b/BaseStation/MainWindow/ConsoleView.xaml.cs index 9a9f182..9004e5f 100644 --- a/BaseStation/MainWindow/ConsoleView.xaml.cs +++ b/BaseStation/MainWindow/ConsoleView.xaml.cs @@ -73,11 +73,11 @@ private void UpdateView() { private static string GetFinalLines(string text, int totalLines, int lineCount) { - int ind = GetIndexAfter(text, totalLines - lineCount); + int ind = GetIndexAfterNewline(text, totalLines - lineCount); return text.Substring(ind); } - private static int GetIndexAfter(string str, int count) + private static int GetIndexAfterNewline(string str, int count) { if (str == string.Empty) return -1; int index = -1; From d00c2b7d67650aa1c995dfa41212543f4672d54f Mon Sep 17 00:00:00 2001 From: Solomon Ritzow Date: Mon, 16 Jul 2018 21:36:26 -0700 Subject: [PATCH 5/6] Use Command Prompt instead of ConsoleView --- BaseStation/BaseStation/BaseStation.csproj | 2 +- BaseStation/MainWindow/MainWindow.xaml.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/BaseStation/BaseStation/BaseStation.csproj b/BaseStation/BaseStation/BaseStation.csproj index ff717f0..b222fd9 100644 --- a/BaseStation/BaseStation/BaseStation.csproj +++ b/BaseStation/BaseStation/BaseStation.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {717939F0-9BDC-4D66-99B5-AE34D586488E} - WinExe + Exe HuskyRobotics.BaseStation BaseStation v4.7 diff --git a/BaseStation/MainWindow/MainWindow.xaml.cs b/BaseStation/MainWindow/MainWindow.xaml.cs index a5b3a85..2800e9c 100644 --- a/BaseStation/MainWindow/MainWindow.xaml.cs +++ b/BaseStation/MainWindow/MainWindow.xaml.cs @@ -35,8 +35,9 @@ public MainWindow() Gst.Application.Init(); Properties = new MockObservableMap(); InitializeComponent(); - Console.SetOut(((ConsoleView)FindName("console")).Writer); - WindowState = WindowState.Maximized; + ((ConsoleView)FindName("console")).Writer.WriteLine("ConsoleView disabled due to performance issues, use Command Prompt view instead."); + //Console.SetOut(((ConsoleView)FindName("console")).Writer); + WindowState = WindowState.Maximized; this.Closing += OnCloseEvent; DataContext = this; From 8fd6fddd9294b8d211a9a3b14af04dbe6a27a2a4 Mon Sep 17 00:00:00 2001 From: Nathan Date: Sat, 21 Jul 2018 11:33:33 -0700 Subject: [PATCH 6/6] Fixed crashes, app working in console mode --- BaseStation/MainWindow/MainWindow.xaml.cs | 3 ++- BaseStation/MainWindow/MapDisplay.xaml.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/BaseStation/MainWindow/MainWindow.xaml.cs b/BaseStation/MainWindow/MainWindow.xaml.cs index 2800e9c..9aca23f 100644 --- a/BaseStation/MainWindow/MainWindow.xaml.cs +++ b/BaseStation/MainWindow/MainWindow.xaml.cs @@ -52,7 +52,8 @@ public MainWindow() Settings.PropertyChanged += SettingChanged; SettingPanel.Settings = Settings; - if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "Images", Settings.CurrentMapFile))) + + if (!File.Exists(Directory.GetCurrentDirectory() + @"\Images\" + Settings.CurrentMapFile)) { string[] mapFiles = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Images"), "*.map"); if (mapFiles.Count() > 0) diff --git a/BaseStation/MainWindow/MapDisplay.xaml.cs b/BaseStation/MainWindow/MapDisplay.xaml.cs index 9c0a5bf..22b20fa 100644 --- a/BaseStation/MainWindow/MapDisplay.xaml.cs +++ b/BaseStation/MainWindow/MapDisplay.xaml.cs @@ -59,10 +59,11 @@ private static BitmapImage LoadImageFromRelativeFile(string file) public void DisplayMap(string mapSetFile) { + ClearCanvas(); // load in individual images // TODO get the path from the settings - string path = Path.Combine(Directory.GetCurrentDirectory(), "Images", mapSetFile); + string path = Directory.GetCurrentDirectory() + @"\Images\" + mapSetFile; if (File.Exists(path)) { String waypointsFile = (mapSetFile.Replace(".map", ".waypoints"));