/// <summary> /// Main execution method /// </summary> /// <param name="programGraph"> Visual program to execute </param> /// <param name="writeToConsole"> Method to writing to console </param> public void Execute(Graph programGraph, Action <string> writeToConsole) { writeToMessageBox = writeToConsole; graph = programGraph; NodeViewModel curNode = GetInitNode(); if (curNode == null) { return; } writeToMessageBox("Running your code"); var client = new MultirotorClient(); while (curNode.Name != "aFinalNode") { Execution.ExecuteNode(curNode, client); curNode = Execution.GetNextNode(curNode, client); if (curNode == null) { return; } writeToMessageBox($"Node {curNode.Name} done"); } client.Land(); client.Dispose(); writeToMessageBox("Program done"); }
private static bool CheckCondition(MultirotorClient client, string conditionString) { string sourceCode = @"using System; using System.IO; using WpfEditor.AirSim; public class Code { public bool Exe(MultirotorClient client) { return " + conditionString + @"; } }"; return(bool.Parse(EvalCode("Code", "Exe", sourceCode, new object[] { client }))); }
public virtual NodeViewModel GetNextNode(NodeViewModel node, MultirotorClient client) { if (graph.DataGraph.OutEdges(node).Count() > 1) { writeToMessageBox("Error: Node " + node.Name + " has more than the 1 out edge "); client.Dispose(); return(null); } if (!graph.DataGraph.OutEdges(node).Any()) { writeToMessageBox("Error: Node " + node.Name + " has no out edges and it is not the final node "); client.Dispose(); return(null); } return(graph.DataGraph.OutEdges(node).ToList()[0].Target); }
public override NodeViewModel GetNextNode(NodeViewModel node, MultirotorClient client) { if (graph.DataGraph.OutEdges(node).Count() != 2) { writeToMessageBox("Error: ifNode out edges count is not equal 2 "); client.Dispose(); return(null); } if (condition) { EdgeViewModel edge = graph.DataGraph.OutEdges(node).ToList()[0]; return(edge.Attributes[0].Value == "true" ? edge.Target : graph.DataGraph.OutEdges(node).ToList()[1].Target); } else { EdgeViewModel edge = graph.DataGraph.OutEdges(node).ToList()[0]; return(edge.Attributes[0].Value == "false" ? edge.Target : graph.DataGraph.OutEdges(node).ToList()[1].Target); } }
public static NodeViewModel GetNextNode(NodeViewModel node, MultirotorClient client) => strategies[node.Name].GetNextNode(node, client);
public static void ExecuteNode(NodeViewModel node, MultirotorClient client) => strategies[node.Name].ExecuteNode(node, client);
public override void ExecuteNode(NodeViewModel node, MultirotorClient client) => condition = CheckCondition(client, node.Attributes[0].Value);
public override void ExecuteNode(NodeViewModel node, MultirotorClient client) { client.Hover(); client.EnableApiControl(); }
public override void ExecuteNode(NodeViewModel node, MultirotorClient client) => client.Sleep(float.Parse(node.Attributes[0].Value));
public override void ExecuteNode(NodeViewModel node, MultirotorClient client) => client.Land();
public override void ExecuteNode(NodeViewModel node, MultirotorClient client) { client.CreateClient(); client.ConfirmConnection(); client.EnableApiControl(); }
public abstract void ExecuteNode(NodeViewModel node, MultirotorClient client);