So currently I'm trying to create and run a new vehicle on the pychrono 
module through anaconda prompt. I created the JSON files and the needed 
mesh files. The only issue I'm having is successfully executing the program 
without errors. To note, I'm just pulling the HMMWV model using 
'WheeledVehicle' to test my code.

*The issues I'm getting are* 'WheeledVehicle' has no attributes to 
'SetContactMethod' and I get a vehicle that falls through the map. 
Additionally, I had issues loading in the tires, but figured that out, and 
now the vehicle floats above the map.

File Get_HMMWV: Vehicle has no wheels and falls through map
File Get_HMMWV_3: Vehicle has wheels but doesn't drop onto map.
(Issues with uploading file, code was copy pasted below)

Is it a lot easier to use the C++ API? Are there other methods that I'm 
missing. Thanks.


*===== Get_HMMWV.py =====*
import pychrono as chrono
import pychrono.vehicle as veh
import os
import math

# 
=============================================================================
# CONFIGURATION
# 
=============================================================================

# Simulation parameters
contact_method = chrono.ChContactMethod_SMC
step_size = 3e-3
tire_step_size = 1e-3
render_step_size = 1.0 / 50  # 50 FPS
t_end = 60.0
debug_step_size = 1.0

# Output
out_dir = "hmmwv_output"
debug_output = True
contact_vis = False

# Visualization types
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
chassis_collision_type = veh.CollisionType_NONE

# Initial vehicle pose
initLoc = chrono.ChVector3d(0, 0, 1.6)
initRot = chrono.QUNIT
trackPoint = chrono.ChVector3d(0.0, 0.0, 1.75)

# Vehicle model choices
engine_model = veh.EngineModelType_SHAFTS
transmission_model = veh.TransmissionModelType_AUTOMATIC_SHAFTS
drive_type = veh.DrivelineTypeWV_AWD
steering_type = veh.SteeringTypeWV_PITMAN_ARM
tire_model = veh.TireModelType_TMEASY

# Terrain dimensions
terrainLength = 100.0
terrainWidth = 100.0

# 
=============================================================================
# MAIN FUNCTION
# 
=============================================================================

def main():
    chrono.SetChronoDataPath(chrono.GetChronoDataPath())
    veh.SetDataPath(chrono.GetChronoDataPath() + "vehicle/")

    # Load HMMWV vehicle from JSON
    hmmwv_json = veh.GetDataFile("hmmwv/vehicle/HMMWV_Vehicle.json") 
#("D:/CHRONO-engine_demos/chrono-9.0.0/chrono-9.0.0/data/vehicle/hmmwv/vehicle/HMMWV_Vehicle.json")
    #truck = veh.WheeledVehicle(hmmwv_json, True)
    truck = veh.WheeledVehicle(
"D:/CHRONO-engine_demos/chrono-9.0.0/chrono-9.0.0/data/vehicle/hmmwv/vehicle/HMMWV_Vehicle.json",
 
chrono.ChContactMethod_NSC)
    

    #truck.SetContactMethod(contact_method)
    #truck.SetContactMethod(chrono.ChContactMethod_NSC)
    #truck.SetChassisCollisionType(chassis_collision_type)
    #truck.SetChassisFixed(False)
    #truck.SetInitPosition(chrono.ChCoordsysD(initLoc, initRot))
    #truck.SetEngineType(engine_model)
    #truck.SetTransmissionType(transmission_model)
    #truck.SetDriveType(drive_type)
    #truck.SetSteeringType(steering_type)
    #truck.SetTireType(tire_model)
    #truck.SetTireStepSize(tire_step_size)
    #initial_pos = chrono.ChCoordsysd(chrono.ChVector3d(5, 0, 1), 
chrono.QUNIT)
    #truck.SetInitialPosition(chassisPos)
    truck.Initialize(chrono.ChCoordsysd(initLoc, initRot))

    truck.SetChassisVisualizationType(chassis_vis_type)
    truck.SetSuspensionVisualizationType(suspension_vis_type)
    truck.SetSteeringVisualizationType(steering_vis_type)
    truck.SetWheelVisualizationType(wheel_vis_type)
    truck.SetTireVisualizationType(tire_vis_type)
    truck.GetSystem().SetCollisionSystemType(chrono.ChCollisionSystem.
Type_BULLET)

    # Create terrain
    terrain = veh.RigidTerrain(truck.GetSystem())
    patch_mat = chrono.ChContactMaterialSMC()
    patch_mat.SetFriction(0.9)
    patch_mat.SetRestitution(0.01)
    patch_mat.SetYoungModulus(2e7)
    patch = terrain.AddPatch(patch_mat, chrono.CSYSNORM, terrainLength, 
terrainWidth)
    patch.SetColor(chrono.ChColor(0.6, 0.6, 0.4))
    patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 200, 200
)
    terrain.Initialize()

    # Visualization system
    vis = veh.ChWheeledVehicleVisualSystemIrrlicht()
    vis.SetWindowTitle("HMMWV JSON Vehicle")
    vis.SetWindowSize(1280, 1024)
    vis.SetChaseCamera(trackPoint, 6.0, 0.5)
    vis.Initialize()
    vis.AddSkyBox()
    vis.AddLogo(chrono.GetChronoDataFile("logo_pychrono_alpha.png"))
    vis.AddLightDirectional()
    vis.AttachVehicle(truck)

    # Driver
    driver = veh.ChInteractiveDriverIRR(vis)
    driver.SetSteeringDelta(render_step_size / 1.0)
    driver.SetThrottleDelta(render_step_size / 1.0)
    driver.SetBrakingDelta(render_step_size / 0.3)
    driver.Initialize()

    # Output directory setup
    os.makedirs(out_dir, exist_ok=True)
    truck.SetChassisOutput(True)
    truck.SetSuspensionOutput(0, True)
    truck.SetSteeringOutput(0, True)
    truck.SetOutput(veh.ChVehicleOutput.ASCII, out_dir, "output", 0.1)
    truck.ExportComponentList(os.path.join(out_dir, "component_list.json"))

    # Simulation loop
    step_number = 0
    render_steps = math.ceil(render_step_size / step_size)
    debug_steps = math.ceil(debug_step_size / step_size)
    truck.EnableRealtime(True)

    while vis.Run():
        time = truck.GetSystem().GetChTime()
        if time >= t_end:
            break

        vis.BeginScene()
        vis.Render()
        vis.EndScene()

        if debug_output and step_number % debug_steps == 0:
            print(f"[{time:.3f} s] Step {step_number}")

        # Synchronize
        driver_inputs = driver.GetInputs()
        driver.Synchronize(time)
        terrain.Synchronize(time)
        truck.Synchronize(time, driver_inputs, terrain)
        vis.Synchronize(time, driver_inputs)

        # Advance
        driver.Advance(step_size)
        terrain.Advance(step_size)
        truck.Advance(step_size)
        vis.Advance(step_size)

        step_number += 1

if __name__ == "__main__":
    main()



*===== Get_HMMWV_3.py =====*
import os
import pychrono as chrono
import pychrono.vehicle as veh
import pychrono.irrlicht as irr
import math

# 
=============================================================================
# SETUP SIMULATION
# 
=============================================================================
def main():
    # Set data path (replace with your vehicle JSON directory)
    veh.SetDataPath(chrono.GetChronoDataPath() + "vehicle/")

    # Create Chrono system
    system = chrono.ChSystemNSC()
    system.SetCollisionSystemType(chrono.ChCollisionSystem.Type_BULLET)
    system.SetGravitationalAcceleration(chrono.ChVector3d(0, 0, -9.81))

    # 
=========================================================================
    # 1. VEHICLE DEFINITION (JSON-based)
    # 
=========================================================================
    # Load vehicle from JSON (replace with your file)
    vehicle_file = 
"D:/CHRONO-engine_demos/chrono-9.0.0/chrono-9.0.0/data/vehicle/hmmwv/vehicle/HMMWV_Vehicle.json"
    #vehicle_file = "D:/Hangups on Crossings/Vehicle 
Models/Scania-old-Charlie/vehicle.json"
    vehicle = veh.WheeledVehicle(system, vehicle_file)
    vehicle.Initialize(chrono.ChCoordsysd(chrono.ChVector3d(0, 0, 1.5), 
chrono.ChQuaterniond(1, 0, 0, 0)))

    # Add this debug print immediately after
    print(f"Vehicle reference frame height: {vehicle.GetChassis().GetPos().z
}")


    for axle in vehicle.GetAxles():
        tireL = veh.ReadTireJSON("D:/Hangups on Crossings/Vehicle 
Models/hmmwv/tire/HMMWV_TMeasyTire.json")  # Replace with your tire file
        tireR = veh.ReadTireJSON("D:/Hangups on Crossings/Vehicle 
Models/hmmwv/tire/HMMWV_TMeasyTire.json")
        vehicle.InitializeTire(tireL, axle.m_wheels[0], veh.
VisualizationType_MESH)
        vehicle.InitializeTire(tireR, axle.m_wheels[1], veh.
VisualizationType_MESH)
        #tireL.EnableCollision(veh.ChTire.CollisionType_MESH)
        #tireR.EnableCollision(veh.ChTire.CollisionType_MESH)
    vehicle.SetWheelVisualizationType(veh.VisualizationType_MESH)

    #debug
    print(f"Vehicle has {vehicle.GetNumberAxles()} axles")  # Should print 
2 for HMMWV
    #print(f"Initialized {len(vehicle.GetTires())} tires")  # Should print 
4 for HMMWV
    #for i, tire in enumerate(vehicle.GetTires()):
    #    print(f"Tire {i} collision enabled: {tire.IsCollisionEnabled()}")

    # Add this check before loading tires:
    #tire_path = veh.GetDataFile("D:/Hangups on Crossings/Vehicle 
Models/hmmwv/tire/HMMWV_TMeasyTire.json")
    tire_path = "D:/Hangups on Crossings/Vehicle 
Models/hmmwv/tire/HMMWV_TMeasyTire.json"
    tireL = veh.ReadTireJSON(tire_path)
    tireL.Initialize(axle.m_wheels[0])
    tireR.Initialize(axle.m_wheels[1])


    if not os.path.exists(tire_path):
        print(f"ERROR: Tire file not found at {tire_path}")
    else:
        print(f"Found tire file at {tire_path}")

    # Set visualization modes
    vehicle.SetChassisVisualizationType(veh.VisualizationType_MESH)
    vehicle.SetSuspensionVisualizationType(veh.VisualizationType_PRIMITIVES)
    vehicle.SetWheelVisualizationType(veh.VisualizationType_MESH)
    vehicle.SetTireVisualizationType(veh.VisualizationType_MESH)

    # 
=========================================================================
    # 2. TERRAIN
    # 
=========================================================================
    
    patch_mat = chrono.ChContactMaterialNSC()
    patch_mat.SetFriction(0.9)
    patch_mat.SetRestitution(0.1)
    terrain = veh.RigidTerrain(system)
    patch = terrain.AddPatch(patch_mat, chrono.CSYSNORM, 100, 100)
    patch.SetTexture(veh.GetDataFile("terrain/textures/tile4.jpg"), 200, 200
)
    terrain.Initialize()


    # 
=========================================================================
    # 3. VISUALIZATION (Irrlicht)
    # 
=========================================================================
    vis = veh.ChWheeledVehicleVisualSystemIrrlicht()
    vis.SetWindowTitle("Custom Vehicle Demo")
    vis.SetWindowSize(1280, 1024)
    vis.SetChaseCamera(chrono.ChVector3d(0.0, 0.0, 1.75), 6.0, 0.5)
    vis.Initialize()
    vis.AddLogo(chrono.GetChronoDataFile("logo_pychrono_alpha.png"))
    vis.AddSkyBox()
    vis.AddLightDirectional()
    vis.AttachVehicle(vehicle)


    # 
=========================================================================
    # 4. DRIVER CONTROLS
    # 
=========================================================================
    # Option A: Interactive driver (keyboard controls)
    driver = veh.ChInteractiveDriverIRR(vis)
    driver.SetSteeringDelta(0.02)
    driver.SetThrottleDelta(0.02)
    driver.SetBrakingDelta(0.06)
    driver.Initialize()

    # Option B: Path-follower (uncomment to use)
    #path = veh.StraightLinePath(chrono.ChVector3d(0, 0, 0), 
chrono.ChVector3d(100, 0, 0))
    #driver = veh.ChPathFollowerDriver(vehicle, path, "my_path", 10.0)  # 
10 m/s target speed
    #driver.Initialize()

    # Debug print vehicle components
    print("\n=== Vehicle Status ===")
    print(f"Chassis pos: {vehicle.GetChassisBody().GetPos()}")
    for i, axle in enumerate(vehicle.GetAxles()):
        print(f"Axle {i}:")
        print(f"  Left wheel pos: {axle.m_wheels[0].GetPos()}")
        print(f"  Right wheel pos: {axle.m_wheels[1].GetPos()}")
        #if i < len(vehicle.GetTires()):
            #print(f"  Left tire contact: 
{vehicle.GetTires()[2*i].IsInContact()}")
            #print(f"  Right tire contact: 
{vehicle.GetTires()[2*i+1].IsInContact()}")

    # Pause briefly to see debug output
    import time
    time.sleep(3)
    # 
=========================================================================
    # 5. SIMULATION LOOP
    # 
=========================================================================
    step_size = 0.002
    while vis.Run():
        time = system.GetChTime()

        # Render scene
        vis.BeginScene()
        vis.Render()
        vis.EndScene()

        # Get driver inputs
        driver_inputs = driver.GetInputs()

        # Update modules
        driver.Synchronize(time)
        terrain.Synchronize(time)
        vehicle.Synchronize(time, driver_inputs, terrain)
        vis.Synchronize(time, driver_inputs)

        # Advance simulation
        driver.Advance(step_size)
        terrain.Advance(step_size)
        vehicle.Advance(step_size)
        vis.Advance(step_size)

# 
=============================================================================
# RUN SIMULATION
# 
=============================================================================
#if __name__ == "__main__":print(f"Vehicle has {vehicle.GetNumberAxles()} 
axles")  # Should print 2 for HMMWV
#print(f"Initialized {len(vehicle.GetTires())} tires")  # Should print 4 
for HMMWV
#for i, tire in enumerate(vehicle.GetTires()):
#    print(f"Tire {i} collision enabled: {tire.IsCollisionEnabled()}")
#    main()

if __name__ == "__main__":
    main()



-- 
You received this message because you are subscribed to the Google Groups 
"ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to projectchrono+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/projectchrono/04145708-1d4a-4e56-bdb3-7181e62c34fen%40googlegroups.com.

Reply via email to