コード例 #1
0
        private static void Main(string[] args)
        {
            // Here we create an endpoint settings object that defines where the fleet manager service is currently running
            // For this demo we are assuming it is running on localhost, using the default TCP port of 41917.

            EndpointSettings endpointSettings = new EndpointSettings(IPAddress.Loopback, 41916, 41917);

            // Now we create a fleet manager client using the client factory;
            IFleetManagerClient fleetManagerClient = ClientFactory.CreateTcpFleetManagerClient(endpointSettings);

            Console.WriteLine("Press <any> key to create a virtual vehicle 192.168.0.1 at 0,0,0");
            Console.ReadKey(true);

            IPAddress          virtualVehicle = IPAddress.Parse("192.168.0.1");
            IServiceCallResult result         = fleetManagerClient.CreateVirtualVehicle(virtualVehicle, 0, 0, 0);

            if (!result.IsSuccessful())
            {
                Console.WriteLine($"Failed to create virtual vehicle serviceCode:{result.ServiceCode}");
            }

            // Now we can update the vehicles pose
            Console.WriteLine("Press <any> key to set the pose of the vehicle to 1,1,1.57");
            Console.ReadKey(true);

            result = fleetManagerClient.SetPose(virtualVehicle, 1, 1, 1.57);
            if (!result.IsSuccessful())
            {
                Console.WriteLine($"Failed to set pose serviceCode:{result.ServiceCode}");
            }

            Console.WriteLine("Press <any> key to quit");
            Console.ReadKey(true);

            // The fleet manager client has its own thread which must be disposed.
            fleetManagerClient.Dispose();
        }
コード例 #2
0
        protected override IServiceCallResult HandleExecution(IJobStateClient client)
        {
            IServiceCallResult <JobSummaryDto> result = client.GetCurrentJobSummaryForAgentId(Id);

            Console.WriteLine($"Getting job summary for agent:{Id}");

            if (result.IsSuccessful())
            {
                if (result.Value != null)
                {
                    Console.WriteLine($"JobId:{result.Value.JobId}");
                }
                else
                {
                    Console.WriteLine($"No active job");
                }
            }
            else
            {
                Console.WriteLine(result.ExceptionMessage);
            }

            return(result);
        }
コード例 #3
0
        private static void Main(string[] args)
        {
            // Here we create an endpoint settings object that defines where the fleet manager service is currently running
            // For this demo we are assuming it is running on localhost, using the default TCP port of 41917.
            EndpointSettings endpointSettings = new EndpointSettings(IPAddress.Loopback, 41916, 41917);

            IEnumerable <int> nodeIds = Enumerable.Empty <int>(); // Create an array to store node ids in

            NodeDto startNode = null;

            // Using the map manager client, get the ids of all nodes in the map
            using (IMapClient mapClient = SchedulingClients.Core.ClientFactory.CreateTcpMapClient(endpointSettings))
            {
                IServiceCallResult <NodeDto[]> nodeResults = mapClient.GetAllNodes();

                if (!nodeResults.IsSuccessful())
                {
                    Console.WriteLine($"Failed to get nodes, serviceCode:{nodeResults.ServiceCode}");
                }
                else
                {
                    nodeIds = nodeResults.Value.Select(e => e.Id);
                }

                startNode = nodeResults.Value.First();
            }

            // Now we create a fleet manager client using the client factory, and create a virtual vehicle at pose at the first node.
            //  see: https://github.com/GuidanceAutomation/FleetClients
            using (IFleetManagerClient fleetManagerClient = FleetClients.Core.ClientFactory.CreateTcpFleetManagerClient(endpointSettings))
            {
                IServiceCallResult result = fleetManagerClient.CreateVirtualVehicle(IPAddress.Parse("192.168.0.1"), startNode.Pose.X, startNode.Pose.Y, startNode.Pose.Heading);

                if (!result.IsSuccessful())
                {
                    Console.WriteLine($"Failed to create virtual vehicle serviceCode:{result.ServiceCode}");
                }
            }


            Random random       = new Random(); // Random number generator
            bool   continueFlag = true;

            while (continueFlag)
            {
                Console.WriteLine("Press <any> key to create a random GoTo job, 'q' to quit");

                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.Q:
                {
                    continueFlag = false;
                    break;
                }

                default:
                {
                    // Use the job builder client to create a new goto job.
                    using (IJobBuilderClient jobBuilder = SchedulingClients.Core.ClientFactory.CreateTcpJobBuilderClient(endpointSettings))
                    {
                        // Boiler plate code to pick a random node from the array of nodes.
                        int index  = random.Next(0, nodeIds.Count());
                        int nodeId = nodeIds.ElementAt(index);

                        Console.WriteLine($"Sending to node:{nodeId}");

                        IServiceCallResult <JobDto> createResult = jobBuilder.CreateJob();
                        if (!createResult.IsSuccessful())
                        {
                            Console.WriteLine($"Failed to create job, serviceCode:{createResult.ServiceCode}");
                        }

                        IServiceCallResult <int> gotoResult = jobBuilder.CreateGoToNodeTask(createResult.Value.RootOrderedListTaskId, nodeId);
                        if (!gotoResult.IsSuccessful())
                        {
                            Console.WriteLine($"Failed to create goto task, serviceCode:{gotoResult.ServiceCode}");
                        }

                        IServiceCallResult commitResult = jobBuilder.CommitJob(createResult.Value.JobId);
                        if (!commitResult.IsSuccessful())
                        {
                            Console.WriteLine($"Failed to commit job, serviceCode:{commitResult.ServiceCode}");
                        }
                    }

                    break;
                }
                }
            }
        }