Test Branch

This commit is contained in:
2019-09-08 22:28:32 -06:00
parent 5b5757c7d4
commit 1190c08729
7 changed files with 64 additions and 27 deletions

View File

@@ -12,28 +12,36 @@ namespace Tello_Drone
{ {
_missions = missions; _missions = missions;
_consoleLogger = consoleLogger; _consoleLogger = consoleLogger;
_missions.SetUpDrone();
} }
public void Run() public void Run()
{ {
_consoleLogger.Log("Choose a mission to run."); while (true)
_consoleLogger.Log("1: Mission 1");
_consoleLogger.Log("2: Mission 2");
_consoleLogger.Log("3: Mission 3");
var userInput = Console.ReadLine();
switch (userInput)
{ {
case "1": _consoleLogger.Log("Choose a mission to run.");
_missions.RunMission1(); _consoleLogger.Log("1: Mission 1");
break; _consoleLogger.Log("2: Mission 2");
default: _consoleLogger.Log("3: Mission 3");
_consoleLogger.Log("Not A Valid Entry...Try Again");
Run();
break;
}
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;
}
}
} }

View File

@@ -20,6 +20,10 @@ namespace Tello_Drone
public void TakeOff() => _droneCommands.TakeOff(); public void TakeOff() => _droneCommands.TakeOff();
public void Land() => _droneCommands.Land(); public void Land() => _droneCommands.Land();
public void RotateClockWise(int r) => _droneCommands.RotateClockWise(r); 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();
} }

View File

@@ -12,7 +12,7 @@ namespace Tello_Drone
_udpClient = udpClient; _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 Reverse(int x) => SendCommand($"back {x}");
public void Up(int z) => SendCommand($"up {z}"); public void Up(int z) => SendCommand($"up {z}");
public void Down(int z) => SendCommand($"down {z}"); public void Down(int z) => SendCommand($"down {z}");
@@ -23,7 +23,12 @@ namespace Tello_Drone
public void TakeOff() => SendCommand("takeoff"); public void TakeOff() => SendCommand("takeoff");
public void Land() => SendCommand("land"); public void Land() => SendCommand("land");
public void RotateClockWise(int r) => SendCommand($"cw {r}"); 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) private void SendCommand(string message)
{ {
var returnValue = _udpClient.TrySend(message, 0_500, 3); var returnValue = _udpClient.TrySend(message, 5_000, 3);
if (returnValue == false) if (returnValue == false)
SendCommand("land"); SendCommand("land");
} }
private bool TrySendCommand(string message) private bool TrySendCommand(string message)
{ {
return _udpClient.TrySend(message, 0_500, 3); return _udpClient.TrySend(message, 5_000, 3);
} }
} }

View File

@@ -13,6 +13,10 @@ namespace Tello_Drone
void TakeOff(); void TakeOff();
void Land(); void Land();
void RotateClockWise(int r); void RotateClockWise(int r);
void FrontFlip();
void BackFlip();
void RightFlip();
void LeftFlip();
} }
} }

View File

@@ -2,6 +2,8 @@ namespace Tello_Drone
{ {
public interface IMissions public interface IMissions
{ {
void SetUpDrone();
void RunMission1(); void RunMission1();
void RunMission2();
} }
} }

View File

@@ -4,12 +4,22 @@ namespace Tello_Drone
{ {
private Drone _drone; private Drone _drone;
private int _setupRetry; private int _setupRetry;
public Missions( IDroneFactory droneFactory) public Missions( IDroneFactory droneFactory)
{ {
_drone = droneFactory.CreateDrone; _drone = droneFactory.CreateDrone;
} }
public void SetUpDrone()
{
var inCommandMode = false;
while (inCommandMode != true && _setupRetry < 3)
{
inCommandMode = _drone.Command();
_setupRetry++;
}
}
public void RunMission1() public void RunMission1()
{ {
MissionSetup(); MissionSetup();
@@ -18,14 +28,18 @@ namespace Tello_Drone
MissionTeardown(); MissionTeardown();
} }
public void RunMission2()
{
MissionSetup();
_drone.BackFlip();
_drone.FrontFlip();
_drone.Forward(30);
_drone.Land();
}
private void MissionSetup() private void MissionSetup()
{ {
var inCommandMode = false;
while (inCommandMode != true && _setupRetry < 3)
{
inCommandMode = _drone.Command();
_setupRetry++;
}
if (!_drone.InitialTakeOff()) if (!_drone.InitialTakeOff())
_drone.InitialTakeOff(); _drone.InitialTakeOff();

View File

@@ -21,7 +21,7 @@ namespace Tello_Drone
var dronePortNumber = Convert.ToInt32(Console.ReadLine()); var dronePortNumber = Convert.ToInt32(Console.ReadLine());
if (droneIpAddress != null) 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), _sendIpEndPoint = new IPEndPoint(IPAddress.Parse(droneIpAddress),
dronePortNumber); dronePortNumber);
} }