Example #1
0
        public WorldObject CreateRobotObj(World world, Point point)
        {
            var camera = _robotCamera ?? InitializeRobotCamera(world);
            NavigationSystem nav;
            IStrategy        strategy;

            if (Settings != null)
            {
                nav = new NavigationSystem(world)
                {
                    ElevationStd           = Settings.EstimatedElevationStd,
                    RotationStd            = Settings.EstimatedRotationStd,
                    TranslationStd         = Settings.EstimatedTranslationStd,
                    MeasurementSuccessProb = Settings.EstimatedCameraSuccessProb
                };
                strategy = new WanderStrategy(_random)
                {
                    ElevateProb   = Settings.DecideElevateProb,
                    TranslateProb = Settings.DecideTranslateProb,
                    RotateProb    = Settings.DecideRotateProb,
                    IsExact       = false,
                    Settings      = Settings
                };
            }
            else
            {
                nav      = new NavigationSystem(world);
                strategy = new WanderStrategy(_random)
                {
                    IsExact = false
                };
            }
            var model       = new Robot(camera, nav, strategy);
            int orientation = _random.Next(0, 4) * 90;
            var obj         = new WorldObject(model, Size, point, orientation);

            return(obj);
        }
Example #2
0
        public SimulationViewModel()
        {
            _worldObjects = new ObservableCollection <WorldObject>();

            FloorObjects           = new ObservableCollection <UIElement>();
            LocalizationIndicators = new ObservableCollection <UIElement>();

            NewSimCommand = new RelayCommand <object>(p =>
            {
                _worldObjects.CollectionChanged -= WorldObjects_CollectionChanged;
                _worldObjects.Clear();

                var generator      = new WorldGenerator(CanvasSize);
                string[,,] map     = WorldGenerator.ParseMapFromJson("Map.json");
                generator.Settings = ProbabilitySettings.ParseFromJson("Settings.json");
                World world        = generator.Generate(map, _worldObjects);
                _worldObjects.CollectionChanged += WorldObjects_CollectionChanged;

                if (generator.Robot != null)
                {
                    if (_navigationSystem != null)
                    {
                        _navigationSystem.LocalizationUpdated -= NavigationSystem_LocalizationUpdated;
                    }

                    _navigationSystem = generator.Robot.NavigationSystem;
                    _navigationSystem.LocalizationUpdated += NavigationSystem_LocalizationUpdated;

                    _localizationWindow?.Close();
                }
                _simulation = new Engine(world);
                _floor      = 0;

                UpdateFloorObjects(_floor);
                StartSimulationWrapper();
                CommandManager.InvalidateRequerySuggested();
            }, p =>
            {
                return(!_isSimulating);
            });

            ContinueSimCommand = new RelayCommand <object>(p =>
            {
                StartSimulationWrapper();
                CommandManager.InvalidateRequerySuggested();
            }, p =>
            {
                return(!_isSimulating && _simulation != null);
            });

            StepSimCommand = new RelayCommand <object>(p =>
            {
                StartSimulationStepWrapper();
                CommandManager.InvalidateRequerySuggested();
            }, p =>
            {
                return(!_isSimulating && _simulation != null);
            });

            StopSimCommand = new RelayCommand <object>(p =>
            {
                var source    = _stopSimSource;
                object locker = new object();
                lock (locker)
                {
                    if (source != null && !source.IsCancellationRequested)
                    {
                        source.Cancel(false);
                    }
                }
            }, p =>
            {
                return(_stopSimSource != null);
            });

            ChangeFloorCommand = new RelayCommand <object>(p =>
            {
                _floor += (int)p;
                UpdateFloorObjects(_floor);
                UpdateLocalizationIndicators(_floor);
                CommandManager.InvalidateRequerySuggested();
            }, p =>
            {
                var world = _simulation?.World;
                if (world == null)
                {
                    return(false);
                }
                int destination = (int)p + _floor;
                return(destination >= 0 && destination <= world.UpperBound.Z);
            });

            OpenLocalizationCommand = new RelayCommand <object>(p =>
            {
                LocalizationWindow window = _localizationWindow;
                if (window == null)
                {
                    _localizationWindow = window = new LocalizationWindow(this);
                    window.Closed      += LocalizationWindow_Closed;
                    window.Show();
                    UpdateLocalizationIndicators(_floor);
                }
                else
                {
                    window.Focus();
                }
            }, p =>
            {
                return(_simulation != null);
            });
        }
Example #3
0
 public Robot(Camera camera, NavigationSystem navigationSystem, IStrategy strategy)
 {
     _camera          = camera;
     _strategy        = strategy;
     NavigationSystem = navigationSystem;
 }