From 2a889cfbbb663607fa6b191b6de9e4144bdd92f2 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Fri, 23 Dec 2022 14:31:10 +0100 Subject: [PATCH] adjust navigation and statemachine --- ADIS_Csharp/RaspiControl/Application.cs | 21 ++++++++++--------- .../RaspiControl/NavigationConstants.cs | 8 +++---- ADIS_Csharp/RaspiControl/RaspiControl.csproj | 2 +- ADIS_Csharp/RaspiControl/StateMachine.cs | 7 ++----- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/ADIS_Csharp/RaspiControl/Application.cs b/ADIS_Csharp/RaspiControl/Application.cs index dd15244..e835dd8 100644 --- a/ADIS_Csharp/RaspiControl/Application.cs +++ b/ADIS_Csharp/RaspiControl/Application.cs @@ -32,7 +32,7 @@ namespace RaspiControl { public void Status_StatusChanged(object? sender, StatusEventArgs e) { try { - if(e.Status == RoboStatus.Manual) { + if (e.Status == RoboStatus.Manual) { this.sm.MoveNext(Command.manualMode); this.smHandler(); } @@ -40,11 +40,11 @@ namespace RaspiControl { this.sm.MoveNext(Command.autoMode); this.smHandler(); } - if(e.Status == RoboStatus.Final) { + if (e.Status == RoboStatus.Final) { this.sm.MoveNext(Command.finished); this.smHandler(); } - if(e.Status == RoboStatus.Failure) { + if (e.Status == RoboStatus.Failure) { this.sm.MoveNext(Command.failure); this.smHandler(); } @@ -53,11 +53,12 @@ namespace RaspiControl { } } - public void Status_PresentChanged(object? sender, PresentEventArgs e) { - if(this.sm.CurrentState == ProcessState.Auto) { - this.PresentCounter++; - this.challenge.RobotStationary.SplitFlap.Display(this.PresentCounter.ToString().PadLeft(4,'0')); - } + public void Status_PresentChanged(object? sender, PresentEventArgs e) { + //if(this.sm.CurrentState == ProcessState.Auto) { + this.challenge.RobotStationary.SplitFlap.Display(e.Present.ToString().PadLeft(4, '0')); + log.Debug(e.Present.ToString()); + log.Debug(e.Present.ToString().PadLeft(4, '0')); + //} } public void Run() { @@ -141,7 +142,7 @@ namespace RaspiControl { this.PresentCounter = 0; this.stopwatch.Stop(); long elapsedTime = stopwatch.ElapsedMilliseconds / 1000; - this.challenge.RobotStationary.SplitFlap.Display(elapsedTime.ToString().PadLeft(4,'0')); + this.challenge.RobotStationary.SplitFlap.Display($"{elapsedTime.ToString().PadLeft(3, '0')}S"); break; case ProcessState.Error: //this.PresentCounter = 0; @@ -170,7 +171,7 @@ namespace RaspiControl { this.sm.MoveNext(Command.JoystickCenter); break; } - if(e.Button != JoystickButton.None) { + if (e.Button != JoystickButton.None) { this.smHandler(); } } catch (Exception ex) { diff --git a/ADIS_Csharp/RaspiControl/NavigationConstants.cs b/ADIS_Csharp/RaspiControl/NavigationConstants.cs index 0a1d671..7f774d6 100644 --- a/ADIS_Csharp/RaspiControl/NavigationConstants.cs +++ b/ADIS_Csharp/RaspiControl/NavigationConstants.cs @@ -1,9 +1,9 @@ namespace RaspiControl { public static class NavigationConstants { - public const int TURN_ANGLE_LEFT = -10; - public const int TURN_ANGLE_RIGHT = 10; - public const int SPEED_FORWARD = 100; - public const int SPEED_BACKWARD = -100; + public const int TURN_ANGLE_LEFT = -15; + public const int TURN_ANGLE_RIGHT = 15; + public const int SPEED_FORWARD = 350; + public const int SPEED_BACKWARD = -350; public const bool STOP = true; } } diff --git a/ADIS_Csharp/RaspiControl/RaspiControl.csproj b/ADIS_Csharp/RaspiControl/RaspiControl.csproj index 4ebbd9f..d41197f 100644 --- a/ADIS_Csharp/RaspiControl/RaspiControl.csproj +++ b/ADIS_Csharp/RaspiControl/RaspiControl.csproj @@ -8,7 +8,7 @@ - + diff --git a/ADIS_Csharp/RaspiControl/StateMachine.cs b/ADIS_Csharp/RaspiControl/StateMachine.cs index b842125..822ec89 100644 --- a/ADIS_Csharp/RaspiControl/StateMachine.cs +++ b/ADIS_Csharp/RaspiControl/StateMachine.cs @@ -94,22 +94,19 @@ namespace RaspiControl { {new StateTransition(ProcessState.MoveManual, Command.JoystickRight), ProcessState.MoveManualR }, {new StateTransition(ProcessState.MoveManual, Command.JoystickCenter), ProcessState.StopManual }, {new StateTransition(ProcessState.MoveManual, Command.autoMode), ProcessState.Auto }, + {new StateTransition(ProcessState.MoveManual, Command.finished), ProcessState.Final }, {new StateTransition(ProcessState.StopManual,Command.JoystickUp), ProcessState.ResumeMoveManual }, {new StateTransition(ProcessState.StopManual,Command.JoystickDown), ProcessState.ResumeMoveManual }, {new StateTransition(ProcessState.StopManual,Command.JoystickLeft), ProcessState.ResumeMoveManual }, {new StateTransition(ProcessState.StopManual,Command.JoystickRight), ProcessState.ResumeMoveManual }, {new StateTransition(ProcessState.StopManual, Command.autoMode), ProcessState.Auto }, + {new StateTransition(ProcessState.StopManual, Command.finished), ProcessState.Final }, {new StateTransition(ProcessState.ResumeMoveManual, Command.none),ProcessState.MoveManual }, {new StateTransition(ProcessState.ResumeMoveManual, Command.autoMode), ProcessState.Auto }, {new StateTransition(ProcessState.Auto, Command.finished), ProcessState.Final }, - //{new StateTransition(ProcessState.Auto, Command.JoystickUp), ProcessState.StartMoveManual }, - //{new StateTransition(ProcessState.Auto, Command.JoystickDown), ProcessState.StartMoveManual }, - //{new StateTransition(ProcessState.Auto, Command.JoystickLeft), ProcessState.StartMoveManual }, - //{new StateTransition(ProcessState.Auto, Command.JoystickRight), ProcessState.StartMoveManual }, - //{new StateTransition(ProcessState.Auto, Command.JoystickCenter), ProcessState.StartMoveManual }, {new StateTransition(ProcessState.Auto, Command.failure), ProcessState.Error }, {new StateTransition(ProcessState.Auto, Command.manualMode), ProcessState.ResumeMoveManual },