コード例 #1
0
ファイル: CodeExecution.cs プロジェクト: tara-sova/REAL.NET
            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));
                }
            }
コード例 #2
0
            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;
            }
コード例 #3
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(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");
        }
コード例 #4
0
ファイル: CodeExecution.cs プロジェクト: tara-sova/REAL.NET
            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));
            }
コード例 #5
0
 public override void ExecuteNode(INode node, MultirotorClient client)
 {
     if (recursionLevel == 0)
     {
         client.CreateClient();
         client.ConfirmConnection();
         client.EnableApiControl();
     }
 }
コード例 #6
0
            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);
            }
コード例 #7
0
            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);
            }
コード例 #8
0
ファイル: CodeExecution.cs プロジェクト: tara-sova/REAL.NET
            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);
            }
コード例 #9
0
            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;
            }
コード例 #10
0
 public abstract void ExecuteNode(INode node, MultirotorClient client);
コード例 #11
0
 public override void ExecuteNode(INode node, MultirotorClient client)
     => this.condition = this.CheckCondition(client, node.Attributes.ToList()[0].StringValue);
コード例 #12
0
 public override void ExecuteNode(INode node, MultirotorClient client)
 {
     client.Hover();
     client.EnableApiControl();
 }
コード例 #13
0
 public override void ExecuteNode(INode node, MultirotorClient client)
     => client.Sleep(float.Parse(node.Attributes.ToList()[0].StringValue));
コード例 #14
0
 public override void ExecuteNode(INode node, MultirotorClient client)
     => client.Land();
コード例 #15
0
 public override void ExecuteNode(INode node, MultirotorClient client)
 {
     --recursionLevel;
 }