Esempio n. 1
0
        FromFiles(string scenefile, string commandfile = "", int particlecount = 5,
                  VehicleType input             = VehicleType.Simulation,
                  NavigationAlgorithm algorithm = NavigationAlgorithm.PHD,
                  bool onlymapping = false, bool realtime   = false,
                  bool sidebar     = true, bool noterminate = false)
        {
            Vehicle <MeasurerT, PoseT, MeasurementT>   explorer;
            Navigator <MeasurerT, PoseT, MeasurementT> navigator;
            List <double[]> commands;

            // batch methods extra information
            TimedState        estimate     = null;
            TimedArray        odometry     = null;
            TimedMeasurements measurements = null;

            try {
                switch (input)
                {
                case VehicleType.Kinect:
                    if (typeof(MeasurementT) == typeof(PixelRangeMeasurement) &&
                        typeof(PoseT) == typeof(Pose3D) &&
                        typeof(MeasurerT) == typeof(KinectMeasurer))
                    {
                        explorer = KinectVehicle.FromSensor(scenefile, sidebar) as
                                   Vehicle <MeasurerT, PoseT, MeasurementT>;
                    }
                    else
                    {
                        throw new ArgumentException("KinectVehicle can only handle 3D Pose + PixelRange");
                    }
                    break;

                case VehicleType.Record:
                    if (algorithm == NavigationAlgorithm.LoopyPHD)
                    {
                        Console.WriteLine("reading Loopy PHD initialization data from file");
                        explorer = RecordVehicle <MeasurerT, PoseT, MeasurementT> .
                                   FromFile(scenefile, true, out estimate, out odometry, out measurements);
                    }
                    else
                    {
                        explorer = RecordVehicle <MeasurerT, PoseT, MeasurementT> .
                                   FromFile(scenefile, false, out estimate, out odometry, out measurements);
                    }
                    break;

                case VehicleType.Simulation:
                default:
                    explorer = SimulatedVehicle <MeasurerT, PoseT, MeasurementT> .
                               FromFile(File.ReadAllText(scenefile));

                    break;
                }
            }
            catch (IOException) {
                Console.WriteLine("Couldn't open vehicle file/device: " + scenefile);
                explorer = new SimulatedVehicle <MeasurerT, PoseT, MeasurementT>();
            }

            try {
                if (!string.IsNullOrEmpty(commandfile))
                {
                    commands = FP.CommandsFromDescriptor(File.ReadAllLines(commandfile));
                }
                else
                {
                    commands = new List <double[]>();
                }
            }
            catch (FileNotFoundException) {
                Console.WriteLine("command file not found: " + commandfile);
                commands = new List <double[]>();
            }

            switch (algorithm)
            {
            case NavigationAlgorithm.Odometry:
                navigator = new OdometryNavigator <MeasurerT, PoseT, MeasurementT>(explorer);
                break;

            case NavigationAlgorithm.ISAM2:
                navigator = new ISAM2Navigator <MeasurerT, PoseT, MeasurementT>(explorer, onlymapping);
                break;

            case NavigationAlgorithm.LoopyPHD:
                Console.WriteLine("initializing Loopy PHD");
                if (estimate != null)
                {
                    navigator = new LoopyPHDNavigator <MeasurerT, PoseT, MeasurementT>(explorer, estimate,
                                                                                       odometry, measurements);
                }
                else
                {
                    navigator = new LoopyPHDNavigator <MeasurerT, PoseT, MeasurementT>(explorer, commands,
                                                                                       new PHDNavigator <MeasurerT, PoseT, MeasurementT>(explorer, particlecount, onlymapping));
                }

                explorer = new FakeVehicle <MeasurerT, PoseT, MeasurementT>(explorer, true);

                Console.WriteLine("Loopy PHD initialized");

                break;

            case NavigationAlgorithm.PHD:
            default:
                navigator = new PHDNavigator <MeasurerT, PoseT, MeasurementT>(explorer, particlecount, onlymapping);
                break;
            }

            string title = "monorfs - simulating " + scenefile + " [" + algorithm + "]";

            return(new Simulation <MeasurerT, PoseT, MeasurementT>(title, explorer, navigator, commands, realtime, noterminate));
        }