Example #1
0
        public static Car createCar(Pose pose, Physics ph)
        {
            // рожаем машину
            Car car;
            var p = new CarParams();
            p.InitDefault();
            p.h = 2.5f;
            p.h_base = 2f;
            car = new Car(p, 0);

            car.Create(ph, pose);
            return car;
        }
Example #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //инциализируем отрисовку и физику
            gh = new GraphicsHelper(pictureBox1);
            ghover = new GraphicsHelper(pictureBoxOverlay);
            ph = new Physics();
            Vec2 target = new Vec2(75F, 6f); //Координаты конечной точки

            // рожаем машину
            var p = new CarParams();
            p.InitDefault(); //Задает машине параметры по умолчанию
            p.h = 2.5f; //Поправляем форму машинки
            p.h_base = 2f;
            var ps = new Pose() { xc = 5, yc = 15, angle_rad = 30 * Helper.angle_to_rad }; //Задаем начальное положение машины
            car = new Car(p, 0);
            car.Create(ph, ps);

            //создание агента и среды
            carAgent = new LICStreeAgent(ps,target);
            pictureBox2.Image = new Bitmap(pictureBox2.Width, pictureBox2.Height);
            env = new Environment(ph, car, target,pictureBox2);

            //создание объектов среды
            //ВАЖНО!!! -- в каком порядке объекты создаются, в таком они и отрисовываются, поэтому в первую очередь создаются объекты заднего плана.
            //занятно...-- НЕсамообучающийся по картинке агент ооочень туго переваривает динамические препятствия. Хотя, всё же, переваривает.

            env.CreateRectZone(new Pose { xc = 30f, yc = 23f, angle_rad = 45 * k_PI }, new Vec2(15f, 25f), 2f);
            env.CreateRectZone(new Pose { xc = 70f, yc = 20f, angle_rad = 45 * k_PI }, new Vec2(10f, 5f), 3f);
            env.CreateWall( new Pose { xc = 25f, yc = 17f, angle_rad = 20 * k_PI },new Vec2(2f, 10f));
            env.CreateWall(new Pose { xc = 20f, yc = 35f, angle_rad = 35 * k_PI }, new Vec2(10f, 10f));
            env.CreateWall(new Pose { xc = 40f, yc = 10f, angle_rad = 35 * k_PI }, new Vec2(40f, 1f));
            env.CreateWall( new Pose { xc = 55f, yc = 30f, angle_rad = 100 * k_PI },new Vec2(2f, 10f));
            env.CreateWall(new Pose { xc = 65f, yc = 45f, angle_rad = 0 * k_PI }, new Vec2(15f, 15f));
            env.CreateWall(new Pose { xc = 25f, yc = 25f, angle_rad = -195 * k_PI }, new Vec2(20f, 1f));
            env.CreateWall(new Pose { xc = 50f, yc = 20f, angle_rad = 105 * k_PI }, new Vec2(2f, 7f));
            env.CreateWall(new Pose { xc = 58f, yc = 18f, angle_rad = 45 * k_PI }, new Vec2(10f, 5f));

            env.CreateWall(new Pose { xc = pictureBox1.Width/20f, yc = pictureBox1.Height/10f, angle_rad = 90 * k_PI }, new Vec2(1f, 10000f));
            env.CreateWall(new Pose { xc = pictureBox1.Width / 20f, yc = 0/10f, angle_rad = 90 * k_PI }, new Vec2(1f, 10000f));
            env.CreateWall(new Pose { xc = pictureBox1.Width / 10f, yc = pictureBox1.Height / 20f, angle_rad = 0 * k_PI }, new Vec2(1f, 10000f));
            env.CreateWall(new Pose { xc = 0/10f, yc = pictureBox1.Height / 20f, angle_rad = 0 * k_PI }, new Vec2(1f, 10000f));

            //env.CreateCircle(new Pose { xc = 25f, yc = 20f, angle_rad = -10 * k_PI }, 3, 10);
            //env.CreateFire(new Pose { xc = 0f, yc = 0f, angle_rad = -10 * k_PI },5);
        }
Example #3
0
        public Car(Physics ph,CarParams p,Pose pose)
        {
            this.p = p;

            car_angle0 = Helper.GetRelAngle(new Vec2(1, 0), forwardVec);

            body = ph.CreateBox(new Pose { xc = pose.xc, yc = pose.yc }, new Box2DX.Common.Vec2 { X = p.w, Y = p.h }, new BodyBehaviour { isDynamic = true, k = 0.98f * p.mass });

            bodyFW1 = ph.CreateBox(new Pose { xc = pose.xc, yc = pose.yc + p.h_base / 2 }, new Box2DX.Common.Vec2 { X = p.w / 10, Y = p.h / 10 }, new BodyBehaviour { isDynamic = true, k = 0.01f * p.mass });
            bodyBW1 = ph.CreateBox(new Pose { xc = pose.xc, yc = pose.yc + -p.h_base / 2 }, new Box2DX.Common.Vec2 { X = p.w / 10, Y = p.h / 10 }, new BodyBehaviour { isDynamic = true, k = 0.01f * p.mass });

            var jFW1def = new RevoluteJointDef();
            jFW1def.Initialize(body, bodyFW1, bodyFW1.GetWorldCenter());
            jFW1def.EnableMotor = true;
            jFW1def.MaxMotorTorque = 1000;
            jFW1def.EnableLimit = true;
            jFW1def.LowerAngle = -p.max_steer_angle * Helper.angle_to_rad;
            jFW1def.UpperAngle = p.max_steer_angle * Helper.angle_to_rad;

            jFW1 = (RevoluteJoint)ph.world.CreateJoint(jFW1def);

            var jBW1def = new PrismaticJointDef();
            jBW1def.Initialize(body, bodyBW1, bodyBW1.GetWorldCenter(), new Vec2(1, 0));
            jBW1def.EnableLimit = true;
            jBW1def.UpperTranslation = jBW1def.LowerTranslation = 0;
            jBW1 = (PrismaticJoint)ph.world.CreateJoint(jBW1def);

            //LidarParams lp = new LidarParams() { dir_deg = 0, d0 = 2.2f, dist = 20, fov_deg = 60, x0 = 0, y0 = 0, num_rays = 20 };
            var p1 = new LidarParams();
            p1.InitDefault();
            p1.d0 = p.h / 2 + 0.2f;
            InitLidar(p1);

            body.SetAngle(pose.angle_rad);

            //rcs = new RCS(this);
        }
Example #4
0
        public bool saveToFile(string name, bool reWrite = true)
        {
            if (name == "")
                return false;
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"saves\" + name);

            if (dir.Exists)
            {
                if (reWrite)
                    try { dir.Delete(true); }
                    catch (Exception e) { return false; }
                else
                    return false;
            }
            dir.Create();

            System.Xml.Serialization.XmlSerializer roboser = new System.Xml.Serialization.XmlSerializer(typeof(carCfg));
            System.IO.StreamWriter writer;

            int digitsCount = agents.Count.ToString().Length;
            int id = 0;
            foreach(var keyValue in agents)
            {
                var agent = keyValue.Value;
                var ids = id.ToString();
                while (ids.Length < digitsCount) ids = "0" + ids;
                writer = System.IO.File.CreateText(@"saves\" + name + @"\robot"+ids+".cfg");

                Pose pos = new Pose { };
                Vec2 target = new Vec2();
                CarParams cparams = new CarParams();
                if (env.robotsDict.ContainsKey(agent))
                {
                    cparams = env.robotsDict[agent].p;
                    pos = env.robotsDict[agent].pos;
                    target = env.targetsDict[agent];
                }

                string groupID = "";
                if (typeOfAgent(agent) == "LICS forest car agent with transfer")
                    groupID = (agent as EvoForestUnitAgent).groupID;
                roboser.Serialize(writer, new carCfg { p = pos, target = target, agentName = keyValue.Key, agentType =typeOfAgent(agent), agentGroup =groupID, cpars = cparams });

                writer.Close();
                id++;
            }

            System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(objInfo));
            int i = 0;
            digitsCount = env.objInfos.Count.ToString().Length;
            foreach (objInfo obj in env.objInfos)
            {
                var ids = i.ToString();
                while (ids.Length < digitsCount) ids = "0" + ids;
                i++;
                writer = System.IO.File.CreateText(@"saves\" + name + @"\object" + ids + ".inf");
                ser.Serialize(writer, obj);
                writer.Close();

            }

            return true;
        }
Example #5
0
        public Car createCar(Pose pose, CarParams pars)
        {
            // рожаем машину
            Car car = new Car(pars, 0);

            car.Create(ph, pose);
            return car;
        }
Example #6
0
 public Car createCar(Pose pose)
 {
     var pars = new CarParams();
     pars.InitDefault();
     pars.h = 2.5f;
     pars.h_base = 2f;
     return createCar(pose, pars);
 }