def Advance(self, step): if self.irrlicht: if not self.app.GetDevice().run(): return -1 if self.step_number % self.render_steps == 0: self.app.BeginScene(True, True, chronoirr.SColor(255, 140, 161, 192)) self.app.DrawAll() self.app.EndScene() # Update modules (process inputs from other modules) time = self.system.GetChTime() self.vehicle.Synchronize(time) self.terrain.Synchronize(time) if self.irrlicht: self.app.Synchronize("", self.vehicle.driver.GetInputs()) if self.obstacles != None: for n in range(len(self.obstacles)): i = list(self.obstacles)[n] obstacle = self.obstacles[i] if obstacle.Update(step): self.obstacles = RandomObstacleGenerator.moveObstacle( self.track.center, self.obstacles, obstacle, i) self.boxes[n].SetPos(obstacle.p1) q = chrono.ChQuaternionD() v1 = obstacle.p2 - obstacle.p1 v2 = chrono.ChVectorD(1, 0, 0) ang = math.atan2((v1 % v2).Length(), v1 ^ v2) if chrono.ChVectorD(0, 0, 1) ^ (v1 % v2) > 0.0: ang *= -1 q.Q_from_AngZ(ang) self.boxes[n].SetRot(q) if self.opponents != None: for opponent in self.opponents: opponent.Update(time, step) # Advance simulation for one timestep for all modules self.vehicle.Advance(step) self.terrain.Advance(step) if self.irrlicht: self.app.Advance(step) self.step_number += 1 if self.pov: self.pov_exporter.ExportData() self.system.DoStepDynamics(step)
def step(self, ac): self.ac = ac.reshape((-1, )) self.steps += 1 if self.render: self.app.GetDevice().run() self.app.BeginScene(True, True, chronoirr.SColor(255, 140, 161, 192)) self.app.DrawAll() self.app.EndScene() else: self.vehicle.GetSystem().DoStepDynamics(self.timestep) # Collect output data from modules (for inter-module communication) driver_inputs = self.driver.GetInputs() # Update modules (process inputs from other modules) time = self.vehicle.GetSystem().GetChTime() self.driver.Synchronize(time) self.vehicle.Synchronize(time, driver_inputs, self.terrain) self.terrain.Synchronize(time) if self.render: self.app.Synchronize("", driver_inputs) self.driver.SetTargetThrottle(self.ac[0, ]) self.driver.SetTargetSteering(self.ac[1, ]) self.driver.SetTargetBraking(self.ac[2, ]) # self.driver.SetTargetThrottle(1) # self.driver.SetTargetSteering(0) # self.driver.SetTargetBraking(0) # Advance simulation for one timestep for all modules self.driver.Advance(self.timestep) self.vehicle.Advance(self.timestep) self.terrain.Advance(self.timestep) if self.render: self.app.Advance(self.timestep) pos = self.vehicle.GetVehiclePos() self.rew = self.calc_rew(pos) self.last_throttle = self.ac[0, ] self.last_steering = self.ac[1, ] self.last_braking = self.ac[2, ] self.obs = self.get_ob() self.is_done(pos) return self.obs, self.rew, self.isdone, self.info
def advance(self, step: float): """Advance the state of the visualization by the specified step Will update the render only if the simulation step is a multiple of render steps Args: step (double): step size to update the visualization by """ if self._first: self.bind() if self._system.step_number % self._render_steps == 0: self._app.BeginScene(True, True, irr.SColor(255, 140, 161, 192)) self._app.DrawAll() self._app.EndScene() if self._record: self._app.WriteImageToFile( f"{self._record_folder}{self._save_number}.png") self._save_number += 1 self._app.Advance(step)
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. application.DrawAll() ## Draw an XZ grid at the global origin to add in visualization. chronoirr.ChIrrTools.drawGrid( application.GetVideoDriver(), 1, 1, 20, 20, chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0), chrono.Q_from_AngX(chrono.CH_C_PI_2)), chronoirr.SColor(255, 80, 100, 100), True) ## Advance simulation by one step. application.DoStep() ## Finalize the graphical scene. application.EndScene()
steeringPID.SetGains(0.8, 0, 0) steeringPID.Reset(my_hmmwv.GetVehicle()) # Create the vehicle Irrlicht application app = veh.ChVehicleIrrApp(my_hmmwv.GetVehicle(), "Constant radius test") app.SetHUDLocation(500, 20) app.SetSkyBox() app.AddTypicalLogo() app.AddTypicalLights(chronoirr.vector3df(-150, 0, 200), chronoirr.vector3df(-150, 0, 200), 100, 100) app.AddTypicalLights(chronoirr.vector3df(150, 0, 200), chronoirr.vector3df(150, 0, 200), 100, 100) app.SetChaseCamera(chrono.ChVectorD(0.0, 0.0, 1.75), 6.0, 0.5) # Visualization of controller points (sentinel & target) ballS = app.GetSceneManager().addSphereSceneNode(0.1) ballT = app.GetSceneManager().addSphereSceneNode(0.1) ballS.getMaterial(0).EmissiveColor = chronoirr.SColor(0, 255, 0, 0) ballT.getMaterial(0).EmissiveColor = chronoirr.SColor(0, 0, 255, 0) # Finalize construction of visualization assets app.AssetBindAll() app.AssetUpdateAll() # --------------- # Simulation loop # --------------- steeringPID_output = 0 while (app.GetDevice().run()) : time = my_hmmwv.GetSystem().GetChTime()
def main(): #print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n") # Create the M113 vehicle # ------------------------ vehicle = veh.M113_Vehicle(False, veh.TrackShoeType_SINGLE_PIN, veh.BrakeType_SIMPLE, chrono.ChContactMethod_SMC, veh.CollisionType_NONE) vehicle.Initialize(chrono.ChCoordsysD(initLoc, initRot)) vehicle.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES) vehicle.SetSprocketVisualizationType(veh.VisualizationType_MESH) vehicle.SetIdlerVisualizationType(veh.VisualizationType_MESH) vehicle.SetRoadWheelAssemblyVisualizationType(veh.VisualizationType_MESH) vehicle.SetRoadWheelVisualizationType(veh.VisualizationType_MESH) vehicle.SetTrackShoeVisualizationType(veh.VisualizationType_MESH) # Create the powertrain system # ---------------------------- powertrain = veh.M113_SimpleCVTPowertrain("Powertrain") vehicle.InitializePowertrain(powertrain) # Create the terrain # ------------------ terrain = veh.RigidTerrain(vehicle.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), terrainLength, terrainWidth) patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 200, 200) patch.SetColor(chrono.ChColor(0.5, 0.8, 0.5)) terrain.Initialize() # Create the vehicle Irrlicht interface # ------------------------------------- app = veh.ChTrackedVehicleIrrApp(vehicle, 'M113', 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() # Create the interactive driver system # ------------------------------------ driver = veh.ChIrrGuiDriver(app) # Set the time response for steering and throttle keyboard inputs. steering_time = 0.5 # 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 # --------------- # Inter-module communication data shoe_forces_left = veh.TerrainForces(vehicle.GetNumTrackShoes(veh.LEFT)) shoe_forces_right = veh.TerrainForces(vehicle.GetNumTrackShoes(veh.RIGHT)) # Number of simulation steps between miscellaneous events render_steps = m.ceil(render_step_size / step_size) # Initialize simulation frame counter and simulation time step_number = 0 realtime_timer = chrono.ChRealtimeStepTimer() while (app.GetDevice().run()): time = vehicle.GetSystem().GetChTime() 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) vehicle.Synchronize(time, driver_inputs, shoe_forces_left, shoe_forces_right) app.Synchronize("", driver_inputs) # Advance simulation for one timestep for all modules driver.Advance(step_size) terrain.Advance(step_size) vehicle.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
def main(): # print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n") # --------- # Load path # --------- path_file = "../data/paths/loop2.txt" path = np.genfromtxt(path_file, delimiter=",") ds = 5 # [m] distance of each intepolated points sp = Spline2D(path[:, 0], path[:, 1]) s = np.arange(0, sp.s[-1], ds) px, py = [], [] for i_s in s: ix, iy = sp.calc_position(i_s) px.append(ix) py.append(iy) px.append(px[0]) py.append(py[0]) initLoc = chrono.ChVectorD(px[0], py[0], 0.5) # -------------------------- # 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.SetStepsize(step_size) 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) # ------------- # Create driver # ------------- driver = Driver(vehicle) # Set the time response for steering and throttle 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) # ------------------ # Draw path # ------------------ if irrlicht: road = vehicle.GetSystem().NewBody() road.SetBodyFixed(True) vehicle.GetSystem().AddBody(road) num_points = len(px) lines = chrono.ChLinePath() for i in range(num_points - 1): lines.AddSubLine( chrono.ChLineSegment( chrono.ChVectorD(px[i], py[i], 0.1), chrono.ChVectorD(px[i + 1], py[i + 1], 0.1))) path_asset = chrono.ChLineShape() path_asset.SetLineGeometry(lines) path_asset.SetColor(chrono.ChColor(0.0, 0.8, 0.0)) path_asset.SetNumRenderPoints(max(2 * num_points, 400)) road.AddAsset(path_asset) # -------------------- # Create controller(s) # -------------------- controller = MPCController(vehicle, driver, path) # ----------------------- # Initialize irrlicht app # ----------------------- if irrlicht: app = veh.ChVehicleIrrApp(vehicle) app.SetHUDLocation(500, 20) app.SetSkyBox() app.AddTypicalLogo() app.AddTypicalLights( chronoirr.vector3df(-150.0, -150.0, 200.0), chronoirr.vector3df(-150.0, 150.0, 200.0), 100, 100, ) app.AddTypicalLights( chronoirr.vector3df(150.0, -150.0, 200.0), chronoirr.vector3df(150.0, 150.0, 200.0), 100, 100, ) app.EnableGrid(False) app.SetChaseCamera(trackPoint, 6.0, 0.5) app.SetTimestep(step_size) app.AssetBindAll() app.AssetUpdateAll() # ----------------- # Initialize output # ----------------- if 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 # --------------- # Number of simulation steps between miscellaneous events render_steps = int(math.ceil(render_step_size / step_size)) # Initialize simulation frame counter and simulation time step_number = 0 time = 0 if irrlicht: while app.GetDevice().run(): # Render scene if step_number % render_steps == 0: 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_inputs) # Advance simulation for one timestep for all modules step = step_size # Update controllers controller.Advance(step) driver.Advance(step) vehicle.Advance(step) terrain.Advance(step) app.Advance(step) # Increment frame number step_number += 1 else: while True: # 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) # Advance simulation for one timestep for all modules step = step_size # Update controllers steering_controller.Advance(step) throttle_controller.Advance(step) driver.Advance(step) vehicle.Advance(step) terrain.Advance(step) vis.Advance(step) # Increment frame number step_number += 1
mphysicalSystem.AddLink(link_pulleyDE) # Complete construction of Irrlicht assets application.AssetBindAll() application.AssetUpdateAll() # Set intergator type mphysicalSystem.SetTimestepperType( chrono.ChTimestepper.Type_EULER_IMPLICIT_PROJECTED) # Simulation loop application.SetTimestep(0.001) application.SetTryRealtime(True) while (application.GetDevice().run()): application.BeginScene(True, True, chronoirr.SColor(255, 140, 161, 192)) application.DrawAll() # Draw some segments for a simplified representation of pulley chronoirr.ChIrrTools.drawSegment(application.GetVideoDriver(), link_pulleyDE.Get_belt_up1(), link_pulleyDE.Get_belt_up2(), chronoirr.SColor(255, 0, 255, 0), True) chronoirr.ChIrrTools.drawSegment(application.GetVideoDriver(), link_pulleyDE.Get_belt_low1(), link_pulleyDE.Get_belt_low2(), chronoirr.SColor(255, 0, 255, 0), True) # Advance simulation for one step application.DoStep()
def main(): print("Copyright (c) 2017 projectchrono.org" + "\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()) 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), 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_hmmwv.GetVehicle(), 'HMMWV', 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() # 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(irr.eCh_ContactsDrawMode::CONTACT_FORCES); # --------------------------------------------- # Create a sensor manager and add a point light # --------------------------------------------- manager = sens.ChSensorManager(my_hmmwv.GetSystem()) manager.scene.AddPointLight(chrono.ChVectorF(0, 0, 100), chrono.ChVectorF(2, 2, 2), 5000) manager.SetKeyframeSizeFromTimeStep(.001, 1 / 5) # ------------------------------------------------ # Create a camera and add it to the sensor manager # ------------------------------------------------ fov = 1.408 lag = 0 update_rate = 5 exposure_time = 1 / update_rate offset_pose = chrono.ChFrameD(chrono.ChVectorD(-5, 0, 2)) cam = sens.ChCameraSensor( my_hmmwv.GetChassisBody(), # body camera is attached to update_rate, # update rate in Hz offset_pose, # offset pose image_width, # image width image_height, # image height fov # camera's horizontal field of view ) cam.SetName("Camera Sensor") # cam.SetLag(0); # cam.SetCollectionWindow(0); # Visualizes the image if vis: cam.PushFilter( sens.ChFilterVisualize(image_width, image_height, "HMMWV Camera")) # Save the current image to a png file at the specified path if save: cam.PushFilter(sens.ChFilterSave(out_dir + "cam/")) # Add a camera to a sensor manager manager.AddSensor(cam) # ---------------------------------------------- # Create an IMU sensor and add it to the manager # ---------------------------------------------- offset_pose = chrono.ChFrameD( chrono.ChVectorD(-8, 0, 1), chrono.Q_from_AngAxis(0, chrono.ChVectorD(0, 1, 0))) imu = sens.ChIMUSensor( my_hmmwv.GetChassisBody(), # body imu is attached to imu_update_rate, # update rate in Hz offset_pose, # offset pose imu_noise_none # noise model ) imu.SetName("IMU Sensor") imu.SetLag(imu_lag) imu.SetCollectionWindow(imu_collection_time) # Provides the host access to the imu data imu.PushFilter(sens.ChFilterIMUAccess()) # Add the imu to the sensor manager manager.AddSensor(imu) # ---------------------------------------------- # Create an GPS sensor and add it to the manager # ---------------------------------------------- offset_pose = chrono.ChFrameD( chrono.ChVectorD(-8, 0, 1), chrono.Q_from_AngAxis(0, chrono.ChVectorD(0, 1, 0))) gps = sens.ChGPSSensor( my_hmmwv.GetChassisBody(), # body imu is attached to gps_update_rate, # update rate in Hz offset_pose, # offset pose gps_reference, gps_noise_none # noise model ) gps.SetName("GPS Sensor") gps.SetLag(gps_lag) gps.SetCollectionWindow(gps_collection_time) # Provides the host access to the gps data gps.PushFilter(sens.ChFilterGPSAccess()) # Add the gps to the sensor manager manager.AddSensor(gps) realtime_timer = chrono.ChRealtimeStepTimer() while (app.GetDevice().run()): time = my_hmmwv.GetSystem().GetChTime() #End simulation if (time >= t_end): break if (step_number % render_steps == 0): app.BeginScene(True, True, irr.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) # Update sensor manager # Will render/save/filter automatically manager.Update() # Increment frame number step_number += 1 # Spin in place for real time to catch up realtime_timer.Spin(step_size) return 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)
def main(): #print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n") step_size = 0.005 sys = chrono.ChSystemNSC() sys.Set_G_acc(chrono.ChVectorD(0, 0, -9.81)) sys.SetSolverType(chrono.ChSolver.Type_BARZILAIBORWEIN) sys.SetSolverMaxIterations(150) sys.SetMaxPenetrationRecoverySpeed(4.0) # Create the terrain terrain = veh.RigidTerrain(sys) patch_mat = chrono.ChMaterialSurfaceNSC() patch_mat.SetFriction(0.9) patch_mat.SetRestitution(0.01) patch = terrain.AddPatch(patch_mat, chrono.ChVectorD(0, 0, 0), chrono.ChVectorD(0, 0, 1), 200, 100) patch.SetColor(chrono.ChColor(0.8, 0.8, 0.5)) patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 200, 200) terrain.Initialize() # Create and initialize the first vehicle hmmwv_1 = veh.HMMWV_Reduced(sys) hmmwv_1.SetInitPosition( chrono.ChCoordsysD(chrono.ChVectorD(0, -1.5, 1.0), chrono.ChQuaternionD(1, 0, 0, 0))) hmmwv_1.SetPowertrainType(veh.PowertrainModelType_SIMPLE) hmmwv_1.SetDriveType(veh.DrivelineType_RWD) hmmwv_1.SetTireType(veh.TireModelType_RIGID) hmmwv_1.Initialize() hmmwv_1.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES) hmmwv_1.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES) hmmwv_1.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES) hmmwv_1.SetWheelVisualizationType(veh.VisualizationType_NONE) hmmwv_1.SetTireVisualizationType(veh.VisualizationType_PRIMITIVES) driver_data_1 = veh.vector_Entry([ veh.DataDriverEntry(0.0, 0.0, 0.0, 0.0), veh.DataDriverEntry(0.5, 0.0, 0.0, 0.0), veh.DataDriverEntry(0.7, 0.3, 0.7, 0.0), veh.DataDriverEntry(1.0, 0.3, 0.7, 0.0), veh.DataDriverEntry(3.0, 0.5, 0.1, 0.0) ]) driver_1 = veh.ChDataDriver(hmmwv_1.GetVehicle(), driver_data_1) driver_1.Initialize() # Create and initialize the second vehicle hmmwv_2 = veh.HMMWV_Reduced(sys) hmmwv_2.SetInitPosition( chrono.ChCoordsysD(chrono.ChVectorD(7, 1.5, 1.0), chrono.ChQuaternionD(1, 0, 0, 0))) hmmwv_2.SetPowertrainType(veh.PowertrainModelType_SIMPLE) hmmwv_2.SetDriveType(veh.DrivelineType_RWD) hmmwv_2.SetTireType(veh.TireModelType_RIGID) hmmwv_2.Initialize() hmmwv_2.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES) hmmwv_2.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES) hmmwv_2.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES) hmmwv_2.SetWheelVisualizationType(veh.VisualizationType_NONE) hmmwv_2.SetTireVisualizationType(veh.VisualizationType_PRIMITIVES) driver_data_2 = veh.vector_Entry([ veh.DataDriverEntry(0.0, 0.0, 0.0, 0.0), veh.DataDriverEntry(0.5, 0.0, 0.0, 0.0), veh.DataDriverEntry(0.7, -0.3, 0.7, 0.0), veh.DataDriverEntry(1.0, -0.3, 0.7, 0.0), veh.DataDriverEntry(3.0, -0.5, 0.1, 0.0) ]) driver_2 = veh.ChDataDriver(hmmwv_2.GetVehicle(), driver_data_2) driver_2.Initialize() # Create the vehicle Irrlicht interface app = veh.ChWheeledVehicleIrrApp(hmmwv_1.GetVehicle(), 'Two Car Demo', 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(chrono.ChVectorD(0.0, 0.0, 0.75), 6.0, 0.5) app.SetChaseCameraState(veh.ChChaseCamera.Track) app.SetChaseCameraPosition(chrono.ChVectorD(-15, 0, 2.0)) app.SetTimestep(step_size) app.AssetBindAll() app.AssetUpdateAll() # Simulation loop realtime_timer = chrono.ChRealtimeStepTimer() while (app.GetDevice().run()): time = hmmwv_1.GetSystem().GetChTime() app.BeginScene(True, True, irr.SColor(255, 140, 161, 192)) app.DrawAll() app.EndScene() # Get driver inputs driver_inputs_1 = driver_1.GetInputs() driver_inputs_2 = driver_2.GetInputs() # Update modules (process inputs from other modules) driver_1.Synchronize(time) driver_2.Synchronize(time) hmmwv_1.Synchronize(time, driver_inputs_1, terrain) hmmwv_2.Synchronize(time, driver_inputs_2, terrain) terrain.Synchronize(time) app.Synchronize("", driver_inputs_1) # Advance simulation for one timestep for all modules driver_1.Advance(step_size) driver_2.Advance(step_size) hmmwv_1.Advance(step_size) hmmwv_2.Advance(step_size) terrain.Advance(step_size) app.Advance(step_size) # Advance state of entire system (containing both vehicles) sys.DoStepDynamics(step_size) # Spin in place for real time to catch up realtime_timer.Spin(step_size) return 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(chrono.ChContactMethod_SMC) my_hmmwv.SetInitPosition( chrono.ChCoordsysD(chrono.ChVectorD(-5, -2, 0.6), chrono.ChQuaternionD(1, 0, 0, 0))) my_hmmwv.SetPowertrainType(veh.PowertrainModelType_SHAFTS) my_hmmwv.SetDriveType(veh.DrivelineType_AWD) my_hmmwv.SetTireType(veh.TireModelType_RIGID) my_hmmwv.Initialize() my_hmmwv.SetChassisVisualizationType(veh.VisualizationType_NONE) my_hmmwv.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES) my_hmmwv.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES) my_hmmwv.SetWheelVisualizationType(veh.VisualizationType_NONE) my_hmmwv.SetTireVisualizationType(veh.VisualizationType_MESH) # Create the (custom) driver driver = MyDriver(my_hmmwv.GetVehicle(), 0.5) driver.Initialize() # Create the SCM deformable terrain patch terrain = veh.SCMDeformableTerrain(my_hmmwv.GetSystem()) terrain.SetSoilParameters( 2e6, # Bekker Kphi 0, # Bekker Kc 1.1, # Bekker n exponent 0, # Mohr cohesive limit (Pa) 30, # Mohr friction limit (degrees) 0.01, # Janosi shear coefficient (m) 2e8, # Elastic stiffness (Pa/m), before plastic yield 3e4 # Damping (Pa s/m), proportional to negative vertical speed (optional) ) # Optionally, enable moving patch feature (single patch around vehicle chassis) terrain.AddMovingPatch(my_hmmwv.GetChassisBody(), chrono.ChVectorD(0, 0, 0), chrono.ChVectorD(5, 3, 1)) # Set plot type for SCM (false color plotting) terrain.SetPlotType(veh.SCMDeformableTerrain.PLOT_SINKAGE, 0, 0.1) # Initialize the SCM terrain, specifying the initial mesh grid terrain.Initialize(terrainLength, terrainWidth, delta) # Create the vehicle Irrlicht interface app = veh.ChWheeledVehicleIrrApp(my_hmmwv.GetVehicle(), 'HMMWV Deformable Soil Demo', 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(chrono.ChVectorD(0.0, 0.0, 1.75), 6.0, 0.5) app.SetTimestep(step_size) app.AssetBindAll() app.AssetUpdateAll() # Simulation loop while (app.GetDevice().run()): time = my_hmmwv.GetSystem().GetChTime() # End simulation if (time >= 4): break # 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) return 0
def main(): # 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.SetVehicleStepSize(step_size) my_hmmwv.Initialize() #VisualizationType tire_vis_type = # (tire_model == TireModelType::RIGID_MESH) ? VisualizationType::MESH : VisualizationType::NONE; tire_vis_type = veh.VisualizationType_MESH # if tire_model == veh.TireModelType_RIGID_MESH else tire_vis_type = veh.VisualizationType_NONE 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 = veh.Patch() """ switch (terrain_model) { case RigidTerrain::BOX: patch = terrain.AddPatch(ChCoordsys<>(ChVector<>(0, 0, terrainHeight - 5), QUNIT), ChVector<>(terrainLength, terrainWidth, 10)); patch->SetTexture(vehicle::GetDataFile("terrain/textures/tile4.jpg"), 200, 200); break; case RigidTerrain::HEIGHT_MAP: patch = terrain.AddPatch(CSYSNORM, vehicle::GetDataFile("terrain/height_maps/test64.bmp"), "test64", 128, 128, 0, 4); patch->SetTexture(vehicle::GetDataFile("terrain/textures/grass.jpg"), 16, 16); break; case RigidTerrain::MESH: patch = terrain.AddPatch(CSYSNORM, vehicle::GetDataFile("terrain/meshes/test.obj"), "test_mesh"); patch->SetTexture(vehicle::GetDataFile("terrain/textures/grass.jpg"), 100, 100); break; } """ 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.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(), my_hmmwv.GetPowertrain()) #, "HMMWV Demo") app.SetSkyBox() app.AddTypicalLights(chronoirr.vector3df(30, -30, 100), chronoirr.vector3df(30, 50, 100), 250, 130) 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 ") if (povray_output): try: os.mkdir(pov_dir) except: print("Error creating POV directory ") terrain.ExportMeshPovray(out_dir) # Initialize output file for driver inputs #driver_file = out_dir + "/driver_inputs.txt" # no RECORD so far #utils::CSV_writer driver_csv(" "); # 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 driver system # 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) # If in playback mode, attach the data file to the driver system and # force it to playback the driver inputs. if (driver_mode == "PLAYBACK"): #driver.SetInputDataFile(driver_file) driver.SetInputMode(veh.ChIrrGuiDriver.DATAFILE) driver.Initialize() # Simulation loop """ if (debug_output) : GetLog() << "\n\n============ System Configuration ============\n" my_hmmwv.LogHardpointLocations()""" # 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 realtime_timer = chrono.ChRealtimeStepTimer() step_number = 0 render_frame = 0 time = 0 if (contact_vis): app.SetSymbolscale(1e-4) #app.SetContactsDrawMode(chronoirr.eCh_ContactsDrawMode::CONTACT_FORCES); 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.AddTypicalLogo(chrono.GetChronoDataPath() + 'logo_pychrono_alpha.png') # Output POV-Ray data if (povray_output and step_number % render_steps == 0): #char filename[100]; print('filename', "%s/data_%03d.dat", pov_dir.c_str(), render_frame + 1) #utils::WriteShapesPovray(my_hmmwv.GetSystem(), filename); #render_frame++; #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) # Collect output data from modules (for inter-module communication) throttle_input = driver.GetThrottle() steering_input = driver.GetSteering() braking_input = driver.GetBraking() # Driver output """ if (driver_mode == RECORD) { driver_csv << time << steering_input << throttle_input << braking_input << std::endl; }""" # Update modules (process inputs from other modules) driver.Synchronize(time) terrain.Synchronize(time) my_hmmwv.Synchronize(time, steering_input, braking_input, throttle_input, terrain) app.Synchronize(driver.GetInputModeAsString(), steering_input, throttle_input, braking_input) # Advance simulation for one timestep for all modules step = realtime_timer.SuggestSimulationStep(step_size) driver.Advance(step) terrain.Advance(step) my_hmmwv.Advance(step) app.Advance(step) # Increment frame number step_number += 1 app.EndScene() """ if (driver_mode == RECORD) { driver_csv.write_to_file(driver_file); }""" return 0
def main(): #print("Copyright (c) 2017 projectchrono.org\nChrono version: ", CHRONO_VERSION , "\n\n") # Create systems # Create the FEDA vehicle, set parameters, and initialize my_feda = veh.FEDA() my_feda.SetContactMethod(contact_method) my_feda.SetChassisCollisionType(chassis_collision_type) my_feda.SetChassisFixed(False) my_feda.SetInitPosition(chrono.ChCoordsysD(initLoc, initRot)) my_feda.SetPowertrainType(powertrain_model) my_feda.SetTireType(tire_model) my_feda.SetTireStepSize(tire_step_size) my_feda.Initialize() my_feda.SetChassisVisualizationType(chassis_vis_type) my_feda.SetSuspensionVisualizationType(suspension_vis_type) my_feda.SetSteeringVisualizationType(steering_vis_type) my_feda.SetWheelVisualizationType(wheel_vis_type) my_feda.SetTireVisualizationType(tire_vis_type) # Create the terrain terrain = veh.RigidTerrain(my_feda.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), 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_feda.GetVehicle(), 'HMMWV', 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() # 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(10 * step_size / steering_time) driver.SetThrottleDelta(10 * step_size / throttle_time) driver.SetBrakingDelta(10 * step_size / braking_time) driver.Initialize() # Simulation loop realtime_timer = chrono.ChRealtimeStepTimer() while (app.GetDevice().run()): time = my_feda.GetSystem().GetChTime() 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_feda.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_feda.Advance(step_size) app.Advance(step_size) # Spin in place for real time to catch up realtime_timer.Spin(step_size) return 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.SetStepsize(step_size) 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) # ------------- # Create driver # ------------- driver = Driver(vehicle) # Set the time response for steering and throttle 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) # ------------------ # Load and draw path # ------------------ # path_file = 'paths/straight.txt' # path_file = 'paths/curve.txt' path_file = 'paths/NATO_double_lane_change.txt' # path_file = 'paths/ISO_double_lane_change.txt' path = chrono.ChBezierCurve.read(veh.GetDataFile(path_file)) if irrlicht: road = vehicle.GetSystem().NewBody() road.SetBodyFixed(True) vehicle.GetSystem().AddBody(road) num_points = path.getNumPoints() path_asset = chrono.ChLineShape() path_asset.SetLineGeometry(chrono.ChLineBezier(path)) path_asset.SetColor(chrono.ChColor(0.0, 0.8, 0.0)) path_asset.SetNumRenderPoints(max(2 * num_points, 400)) road.AddAsset(path_asset) # -------------------- # Create controller(s) # -------------------- steering_controller = PIDSteeringController(vehicle, driver, path) steering_controller.SetGains(Kp=0.4, Ki=0, Kd=0.25) steering_controller.SetLookAheadDistance(dist=5.0) throttle_controller = PIDThrottleController(vehicle, driver) throttle_controller.SetGains(Kp=0.4, Ki=0, Kd=0) throttle_controller.SetTargetSpeed(target_speed) # ----------------------- # Initialize irrlicht app # ----------------------- if irrlicht: app = veh.ChVehicleIrrApp(vehicle) app.SetHUDLocation(500, 20) app.SetSkyBox() app.AddTypicalLogo() app.AddTypicalLights(chronoirr.vector3df(-150., -150., 200.), chronoirr.vector3df(-150., 150., 200.), 100, 100) app.AddTypicalLights(chronoirr.vector3df(150., -150., 200.), chronoirr.vector3df(150., 150., 200.), 100, 100) app.EnableGrid(False) app.SetChaseCamera(trackPoint, 6.0, 0.5) app.SetTimestep(step_size) app.AssetBindAll() app.AssetUpdateAll() # ----------------- # Initialize output # ----------------- if 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 # --------------- # Number of simulation steps between miscellaneous events render_steps = int(math.ceil(render_step_size / step_size)) # Initialize simulation frame counter and simulation time step_number = 0 time = 0 if irrlicht: while (app.GetDevice().run()): # Render scene if step_number % render_steps == 0: 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_inputs) # Advance simulation for one timestep for all modules step = step_size # Update controllers steering_controller.Advance(step) throttle_controller.Advance(step) driver.Advance(step) vehicle.Advance(step) terrain.Advance(step) app.Advance(step) # Increment frame number step_number += 1 else: while (True): vehicle.GetSystem().DoStepDynamics(step_size) # 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) # Advance simulation for one timestep for all modules step = step_size # Update controllers steering_controller.Advance(step) throttle_controller.Advance(step) driver.Advance(step) vehicle.Advance(step) terrain.Advance(step) # Increment frame number step_number += 1
def main(): # ---------------------- # Set path to data files # ---------------------- # Path to Chrono data files (textures, etc.) chrono.SetChronoDataPath(CHRONO_DATA_DIR) # Path to the data files for this vehicle (JSON specification files) veh.SetDataPath("./data/") # -------------------------- # Create the various modules # -------------------------- # Create and initialize the vehicle system vehicle = veh.WheeledVehicle(veh.GetDataFile(vehicle_file), NSC_SMC) vehicle.Initialize(chrono.ChCoordsysD(initLoc, initRot)) vehicle.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES) vehicle.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES) vehicle.SetWheelVisualizationType(veh.VisualizationType_NONE) # Create the terrain terrain = veh.RigidTerrain(vehicle.GetSystem(), veh.GetDataFile(rigidterrain_file)) AddFixedObstacles(vehicle.GetSystem()) AddMovingObstacles(vehicle.GetSystem()) # Create and initialize the powertrain system powertrain = veh.SimplePowertrain(veh.GetDataFile(simplepowertrain_file)) vehicle.InitializePowertrain(powertrain) # Create and initialize the tires for axle in vehicle.GetAxles(): tireL = veh.RigidTire(veh.GetDataFile(rigidtire_file)) tireR = veh.RigidTire(veh.GetDataFile(rigidtire_file)) vehicle.InitializeTire(tireL, axle.m_wheels[0], veh.VisualizationType_MESH) vehicle.InitializeTire(tireR, axle.m_wheels[1], veh.VisualizationType_MESH) # Create the Irrlicht vehicle application app = veh.ChVehicleIrrApp(vehicle, "Vehicle Demo") app.SetSkyBox() app.AddTypicalLights(chronoirr.vector3df(30, -30, 100), chronoirr.vector3df(30, 50, 100), 250, 130) app.SetChaseCamera(trackPoint, 6.0, 0.5) app.SetTimestep(step_size) app.AssetBindAll() app.AssetUpdateAll() # Create the driver system (interactive) 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) # ----------------- # Initialize output # ----------------- try: os.mkdir(out_dir) except: print("Error creating directory ") if (povray_output): try: os.mkdir(pov_dir) except: print("Error creating POV directory ") terrain.ExportMeshPovray(out_dir) # --------------- # Simulation loop # --------------- """driveshaft_speed powertrain_torque throttle_input steering_input braking_input""" # Number of simulation steps between two 3D view render frames render_steps = m.ceil(render_step_size / step_size) #Initialize simulation frame counter and simulation time step_number = 0 frame_number = 0 time = 0 realtime_timer = chrono.ChRealtimeStepTimer() while (app.GetDevice().run()): # Render scene if (step_number % render_steps == 0): app.BeginScene(True, True, chronoirr.SColor(255, 140, 161, 192)) app.DrawAll() app.EndScene() #char filename[100]; #sprintf(filename, "%s/data_%03d.dat", pov_dir.c_str(), frame_number + 1); #utils::WriteShapesPovray(vehicle.GetSystem(), filename); frame_number += 1 # Get driver inputs 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) # Increment frame number step_number += 1 # Spin in place for real time to catch up realtime_timer.Spin(step_size) return 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.SetStepsize(step_size) 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) powertrain.Initialize(vehicle.GetChassisBody(), vehicle.GetDriveshaft()) #// Create and initialize the tires num_axles = vehicle.GetNumberAxles() num_wheels = 2 * num_axles tires = [ veh.RigidTire(rigidtire_file) for i in range(num_wheels)] for i, t in enumerate(tires): #t = std::make_shared<vehicle::RigidTire>(vehicle::GetDataFile(rigidtire_file)); s = [veh.LEFT, veh.RIGHT] t.Initialize(vehicle.GetWheelBody(veh.WheelID(i)), s[i % 2]) t.SetVisualizationType(veh.VisualizationType_MESH) app = veh.ChVehicleIrrApp (vehicle, powertrain) app.SetSkyBox() app.AddTypicalLights(chronoirr.vector3df(30, -30, 100), chronoirr.vector3df(30, 50, 100), 250, 130) app.SetChaseCamera(trackPoint, 6.0, 0.5) app.SetTimestep(step_size) app.AssetBindAll() app.AssetUpdateAll() """ bool do_shadows = false; // shadow map is experimental irr::scene::ILightSceneNode* mlight = 0; if (do_shadows) { mlight = application.AddLightWithShadow( irr::core::vector3df(10.f, 30.f, 60.f), irr::core::vector3df(0.f, 0.f, 0.f), 150, 60, 80, 15, 512, irr::video::SColorf(1, 1, 1), false, false); } else { application.AddTypicalLights( irr::core::vector3df(30.f, -30.f, 100.f), irr::core::vector3df(30.f, 50.f, 100.f), 250, 130); } if (do_shadows) application.AddShadowAll(); """ 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) # Set file with driver input time series driver.SetInputDataFile(driver_file) """ #else ChDataDriver driver(vehicle, vehicle::GetDataFile(driver_file)); #endif """ driver.Initialize() # ----------------- # Initialize output # ----------------- try: os.mkdir(out_dir) except: print("Error creating directory " ) """if (povray_output): try: os.mkdir(pov_dir) except: print("Error creating POV directory ") terrain.ExportMeshPovray(out_dir)""" # Generate JSON information with available output channels out_json = vehicle.ExportComponentList() print(out_json) vehicle.ExportComponentList(out_dir + "/component_list.json") # --------------- # Simulation loop # --------------- # Inter-module communication data tire_forces = veh.TerrainForces(num_wheels) wheel_states = veh.WheelStates(num_wheels) # Initialize simulation frame counter and simulation time step_number = 0 time = 0 #ifdef USE_IRRLICHT realtime_timer = chrono.ChRealtimeStepTimer() while (app.GetDevice().run()) : # Render scene app.BeginScene(True, True, chronoirr.SColor(255, 140, 161, 192)) app.DrawAll() # Collect output data from modules (for inter-module communication) throttle_input = driver.GetThrottle() steering_input = driver.GetSteering() braking_input = driver.GetBraking() powertrain_torque = powertrain.GetOutputTorque() driveshaft_speed = vehicle.GetDriveshaftSpeed() for i in range (num_wheels) : tire_forces[i] = tires[i].GetTireForce() wheel_states[i] = vehicle.GetWheelState(veh.WheelID(i)) # Update modules (process inputs from other modules) time = vehicle.GetSystem().GetChTime() driver.Synchronize(time) powertrain.Synchronize(time, throttle_input, driveshaft_speed) vehicle.Synchronize(time, steering_input, braking_input, powertrain_torque, tire_forces) terrain.Synchronize(time) for i in range (num_wheels): tires[i].Synchronize(time, wheel_states[i], terrain) app.Synchronize(driver.GetInputModeAsString(), steering_input, throttle_input, braking_input) # Advance simulation for one timestep for all modules step = realtime_timer.SuggestSimulationStep(step_size) driver.Advance(step) powertrain.Advance(step) vehicle.Advance(step) terrain.Advance(step) for i in range(num_wheels) : tires[i].Advance(step) app.Advance(step) # Increment frame number step_number += 1 app.EndScene()
# Initialize simulation frame counter s realtime_timer = chrono.ChRealtimeStepTimer() step_number = 0 render_frame = 0 while (app.GetDevice().run()): time = my_bus.GetSystem().GetChTime() # End simulation if (time >= t_end): break # Render scene and output POV-Ray data if (step_number % render_steps == 0): app.BeginScene(True, True, irr.SColor(255, 140, 161, 192)) app.DrawAll() app.EndScene() render_frame += 1 # Get driver inputs driver_inputs = driver.GetInputs() # Update modules (process inputs from other modules) driver.Synchronize(time) terrain.Synchronize(time) my_bus.Synchronize(time, driver_inputs, terrain) app.Synchronize(driver.GetInputModeAsString(), driver_inputs) # Advance simulation for one timestep for all modules driver.Advance(step_size)
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)
## 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. application.DrawAll() ## Render the distance constraint. chronoirr.ChIrrTools.drawSegment(application.GetVideoDriver(), dist_crank_slider.GetEndPoint1Abs(), dist_crank_slider.GetEndPoint2Abs(), chronoirr.SColor(255, 200, 20, 0), True) ## Draw an XZ grid at the global origin to add in visualization. chronoirr.ChIrrTools.drawGrid( application.GetVideoDriver(), 1, 1, 20, 20, chrono.ChCoordsysD(chrono.ChVectorD(0, 0, 0), chrono.Q_from_AngX(chrono.CH_C_PI_2)), chronoirr.SColor(255, 80, 100, 100), True) ## Advance simulation by one step. application.DoStep() ## Finalize the graphical scene. application.EndScene()
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
rev.GetLimit_Rz().SetMin(min_angle) rev.GetLimit_Rz().SetMax(max_angle) # Initialize the joint specifying a coordinate system (expressed in the absolute frame). rev.Initialize(ground, pend, chrono.ChCoordsysD(chrono.VNULL, chrono.QUNIT)) # Create the Irrlicht application application = irr.ChIrrApp(system, "Limits on LinkLockRevolute demo", irr.dimension2du(800, 600), False, True) application.AddTypicalLogo() application.AddTypicalSky() application.AddTypicalLights() application.AddTypicalCamera(irr.vector3df(-2, 1.5, 5)) application.AssetBindAll() application.AssetUpdateAll() # Points for drawing line segments p0 = chrono.ChVectorD(0, 0, 0) p1 = chrono.ChVectorD(m.cos(min_angle), -m.sin(min_angle), 0) p2 = chrono.ChVectorD(m.cos(max_angle), -m.sin(max_angle), 0) # Simulation loop application.SetTimestep(0.01) application.SetTryRealtime(True) while (application.GetDevice().run()) : application.BeginScene() application.DrawAll() irr.ChIrrTools.drawSegment(application.GetVideoDriver(), p0, p0 + p1 * 4, irr.SColor(255, 255, 150, 0), True); irr.ChIrrTools.drawSegment(application.GetVideoDriver(), p0, p0 + p2 * 4, irr.SColor(255, 255, 150, 0), True); application.DoStep() application.EndScene()
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
application.SetTimestep(0.001) application.SetVideoframeSaveInterval(10) # Use the following for less numerical damping, 2nd order accuracy (but slower) ts = chrono.ChTimestepperHHT(my_system) ts.SetStepControl(False) my_system.SetTimestepper(ts) # Output data if not os.path.isdir(out_dir): print("Error creating directory ") filename = out_dir + "/buckling_mid.dat" #file_out1 = chrono.ChStreamOutAsciiFile(filename) while (application.GetDevice().run()): application.BeginScene() application.DrawAll() chronoirr.ChIrrTools.drawGrid( application.GetVideoDriver(), 0.05, 0.05, 20, 20, chrono.ChCoordsysD(chrono.VNULL, chrono.CH_C_PI_2, chrono.VECT_Z), chronoirr.SColor(50, 90, 90, 90), True) application.DoStep() # Save output for the first 0.4 seconds #if (application.GetSystem().GetChTime() <= 0.4): #file_out1(application.GetSystem().GetChTime() + " " + node_mid.GetPos().z() + " " + node_mid.GetWvel_par().x() + "\n") application.EndScene()