コード例 #1
0
link_motor.SetSpindleConstraint(
    chrono.ChLinkMotorRotationSpeed.SpindleConstraint_CYLINDRICAL
)  # Set_shaft_mode(chrono.ChLinkEngine.ENG_SHAFT_PRISM)
link_motor.SetMotorFunction(chrono.ChFunction_Const(
    1.0 * chrono.CH_C_2PI))  # 1.0 Hz to rad/s
my_system.Add(link_motor)

if m_visualization == "pov":

    # ---------------------------------------------------------------------
    #
    #  Render a short animation by generating scripts
    #  to be used with POV-Ray
    #

    pov_exporter = postprocess.ChPovRay(my_system)

    # Sets some file names for in-out processes.
    pov_exporter.SetTemplateFile("_template_POV.pov")
    pov_exporter.SetOutputScriptFile("rendering_frames.pov")
    if not os.path.exists("output"):
        os.mkdir("output")
    if not os.path.exists("anim"):
        os.mkdir("anim")
    pov_exporter.SetOutputDataFilebase("output/my_state")
    pov_exporter.SetPictureFilebase("anim/picture")

    # Sets the viewpoint, aimed point, lens angle
    pov_exporter.SetCamera(chrono.ChVectorD(0.4, 0.6, 0.9),
                           chrono.ChVectorD(0.2, 0, 0), 30)
コード例 #2
0
    def __init__(self,
                 step_size,
                 system,
                 track,
                 vehicle,
                 terrain,
                 irrlicht=False,
                 obstacles=None,
                 opponents=None,
                 draw_barriers=False,
                 draw_cones=False,
                 draw_track=True,
                 bind_all=True,
                 pov=False,
                 camera_save=False):
        # Chrono parameters
        self.step_size = step_size
        self.irrlicht = irrlicht
        self.step_number = 0

        # Time interval between two render frames
        self.render_step_size = 1.0 / 60  # FPS = 60
        self.render_steps = int(
            math.ceil(self.render_step_size / self.step_size))

        # Track that vehicle is going through
        self.track = track

        # Static obstacles in the environment
        self.obstacles = obstacles

        # Dynamic opponents in the environment
        self.opponents = opponents

        self.system = system
        self.vehicle = vehicle
        self.terrain = terrain

        if self.irrlicht:
            if draw_track:
                self.DrawPath(track.center)

        if obstacles != None:
            self.DrawObstacles(obstacles)

        if opponents != None:
            temp = dict()
            for opponent in opponents:
                temp[opponent] = (opponent.vehicle, opponent.vehicle.driver)
            self.opponents = temp

        if draw_barriers:
            self.DrawBarriers(self.track.left.points)
            self.DrawBarriers(self.track.right.points)
        if draw_cones:
            self.DrawCones(self.track.left.points, 'red')
            self.DrawCones(self.track.right.points, 'green')

        if self.irrlicht and bind_all:
            self.app = veh.ChVehicleIrrApp(self.vehicle.vehicle)
            self.app.SetHUDLocation(500, 20)
            self.app.SetSkyBox()
            self.app.AddTypicalLogo()
            self.app.AddTypicalLights(chronoirr.vector3df(-150., -150., 200.),
                                      chronoirr.vector3df(-150., 150., 200.),
                                      100, 100)
            self.app.AddTypicalLights(chronoirr.vector3df(150., -150., 200.),
                                      chronoirr.vector3df(150., 150., 200.),
                                      100, 100)
            self.app.EnableGrid(False)
            self.app.SetChaseCamera(self.vehicle.trackPoint, 6.0, 0.5)

            self.app.SetTimestep(self.step_size)
            # ---------------------------------------------------------------------
            #
            #  Create an Irrlicht application to visualize the system
            #
            # ==IMPORTANT!== Use this function for adding a ChIrrNodeAsset to all items
            # in the system. These ChIrrNodeAsset assets are 'proxies' to the Irrlicht meshes.
            # If you need a finer control on which item really needs a visualization proxy
            # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

            self.app.AssetBindAll()

            # ==IMPORTANT!== Use this function for 'converting' into Irrlicht meshes the assets
            # that you added to the bodies into 3D shapes, they can be visualized by Irrlicht!

            self.app.AssetUpdateAll()

        self.pov = pov
        if self.pov:
            self.pov_exporter = postprocess.ChPovRay(self.system)

            # Sets some file names for in-out processes.
            self.pov_exporter.SetTemplateFile(
                chrono.GetChronoDataFile('_template_POV.pov'))
            self.pov_exporter.SetOutputScriptFile("rendering_frames.pov")
            if not os.path.exists("output"):
                os.mkdir("output")
            if not os.path.exists("anim"):
                os.mkdir("anim")
            self.pov_exporter.SetOutputDataFilebase("output/my_state")
            self.pov_exporter.SetPictureFilebase("anim/picture")

            self.pov_exporter.SetCamera(chrono.ChVectorD(0.2, 0.3, 0.5),
                                        chrono.ChVectorD(0, 0, 0), 35)
            self.pov_exporter.SetLight(chrono.ChVectorD(-2, 2, -1),
                                       chrono.ChColor(1.1, 1.2, 1.2), True)
            self.pov_exporter.SetPictureSize(1280, 720)
            self.pov_exporter.SetAmbientLight(chrono.ChColor(2, 2, 2))

            # Add additional POV objects/lights/materials in the following way
            self.pov_exporter.SetCustomPOVcommandsScript('''
            light_source{ <1,3,1.5> color rgb<1.1,1.1,1.1> }
            Grid(0.05,0.04, rgb<0.7,0.7,0.7>, rgbt<1,1,1,1>)
            ''')

            # Tell which physical items you want to render
            self.pov_exporter.AddAll()

            # Tell that you want to render the contacts
            # self.pov_exporter.SetShowContacts(True,
            #                             postprocess.ChPovRay.SYMBOL_VECTOR_SCALELENGTH,
            #                             0.2,    # scale
            #                             0.0007, # width
            #                             0.1,    # max size
            #                             True,0,0.5 ) # colormap on, blue at 0, red at 0.5

            # 1) Create the two .pov and .ini files for POV-Ray (this must be done
            #    only once at the beginning of the simulation).
            self.pov_exporter.ExportScript()