public SimulationModeItemManager(ContextMenuStrip contextMenuStrip, CarModelGraphicControl graphicControl)
        {
            model = new CarModel(new CarModelState(new PointD(ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X),
                                                             ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)),
                                                  new PointD(0, 1)));
            finish = new FinishModel(new PointD(ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X),
                                                ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)),
                                     0);
            obstacles = new List<ObstacleModel>();
            dragables = new List<IDragable>();

            sampledCarState = model.state;
            
            dragables.Add(model);
            dragables.Add(finish);
            dragged = null;

            state = State.NONE;

            this.contextMenuStrip = contextMenuStrip;
            this.graphicControl = graphicControl;

            contextMenuStrip.Items[0].Click += new EventHandler(newObstacle);
            contextMenuStrip.Items[1].Click += new EventHandler(deleteObstacle);
        }
 public void Simulate(IModelSimulator modelsim, CarModelInput input, double timestep)
 {
     CarModel model = new CarModel(GetCarState());
     model.SimulateModel(input, modelsim, timestep);
     currentCarModelState = model.state;
 }
Ejemplo n.º 3
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics g = pe.Graphics;

            g.Clear(Color.White);
            if (transform == null)
            {
                CalcTransform();
            }
            g.Transform = transform;


            int w = (int)((CarModelState.MAX_POS_X - CarModelState.MIN_POS_X) / CarModel.MM_PER_PIXEL);
            int h = (int)((CarModelState.MAX_POS_Y - CarModelState.MIN_POS_Y) / CarModel.MM_PER_PIXEL);


            if (neuralController != null)
            {
                double orix = Math.Cos(carPositionProvider.GetCarState().Angle);
                double oriy = Math.Sin(carPositionProvider.GetCarState().Angle);

                PointF[] pp = new PointF[] { new PointF(0, 0), new PointF(Width - 1, Height - 1) };
                itransform.TransformPoints(pp);

                pp[0].X = (float)ComMath.Normal((pp[0].X - CarModel.OFFSET_X) * CarModel.MM_PER_PIXEL, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X, NeuralController.MIN_NEURON_VALUE, NeuralController.MAX_NEURON_VALUE);
                pp[0].Y = (float)ComMath.Normal((pp[0].Y - CarModel.OFFSET_Y) * CarModel.MM_PER_PIXEL, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y, NeuralController.MIN_NEURON_VALUE, NeuralController.MAX_NEURON_VALUE);
                pp[1].X = (float)ComMath.Normal((pp[1].X - CarModel.OFFSET_X) * CarModel.MM_PER_PIXEL, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X, NeuralController.MIN_NEURON_VALUE, NeuralController.MAX_NEURON_VALUE);
                pp[1].Y = (float)ComMath.Normal((pp[1].Y - CarModel.OFFSET_Y) * CarModel.MM_PER_PIXEL, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y, NeuralController.MIN_NEURON_VALUE, NeuralController.MAX_NEURON_VALUE);
                Bitmap background = neuralController.controller.Visualize(20, 20, new RectangleF(pp[0].X, pp[0].Y, pp[1].X - pp[0].X, pp[1].Y - pp[0].Y), 0, 1, new double[] { 0, 0, orix, oriy }, 0, -10, 10);


                pp = new PointF[] { new PointF(0, 0), new PointF(Width - 1, Height - 1) };
                itransform.TransformPoints(pp);

                g.DrawImage(background, new RectangleF(pp[0].X, pp[0].Y, pp[1].X - pp[0].X, pp[1].Y - pp[0].Y), new RectangleF(0, 0, background.Width - 1, background.Height - 1), GraphicsUnit.Pixel);
            }


            if (cameraCarPos != null)
            {
                Image im = cameraCarPos.GetImage();


                if (im != null)
                {
                    g.DrawImage(im, new Rectangle(0, 0, w, h), new Rectangle(0, 0, im.Width, im.Height), GraphicsUnit.Pixel);
                }
            }
            //g.DrawRectangle(new Pen(Color.Blue, 3), new Rectangle(0, 0, w, h));


            if (obstacleProvider != null)
            {
                List <ObstacleModel> obstacles = obstacleProvider.GetObstacleModels(0);
                foreach (ObstacleModel om in obstacles)
                {
                    om.Render(g);
                }
            }

            if (finishPositionProvider != null)
            {
                finishPositionProvider.GetFinishModel(0).Render(g);
            }


            if (trainingModels != null)
            {
                lock (trainingModels)
                {
                    foreach (CarModel m in trainingModels)
                    {
                        if (m != null)
                        {
                            m.Render(g, 120, false);
                        }
                    }
                }
            }

            if (carPositionProvider != null)
            {
                CarModel model = carPositionProvider.GetCarModel();
                model.Render(g, 255, true);
                if (recv)
                {
                    g.FillEllipse(new SolidBrush(Color.Red), new Rectangle((int)(model.state.Position.X / CarModel.MM_PER_PIXEL + CarModel.OFFSET_X) - 2, (int)(model.state.Position.Y / CarModel.MM_PER_PIXEL + CarModel.OFFSET_Y) - 2, 4, 4));
                    recv = false;
                }
            }

            // Calling the base class OnPaint
            base.OnPaint(pe);
            if (OnRefreshed != null)
            {
                OnRefreshed.Invoke();
            }
        }