Exemple #1
0
    def __init__(self, render):
        self.render = render

        self.observation_space = np.empty([9, 1])
        self.action_space = np.empty([
            3,
        ])
        self.info = {}
        self.timestep = 0.01
        # ---------------------------------------------------------------------
        #
        #  Create the simulation system and add items
        #

        self.timeend = 30

        # Create the vehicle system
        chrono.SetChronoDataPath("/home/aaron/chrono/data/")
        veh.SetDataPath("/home/aaron/chrono/data/vehicle/")

        # JSON file for vehicle model
        self.vehicle_file = veh.GetDataPath(
        ) + "hmmwv/vehicle/HMMWV_Vehicle.json"

        # JSON files for terrain
        self.rigidterrain_file = veh.GetDataPath() + "terrain/RigidPlane.json"

        # JSON file for powertrain (simple)
        self.simplepowertrain_file = veh.GetDataPath(
        ) + "generic/powertrain/SimplePowertrain.json"

        # JSON files tire models (rigid)
        self.rigidtire_file = veh.GetDataPath(
        ) + "hmmwv/tire/HMMWV_RigidTire.json"

        # Initial vehicle position
        self.initLoc = chrono.ChVectorD(-125, -130, 0.5)

        # Initial vehicle orientation
        self.initRot = chrono.ChQuaternionD(1, 0, 0, 0)

        # Rigid terrain dimensions
        self.terrainHeight = 0
        self.terrainLength = 300.0  # size in X direction
        self.terrainWidth = 300.0  # size in Y direction

        # Point on chassis tracked by the camera (Irrlicht only)
        self.trackPoint = chrono.ChVectorD(0.0, 0.0, 1.75)

        self.dist = 5.0

        self.generator = RandomPathGenerator(width=100,
                                             height=100,
                                             maxDisplacement=2,
                                             steps=1)

        self.tracknum = 0
Exemple #2
0
    def __init__(self, step_size, sys, controller, irrlicht=False, vehicle_type='json', initLoc=chrono.ChVectorD(0,0,0), initRot=chrono.ChQuaternionD(1,0,0,0), vis_balls=False, render_step_size=1.0/60):
        # Chrono parameters
        self.step_size = step_size
        self.irrlicht = irrlicht
        self.step_number = 0

        # Vehicle controller
        self.controller = controller

        # Initial vehicle position
        self.initLoc = initLoc

        # Initial vehicle orientation
        self.initRot = initRot

        # Point on chassis tracked by the camera (Irrlicht only)
        self.trackPoint = chrono.ChVectorD(0.0, 0.0, 1.75)

        if vehicle_type == 'json':

            # JSON file for vehicle model
            self.vehicle_file = veh.GetDataPath() + os.path.join('hmmwv', 'vehicle', 'HMMWV_Vehicle.json')
            checkFile(self.vehicle_file)

            # JSON file for powertrain (simple)
            self.simplepowertrain_file = veh.GetDataPath() + os.path.join('generic', 'powertrain', 'SimplePowertrain.json')
            checkFile(self.simplepowertrain_file)

            # JSON files tire models (rigid)
            self.rigidtire_file = veh.GetDataPath() + os.path.join('hmmwv', 'tire', 'HMMWV_RigidTire.json')
            checkFile(self.rigidtire_file)

            # --------------------------
            # Create the various modules
            # --------------------------
            if sys == None:
                self.wheeled_vehicle = veh.WheeledVehicle(self.vehicle_file)
            else:
                self.wheeled_vehicle = veh.WheeledVehicle(sys, self.vehicle_file)
            self.wheeled_vehicle.Initialize(chrono.ChCoordsysD(self.initLoc, self.initRot))
            self.wheeled_vehicle.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.wheeled_vehicle.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.wheeled_vehicle.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.wheeled_vehicle.SetWheelVisualizationType(veh.VisualizationType_NONE)

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

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

            self.vehicle = self.wheeled_vehicle
            self.sys = self.wheeled_vehicle.GetSystem()

        elif vehicle_type == 'rccar':
            if sys == None:
                self.rc_vehicle = veh.RCCar()
                self.rc_vehicle.SetContactMethod(chrono.ChMaterialSurface.SMC)
                self.rc_vehicle.SetChassisCollisionType(veh.ChassisCollisionType_NONE)
            else:
                self.rc_vehicle = veh.RCCar(sys)
            self.rc_vehicle.SetChassisFixed(False)
            self.rc_vehicle.SetInitPosition(chrono.ChCoordsysD(initLoc, initRot))
            self.rc_vehicle.SetTireType(veh.TireModelType_RIGID)
            self.rc_vehicle.SetTireStepSize(step_size)
            self.rc_vehicle.Initialize()

            self.rc_vehicle.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.rc_vehicle.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.rc_vehicle.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.rc_vehicle.SetWheelVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.rc_vehicle.SetTireVisualizationType(veh.VisualizationType_PRIMITIVES)

            self.vehicle = self.rc_vehicle.GetVehicle()
            self.sys = self.vehicle.GetSystem()

            self.trackPoint = chrono.ChVectorD(4, 0.0, .15)

        elif vehicle_type == 'sedan':
            if sys == None:
                self.sedan = veh.Sedan()
                self.sedan.SetContactMethod(chrono.ChMaterialSurface.NSC)
                self.sedan.SetChassisCollisionType(veh.ChassisCollisionType_NONE)
            else:
                self.sedan = veh.Sedan(sys)
            self.sedan.SetChassisFixed(False)
            self.sedan.SetInitPosition(chrono.ChCoordsysD(initLoc, initRot))
            self.sedan.SetTireType(veh.TireModelType_RIGID)
            self.sedan.SetTireStepSize(step_size)
            self.sedan.Initialize()

            self.sedan.SetChassisVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.sedan.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.sedan.SetSteeringVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.sedan.SetWheelVisualizationType(veh.VisualizationType_PRIMITIVES)
            self.sedan.SetTireVisualizationType(veh.VisualizationType_PRIMITIVES)

            self.vehicle = self.sedan.GetVehicle()
            self.sys = self.vehicle.GetVehicle().GetSystem()

        # -------------
        # Create driver
        # -------------
        self.driver = Driver(self.vehicle)
        self.driver.SetStepSize(step_size)

        # 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
        self.driver.SetSteeringDelta(render_step_size / steering_time)
        self.driver.SetThrottleDelta(render_step_size / throttle_time)
        self.driver.SetBrakingDelta(render_step_size / braking_time)

        self.vis_balls = vis_balls
        if self.vis_balls:
            self.sentinel_sphere = chrono.ChBodyEasySphere(.25, 1000, False, True)
            self.sentinel_sphere.SetBodyFixed(True)
            self.sentinel_sphere.AddAsset(chrono.ChColorAsset(1,0,0))
            self.sys.Add(self.sentinel_sphere)

            self.sentinel_target = chrono.ChBodyEasySphere(.25, 1000, False, True)
            self.sentinel_target.SetBodyFixed(True)
            self.sentinel_target.AddAsset(chrono.ChColorAsset(0,1,0));
            self.sys.Add(self.sentinel_target)

        # Vehicle parameters for matplotlib
        self.length = self.vehicle.GetWheelbase() + 2.0 # [m]
        self.width = self.vehicle.GetWheeltrack(0) # [m]
        self.backtowheel = 1.0 # [m]
        self.wheel_len = self.vehicle.GetWheel(0, 1).GetWidth() * 2 # [m]
        self.wheel_width = self.vehicle.GetWheel(0, 1).GetWidth() # [m]
        self.tread = self.vehicle.GetWheeltrack(0) / 2 # [m]
        self.wb = self.vehicle.GetWheelbase() # [m]
        self.offset = [-4.0,0] # [m]
        terrain.Advance(step_size)
        app.Advance(step_size)

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

# =============================================================================

"""
!!!! Set this path before running the demo!
"""
chrono.SetChronoDataPath('../../../../Library/data/')
veh.SetDataPath('../../../../Library/data/vehicle/')

# JSON file for vehicle model
vehicle_file = veh.GetDataPath() +"hmmwv/vehicle/HMMWV_Vehicle.json"

# JSON files for terrain
rigidterrain_file = veh.GetDataPath() +"terrain/RigidPlane.json"

# JSON file for powertrain (simple)
simplepowertrain_file = veh.GetDataPath() + "generic/powertrain/SimplePowertrain.json"

# JSON files tire models (rigid)
rigidtire_file = veh.GetDataPath() +"hmmwv/tire/HMMWV_RigidTire.json"

# Initial vehicle position
initLoc = chrono.ChVectorD(0, 0, 1.6)

# Initial vehicle orientation
initRot = chrono.ChQuaternionD(1, 0, 0, 0)
Exemple #4
0
    def __init__(self, step_size, sys, irrlicht=False, terrain_type='json', height=-0.5, width=300, length=300):
        # Chrono parameters
        self.step_size = step_size
        self.irrlicht = irrlicht
        self.step_number = 0

        # Rigid terrain dimensions
        self.height = height
        self.length = length  # size in X direction
        self.width = width  # size in Y direction

        self.sys = sys

        if terrain_type == 'json':
            import os
            # JSON files for terrain
            self.rigidterrain_file = veh.GetDataPath() + os.path.join('terrain', 'RigidPlane.json')
            checkFile(self.rigidterrain_file)

            # Create the ground
            self.terrain = veh.RigidTerrain(self.sys, self.rigidterrain_file)

        elif terrain_type == 'concrete':
            # Create the terrain
            self.terrain = veh.RigidTerrain(self.sys)
            patch = self.terrain.AddPatch(chrono.ChCoordsysD(chrono.ChVectorD(0, 0, self.height - 5), chrono.QUNIT),
                                     chrono.ChVectorD(self.width, self.length, 10))

            patch.SetContactFrictionCoefficient(0.9)
            patch.SetContactRestitutionCoefficient(0.01)
            patch.SetContactMaterialProperties(2e7, 0.3)
            patch.SetTexture(chrono.GetChronoDataFile("concrete.jpg"), self.length, self.width)
            patch.SetColor(chrono.ChColor(0.8, 0.8, 0.5))
            self.terrain.Initialize()

            try:
                ground_body = patch.GetGroundBody()
                ground_asset = ground_body.GetAssets()[0]
                visual_asset = chrono.CastToChVisualization(ground_asset)
                vis_mat = chrono.ChVisualMaterial()
                vis_mat.SetKdTexture(chrono.GetChronoDataFile("concrete.jpg"))
                vis_mat.SetFresnelMax(0);
                visual_asset.material_list.append(vis_mat)
            except:
                print("Not Visual Material")

        elif terrain_type == 'hallway':
            y_max = 5.65
            x_max = 23
            offset = chrono.ChVectorD(-x_max/2, -y_max/2, .21)
            offsetF = chrono.ChVectorF(offset.x, offset.y, offset.z)

            self.terrain = veh.RigidTerrain(self.sys)
            coord_sys = chrono.ChCoordsysD(offset, chrono.ChQuaternionD(1,0,0,0))
            patch = self.terrain.AddPatch(coord_sys, chrono.GetChronoDataFile("sensor/textures/hallway.obj"), "mesh", 0.01, False)


            vis_mesh = chrono.ChTriangleMeshConnected()
            vis_mesh.LoadWavefrontMesh(chrono.GetChronoDataFile("sensor/textures/hallway.obj"), True, True)

            trimesh_shape = chrono.ChTriangleMeshShape()
            trimesh_shape.SetMesh(vis_mesh)
            trimesh_shape.SetName("mesh_name")
            trimesh_shape.SetStatic(True)

            patch.GetGroundBody().AddAsset(trimesh_shape)

            patch.SetContactFrictionCoefficient(0.9)
            patch.SetContactRestitutionCoefficient(0.01)
            patch.SetContactMaterialProperties(2e7, 0.3)

            self.terrain.Initialize()