Skip to content

Instantly share code, notes, and snippets.

@valkjsaaa
Created March 28, 2018 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valkjsaaa/151ae34a4da43368b0da771a344d4d37 to your computer and use it in GitHub Desktop.
Save valkjsaaa/151ae34a4da43368b0da771a344d4d37 to your computer and use it in GitHub Desktop.
DroneControlCLI
using System;
using System.Collections;
using System.Collections.Generic;
using NetMQ;
using NetMQ.Sockets;
namespace DroneControlCLI
{
struct Vector3
{
public float x, y, z;
}
struct Quaternion
{
public float w, x, y, z;
}
struct WayPoint
{
public bool Landing;
public Vector3 Position;
public Quaternion Rotation;
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
}
internal class Program
{
private static PublisherSocket _logPublisherSocket;
public const string LogSocket = "tcp://*:35002";
public static readonly List<WayPoint> WayPoints = new List<WayPoint>()
{
new WayPoint()
{
Landing = true,
Position = new Vector3()
{
x = 0, y = 0, z = 0
},
Rotation = new Quaternion()
{
w = 1, x= 0, y = 0, z = 0
}
},
new WayPoint()
{
Landing = false,
Position = new Vector3()
{
x = 0, y = 0, z = 1
},
Rotation = new Quaternion()
{
w = 1, x= 0, y = 0, z = 0
}
},
new WayPoint()
{
Landing = false,
Position = new Vector3()
{
x = 1, y = 0, z = 1
},
Rotation = new Quaternion()
{
w = 1, x = 0, y = 0, z = 0
}
},
new WayPoint()
{
Landing = false,
Position = new Vector3()
{
x = 1, y = 0, z = 1
},
Rotation = new Quaternion()
{
w = 0, x= 0, y = 0, z = 1
}
},
new WayPoint()
{
Landing = false,
Position = new Vector3()
{
x = 1, y = 0, z = 0
},
Rotation = new Quaternion()
{
w = 1, x= 0, y = 0, z = 0
}
},
};
public static int WayPointIndex = 0;
public static void Main(string[] args)
{
using (_logPublisherSocket)
{
_logPublisherSocket = new PublisherSocket();
_logPublisherSocket.Bind(LogSocket);
while (true)
{
try
{
if (Console.KeyAvailable)
{
if (Console.ReadKey().Key == ConsoleKey.Enter)
{
WayPointIndex = (WayPointIndex + 1) % WayPoints.Count;
}
else
{
break;
}
}
}
catch (InvalidOperationException)
{
}
var currentWayPoint = WayPoints[WayPointIndex];
var response =
$"{(currentWayPoint.Landing? 0 : 1)} {currentWayPoint.Position.x} {currentWayPoint.Position.y} {currentWayPoint.Position.z} " +
$"{currentWayPoint.Rotation.x} {currentWayPoint.Rotation.y} {currentWayPoint.Rotation.z} {currentWayPoint.Rotation.w}";
Console.WriteLine(response);
_logPublisherSocket.SendFrame(response);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment