Example #1
0
            public override INode GetNextNode(INode node, MultirotorClient client, IModel graph, Action <string> writeToMessageBox)
            {
                var outEdges = graph.Edges.Where(x => x.From == node).ToList();

                if (outEdges.Count != 2)
                {
                    writeToMessageBox("Error: ifNode out edges count is not equal 2 ");
                    client.Dispose();
                    return(null);
                }

                IEdge edge = outEdges[0];

                if (this.condition)
                {
                    return((INode)(edge.Attributes.ToList()[0].StringValue == "true"
                        ? edge.To
                        : outEdges[1].To));
                }
                else
                {
                    return((INode)(edge.Attributes.ToList()[0].StringValue == "false"
                        ? edge.To
                        : outEdges[1].To));
                }
            }
            public virtual INode GetNextNode(
                                                INode node,
                                                MultirotorClient client,
                                                IModel graph,
                                                Action<string> writeToMessageBox)
            {
                var outEdges = graph.Edges.Where(x => x.From == node).ToList();
                if (outEdges.Count > 1)
                {
                    writeToMessageBox("Error: Node " + node.Name + " has more than the 1 out edge ");
                    client.Dispose();
                    return null;
                }

                if (outEdges.Count == 0)
                {
                    if (recursionNodes.Count > 0)
                    {
                        return recursionNodes.Pop();
                    }

                    writeToMessageBox("Error: Node " + node.Name +
                                      " has no out edges and it is not the final node ");
                    client.Dispose();
                    return null;
                }

                return (INode)outEdges[0].To;
            }
        /// <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(IModel programGraph, Action<string> writeToConsole)
        {
            var curNode = this.GetInitNode(programGraph, writeToConsole);
            if (curNode == null)
            {
                return;
            }

            writeToConsole("Running your code");
            var client = new MultirotorClient();
            while (recursionLevel >= 0)
            {
                Execution.Exec.ExecuteNode(ref curNode, client, programGraph, writeToConsole);
                curNode = Execution.Exec.GetNextNode(curNode, client, programGraph, writeToConsole);
                if (curNode == null)
                {
                    return;
                }

                writeToConsole($"Node {curNode.Name} done");
            }

            client.Land();
            client.Dispose();
            writeToConsole("Program done");
        }
Example #4
0
            public override void ExecuteNode(INode node, MultirotorClient client)
            {
                var t = float.Parse(node.Attributes.ToList()[0].StringValue);

                client.EnableApiControl();
                client.MoveByVelocityZ(float.Parse(node.Attributes.ToList()[0].StringValue));
            }
 public override void ExecuteNode(INode node, MultirotorClient client)
 {
     if (recursionLevel == 0)
     {
         client.CreateClient();
         client.ConfirmConnection();
         client.EnableApiControl();
     }
 }
            public INode GetNextNode(
                                        INode node,
                                        MultirotorClient client,
                                        IModel graph,
                                        Action<string> writeToMessageBox)
            {
                if (!strategies.ContainsKey(node.Name))
                {
                    return strategies["aInitialNode"].GetNextNode(node, client, graph, writeToMessageBox);
                }

                return strategies[node.Name].GetNextNode(node, client, graph, writeToMessageBox);
            }
            public void ExecuteNode(ref INode node, MultirotorClient client, IModel graph, Action<string> writeToMessageBox)
            {
                if (!strategies.ContainsKey(node.Name))
                {
                    recursionNodes.Push(strategies["aInitialNode"].GetNextNode(node, client, graph, writeToMessageBox));
                    node = (INode)node.Function;
                    ++recursionLevel;
                    this.ExecuteNode(ref node, client, graph, writeToMessageBox);
                    return;
                }

                strategies[node.Name].ExecuteNode(node, client);
            }
Example #8
0
            public void ExecuteNode(ref INode node, MultirotorClient client, IModel graph, Action <string> writeToMessageBox)
            {
                if (!strategies.ContainsKey(node.Name))
                {
                    // TODO: Functions were removed from repo, so this code does not work now.
                    recursionNodes.Push(strategies["aInitialNode"].GetNextNode(node, client, graph, writeToMessageBox));
                    ++recursionLevel;
                    this.ExecuteNode(ref node, client, graph, writeToMessageBox);
                    return;
                }

                strategies[node.Name].ExecuteNode(node, client);
            }
            private 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 + @";
                    }
                }";
                bool ans = false;
                if (!bool.TryParse(this.EvalCode("Code", "Exe", sourceCode, new object[] { client }), out ans))
                {
                    return true;
                }

                return ans;
            }
 public abstract void ExecuteNode(INode node, MultirotorClient client);
 public override void ExecuteNode(INode node, MultirotorClient client)
     => this.condition = this.CheckCondition(client, node.Attributes.ToList()[0].StringValue);
 public override void ExecuteNode(INode node, MultirotorClient client)
 {
     client.Hover();
     client.EnableApiControl();
 }
 public override void ExecuteNode(INode node, MultirotorClient client)
     => client.Sleep(float.Parse(node.Attributes.ToList()[0].StringValue));
 public override void ExecuteNode(INode node, MultirotorClient client)
     => client.Land();
 public override void ExecuteNode(INode node, MultirotorClient client)
 {
     --recursionLevel;
 }