示例#1
0
 private string GetSimulationScriptEntry(CyPhy.CarSimulation sim)
 {
     if (sim.Kind == "Acceleration")
     {
         AccelSim outp = new AccelSim();
         CyPhy.Acceleration accelsim = sim as CyPhy.Acceleration;
         CyPhy.Parameter endtimeparam = accelsim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
         int endtime = GetParamOrDefault(endtimeparam, 20);
         outp.ModelName = "DefaultCar";
         outp.InitialVelocity = "3";
         outp.NumSteps = (endtime * 10).ToString();
         outp.EndTime = endtime.ToString();
         outp.FinalThrottle = "100.0";
         outp.StepDuration = "1.0";
         outp.StartTime = "0.0";
         outp.ShiftGears = "no";
         outp.OutputPrefix = "test";
         outp.OutputPostfix = sim.Kind;
         outp.GearPosition = "2";
         outp.Acceleration = "0";
         outp.RoadData = "acar_shared/roads.tbl/2d_flat.rdf";
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" });
         return outp.TransformText();
     }
     else if (sim.Kind == "Braking")
     {
         BrakingSim outp = new BrakingSim();
         outp.ModelName = "DefaultCar";
         outp.InitialVelocity = "20";
         outp.NumSteps = "300";
         outp.EndTime = "30";
         outp.FinalBrake = "100.0";
         outp.StepDuration = "1.0";
         outp.StartValue = "0.0";
         outp.OutputPrefix = "test";
         outp.OutputPostfix = sim.Kind;
         outp.GearPosition = "5";
         return outp.TransformText();
     }
     else if (sim.Kind == "ConstantSpeed")
     {
         ConstantSpeedSim outp = new ConstantSpeedSim();
         CyPhy.ConstantSpeed csim = sim as CyPhy.ConstantSpeed;
         CyPhy.Parameter endtimeparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
         CyPhy.Parameter speedparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Speed").FirstOrDefault();
         CyPhy.Parameter gearparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Gear").FirstOrDefault();
         int endtime = GetParamOrDefault(endtimeparam, 20);
         int speed = GetParamOrDefault(speedparam, 15);
         int gear = GetParamOrDefault(gearparam, 2);
         outp.ModelName = "DefaultCar";
         outp.InitialVelocity = speed.ToString();
         outp.NumSteps = (endtime * 10).ToString();
         outp.GearPosition = gear.ToString();
         outp.OutputPrefix = "test";
         outp.OutputPostfix = sim.Kind;
         outp.EndTime = endtime.ToString();
         outp.RoadData = "roads.tbl\\pothole_4in.rdf";
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" });
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(speedparam).Name, ParamID = "Speed" });
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(gearparam).Name, ParamID = "Gear" });
         /*AccelSim outp = new AccelSim();
         CyPhy.ConstantSpeed csim = sim as CyPhy.ConstantSpeed;
         CyPhy.Parameter endtimeparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
         int endtime = GetParamOrDefault(endtimeparam, 20);
         outp.ModelName = "DefaultCar";
         outp.InitialVelocity = "3";
         outp.NumSteps = (endtime * 10).ToString();
         outp.EndTime = endtime.ToString();
         outp.FinalThrottle = "100.0";
         outp.StepDuration = "5.0";
         outp.StartTime = "0.0";
         outp.ShiftGears = "no";
         outp.OutputPrefix = "test";
         outp.OutputPostfix = sim.Kind;
         outp.GearPosition = "2";
         outp.Acceleration = "1";
         outp.RoadData = "isis_test\\roads.tbl\\pothole_4in.rdf";
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" });
          */
         return outp.TransformText();
     }
     else if (sim.Kind == "Steering")
     {
         SteerSim outp = new SteerSim();
         CyPhy.Steering ssim = sim as CyPhy.Steering;
         CyPhy.Parameter endtimeparam = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
         CyPhy.Parameter speedparam = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Speed").FirstOrDefault();
         CyPhy.Parameter angleparam = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Angle").FirstOrDefault();
         int endtime = GetParamOrDefault(endtimeparam, 20);
         int speed = GetParamOrDefault(speedparam, 50);
         int angle = GetParamOrDefault(angleparam, 20);
         outp.ModelName = "DefaultCar";
         outp.OutputPrefix = "test";
         outp.OutputPostfix = sim.Kind;
         outp.EndTime = endtime.ToString();
         outp.InitialVelocity = speed.ToString();
         outp.NumSteps = (endtime * 10).ToString();
         outp.SteerAngle = angle.ToString();
         outp.GearPosition = "1";
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" });
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(speedparam).Name, ParamID = "Speed" });
         CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(angleparam).Name, ParamID = "Angle" });
         return outp.TransformText();
     }
     else
     {
         GMEConsole.Warning.WriteLine("Unknown simulation type:" + sim.Kind);
     }
     return null;
 }
示例#2
0
        private string GetSimulationScriptEntry(CyPhy.CarSimulation sim)
        {
            if (sim.Kind == "Acceleration")
            {
                AccelSim           outp         = new AccelSim();
                CyPhy.Acceleration accelsim     = sim as CyPhy.Acceleration;
                CyPhy.Parameter    endtimeparam = accelsim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
                int endtime = GetParamOrDefault(endtimeparam, 20);
                outp.ModelName       = "DefaultCar";
                outp.InitialVelocity = "3";
                outp.NumSteps        = (endtime * 10).ToString();
                outp.EndTime         = endtime.ToString();
                outp.FinalThrottle   = "100.0";
                outp.StepDuration    = "1.0";
                outp.StartTime       = "0.0";
                outp.ShiftGears      = "no";
                outp.OutputPrefix    = "test";
                outp.OutputPostfix   = sim.Kind;
                outp.GearPosition    = "2";
                outp.Acceleration    = "0";
                outp.RoadData        = "acar_shared/roads.tbl/2d_flat.rdf";
                CarParamMap.Add(new CarParamMapping()
                {
                    FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime"
                });
                return(outp.TransformText());
            }
            else if (sim.Kind == "Braking")
            {
                BrakingSim outp = new BrakingSim();
                outp.ModelName       = "DefaultCar";
                outp.InitialVelocity = "20";
                outp.NumSteps        = "300";
                outp.EndTime         = "30";
                outp.FinalBrake      = "100.0";
                outp.StepDuration    = "1.0";
                outp.StartValue      = "0.0";
                outp.OutputPrefix    = "test";
                outp.OutputPostfix   = sim.Kind;
                outp.GearPosition    = "5";
                return(outp.TransformText());
            }
            else if (sim.Kind == "ConstantSpeed")
            {
                ConstantSpeedSim    outp         = new ConstantSpeedSim();
                CyPhy.ConstantSpeed csim         = sim as CyPhy.ConstantSpeed;
                CyPhy.Parameter     endtimeparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
                CyPhy.Parameter     speedparam   = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Speed").FirstOrDefault();
                CyPhy.Parameter     gearparam    = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Gear").FirstOrDefault();
                int endtime = GetParamOrDefault(endtimeparam, 20);
                int speed   = GetParamOrDefault(speedparam, 15);
                int gear    = GetParamOrDefault(gearparam, 2);
                outp.ModelName       = "DefaultCar";
                outp.InitialVelocity = speed.ToString();
                outp.NumSteps        = (endtime * 10).ToString();
                outp.GearPosition    = gear.ToString();
                outp.OutputPrefix    = "test";
                outp.OutputPostfix   = sim.Kind;
                outp.EndTime         = endtime.ToString();
                outp.RoadData        = "roads.tbl\\pothole_4in.rdf";
                CarParamMap.Add(new CarParamMapping()
                {
                    FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime"
                });
                CarParamMap.Add(new CarParamMapping()
                {
                    FileName = "adams_car.cmd", TBParamName = FollowParam(speedparam).Name, ParamID = "Speed"
                });
                CarParamMap.Add(new CarParamMapping()
                {
                    FileName = "adams_car.cmd", TBParamName = FollowParam(gearparam).Name, ParamID = "Gear"
                });

                /*AccelSim outp = new AccelSim();
                 * CyPhy.ConstantSpeed csim = sim as CyPhy.ConstantSpeed;
                 * CyPhy.Parameter endtimeparam = csim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
                 * int endtime = GetParamOrDefault(endtimeparam, 20);
                 * outp.ModelName = "DefaultCar";
                 * outp.InitialVelocity = "3";
                 * outp.NumSteps = (endtime * 10).ToString();
                 * outp.EndTime = endtime.ToString();
                 * outp.FinalThrottle = "100.0";
                 * outp.StepDuration = "5.0";
                 * outp.StartTime = "0.0";
                 * outp.ShiftGears = "no";
                 * outp.OutputPrefix = "test";
                 * outp.OutputPostfix = sim.Kind;
                 * outp.GearPosition = "2";
                 * outp.Acceleration = "1";
                 * outp.RoadData = "isis_test\\roads.tbl\\pothole_4in.rdf";
                 * CarParamMap.Add(new CarParamMapping() { FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime" });
                 */
                return(outp.TransformText());
            }
            else if (sim.Kind == "Steering")
            {
                SteerSim        outp         = new SteerSim();
                CyPhy.Steering  ssim         = sim as CyPhy.Steering;
                CyPhy.Parameter endtimeparam = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "EndTime").FirstOrDefault();
                CyPhy.Parameter speedparam   = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Speed").FirstOrDefault();
                CyPhy.Parameter angleparam   = ssim.Children.ParameterCollection.Where(p => ((MgaFCO)p.Impl).MetaRole.Name == "Angle").FirstOrDefault();
                int             endtime      = GetParamOrDefault(endtimeparam, 20);
                int             speed        = GetParamOrDefault(speedparam, 50);
                int             angle        = GetParamOrDefault(angleparam, 20);
                outp.ModelName       = "DefaultCar";
                outp.OutputPrefix    = "test";
                outp.OutputPostfix   = sim.Kind;
                outp.EndTime         = endtime.ToString();
                outp.InitialVelocity = speed.ToString();
                outp.NumSteps        = (endtime * 10).ToString();
                outp.SteerAngle      = angle.ToString();
                outp.GearPosition    = "1";
                CarParamMap.Add(new CarParamMapping()
                {
                    FileName = "adams_car.cmd", TBParamName = FollowParam(endtimeparam).Name, ParamID = "EndTime"
                });
                CarParamMap.Add(new CarParamMapping()
                {
                    FileName = "adams_car.cmd", TBParamName = FollowParam(speedparam).Name, ParamID = "Speed"
                });
                CarParamMap.Add(new CarParamMapping()
                {
                    FileName = "adams_car.cmd", TBParamName = FollowParam(angleparam).Name, ParamID = "Angle"
                });
                return(outp.TransformText());
            }
            else
            {
                GMEConsole.Warning.WriteLine("Unknown simulation type:" + sim.Kind);
            }
            return(null);
        }