コード例 #1
0
        /// <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");
        }
コード例 #2
0
        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 })));
        }
コード例 #3
0
 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);
 }
コード例 #4
0
 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);
     }
 }
コード例 #5
0
 public static NodeViewModel GetNextNode(NodeViewModel node, MultirotorClient client)
 => strategies[node.Name].GetNextNode(node, client);
コード例 #6
0
 public static void ExecuteNode(NodeViewModel node, MultirotorClient client)
 => strategies[node.Name].ExecuteNode(node, client);
コード例 #7
0
 public override void ExecuteNode(NodeViewModel node, MultirotorClient client)
 => condition = CheckCondition(client, node.Attributes[0].Value);
コード例 #8
0
 public override void ExecuteNode(NodeViewModel node, MultirotorClient client)
 {
     client.Hover();
     client.EnableApiControl();
 }
コード例 #9
0
 public override void ExecuteNode(NodeViewModel node, MultirotorClient client)
 => client.Sleep(float.Parse(node.Attributes[0].Value));
コード例 #10
0
 public override void ExecuteNode(NodeViewModel node, MultirotorClient client)
 => client.Land();
コード例 #11
0
 public override void ExecuteNode(NodeViewModel node, MultirotorClient client)
 {
     client.CreateClient();
     client.ConfirmConnection();
     client.EnableApiControl();
 }
コード例 #12
0
 public abstract void ExecuteNode(NodeViewModel node, MultirotorClient client);