Test Branch
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace Tello_Drone
|
||||
void TakeOff();
|
||||
void Land();
|
||||
void RotateClockWise(int r);
|
||||
void FrontFlip();
|
||||
void BackFlip();
|
||||
void RightFlip();
|
||||
void LeftFlip();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ namespace Tello_Drone
|
||||
{
|
||||
public interface IMissions
|
||||
{
|
||||
void SetUpDrone();
|
||||
void RunMission1();
|
||||
void RunMission2();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user