diff --git a/.idea/.idea.Tello Drone/.idea/contentModel.xml b/.idea/.idea.Tello Drone/.idea/contentModel.xml
index ccde461..3a7b1d4 100644
--- a/.idea/.idea.Tello Drone/.idea/contentModel.xml
+++ b/.idea/.idea.Tello Drone/.idea/contentModel.xml
@@ -22,7 +22,6 @@
-
diff --git a/Tello Drone/CoreModule.cs b/Tello Drone/CoreModule.cs
index 626980e..4877330 100644
--- a/Tello Drone/CoreModule.cs
+++ b/Tello Drone/CoreModule.cs
@@ -8,10 +8,8 @@ namespace Tello_Drone
{
container.Register(Reuse.Singleton);
container.Register(Reuse.Singleton);
- container.Register(Reuse.Singleton);
container.Register(Reuse.Singleton);
container.Register(Reuse.Singleton);
- //container.Register(Reuse.Singleton);
}
public void Resolve(IContainer container)
diff --git a/Tello Drone/Drone.cs b/Tello Drone/Drone.cs
index 65e00d3..32ccadf 100644
--- a/Tello Drone/Drone.cs
+++ b/Tello Drone/Drone.cs
@@ -2,7 +2,7 @@ using System.Runtime.CompilerServices;
namespace Tello_Drone
{
- public class Drone : IDrone
+ public class Drone
{
private readonly IDroneCommands _droneCommands;
@@ -11,10 +11,17 @@ namespace Tello_Drone
_droneCommands = droneCommands;
}
- public bool Forward() => _droneCommands.Forward();
- public bool Reverse() => _droneCommands.Reverse();
- public bool Up() => _droneCommands.Up();
- public bool Down() => _droneCommands.Down();
+ public void Forward(int x) => _droneCommands.Forward(x);
+ public void Reverse(int x) => _droneCommands.Reverse(x);
+ public void Up(int z) => _droneCommands.Up(z);
+ public void Down(int z) => _droneCommands.Down(z);
+ public void Left(int y) => _droneCommands.Left(y);
+ public void Right(int y) => _droneCommands.Right(y);
+ public bool Command() => _droneCommands.Command();
+ public bool InitialTakeOff() => _droneCommands.InitialTakeOff();
+ public void TakeOff() => _droneCommands.TakeOff();
+ public void Land() => _droneCommands.Land();
+ public void RotateClockWise(int r) => _droneCommands.RotateClockWise(r);
}
diff --git a/Tello Drone/DroneComands.cs b/Tello Drone/DroneComands.cs
index 89e4224..90e53c3 100644
--- a/Tello Drone/DroneComands.cs
+++ b/Tello Drone/DroneComands.cs
@@ -1,5 +1,7 @@
using System;
using System.Net;
+using System.Reflection.Metadata.Ecma335;
+using System.Xml.Schema;
namespace Tello_Drone
{
@@ -13,17 +15,38 @@ namespace Tello_Drone
_udpClient = udpClient;
}
- public bool Forward() => SendCommand("Forward");
+ 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}");
+ public void Left(int y) => SendCommand($"left {y}");
+ public void Right(int y) => SendCommand($"right {y}");
+ public bool Command() => TrySendCommand("command");
+ public bool InitialTakeOff() => TrySendCommand("takeoff");
+ public void TakeOff() => SendCommand("takeoff");
+ public void Land() => SendCommand("land");
+ public void RotateClockWise(int r) => SendCommand($"cw {r}");
+
+
+
+
+
- public bool Reverse() => SendCommand("Reverse");
-
- public bool Up() => SendCommand("Up");
-
- public bool Down() => SendCommand("Down");
-
- private bool SendCommand(string message)
+ private void SendCommand(string message)
{
- return _udpClient.TrySend(message, 1_500);
+ var returnValue = _udpClient.TrySend(message, 0_500);
+ if (returnValue == false)
+ SendCommand("land");
+ }
+
+ private bool TrySendCommand(string message)
+ {
+ return _udpClient.TrySend(message, 0_500);
+
}
}
}
+
+
+
+
diff --git a/Tello Drone/DroneFactory.cs b/Tello Drone/DroneFactory.cs
index 2d31420..edc4173 100644
--- a/Tello Drone/DroneFactory.cs
+++ b/Tello Drone/DroneFactory.cs
@@ -3,8 +3,7 @@ namespace Tello_Drone
public class DroneFactory : IDroneFactory
{
private readonly IDroneCommands _droneCommands;
- private Drone _createDrone;
-
+
public DroneFactory(IDroneCommands droneCommands)
{
_droneCommands = droneCommands;
diff --git a/Tello Drone/IDrone.cs b/Tello Drone/IDrone.cs
deleted file mode 100644
index 1142e1e..0000000
--- a/Tello Drone/IDrone.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace Tello_Drone
-{
- public interface IDrone
- {
-
-
- }
-}
\ No newline at end of file
diff --git a/Tello Drone/IDroneCommands.cs b/Tello Drone/IDroneCommands.cs
index a17fd45..a93c115 100644
--- a/Tello Drone/IDroneCommands.cs
+++ b/Tello Drone/IDroneCommands.cs
@@ -2,9 +2,17 @@ namespace Tello_Drone
{
public interface IDroneCommands
{
- bool Forward();
- bool Reverse();
- bool Up();
- bool Down();
+ void Forward(int x);
+ void Reverse(int x);
+ void Up(int z);
+ void Down(int z);
+ void Left(int y);
+ void Right(int y);
+ bool Command();
+ bool InitialTakeOff();
+ void TakeOff();
+ void Land();
+ void RotateClockWise(int r);
+
}
}
\ No newline at end of file
diff --git a/Tello Drone/Missions.cs b/Tello Drone/Missions.cs
index 2bd971d..6abb8e9 100644
--- a/Tello Drone/Missions.cs
+++ b/Tello Drone/Missions.cs
@@ -1,4 +1,6 @@
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using DryIoc;
namespace Tello_Drone
{
@@ -6,6 +8,7 @@ namespace Tello_Drone
{
private readonly IConsoleLogger _consoleLogger;
private Drone _drone;
+ private int setupRetry = 0;
public Missions( IDroneFactory droneFactory, IConsoleLogger consoleLogger)
{
@@ -15,12 +18,20 @@ namespace Tello_Drone
public void RunMission1()
{
- _drone.Down();
- _drone.Up();
+ MissionSetup();
+ _drone.Down(3);
+ _drone.Up(3);
}
private void MissionSetup()
{
+ var inCommandMode = false;
+ while (inCommandMode != true && setupRetry < 3)
+ {
+ inCommandMode = _drone.Command();
+ setupRetry++;
+ _consoleLogger.Log(inCommandMode.ToString());
+ }
}
}
diff --git a/Tello Drone/UdpClientWrapper.cs b/Tello Drone/UdpClientWrapper.cs
index 72b6206..a112716 100644
--- a/Tello Drone/UdpClientWrapper.cs
+++ b/Tello Drone/UdpClientWrapper.cs
@@ -14,7 +14,7 @@ namespace Tello_Drone
{
private readonly UdpClient _client;
private int retryCount = 0;
- private IPEndPoint _ipEndPoint;
+ private IPEndPoint _sendIpEndPoint;
private IDroneConstants _droneConstants;
private IConsoleLogger _consoleLogger;
@@ -28,27 +28,28 @@ namespace Tello_Drone
consoleLogger.Log("Enter Drone Port Number:");
_droneConstants.DronePortNumber = Convert.ToInt32(Console.ReadLine());
_client = new UdpClient(_droneConstants.DroneIPAddress, _droneConstants.DronePortNumber);
- _ipEndPoint = new IPEndPoint(IPAddress.Parse(_droneConstants.DroneIPAddress), _droneConstants.DronePortNumber);
+ _sendIpEndPoint = new IPEndPoint(IPAddress.Parse(_droneConstants.DroneIPAddress), _droneConstants.DronePortNumber);
}
- public bool TrySend(string message, int timeOut)
+ public bool TrySend(string message, int timeout)
{
bool successfullFlag = false;
while(retryCount < 3 && successfullFlag == false)
{
- _client.Client.ReceiveTimeout = 1_500;
- _client.Send(Encoding.UTF8.GetBytes(message), 1);
+ _client.Client.ReceiveTimeout = timeout;
+ _client.Send(Encoding.ASCII.GetBytes(message), message.Length);
try
{
- var bytes = _client.Receive(ref _ipEndPoint);
+ var bytes = _client.Receive(ref _sendIpEndPoint);
var returnMessage = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
- if (returnMessage == "Ok")
+ if (returnMessage == "ok")
successfullFlag = true;
+ _consoleLogger.Log($"successfull flag = {successfullFlag}");
}
catch
{
- _consoleLogger.Log("SHIT BROKE");
+ _consoleLogger.Log("Did not get a response from the drone retrying.");
}
retryCount++;
}