Exemplo n.º 1
0
    def BindAll(self):
        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()
Exemplo n.º 2
0
 def render(self):
     if not self.animate:
         print(
             'It seems that for efficiency reasons visualization has been turned OFF. To render the simulation set self.animate = True in ChronoHexapod.py'
         )
         sys.exit(1)
     if not self.render_setup:
         self.myapplication = chronoirr.ChIrrApp(
             self.hexapod_sys, 'Test', chronoirr.dimension2du(1280, 720))
         self.myapplication.AddShadowAll()
         self.myapplication.SetStepManage(True)
         self.myapplication.SetTimestep(self.timestep)
         self.myapplication.AddTypicalSky(chrono.GetChronoDataPath() +
                                          '/skybox/')
         self.myapplication.AddTypicalLogo(chrono.GetChronoDataPath() +
                                           '/logo_pychrono_alpha.png')
         self.myapplication.AddTypicalCamera(
             chronoirr.vector3df(1, 1, 1),
             chronoirr.vector3df(0.0, 0.0, 0.0))
         self.myapplication.AddTypicalLights(
         )  # angle of FOV              # angle of FOV
         self.myapplication.AssetBindAll()
         self.myapplication.AssetUpdateAll()
         self.render_setup = True
     #self.myapplication.GetSceneManager().getActiveCamera().setPosition(chronoirr.vector3df(self.centralbody.GetPos().x - 0.75 , 0.4, self.centralbody.GetPos().z + 0.25))
     #self.myapplication.GetSceneManager().getActiveCamera().setTarget(chronoirr.vector3df(self.centralbody.GetPos().x , 0.25, self.centralbody.GetPos().z))
     self.myapplication.GetDevice().run()
     self.myapplication.BeginScene()
     self.myapplication.DrawAll()
     self.myapplication.EndScene()
Exemplo n.º 3
0
   def render(self):
         if not self.render_setup :
             self.myapplication = chronoirr.ChIrrApp(self.ant_sys)
             self.myapplication.AddShadowAll()
             self.myapplication.SetTimestep(self.timestep)
             self.myapplication.AddTypicalSky(chrono.GetChronoDataPath() + '/skybox/')
             self.myapplication.AddTypicalCamera(chronoirr.vector3df(0,1.5,0))
             self.myapplication.AddLightWithShadow(chronoirr.vector3df(4,4,0),    # point
                                            chronoirr.vector3df(0,0,0),    # aimpoint
                                            20,                 # radius (power)
                                            1,9,               # near, far
                                            90)                # angle of FOV
             self.myapplication.AssetBindAll()
             self.myapplication.AssetUpdateAll()
             self.render_setup = True
         
         self.myapplication.GetDevice().run()
         self.myapplication.BeginScene()
         self.myapplication.DrawAll()
         #self.myapplication.DoStep()
         
         self.myapplication.EndScene()
        

                     
Exemplo n.º 4
0
    def createApplication(self):
        #  Create an Irrlicht application to visualize the system

        self.myapplication = chronoirr.ChIrrApp(
            self.mysystem, 'PyChrono example',
            chronoirr.dimension2du(1024, 768))

        self.myapplication.AddTypicalSky()
        self.myapplication.AddTypicalLogo()
        self.myapplication.AddTypicalCamera(chronoirr.vector3df(0.6, 0.6, 0.8))
        self.myapplication.AddLightWithShadow(
            chronoirr.vector3df(2, 4, 2),  # point
            chronoirr.vector3df(0, 0, 0),  # aimpoint
            9,  # radius (power)
            1,
            9,  # near, far
            30)  # angle of FOV

        # ==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 in
        # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

        self.myapplication.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.myapplication.AssetUpdateAll()
        self.myapplication.AddShadowAll()
        self.myapplication.SetShowInfos(True)
Exemplo n.º 5
0
def ChIrrVecify(vec):
    if type(vec) == type([]):
        ChIrrVec = chronoirr.vector3df(float(vec[0]), float(vec[1]), float(vec[2]))
    elif type(vec) == type(np.array([])):
        ChIrrVec = chronoirr.vector3df(float(vec[0]), float(vec[1]), float(vec[2]))
    else:
        ChIrrVec = chronoirr.vector3df(vec)
    return ChIrrVec
Exemplo n.º 6
0
def Set_Lights(ChSimulation, Sources, ambients = True):
    for light in Sources:
        add_light = True
        if light[6] and not ambients: # if light is Ambient but ambients are off
            add_light = False
        if add_light:
            pos = chronoirr.vector3df(light[0][0], light[0][1], light[0][2])
            if light[7]:
                aim = chronoirr.vector3df(light[1][0], light[1][1], light[1][2])
                ChSimulation.AddLightWithShadow(pos, aim, light[2], light[3], light[4], light[5])
            else:
                ChSimulation.AddLight(pos, light[2])
Exemplo n.º 7
0
    def run_visible(self):
        visible_sim = chronoirr.ChIrrApp(self.system, 'Falling',
                                         chronoirr.dimension2du(1024, 768))

        # visible_sim.AddTypicalSky()
        # visible_sim.AddTypicalLogo(chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
        visible_sim.AddTypicalCamera(chronoirr.vector3df(0, 14, -20))
        visible_sim.AddTypicalLights()

        visible_sim.AssetBindAll()
        visible_sim.AssetUpdateAll()
        visible_sim.SetTimestep(0.02)
        visible_sim.SetTryRealtime(True)

        start_t = time.time()
        while visible_sim.GetDevice().run():
            visible_sim.BeginScene()
            visible_sim.DrawAll()
            visible_sim.DoStep()
            visible_sim.EndScene()

            # break if velocity and rotational velocity is below threshold
            if self.is_settled():
                break

        end_t = time.time()
        duration = end_t - start_t

        self.post_run(duration, silent=False)
Exemplo n.º 8
0
    def __init__(self,
                 system: 'WAChronoSystem',
                 vehicle: 'WAChronoVehicle',
                 vehicle_inputs: 'WAVehicleInputs',
                 environment: 'WAEnvironment' = None,
                 opponents: list = [],
                 record: bool = False,
                 record_folder: str = "OUTPUT/",
                 should_bind: bool = True):
        self._render_steps = int(
            ceil(system.render_step_size / system.step_size))

        self._system = system
        self._vehicle_inputs = vehicle_inputs

        self._record = record
        self._record_folder = record_folder
        self._save_number = 0

        self._app = veh.ChVehicleIrrApp(vehicle._vehicle)
        self._app.SetHUDLocation(500, 20)
        self._app.SetSkyBox()
        self._app.AddTypicalLogo()
        self._app.AddTypicalLights(
            irr.vector3df(-150.0, -150.0, 200.0),
            irr.vector3df(-150.0, 150.0, 200.0),
            100,
            100,
        )
        self._app.AddTypicalLights(
            irr.vector3df(150.0, -150.0, 200.0),
            irr.vector3df(150.0, 150.0, 200.0),
            100,
            100,
        )
        self._app.SetChaseCamera(chrono.ChVectorD(0.0, 0.0, 1.75), 6.0, 0.5)
        self._app.SetTimestep(system.step_size)

        self._first = True
        if should_bind:
            self.bind()

        if environment is not None:
            self.visualize(environment.get_assets())
Exemplo n.º 9
0
    def render(self):
        if not self.render_setup:
            self.myapplication = chronoirr.ChIrrApp(
                self.robosystem, 'Test', chronoirr.dimension2du(1280, 720))
            self.myapplication.AddShadowAll()
            self.myapplication.SetStepManage(True)
            self.myapplication.SetTimestep(self.timestep)
            self.myapplication.AddTypicalSky(chrono.GetChronoDataPath() +
                                             '/skybox/')
            self.myapplication.AddTypicalLogo(chrono.GetChronoDataPath() +
                                              '/logo_pychrono_alpha.png')
            self.myapplication.AddTypicalCamera(
                chronoirr.vector3df(1, 1, 1),
                chronoirr.vector3df(0.0, 0.0, 0.0))
            self.myapplication.AddTypicalLights()  # angle of FOV
            self.myapplication.AssetBindAll()
            self.myapplication.AssetUpdateAll()
            self.render_setup = True

        self.myapplication.GetDevice().run()
        self.myapplication.BeginScene()
        self.myapplication.DrawAll()
        self.myapplication.EndScene()
Exemplo n.º 10
0
def main():
    mysystem = chrono.ChSystemNSC()

    model.make_model(mysystem)

    # ---------------------------------------------------------------------
    #
    #  Create an Irrlicht application to visualize the system
    #

    myapplication = chronoirr.ChIrrApp(mysystem, 'Oswald',
                                       chronoirr.dimension2du(1024, 768))

    # myapplication.AddTypicalSky()
    # myapplication.AddShadowAll()
    myapplication.AddTypicalLogo()
    myapplication.AddTypicalCamera(chronoirr.vector3df(0.6, 0.6, 0.8))
    myapplication.AddTypicalLights()

    # ==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 in
    # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

    myapplication.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!

    myapplication.AssetUpdateAll()

    # ---------------------------------------------------------------------
    #
    #  Run the simulation
    #

    myapplication.SetTimestep(0.005)
    # myapplication.SetTryRealtime(True)

    while myapplication.GetDevice().run():
        myapplication.BeginScene()
        myapplication.DrawAll()
        myapplication.DoStep()
        myapplication.EndScene()
    def window(self,
               arm1,
               arm2,
               print_time=False,
               timestep=0.005,
               headless=True):

        if not headless:
            self.window = chronoirr.ChIrrApp(
                self.system, self.name,
                chronoirr.dimension2du(1920,
                                       1080))  #Create window for visualization
            self.window.AddTypicalCamera(chronoirr.vector3df(1, 1, 2))
            self.window.AddTypicalLights()
            self.window.AddTypicalSky()
            self.window.AssetBindAll()
            self.window.AssetUpdateAll()
            self.window.SetTimestep(timestep)
            self.window.AddTypicalLogo(
                chrono.GetChronoDataFile('logo_pychrono_alpha.png'))

            while (self.window.GetDevice().run()
                   ):  #create a window and display simulation
                s = time.perf_counter()
                self.window.BeginScene()
                self.window.DrawAll()
                motor_torque(arm1)
                motor_torque(arm2)
                self.window.DoStep()
                print(arm1.arm_tip.GetPos())
                self.window.EndScene()
                if print_time == True:
                    print(time.perf_counter() - s)

        else:
            while (self.system.GetChTime() <
                   10):  #Run simulation without viewing
                motor_torque(arm1)
                motor_torque(arm2)
                self.system.DoStepDynamics(timestep)
                print(arm1.arm_tip.GetPos())
                if print_time == True:
                    print(time.perf_counter() - s)
Exemplo n.º 12
0
    def window(
        self,
        arm1,
        arm2,
        timestep,
        print_time=False,
        headless=True,
    ):

        if not headless:
            self.window = chronoirr.ChIrrApp(
                self.system, self.name,
                chronoirr.dimension2du(1920,
                                       1080))  #Create window for visualization
            self.window.AddTypicalCamera(chronoirr.vector3df(1, 1, 2))
            self.window.AddTypicalLights()
            self.window.AddTypicalSky()
            self.window.AssetBindAll()
            self.window.AssetUpdateAll()
            self.window.SetTimestep(timestep)
            self.window.AddTypicalLogo(
                chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
Exemplo n.º 13
0
def animateSystem(system, am=animationModifiers()):
    """
    animate the system using the chrono 
    """
    # -------------------------------------------------------------------------
    #            Create an Irrlicht application to visualize the system
    # -------------------------------------------------------------------------
    myapplication = chronoirr.ChIrrApp(system, 'PyChrono example',
                                       chronoirr.dimension2du(1024, 768))

    myapplication.AddTypicalSky()
    myapplication.AddTypicalLogo()
    myapplication.AddTypicalCamera(chronoirr.vector3df(0.6, 0.6, 0.8))
    myapplication.AddTypicalLights()

    # ==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 in
    # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

    myapplication.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!

    myapplication.AssetUpdateAll()

    # -------------------------------------------------------------------------
    #                             Run the simulation
    # -------------------------------------------------------------------------

    myapplication.SetTimestep(0.005)

    while (myapplication.GetDevice().run()):
        myapplication.BeginScene()
        myapplication.DrawAll()
        am.draw(myapplication)
        myapplication.DoStep()
        myapplication.EndScene()
Exemplo n.º 14
0
    patch_mat = chrono.ChMaterialSurfaceSMC()
    patch_mat.SetFriction(0.9)
    patch_mat.SetRestitution(0.01)
    patch_mat.SetYoungModulus(2e7)
patch = terrain.AddPatch(patch_mat, chrono.ChVectorD(0, 0, 0),
                         chrono.ChVectorD(0, 0, 1), terrainLength,
                         terrainWidth)
patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 200, 200)
patch.SetColor(chrono.ChColor(0.8, 0.8, 0.5))
terrain.Initialize()

# Create the vehicle Irrlicht interface
app = veh.ChWheeledVehicleIrrApp(my_bus.GetVehicle(), 'Citybus',
                                 irr.dimension2du(1000, 800))
app.SetSkyBox()
app.AddTypicalLights(irr.vector3df(30, -30, 100), irr.vector3df(30, 50, 100),
                     250, 130)
app.AddTypicalLogo(chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
app.SetChaseCamera(trackPoint, 15.0, 0.5)
app.SetTimestep(step_size)
app.AssetBindAll()
app.AssetUpdateAll()

# Create the driver system
driver = veh.ChIrrGuiDriver(app)

# Set the time response for steering and throttle keyboard inputs.
steering_time = 1.0  # time to go from 0 to +1 (or from 0 to -1)
throttle_time = 1.0  # time to go from 0 to +1
braking_time = 0.3  # time to go from 0 to +1
driver.SetSteeringDelta(render_step_size / steering_time)
Exemplo n.º 15
0
my_system.Add(body_floor)



if True: # m_visualization == "irrlicht":

    # ---------------------------------------------------------------------
    #
    #  Create an Irrlicht application to visualize the system
    #

    myapplication = chronoirr.ChIrrApp(my_system, 'Test', chronoirr.dimension2du(1280,720))

    myapplication.AddTypicalSky(chrono.GetChronoDataPath() + 'skybox/')
    myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
    myapplication.AddTypicalCamera(chronoirr.vector3df(0.5,0.5,0.5),chronoirr.vector3df(0.0,0.0,0.0))
    myapplication.AddTypicalLights()
    #myapplication.AddLightWithShadow(chronoirr.vector3df(10,20,10),chronoirr.vector3df(0,2.6,0), 10 ,10,40, 60, 512);

                # ==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 in
                # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

    myapplication.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!

    myapplication.AssetUpdateAll();
Exemplo n.º 16
0
   def __init__(self, render):

      self.animate = render
      self.observation_space = np.empty([30,])
      self.action_space = np.zeros([8,])
      self.info =  {}
    # ---------------------------------------------------------------------
    #
    #  Create the simulation system and add items
    #
      self.stepcounter = 0
      self.Xtarg = 1000.0
      self.Ytarg = 0.0
      self.d_old = np.linalg.norm(self.Xtarg + self.Ytarg)
      self.ant_sys = chrono.ChSystemNSC()

    # Set the default outward/inward shape margins for collision detection,
    # this is epecially important for very large or very small objects.
      chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001)
      chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001)

    #ant_sys.SetSolverType(chrono.ChSolver.Type_BARZILAIBORWEIN) # precise, more slow
      self.ant_sys.SetMaxItersSolverSpeed(70)
      
      #TODO: check contact parameters
      self.ant_material = chrono.ChMaterialSurfaceNSC()
      self.ant_material.SetFriction(0.5)
      self.ant_material.SetDampingF(0.2)
      self.ant_material.SetCompliance (0.0005)
      self.ant_material.SetComplianceT(0.0005)
    # ant_material.SetRollingFriction(rollfrict_param)
    # ant_material.SetSpinningFriction(0)
    # ant_material.SetComplianceRolling(0.0000001)
    # ant_material.SetComplianceSpinning(0.0000001)
    #TODO: timestep tuning (initialization argument?)
      self.timestep = 0.01
      self.abdomen_x = 0.25
      self.abdomen_y = 0.25
      self.abdomen_z = 0.25
      #TODO: check densisties
      self.leg_density = 250    # kg/m^3
      self.abdomen_density = 100
      self.abdomen_y0 = 0.4
      self.leg_length = 0.3
      self.leg_radius = 0.04
      self.ankle_angle = 60*(math.pi/180)
      self.ankle_length = 0.4
      self.ankle_radius = 0.04
      self.gain = 30

      self.abdomen_mass = self.abdomen_density * ((4/3)*chrono.CH_C_PI*self.abdomen_x*self.abdomen_y*self.abdomen_z)
      self.abdomen_inertia = chrono.ChVectorD((1/5)*self.abdomen_mass*(pow(self.abdomen_y,2)+pow(self.abdomen_z,2)),(1/5)*self.abdomen_mass*(pow(self.abdomen_x,2)+pow(self.abdomen_z,2)),(1/5)*self.abdomen_mass*(pow(self.abdomen_y,2)+pow(self.abdomen_x,2)))
      self.leg_mass = self.leg_density * self.leg_length * math.pi* pow (self.leg_radius,2)
      self.leg_inertia = chrono.ChVectorD(0.5*self.leg_mass*pow(self.leg_radius,2), (self.leg_mass/12)*(3*pow(self.leg_radius,2)+pow(self.leg_length,2)),(self.leg_mass/12)*(3*pow(self.leg_radius,2)+pow(self.leg_length,2)))
      self.ankle_mass = self.leg_density * self.ankle_length * math.pi* pow (self.ankle_radius,2)
      self.ankle_inertia = chrono.ChVectorD(0.5*self.ankle_mass*pow(self.ankle_radius,2), (self.ankle_mass/12)*(3*pow(self.ankle_radius,2)+pow(self.ankle_length,2)),(self.ankle_mass/12)*(3*pow(self.ankle_radius,2)+pow(self.ankle_length,2)))
      
      self.leg_limit = chrono.ChLinkLimit()
      self.ankle_limit = chrono.ChLinkLimit()
      self.leg_limit.Set_Rmax(math.pi/9)
      self.leg_limit.Set_Rmin(-math.pi/9)
      self.ankle_limit.Set_Rmax(math.pi/9)
      self.ankle_limit.Set_Rmin(-math.pi/9)
      
      if (self.animate) :
             self.myapplication = chronoirr.ChIrrApp(self.ant_sys)
             self.myapplication.AddShadowAll()
             self.myapplication.SetStepManage(True)
             self.myapplication.SetTimestep(self.timestep)
             self. myapplication.SetTryRealtime(True)  
             self.myapplication.AddTypicalSky('../data/skybox/')
             self.myapplication.AddTypicalCamera(chronoirr.vector3df(0,1.5,0))
             self.myapplication.AddLightWithShadow(chronoirr.vector3df(4,4,0),    # point
                                            chronoirr.vector3df(0,0,0),    # aimpoint
                                            20,                 # radius (power)
                                            1,9,               # near, far
                                            90)                # angle of FOV
Exemplo n.º 17
0
my_color = chrono.ChColorAsset(0.2, 0.2, 0.5)
my_floor.AddAsset(my_color)

# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'Use OpenCascade shapes',
                                   chronoirr.dimension2du(1024, 768))

myapplication.AddTypicalSky(chrono.GetChronoDataPath() + 'skybox/')
myapplication.AddTypicalLogo(chrono.GetChronoDataPath() +
                             'logo_pychrono_alpha.png')
myapplication.AddTypicalCamera(chronoirr.vector3df(0.2, 0.2, -0.2))
myapplication.AddTypicalLights()

# ==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 in
# Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll()

# ---------------------------------------------------------------------
Exemplo n.º 18
0
def main():
    #print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n")

    # Create systems

    #  Create the HMMWV vehicle, set parameters, and initialize
    my_hmmwv = veh.HMMWV_Full()
    my_hmmwv.SetContactMethod(contact_method)
    my_hmmwv.SetChassisCollisionType(chassis_collision_type)
    my_hmmwv.SetChassisFixed(False) 
    my_hmmwv.SetInitPosition(chrono.ChCoordsysD(initLoc, initRot))
    my_hmmwv.SetPowertrainType(powertrain_model)
    my_hmmwv.SetDriveType(drive_type)
    my_hmmwv.SetSteeringType(steering_type)
    my_hmmwv.SetTireType(tire_model)
    my_hmmwv.SetTireStepSize(tire_step_size)
    my_hmmwv.Initialize()

    my_hmmwv.SetChassisVisualizationType(chassis_vis_type)
    my_hmmwv.SetSuspensionVisualizationType(suspension_vis_type)
    my_hmmwv.SetSteeringVisualizationType(steering_vis_type)
    my_hmmwv.SetWheelVisualizationType(wheel_vis_type)
    my_hmmwv.SetTireVisualizationType(tire_vis_type)

    # Create the terrain

    terrain = veh.RigidTerrain(my_hmmwv.GetSystem())
    patch = terrain.AddPatch(chrono.ChCoordsysD(chrono.ChVectorD(0, 0, terrainHeight - 5), chrono.QUNIT), chrono.ChVectorD(terrainLength, terrainWidth, 10))

    patch.SetContactFrictionCoefficient(0.9)
    patch.SetContactRestitutionCoefficient(0.01)
    patch.SetContactMaterialProperties(2e7, 0.3)
    patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 200, 200)
    patch.SetColor(chrono.ChColor(0.8, 0.8, 0.5))
    terrain.Initialize()

    # Create the vehicle Irrlicht interface
    # please note that wchar_t conversion requres some workaround
    app = veh.ChWheeledVehicleIrrApp(my_hmmwv.GetVehicle())

    app.SetSkyBox()
    app.AddTypicalLights(chronoirr.vector3df(30, -30, 100), chronoirr.vector3df(30, 50, 100), 250, 130)
    app.AddTypicalLogo(chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
    app.SetChaseCamera(trackPoint, 6.0, 0.5)
    app.SetTimestep(step_size)
    app.AssetBindAll()
    app.AssetUpdateAll()

    # Initialize output

    try:
           os.mkdir(out_dir)
    except:
           print("Error creating directory " )

    # Set up vehicle output
    my_hmmwv.GetVehicle().SetChassisOutput(True);
    my_hmmwv.GetVehicle().SetSuspensionOutput(0, True);
    my_hmmwv.GetVehicle().SetSteeringOutput(0, True);
    my_hmmwv.GetVehicle().SetOutput(veh.ChVehicleOutput.ASCII , out_dir, "output", 0.1);

    # Generate JSON information with available output channels
    my_hmmwv.GetVehicle().ExportComponentList(out_dir + "/component_list.json");

    # Create the interactive driver system
    driver = veh.ChIrrGuiDriver(app)

    # Set the time response for steering and throttle keyboard inputs.
    steering_time = 1.0  # time to go from 0 to +1 (or from 0 to -1)
    throttle_time = 1.0  # time to go from 0 to +1
    braking_time = 0.3   # time to go from 0 to +1
    driver.SetSteeringDelta(render_step_size / steering_time)
    driver.SetThrottleDelta(render_step_size / throttle_time)
    driver.SetBrakingDelta(render_step_size / braking_time)

    driver.Initialize()


    # Simulation loop


    # Number of simulation steps between miscellaneous events
    render_steps = m.ceil(render_step_size / step_size)
    debug_steps = m.ceil(debug_step_size / step_size)

    # Initialize simulation frame counter and simulation time
    step_number = 0
    render_frame = 0

    if (contact_vis):
        app.SetSymbolscale(1e-4);
        #app.SetContactsDrawMode(chronoirr.eCh_ContactsDrawMode::CONTACT_FORCES);

    realtime_timer = chrono.ChRealtimeStepTimer()
    while (app.GetDevice().run()):
        time = my_hmmwv.GetSystem().GetChTime()

        #End simulation
        if (time >= t_end):
            break

        app.BeginScene(True, True, chronoirr.SColor(255, 140, 161, 192))
        app.DrawAll()
        app.EndScene()

        #Debug logging
        if (debug_output and step_number % debug_steps == 0) :
            print("\n\n============ System Information ============\n")
            print( "Time = " << time << "\n\n")
            #my_hmmwv.DebugLog(OUT_SPRINGS | OUT_SHOCKS | OUT_CONSTRAINTS)

            marker_driver = my_hmmwv.GetChassis().GetMarkers()[0].GetAbsCoord().pos
            marker_com = my_hmmwv.GetChassis().GetMarkers()[1].GetAbsCoord().pos
            print( "Markers\n")
            print( "  Driver loc:      " , marker_driver.x , " " , marker_driver.y , " " , marker_driver.z)
            print( "  Chassis COM loc: " , marker_com.x, " ", marker_com.y, " ",marker_com.z)

        # Get driver inputs
        driver_inputs = driver.GetInputs()

        # Update modules (process inputs from other modules)
        driver.Synchronize(time)
        terrain.Synchronize(time)
        my_hmmwv.Synchronize(time, driver_inputs, terrain)
        app.Synchronize(driver.GetInputModeAsString(), driver_inputs)

        # Advance simulation for one timestep for all modules
        driver.Advance(step_size)
        terrain.Advance(step_size)
        my_hmmwv.Advance(step_size)
        app.Advance(step_size)

        # Increment frame number
        step_number += 1

        # Spin in place for real time to catch up
        realtime_timer.Spin(step_size)

    return 0
Exemplo n.º 19
0
    f.write("message:" + ','.join([f"{m}" for m in messages]) + '\n')
    f.write("success:" + ','.join([f"{s}" for s in successes]) + '\n')

# with open(f"./../data/reconstruction/{filename}_real.txt", 'w') as f:
#     offset = bb_dz / 2.3
#     H = eval('_'.split(filename)[-1]) / math.tan(math.pi / 180.)
#     f.write("nodes_mm:" + ','.join([f"{n:.6f}" for n in nodes_inf_final]) + '\n')

# ---------------------------------------------------------------------
# IRRLICHT
# Create an Irrlicht application to visualize the system
#
myapplication = chronoirr.ChIrrApp(mysystem, 'Reconstruction shape',
                                   chronoirr.dimension2du(720, 540))
myapplication.AddTypicalSky(chrono.GetChronoDataPath() + 'skybox2/')
myapplication.AddTypicalCamera(chronoirr.vector3df(1.3 * bb_dz, 0., 0.))
myapplication.AddTypicalLights()
myapplication.SetShowInfos(False)

# ==IMPORTANT!== for Irrlicht to work
myapplication.AssetBindAll()
myapplication.AssetUpdateAll()
mysystem.SetupInitial()

# ---------------------------------------------------------------------
# SIMULATION
# Run the simulation

# Change the solver form the default SOR to the MKL Pardiso, more precise for fea.
msolver = mkl.ChSolverMKLcsm()
mysystem.SetSolver(msolver)
Exemplo n.º 20
0
    mbodyG.SetBodyFixed(True)
    mbodyG.SetMaterialSurface(brick_material)
    mysystem.Add(mbodyG)

# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'Test',
                                   chronoirr.dimension2du(1024, 768))

myapplication.AddTypicalLogo(
    chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
myapplication.AddTypicalSky()
myapplication.AddTypicalCamera(chronoirr.vector3df(0.6, 0.6, 0.8))
myapplication.AddTypicalLights()

# ==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 in
# Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll()

# ---------------------------------------------------------------------
    def __init__(self,
                 configuration,
                 visualization: bool = False,
                 output: Optional = None) -> None:
        # TODO a copy of the configuration is better
        self._conf = configuration
        self._visualization = visualization
        self._output = output
        self._app = None

        # TODO not sure about the meaning of theese two parameters, take them from the configuation
        chrono.ChCollisionInfo.SetDefaultEffectiveCurvatureRadius(1)
        chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.006)

        # TODO look into the parameters of the system
        # e.g. MinBounceSpeed, Gravity
        self._system = chrono.ChSystemSMC()

        if self._visualization:
            # TODO take the data path, the title, the dimension and do_[something] from the configuration
            chrono.SetChronoDataPath(
                "/home/gianluca/anaconda3/envs/chrono/share/chrono/data/")
            self._app = irr.ChIrrApp(
                self._system,
                "Artificial Skin",
                irr.dimension2du(1024, 768),
                do_fullscreen=False,
                do_shadows=True,
                do_antialias=True,
            )
            self._app.AddTypicalSky()
            self._app.AddTypicalLights()
            # TODO take the info for the came and lighs from the configuation
            self._app.AddTypicalCamera(irr.vector3df(-1, -1, 0),
                                       irr.vector3df(0, 0, 0))
            # TODO this has too many parameters and it is not that important
            self._app.AddLightWithShadow(
                irr.vector3df(1.5, 5.5, -2.5),
                irr.vector3df(0, 0, 0),
                3,
                2.2,
                7.2,
                40,
                512,
                irr.SColorf(1, 1, 1),
            )
            self._app.AddShadowAll()
            self._app.SetTimestep(0.004)

        self._make_sheets()
        self._make_sensors()
        # TODO make the load class -> it takes a node / pair of indexes and time and return the force
        self._add_forces()

        # TODO look at all the parameters of the solver and the stepper
        # TODO consider also mkl.ChSolverMKL
        # TODO take the parameters from the configuration
        self._solver = chrono.ChSolverMINRES()
        self._system.SetSolver(self._solver)
        self._solver.SetMaxIterations(1000)
        self._solver.SetTolerance(1e-12)
        self._solver.EnableDiagonalPreconditioner(True)
        self._solver.SetVerbose(
            False)  # don't take this from the configuration

        # HHT implicit integrator for II order systems, adaptive
        # TODO take the parameters from the configuaration
        self._stepper = chrono.ChTimestepperHHT(self._system)
        self._system.SetTimestepper(self._stepper)
        self._stepper.SetAlpha(-0.2)
        self._stepper.SetMaxiters(100)
        self._stepper.SetAbsTolerances(1e-5)
        self._stepper.SetMode(chrono.ChTimestepperHHT.POSITION)
        self._stepper.SetScaling(True)

        # TODO from configuarion
        # length of the simulation
        self._life = 5  # seconds
Exemplo n.º 22
0
print("Copyright (c) 2017 projectchrono.org")

my_system = chrono.ChSystemSMC()

# Create the Irrlicht visualization (open the Irrlicht device,
# bind a simple user interface, etc. etc.)
application = chronoirr.ChIrrApp(my_system, "Brick Elements",
                                 chronoirr.dimension2du(800, 600), False, True)

# Easy shortcuts to add camera, lights, logo and sky in Irrlicht scene:
application.AddTypicalLogo()
application.AddTypicalSky()
application.AddTypicalLights()

application.AddTypicalCamera(
    chronoirr.vector3df(1.2, 0.6, 0.3),  # camera location
    chronoirr.vector3df(0.2, -0.2, 0.))  # "look at" location

print("-----------------------------------------------------------")
print("-----------------------------------------------------------")
print("     Brick Elements demo with implicit integration ")
print("-----------------------------------------------------------")

# The physical system: it contains all physical objects.
# Create a mesh, that is a container for groups
# of elements and their referenced nodes.
my_mesh = fea.ChMesh()
# Geometry of the plate
plate_lenght_x = 1
plate_lenght_y = 1
plate_lenght_z = 0.05  # small thickness
Exemplo n.º 23
0
mcolor = chrono.ChColorAsset(0.3, 0.3, 0.8)
mfloor.AddAsset(mcolor)



# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'Test', chronoirr.dimension2du(1024,768))

myapplication.AddTypicalSky()
myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
myapplication.AddTypicalCamera(chronoirr.vector3df(0.2,0.2,-0.2))
myapplication.AddTypicalLights()

            # ==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 in
			# Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll();

# Add items to the physical system
for my_item in exported_items:
    my_system.Add(my_item)


# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#
print (chrono.GetChronoDataFile("skybox/"))

myapplication = chronoirr.ChIrrApp(my_system, 'Test: using data exported by Chrono::Solidworks', chronoirr.dimension2du(1024,768));

myapplication.AddTypicalSky()
myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
myapplication.AddTypicalCamera(chronoirr.vector3df(0.3,0.3,0.4))
myapplication.AddTypicalLights()

            # ==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 in
			# Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll();

Exemplo n.º 25
0
def main() : 
    #print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n")

    # --------------------------
    # Create the various modules
    # --------------------------

    # Create the vehicle system
    vehicle = veh.WheeledVehicle(vehicle_file ,chrono.ChMaterialSurface.NSC)
    vehicle.Initialize(chrono.ChCoordsysD(initLoc, initRot))
    #vehicle.GetChassis().SetFixed(True)
    vehicle.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES)
    vehicle.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES)
    vehicle.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES)
    vehicle.SetWheelVisualizationType(veh.VisualizationType_NONE)

    # Create the ground
    terrain = veh.RigidTerrain(vehicle.GetSystem(), rigidterrain_file)

    # Create and initialize the powertrain system
    powertrain = veh.SimplePowertrain(simplepowertrain_file)
    vehicle.InitializePowertrain(powertrain)

    # Create and initialize the tires
    for axle in vehicle.GetAxles() :
        tireL = veh.RigidTire(rigidtire_file)
        vehicle.InitializeTire(tireL, axle.m_wheels[0], veh.VisualizationType_MESH)
        tireR = veh.RigidTire(rigidtire_file)
        vehicle.InitializeTire(tireR, axle.m_wheels[1], veh.VisualizationType_MESH)

    app = veh.ChVehicleIrrApp(vehicle)

    app.SetSkyBox()
    app.AddTypicalLights(chronoirr.vector3df(30, -30, 100), chronoirr.vector3df(30, 50, 100), 250, 130)
    app.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
    app.SetChaseCamera(trackPoint, 6.0, 0.5)
    app.SetTimestep(step_size)
    app.AssetBindAll()
    app.AssetUpdateAll()

    driver = veh.ChIrrGuiDriver(app)

    # Set the time response for steering and throttle keyboard inputs.
    # NOTE: this is not exact, since we do not render quite at the specified FPS.
    steering_time = 1.0;  # time to go from 0 to +1 (or from 0 to -1)
    throttle_time = 1.0;  # time to go from 0 to +1
    braking_time = 0.3;   # time to go from 0 to +1
    driver.SetSteeringDelta(render_step_size / steering_time)
    driver.SetThrottleDelta(render_step_size / throttle_time)
    driver.SetBrakingDelta(render_step_size / braking_time)

    driver.Initialize()

    # -----------------
    # Initialize output
    # -----------------

    try:
           os.mkdir(out_dir)
    except:
           print("Error creating directory " )

    # Generate JSON information with available output channels
    out_json = vehicle.ExportComponentList()
    print(out_json)
    vehicle.ExportComponentList(out_dir + "/component_list.json")

    # ---------------
    # Simulation loop
    # ---------------

    realtime_timer = chrono.ChRealtimeStepTimer()
    while (app.GetDevice().run()) :

        # Render scene
        app.BeginScene(True, True, chronoirr.SColor(255, 140, 161, 192))
        app.DrawAll()
        app.EndScene()

        # Collect output data from modules (for inter-module communication)
        driver_inputs = driver.GetInputs()

        # Update modules (process inputs from other modules)
        time = vehicle.GetSystem().GetChTime()
        driver.Synchronize(time)
        vehicle.Synchronize(time, driver_inputs, terrain)
        terrain.Synchronize(time)
        app.Synchronize(driver.GetInputModeAsString(), driver_inputs)

        # Advance simulation for one timestep for all modules
        driver.Advance(step_size)
        vehicle.Advance(step_size)
        terrain.Advance(step_size)
        app.Advance(step_size)

        # Spin in place for real time to catch up
        realtime_timer.Spin(step_size)
Exemplo n.º 26
0
def main():
    #print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n")

    # --------------------------
    # Create the various modules
    # --------------------------

    # Create the vehicle system
    vehicle = veh.WheeledVehicle(vehicle_file, chrono.ChContactMethod_NSC)
    vehicle.Initialize(chrono.ChCoordsysD(initLoc, initRot))
    #vehicle.GetChassis().SetFixed(True)
    vehicle.SetChassisVisualizationType(veh.VisualizationType_MESH)
    vehicle.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES)
    vehicle.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES)
    vehicle.SetWheelVisualizationType(veh.VisualizationType_MESH)

    # Create and initialize the vehicle tires
    for axle in vehicle.GetAxles():
        tireL = veh.TMeasyTire(vehicle_tire_file)
        vehicle.InitializeTire(tireL, axle.m_wheels[0],
                               veh.VisualizationType_MESH)
        tireR = veh.TMeasyTire(vehicle_tire_file)
        vehicle.InitializeTire(tireR, axle.m_wheels[1],
                               veh.VisualizationType_MESH)

    # Create and initialize the powertrain system
    powertrain = veh.SimpleMapPowertrain(vehicle_powertrain_file)
    vehicle.InitializePowertrain(powertrain)

    # Create and initialize the trailer
    trailer = veh.WheeledTrailer(vehicle.GetSystem(), trailer_file)
    trailer.Initialize(vehicle.GetChassis())
    trailer.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES)
    trailer.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES)
    trailer.SetWheelVisualizationType(veh.VisualizationType_NONE)

    # Create abd initialize the trailer tires
    for axle in trailer.GetAxles():
        tireL = veh.TMeasyTire(trailer_tire_file)
        trailer.InitializeTire(tireL, axle.m_wheels[0],
                               veh.VisualizationType_PRIMITIVES)
        tireR = veh.TMeasyTire(trailer_tire_file)
        trailer.InitializeTire(tireR, axle.m_wheels[1],
                               veh.VisualizationType_PRIMITIVES)

    # Create the ground
    terrain = veh.RigidTerrain(vehicle.GetSystem(), rigidterrain_file)

    app = veh.ChVehicleIrrApp(vehicle, 'Sedan+Trailer (JSON specification)',
                              irr.dimension2du(1000, 800))
    app.SetSkyBox()
    app.AddTypicalLights(irr.vector3df(30, -30, 100),
                         irr.vector3df(30, 50, 100), 250, 130)
    app.AddTypicalLogo(chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
    app.SetChaseCamera(trackPoint, 6.0, 0.5)
    app.SetTimestep(step_size)
    app.AssetBindAll()
    app.AssetUpdateAll()

    driver = veh.ChIrrGuiDriver(app)

    # Set the time response for steering and throttle keyboard inputs.
    # NOTE: this is not exact, since we do not render quite at the specified FPS.
    steering_time = 1.0
    # time to go from 0 to +1 (or from 0 to -1)
    throttle_time = 1.0
    # time to go from 0 to +1
    braking_time = 0.3
    # time to go from 0 to +1
    driver.SetSteeringDelta(render_step_size / steering_time)
    driver.SetThrottleDelta(render_step_size / throttle_time)
    driver.SetBrakingDelta(render_step_size / braking_time)

    driver.Initialize()

    # ---------------
    # Simulation loop
    # ---------------

    realtime_timer = chrono.ChRealtimeStepTimer()
    while (app.GetDevice().run()):

        # Render scene
        app.BeginScene(True, True, irr.SColor(255, 140, 161, 192))
        app.DrawAll()
        app.EndScene()

        # Collect output data from modules (for inter-module communication)
        driver_inputs = driver.GetInputs()

        # Update modules (process inputs from other modules)
        time = vehicle.GetSystem().GetChTime()
        driver.Synchronize(time)
        vehicle.Synchronize(time, driver_inputs, terrain)
        trailer.Synchronize(time, driver_inputs.m_braking, terrain)
        terrain.Synchronize(time)
        app.Synchronize(driver.GetInputModeAsString(), driver_inputs)

        # Advance simulation for one timestep for all modules
        driver.Advance(step_size)
        vehicle.Advance(step_size)
        trailer.Advance(step_size)
        terrain.Advance(step_size)
        app.Advance(step_size)

        # Spin in place for real time to catch up
        realtime_timer.Spin(step_size)
Exemplo n.º 27
0
prismatic1.GetForce_Z().SetActive(True)
prismatic1.GetForce_Z().SetF(1)
prismatic1.GetForce_Z().SetModulationF(mod)

# Actuate second slider using a body force
frc2 = chrono.ChForce()
frc2.SetF_x(mod)
slider2.AddForce(frc2)

# Create the Irrlicht application
application = irr.ChIrrApp(system, "Actuated prismatic joint",
                           irr.dimension2du(800, 600), False, True)
application.AddTypicalLogo()
application.AddTypicalSky()
application.AddTypicalLights()
application.AddTypicalCamera(irr.vector3df(-1, 1.5, -6))

application.AssetBindAll()
application.AssetUpdateAll()

application.SetTimestep(1e-3)

x0 = slider1.GetPos().x

while application.GetDevice().run():
    time = system.GetChTime()

    # Output slider x position/velocity and analytical solution
    # x = slider1.GetPos().x
    # x_d = slider1.GetPos_dt().x
    # xa = x0 + (ampl / omg) * (time - m.sin(omg * time) / omg)
Exemplo n.º 28
0
# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

# Create the Irrlicht visualization (open the Irrlicht device,
# bind a simple user interface, etc. etc.)
myapplication = chronoirr.ChIrrApp(
    my_system, 'Test FEA: the Jeffcott rotor with IGA beams',
    chronoirr.dimension2du(1024, 768))

myapplication.AddTypicalLogo(
    chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
myapplication.AddTypicalSky()
myapplication.AddTypicalCamera(chronoirr.vector3df(0, 1, 4),
                               chronoirr.vector3df(beam_L / 2, 0, 0))
myapplication.AddTypicalLights()

# This is needed if you want to see things in Irrlicht 3D view.
myapplication.AssetBindAll()
myapplication.AssetUpdateAll()

# ---------------------------------------------------------------------
#
#  Run the simulation
#

# Set to a more precise HHT timestepper if needed
# my_system.SetTimestepperType(chrono.ChTimestepper.Type_HHT)
Exemplo n.º 29
0
   def __init__(self, render):

      self.animate = render
      self.observation_space = np.empty([30,])
      self.action_space = np.zeros([8,])
      self.info =  {}
    # ---------------------------------------------------------------------
    #
    #  Create the simulation system and add items
    #
      self.Xtarg = 1000.0
      self.Ytarg = 0.0
      self.d_old = np.linalg.norm(self.Xtarg + self.Ytarg)
      self.ant_sys = chrono.ChSystemNSC()

    # Set the default outward/inward shape margins for collision detection,
    # this is epecially important for very large or very small objects.
      chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001)
      chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001)

    #ant_sys.SetSolverType(chrono.ChSolver.Type_BARZILAIBORWEIN) # precise, more slow
      self.ant_sys.SetSolverMaxIterations(70)
      

      self.ant_material = chrono.ChMaterialSurfaceNSC()
      self.ant_material.SetFriction(0.5)
      self.ant_material.SetDampingF(0.2)
      self.ant_material.SetCompliance (0.0005)
      self.ant_material.SetComplianceT(0.0005)

      self.timestep = 0.01
      self.abdomen_x = 0.25
      self.abdomen_y = 0.25
      self.abdomen_z = 0.25

      self.leg_density = 250    # kg/m^3
      self.abdomen_density = 100
      self.abdomen_y0 = 0.4
      self.leg_length = 0.3
      self.leg_radius = 0.04
      self.ankle_angle = 60*(math.pi/180)
      self.ankle_length = 0.4
      self.ankle_radius = 0.04
      self.gain = 30

      self.abdomen_mass = self.abdomen_density * ((4/3)*chrono.CH_C_PI*self.abdomen_x*self.abdomen_y*self.abdomen_z)
      self.abdomen_inertia = chrono.ChVectorD((1/5)*self.abdomen_mass*(pow(self.abdomen_y,2)+pow(self.abdomen_z,2)),(1/5)*self.abdomen_mass*(pow(self.abdomen_x,2)+pow(self.abdomen_z,2)),(1/5)*self.abdomen_mass*(pow(self.abdomen_y,2)+pow(self.abdomen_x,2)))
      self.leg_mass = self.leg_density * self.leg_length * math.pi* pow (self.leg_radius,2)
      self.leg_inertia = chrono.ChVectorD(0.5*self.leg_mass*pow(self.leg_radius,2), (self.leg_mass/12)*(3*pow(self.leg_radius,2)+pow(self.leg_length,2)),(self.leg_mass/12)*(3*pow(self.leg_radius,2)+pow(self.leg_length,2)))
      self.ankle_mass = self.leg_density * self.ankle_length * math.pi* pow (self.ankle_radius,2)
      self.ankle_inertia = chrono.ChVectorD(0.5*self.ankle_mass*pow(self.ankle_radius,2), (self.ankle_mass/12)*(3*pow(self.ankle_radius,2)+pow(self.ankle_length,2)),(self.ankle_mass/12)*(3*pow(self.ankle_radius,2)+pow(self.ankle_length,2)))
      
      self.leg_limit = chrono.ChLinkLimit()
      self.ankle_limit = chrono.ChLinkLimit()
      self.leg_limit.SetRmax(math.pi/9)
      self.leg_limit.SetRmin(-math.pi/9)
      self.ankle_limit.SetRmax(math.pi/9)
      self.ankle_limit.SetRmin(-math.pi/9)
      
      if (self.animate) :
             self.myapplication = chronoirr.ChIrrApp(self.ant_sys)
             self.myapplication.AddShadowAll()
             self.myapplication.SetStepManage(True)
             self.myapplication.SetTimestep(self.timestep)
             self. myapplication.SetTryRealtime(True)  
             self.myapplication.AddTypicalSky()
             self.myapplication.AddTypicalLogo(chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
             self.myapplication.AddTypicalCamera(chronoirr.vector3df(0,1.5,0))
             self.myapplication.AddLightWithShadow(chronoirr.vector3df(4,4,0),    # point
                                            chronoirr.vector3df(0,0,0),    # aimpoint
                                            20,                 # radius (power)
                                            1,9,               # near, far
                                            90)                # angle of FOV
Exemplo n.º 30
0
mglyphconstraint.Set_trajectory_line(mglyph)

mysystem.Add(mglyphconstraint)


# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'PyChrono example', chronoirr.dimension2du(1024,768))

myapplication.AddTypicalSky()
myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
myapplication.AddTypicalCamera(chronoirr.vector3df(1,4,5), chronoirr.vector3df(0,2,0))
myapplication.AddTypicalLights()

            # ==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 in
			# Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll();

Exemplo n.º 31
0
def main():
    #print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n")

    #  Create the HMMWV vehicle, set parameters, and initialize
    my_hmmwv = veh.HMMWV_Full()
    my_hmmwv.SetContactMethod(contact_method)
    my_hmmwv.SetChassisFixed(False)
    my_hmmwv.SetInitPosition(
        chrono.ChCoordsysD(initLoc, chrono.ChQuaternionD(1, 0, 0, 0)))
    my_hmmwv.SetPowertrainType(powertrain_model)
    my_hmmwv.SetDriveType(drive_type)
    my_hmmwv.SetSteeringType(steering_type)
    my_hmmwv.SetTireType(tire_model)
    my_hmmwv.SetTireStepSize(tire_step_size)
    my_hmmwv.Initialize()

    my_hmmwv.SetChassisVisualizationType(chassis_vis_type)
    my_hmmwv.SetSuspensionVisualizationType(suspension_vis_type)
    my_hmmwv.SetSteeringVisualizationType(steering_vis_type)
    my_hmmwv.SetWheelVisualizationType(wheel_vis_type)
    my_hmmwv.SetTireVisualizationType(tire_vis_type)

    # Create the terrain

    terrain = veh.RigidTerrain(my_hmmwv.GetSystem())
    if (contact_method == chrono.ChContactMethod_NSC):
        patch_mat = chrono.ChMaterialSurfaceNSC()
        patch_mat.SetFriction(0.9)
        patch_mat.SetRestitution(0.01)
    elif (contact_method == chrono.ChContactMethod_SMC):
        patch_mat = chrono.ChMaterialSurfaceSMC()
        patch_mat.SetFriction(0.9)
        patch_mat.SetRestitution(0.01)
        patch_mat.SetYoungModulus(2e7)
    patch = terrain.AddPatch(patch_mat, chrono.ChVectorD(0, 0, 0),
                             chrono.ChVectorD(0, 0, 1), 300, 50)
    patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 200, 200)
    patch.SetColor(chrono.ChColor(0.8, 0.8, 0.5))
    terrain.Initialize()

    # Create the path-follower, cruise-control driver
    # Use a parameterized ISO double lane change (to left)
    path = veh.DoubleLaneChangePath(initLoc, 13.5, 4.0, 11.0, 50.0, True)
    driver = veh.ChPathFollowerDriver(my_hmmwv.GetVehicle(), path, "my_path",
                                      target_speed)
    driver.GetSteeringController().SetLookAheadDistance(5)
    driver.GetSteeringController().SetGains(0.8, 0, 0)
    driver.GetSpeedController().SetGains(0.4, 0, 0)
    driver.Initialize()

    # Create the vehicle Irrlicht interface
    app = veh.ChWheeledVehicleIrrApp(my_hmmwv.GetVehicle(), 'HMMWV',
                                     irr.dimension2du(1000, 800))
    app.SetSkyBox()
    app.AddTypicalLights(irr.vector3df(-60, -30, 100),
                         irr.vector3df(60, 30, 100), 250, 130)
    app.AddTypicalLogo(chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
    app.SetChaseCamera(chrono.ChVectorD(0.0, 0.0, 1.75), 6.0, 0.5)
    app.SetTimestep(step_size)
    app.AssetBindAll()
    app.AssetUpdateAll()

    # Visualization of controller points (sentinel & target)
    ballS = app.GetSceneManager().addSphereSceneNode(0.1)
    ballT = app.GetSceneManager().addSphereSceneNode(0.1)
    ballS.getMaterial(0).EmissiveColor = irr.SColor(0, 255, 0, 0)
    ballT.getMaterial(0).EmissiveColor = irr.SColor(0, 0, 255, 0)

    # Simulation loop
    realtime_timer = chrono.ChRealtimeStepTimer()
    while (app.GetDevice().run()):
        time = my_hmmwv.GetSystem().GetChTime()

        # End simulation
        if (time >= t_end):
            break

        # Update sentinel and target location markers for the path-follower controller.
        pS = driver.GetSteeringController().GetSentinelLocation()
        pT = driver.GetSteeringController().GetTargetLocation()
        ballS.setPosition(irr.vector3df(pS.x, pS.y, pS.z))
        ballT.setPosition(irr.vector3df(pT.x, pT.y, pT.z))

        # Draw scene
        app.BeginScene(True, True, irr.SColor(255, 140, 161, 192))
        app.DrawAll()
        app.EndScene()

        # Get driver inputs
        driver_inputs = driver.GetInputs()

        # Update modules (process inputs from other modules)
        driver.Synchronize(time)
        terrain.Synchronize(time)
        my_hmmwv.Synchronize(time, driver_inputs, terrain)
        app.Synchronize("", driver_inputs)

        # Advance simulation for one timestep for all modules
        driver.Advance(step_size)
        terrain.Advance(step_size)
        my_hmmwv.Advance(step_size)
        app.Advance(step_size)

        # Spin in place for real time to catch up
        realtime_timer.Spin(step_size)

    return 0
Exemplo n.º 32
0
my_mesh.AddAsset(mvisualizebeamC)


# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#


# Create the Irrlicht visualization (open the Irrlicht device,
# bind a simple user interface, etc. etc.)
myapplication = chronoirr.ChIrrApp(my_system, 'Test FEA: the Jeffcott rotor with IGA beams', chronoirr.dimension2du(1024,768))

myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
myapplication.AddTypicalSky()
myapplication.AddTypicalCamera(chronoirr.vector3df(0,1,4), chronoirr.vector3df(beam_L/2, 0, 0))
myapplication.AddTypicalLights()

# This is needed if you want to see things in Irrlicht 3D view.
myapplication.AssetBindAll()
myapplication.AssetUpdateAll()


# ---------------------------------------------------------------------
#
#  Run the simulation
#


my_system.SetupInitial();
Exemplo n.º 33
0
        crank_center + chrono.ChVectorD(crank_rad + rod_length, 0, 0),
        chrono.Q_ROTATE_Z_TO_X))
mysystem.Add(mjointC)

# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'PyChrono example',
                                   chronoirr.dimension2du(1024, 768))

myapplication.AddTypicalSky()
myapplication.AddTypicalLogo(chrono.GetChronoDataPath() +
                             'logo_pychrono_alpha.png')
myapplication.AddTypicalCamera(chronoirr.vector3df(1, 1, 3),
                               chronoirr.vector3df(0, 1, 0))
myapplication.AddTypicalLights()

# ==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 in
# Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll()
Exemplo n.º 34
0





# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'PyChrono example', chronoirr.dimension2du(1024,768))

myapplication.AddTypicalSky()
myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
myapplication.AddTypicalCamera(chronoirr.vector3df(0.5,1,1), chronoirr.vector3df(0,0,0))
#myapplication.AddTypicalLights()
myapplication.AddLightWithShadow(chronoirr.vector3df(3,6,2),    # point
                                 chronoirr.vector3df(0,0,0),    # aimpoint
                                 12,                 # radius (power)
                                 1,11,              # near, far
                                 55)                # angle of FOV

            # ==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 in
			# Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.AssetBindAll();

			# ==IMPORTANT!== Use this function for 'converting' into Irrlicht meshes the assets
Exemplo n.º 35
0
## 5. Prepare visualization with Irrlicht
##    Note that Irrlicht uses left-handed frames with Y up.

## Create the Irrlicht application and set-up the camera.
application = chronoirr.ChIrrApp(
    system,  ## pointer to the mechanical system
    "Slider-Crank Demo 0",  ## title of the Irrlicht window
    chronoirr.dimension2du(800, 600),  ## window dimension (width x height)
    False,  ## use full screen?
    True)  ## enable shadows?
application.AddTypicalLogo()
application.AddTypicalSky()
application.AddTypicalLights()
application.AddTypicalCamera(
    chronoirr.vector3df(2, 5, -3),  ## camera location
    chronoirr.vector3df(2, 0, 0))  ## "look at" location

## Let the Irrlicht application convert the visualization assets.
application.AssetBindAll()
application.AssetUpdateAll()
## 6. Perform the simulation.
## Specify the step-size.
application.SetTimestep(0.01)
application.SetTryRealtime(True)

while (application.GetDevice().run()):
    ## Initialize the graphical scene.
    application.BeginScene()

    ## Render all visualization objects.
Exemplo n.º 36
0
patch_mat.SetRestitution(0.01)
patch = terrain.AddPatch(patch_mat, 
                         chrono.ChVectorD(0, 0, 0), chrono.ChVectorD(0, 0, 1), 
                         600, 600)
patch.SetColor(chrono.ChColor(0.8, 0.8, 1.0))
patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 1200, 1200)
terrain.Initialize()

# -------------------------------------
# Create the vehicle Irrlicht interface
# Create the driver system
# -------------------------------------

app = veh.ChWheeledVehicleIrrApp(gator.GetVehicle(), 'Gator', irr.dimension2du(1000,800))
app.SetSkyBox()
app.AddTypicalLights(irr.vector3df(+130, +130, 150), irr.vector3df(-130, +130, 150), 120,
                     120, irr.SColorf(0.7, 0.7, 0.7, 1.0), irr.SColorf(0.7, 0.7, 0.7, 1.0))
app.AddTypicalLights(irr.vector3df(+130, -130, 150), irr.vector3df(-130, -130, 150), 120,
                     120, irr.SColorf(0.7, 0.7, 0.7, 1.0), irr.SColorf(0.7, 0.7, 0.7, 1.0))

app.SetChaseCamera(trackPoint, 6.0, 0.5)
app.SetTimestep(step_size)
app.AssetBindAll()
app.AssetUpdateAll()

# Create the interactive driver system
driver = veh.ChIrrGuiDriver(app)

# Set the time response for steering and throttle keyboard inputs.
steering_time = 1.0  # time to go from 0 to +1 (or from 0 to -1)
throttle_time = 1.0  # time to go from 0 to +1
Exemplo n.º 37
0
ujoint.Initialize(shaft_1, shaft_2,
                  chrono.ChFrameD(chrono.ChVectorD(0, 0, 0), rot))

# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem,
                                   'PyChrono example: universal joint',
                                   chronoirr.dimension2du(1024, 768))

myapplication.AddTypicalSky()
myapplication.AddTypicalLogo(
    chrono.GetChronoDataFile('logo_pychrono_alpha.png'))
myapplication.AddTypicalCamera(chronoirr.vector3df(3, 1, -1.5))
myapplication.AddTypicalLights()

# ==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 in
# Irrlicht, just use application.AssetBind(myitem) on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll()

# ---------------------------------------------------------------------
Exemplo n.º 38
0
                               chrono.Q_ROTATE_Z_TO_X)
                  )
mysystem.Add(mjointC)



# ---------------------------------------------------------------------
#
#  Create an Irrlicht application to visualize the system
#

myapplication = chronoirr.ChIrrApp(mysystem, 'PyChrono example', chronoirr.dimension2du(1024,768))

myapplication.AddTypicalSky()
myapplication.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png')
myapplication.AddTypicalCamera(chronoirr.vector3df(1,1,3), chronoirr.vector3df(0,1,0))
myapplication.AddTypicalLights()

            # ==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 in
            # Irrlicht, just use application.AssetBind(myitem); on a per-item basis.

myapplication.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!

myapplication.AssetUpdateAll();