예제 #1
0
def setDataDirectory():
    """
    Set data directory

    This is useful so data directory paths don't need to be changed everytime
    you pull from or push to github. To make this useful, make sure you perform
    step 2, as defined for your operating system.

    For Linux or Mac users:
      Replace bashrc with the shell your using. Could be .zshrc.
      1. echo 'export CHRONO_DATA_DIR=<chrono's data directory>' >> ~/.bashrc
          Ex. echo 'export CHRONO_DATA_DIR=/home/user/chrono/data/' >> ~/.zshrc
      2. source ~/.zshrc

    For Windows users:
      Link as reference: https://helpdeskgeek.com/how-to/create-custom-environment-variables-in-windows/
      1. Open the System Properties dialog, click on Advanced and then Environment Variables
      2. Under User variables, click New... and create a variable as described below
          Variable name: CHRONO_DATA_DIR
          Variable value: <chrono's data directory>
              Ex. Variable value: C:\ Users\ user\ chrono\ data\
    """
    from pathlib import Path

    CONDA_PREFIX = os.environ.get('CONDA_PREFIX')
    CHRONO_DATA_DIR = os.environ.get('CHRONO_DATA_DIR')
    if CONDA_PREFIX and not CHRONO_DATA_DIR:
        CHRONO_DATA_DIR = os.path.join(CONDA_PREFIX, "share", "chrono", "data")
    if not CHRONO_DATA_DIR:
        CHRONO_DATA_DIR = os.path.join(Path(os.path.dirname(os.path.realpath(__file__))).parents[1], "chrono", "data", "")
    elif not CHRONO_DATA_DIR:
        raise Exception('Cannot find the chrono data directory. Please verify that CHRONO_DATA_DIR is set correctly.')

    chrono.SetChronoDataPath(CHRONO_DATA_DIR)
    veh.SetDataPath(os.path.join(CHRONO_DATA_DIR, 'vehicle', ''))
예제 #2
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
예제 #3
0
def _update_chrono_data_directories():
    global _DATA_DIRECTORY, _CHRONO_DATA_DIRECTORY, _CHRONO_VEH_DATA_DIRECTORY

    if not _OVERRIDE_CHRONO_DIRECTORIES and _DATA_DIRECTORY != get_wa_data_directory(
    ):
        _DATA_DIRECTORY = get_wa_data_directory()

        _CHRONO_DATA_DIRECTORY = str(
            pathlib.Path(_DATA_DIRECTORY) / "chrono" / " ")[:-1]
        _CHRONO_VEH_DATA_DIRECTORY = str(
            pathlib.Path(_DATA_DIRECTORY) / "chrono" / "vehicle" / " ")[:-1]

        # Update the chrono paths
        chrono.SetChronoDataPath(_CHRONO_DATA_DIRECTORY)
        veh.SetDataPath(_CHRONO_VEH_DATA_DIRECTORY)
예제 #4
0
def set_chrono_vehicle_data_directory(path: str):
    """Set the chrono vehicle data directory

    Normally, it is assumed that the chrono vehicle data directory is located inside wherever :meth:`~get_wa_data_directory`
    is set to. Using this method will override that functionality and statically assign the chrono vehicle data directory.
    If you'd like to return to the overriding functionality, call :meth:`~set_chrono_directories_override`.

    Args:
        path (str): relative (or absolute) path where the data is stored
    """
    global _CHRONO_DATA_DIRECTORY, _OVERRIDE_CHRONO_DIRECTORIES

    _CHRONO_DATA_DIRECTORY = path
    _OVERRIDE_CHRONO_DIRECTORIES = True

    veh.SetDataPath(_CHRONO_VEH_DATA_DIRECTORY)
예제 #5
0
        # Increment frame number
        step_number += 1

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

    return 0


# The path to the Chrono data directory containing various assets (meshes, textures, data files)
# is automatically set, relative to the default location of this demo.
# If running from a different directory, you must change the path to the data directory with: 
#chrono.SetChronoDataPath('path/to/data')

veh.SetDataPath(chrono.GetChronoDataPath() + 'vehicle/')

# Initial vehicle location and orientation
initLoc = chrono.ChVectorD(0, 0, 1.6)
initRot = chrono.ChQuaternionD(1, 0, 0, 0)

# Visualization type for vehicle parts (PRIMITIVES, MESH, or NONE)
chassis_vis_type = veh.VisualizationType_MESH
suspension_vis_type =  veh.VisualizationType_PRIMITIVES
steering_vis_type = veh.VisualizationType_PRIMITIVES
wheel_vis_type = veh.VisualizationType_MESH
tire_vis_type = veh.VisualizationType_MESH 

# Collision type for chassis (PRIMITIVES, MESH, or NONE)
chassis_collision_type = veh.ChassisCollisionType_NONE
예제 #6
0
        # 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)

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

"""
!!!! 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)
예제 #7
0
            driver.Advance(step)
            vehicle.Advance(step)
            terrain.Advance(step)
            vis.Advance(step)

            # Increment frame number
            step_number += 1


# =============================================================================
"""
!!!! Set this path before running the demo!
"""
chrono.SetChronoDataPath("/home/aaron/chrono/data/")
veh.SetDataPath("/home/aaron/chrono/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
예제 #8
0
import cv2

from control_utilities.track import RandomTrack, Track

import numpy as np
# import cv2


save_data = False
visualize = True

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

# Initial vehicle location and orientation
initLoc = chrono.ChVectorD(0, 0, 0.5)
initRot = chrono.ChQuaternionD(1, 0, 0, 0)

# Visualization type for vehicle parts (PRIMITIVES, MESH, or NONE)
chassis_vis_type = veh.VisualizationType_PRIMITIVES
suspension_vis_type = veh.VisualizationType_PRIMITIVES
steering_vis_type = veh.VisualizationType_PRIMITIVES
wheel_vis_type = veh.VisualizationType_MESH

# Collision type for chassis (PRIMITIVES, MESH, or NONE)
chassis_collision_type = veh.ChassisCollisionType_NONE

# Type of tire model (RIGID, TMEASY)
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
예제 #10
0
#
# The vehicle reference frame has Z up, X towards the front of the vehicle, and
# Y pointing to the left.
#
# =============================================================================
import pychrono.core as chrono
import pychrono.irrlicht as irr
import pychrono.vehicle as veh

import math
"""
!!!! Set this path before running the demo!
"""
chrono.SetChronoDataPath(
    '/home/hubble-02/miniconda3/envs/isro/share/chrono/data/')
veh.SetDataPath(
    '/home/hubble-02/miniconda3/envs/isro/share/chrono/data/vehicle')

# Initial vehicle location and orientation
initLoc = chrono.ChVectorD(2, 2, 0.5)
initRot = chrono.ChQuaternionD(1, 0, 0, 0)

# Visualization type for vehicle parts (PRIMITIVES, MESH, or NONE)
chassis_vis_type = veh.VisualizationType_PRIMITIVES
suspension_vis_type = veh.VisualizationType_PRIMITIVES
steering_vis_type = veh.VisualizationType_PRIMITIVES
wheel_vis_type = veh.VisualizationType_PRIMITIVES

# Collision type for chassis (PRIMITIVES, MESH, or NONE)
chassis_collision_type = veh.CollisionType_NONE

# Type of tire model (RIGID, TMEASY)