From 1190c08729d4ee70fdcd018014abbb6bd614cb5f Mon Sep 17 00:00:00 2001 From: bbod Date: Sun, 8 Sep 2019 22:28:32 -0600 Subject: [PATCH] Test Branch --- Tello Drone/ConsoleClient.cs | 40 ++++++++++++++++++++------------- Tello Drone/Drone.cs | 4 ++++ Tello Drone/DroneComands.cs | 13 +++++++---- Tello Drone/IDroneCommands.cs | 4 ++++ Tello Drone/IMissions.cs | 2 ++ Tello Drone/Missions.cs | 26 ++++++++++++++++----- Tello Drone/UdpClientWrapper.cs | 2 +- 7 files changed, 64 insertions(+), 27 deletions(-) diff --git a/Tello Drone/ConsoleClient.cs b/Tello Drone/ConsoleClient.cs index 6a0ca76..06491f0 100644 --- a/Tello Drone/ConsoleClient.cs +++ b/Tello Drone/ConsoleClient.cs @@ -12,28 +12,36 @@ namespace Tello_Drone { _missions = missions; _consoleLogger = consoleLogger; + _missions.SetUpDrone(); } public void Run() { - _consoleLogger.Log("Choose a mission to run."); - _consoleLogger.Log("1: Mission 1"); - _consoleLogger.Log("2: Mission 2"); - _consoleLogger.Log("3: Mission 3"); - - var userInput = Console.ReadLine(); - - switch (userInput) + while (true) { - case "1": - _missions.RunMission1(); - break; - default: - _consoleLogger.Log("Not A Valid Entry...Try Again"); - Run(); - break; - } + _consoleLogger.Log("Choose a mission to run."); + _consoleLogger.Log("1: Mission 1"); + _consoleLogger.Log("2: Mission 2"); + _consoleLogger.Log("3: Mission 3"); + var userInput = Console.ReadLine(); + + switch (userInput) + { + case "1": + _missions.RunMission1(); + break; + case "2": + _missions.RunMission2(); + break; + case "exit": + return; + default: + _consoleLogger.Log("Not A Valid Entry...Try Again"); + Run(); + break; + } + } } diff --git a/Tello Drone/Drone.cs b/Tello Drone/Drone.cs index 1a96561..549c0c1 100644 --- a/Tello Drone/Drone.cs +++ b/Tello Drone/Drone.cs @@ -20,6 +20,10 @@ namespace Tello_Drone public void TakeOff() => _droneCommands.TakeOff(); public void Land() => _droneCommands.Land(); public void RotateClockWise(int r) => _droneCommands.RotateClockWise(r); + public void FrontFlip() => _droneCommands.FrontFlip(); + public void BackFlip() => _droneCommands.BackFlip(); + public void RightFlip() => _droneCommands.RightFlip(); + public void LeftFlip() => _droneCommands.LeftFlip(); } diff --git a/Tello Drone/DroneComands.cs b/Tello Drone/DroneComands.cs index 8b0fbeb..3e09b87 100644 --- a/Tello Drone/DroneComands.cs +++ b/Tello Drone/DroneComands.cs @@ -12,7 +12,7 @@ namespace Tello_Drone _udpClient = udpClient; } - public void Forward(int x) =>SendCommand() ($"forward {x}"); + public void Forward(int x) =>SendCommand($"forward {x}"); public void Reverse(int x) => SendCommand($"back {x}"); public void Up(int z) => SendCommand($"up {z}"); public void Down(int z) => SendCommand($"down {z}"); @@ -23,7 +23,12 @@ namespace Tello_Drone public void TakeOff() => SendCommand("takeoff"); public void Land() => SendCommand("land"); public void RotateClockWise(int r) => SendCommand($"cw {r}"); - + public void FrontFlip() => SendCommand($"flip f"); + public void BackFlip() => SendCommand($"flip b"); + public void RightFlip() => SendCommand($"flip r"); + public void LeftFlip() => SendCommand($"flip l"); + + @@ -31,14 +36,14 @@ namespace Tello_Drone private void SendCommand(string message) { - var returnValue = _udpClient.TrySend(message, 0_500, 3); + var returnValue = _udpClient.TrySend(message, 5_000, 3); if (returnValue == false) SendCommand("land"); } private bool TrySendCommand(string message) { - return _udpClient.TrySend(message, 0_500, 3); + return _udpClient.TrySend(message, 5_000, 3); } } diff --git a/Tello Drone/IDroneCommands.cs b/Tello Drone/IDroneCommands.cs index a93c115..cad966c 100644 --- a/Tello Drone/IDroneCommands.cs +++ b/Tello Drone/IDroneCommands.cs @@ -13,6 +13,10 @@ namespace Tello_Drone void TakeOff(); void Land(); void RotateClockWise(int r); + void FrontFlip(); + void BackFlip(); + void RightFlip(); + void LeftFlip(); } } \ No newline at end of file diff --git a/Tello Drone/IMissions.cs b/Tello Drone/IMissions.cs index 54bf17d..cc738da 100644 --- a/Tello Drone/IMissions.cs +++ b/Tello Drone/IMissions.cs @@ -2,6 +2,8 @@ namespace Tello_Drone { public interface IMissions { + void SetUpDrone(); void RunMission1(); + void RunMission2(); } } \ No newline at end of file diff --git a/Tello Drone/Missions.cs b/Tello Drone/Missions.cs index 5d84ba8..43a1a39 100644 --- a/Tello Drone/Missions.cs +++ b/Tello Drone/Missions.cs @@ -4,12 +4,22 @@ namespace Tello_Drone { private Drone _drone; private int _setupRetry; + public Missions( IDroneFactory droneFactory) { _drone = droneFactory.CreateDrone; } + public void SetUpDrone() + { + var inCommandMode = false; + while (inCommandMode != true && _setupRetry < 3) + { + inCommandMode = _drone.Command(); + _setupRetry++; + } + } public void RunMission1() { MissionSetup(); @@ -18,14 +28,18 @@ namespace Tello_Drone MissionTeardown(); } + public void RunMission2() + { + MissionSetup(); + _drone.BackFlip(); + _drone.FrontFlip(); + _drone.Forward(30); + _drone.Land(); + } + private void MissionSetup() { - var inCommandMode = false; - while (inCommandMode != true && _setupRetry < 3) - { - inCommandMode = _drone.Command(); - _setupRetry++; - } + if (!_drone.InitialTakeOff()) _drone.InitialTakeOff(); diff --git a/Tello Drone/UdpClientWrapper.cs b/Tello Drone/UdpClientWrapper.cs index 5373902..7432420 100644 --- a/Tello Drone/UdpClientWrapper.cs +++ b/Tello Drone/UdpClientWrapper.cs @@ -21,7 +21,7 @@ namespace Tello_Drone var dronePortNumber = Convert.ToInt32(Console.ReadLine()); if (droneIpAddress != null) { - _client = new UdpClient(droneIpAddress ?? throw new NullReferenceException($"{nameof(droneIpAddress)} was null."), dronePortNumber); + _client = new UdpClient(droneIpAddress, dronePortNumber); _sendIpEndPoint = new IPEndPoint(IPAddress.Parse(droneIpAddress), dronePortNumber); }