# Author: Alessandro Tasora # # Created: 1/01/2019 # Copyright: (c) ProjectChrono 2019 #------------------------------------------------------------------------------ import pychrono.core as chrono import pychrono.irrlicht as chronoirr import matplotlib.pyplot as plt import numpy as np print("Example: create a slider crank and plot results") # Change this path to asset path, if running from other working dir. # It must point to the data folder, containing GUI assets (textures, fonts, meshes, etc.) chrono.SetChronoDataPath("../../../data/") # --------------------------------------------------------------------- # # Create the simulation system and add items # mysystem = chrono.ChSystemNSC() # Some data shared in the following crank_center = chrono.ChVectorD(-1, 0.5, 0) crank_rad = 0.4 crank_thick = 0.1 rod_length = 1.5 # Create four rigid bodies: the truss, the crank, the rod, the piston.
import math 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
def PreSetup(args, SetupFunction): chrono.SetChronoDataPath(os.getcwd() + "/") SetupFunction()
# # Main driver function for the City Bus full model. # # 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('../../../../Library/data/') veh.SetDataPath('../../../../Library/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_MESH 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
#------------------------------------------------------------------------------ # Adjustable Leaning EXersize Robot (ALEXR) Dynamic Simulations #------------------------------------------------------------------------------ #---------------------------- Imports ----------------------------------------- import pychrono.core as chrono import pychrono.irrlicht as chronoirr import numpy as np # Change this path to asset path, if running from other working dir. # It must point to the data folder, containing GUI assets (textures, fonts, meshes, etc.) chronoDataDir = "D:/programFiles/Miniconda3/pkgs/pychrono-5.0.0-py37_9/Library/data/" chrono.SetChronoDataPath(chronoDataDir) assetsPath = "C:/Users/adaws/Documents/gitRepos/NRI_Analyses/chrono/assets/" # ----------- Calculate IK angles using custom Library ------------------------ #initial location of the end effector (EE) of the ALEX Robot Xee = .5 #(these form the initial conditions of the robot) Yee = -.5 #specify mass properties of the payload at the end effector. eeMass = 1 #set the elbow discrete vars this will flip for right vs. left side useage side = "right" # "left" if side == "right": ef = "up" e3 = "down" elif side == "left": ef = "down"
import pychrono.core as chrono import pychrono.irrlicht as chronoirr import settings # This file is used to evaluate the candidate's fitness, along with, along with returning its fitness. # Fitness is calculated in the later parts of run_sim chrono.SetChronoDataPath(settings.DATAPATH) # Traits are in the format of [[block_x, block_z, block_y], ..., mass] def run_sim(traits, trial_num, gen_num, difficulty_level): my_system = chrono.ChSystemNSC() # Set the default outward/inward shape margins for collision detection chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001) chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001) # Sets simulation precision my_system.SetMaxItersSolverSpeed(70) # Create a contact material (surface property)to share between all objects. rollfrict_param = 0.5 / 10.0 * 0.05 brick_material = chrono.ChMaterialSurfaceNSC() brick_material.SetFriction(0.5) brick_material.SetDampingF(0.2) brick_material.SetCompliance(0.0000001) brick_material.SetComplianceT(0.0000001) brick_material.SetRollingFriction(rollfrict_param) brick_material.SetSpinningFriction(0.00000001)
# # Main driver function for the RCCar model. # # 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
def main(): chrono.SetChronoDataPath("../../../data/") # ----------------- # Create the system # ----------------- mphysicalSystem = chrono.ChSystemNSC() # ---------------------------------- # add a mesh to be sensed by a lidar # ---------------------------------- mmesh = chrono.ChTriangleMeshConnected() mmesh.LoadWavefrontMesh( chrono.GetChronoDataFile("vehicle/hmmwv/hmmwv_chassis.obj"), False, True) mmesh.Transform(chrono.ChVectorD(0, 0, 0), chrono.ChMatrix33D(2)) # scale to a different size trimesh_shape = chrono.ChTriangleMeshShape() trimesh_shape.SetMesh(mmesh) trimesh_shape.SetName("HMMWV Chassis Mesh") trimesh_shape.SetStatic(True) mesh_body = chrono.ChBody() mesh_body.SetPos(chrono.ChVectorD(0, 0, 0)) mesh_body.AddAsset(trimesh_shape) mesh_body.SetBodyFixed(True) mphysicalSystem.Add(mesh_body) # ----------------------- # Create a sensor manager # ----------------------- manager = sens.ChSensorManager(mphysicalSystem) manager.SetKeyframeSizeFromTimeStep(.001, 1 / collection_time) # ------------------------------------------------ # Create a lidar and add it to the sensor manager # ------------------------------------------------ offset_pose = chrono.ChFrameD( chrono.ChVectorD(-8, 0, 1), chrono.Q_from_AngAxis(0, chrono.ChVectorD(0, 1, 0))) lidar = sens.ChLidarSensor( mesh_body, # body lidar is attached to update_rate, # scanning rate in Hz offset_pose, # offset pose horizontal_samples, # number of horizontal samples vertical_samples, # number of vertical channels horizontal_fov, # horizontal field of view max_vert_angle, # vertical field of view min_vert_angle, 100.0, #max lidar range sample_radius, # sample radius divergence_angle, # divergence angle return_mode, # return mode for the lidar lens_model # method/model to use for generating data ) lidar.SetName("Lidar Sensor") lidar.SetLag(lag) lidar.SetCollectionWindow(collection_time) # ----------------------------------------------------------------- # Create a filter graph for post-processing the data from the lidar # ----------------------------------------------------------------- if noise_model == "CONST_NORMAL_XYZI": lidar.PushFilter(sens.ChFilterLidarNoiseXYZI(0.01, 0.001, 0.001, 0.01)) elif noise_model == "NONE": # Don't add any noise models pass if vis: # Visualize the raw lidar data lidar.PushFilter( sens.ChFilterVisualize(horizontal_samples, vertical_samples, "Raw Lidar Depth Data")) # Provides the host access to the Depth,Intensity data lidar.PushFilter(sens.ChFilterDIAccess()) # Convert Depth,Intensity data to XYZI point cloud data lidar.PushFilter(sens.ChFilterPCfromDepth()) if vis: # Visualize the point cloud lidar.PushFilter( sens.ChFilterVisualizePointCloud(640, 480, 1.0, "Lidar Point Cloud")) # Provides the host access to the XYZI data lidar.PushFilter(sens.ChFilterXYZIAccess()) # Add the lidar to the sensor manager manager.AddSensor(lidar) # --------------- # Simulate system # --------------- orbit_radius = 5 orbit_rate = 0.2 ch_time = 0.0 render_time = 0 t1 = time.time() while (ch_time < end_time): lidar.SetOffsetPose( chrono.ChFrameD( chrono.ChVectorD( -orbit_radius * math.cos(ch_time * orbit_rate), -orbit_radius * math.sin(ch_time * orbit_rate), 1), chrono.Q_from_AngAxis(ch_time * orbit_rate, chrono.ChVectorD(0, 0, 1)))) # Access the XYZI buffer from lidar xyzi_buffer = lidar.GetMostRecentXYZIBuffer() if xyzi_buffer.HasData(): xyzi_data = xyzi_buffer.GetXYZIData() print('XYZI buffer recieved from lidar. Lidar resolution: {0}x{1}'\ .format(xyzi_buffer.Width, xyzi_buffer.Height)) print('Max Value: {0}'.format(np.max(xyzi_data))) # Update sensor manager # Will render/save/filter automatically manager.Update() # Perform step of dynamics mphysicalSystem.DoStepDynamics(step_size) # Get the current time of the simulation ch_time = mphysicalSystem.GetChTime() print("Sim time:", end_time, "Wall time:", time.time() - t1)
print(*traits, sep='\n') # Get the fitness for this tower: fitness = "" with open(parent_path + '/data/' + folder + file + '_trial_' + str(trial) + '.csv', newline='') as csvfile: csvreader = csv.reader(csvfile, delimiter=',', quotechar='|') # next(csvfile) for row in reversed(list(csvreader)): fitness = row[-1] break print(fitness) chrono.SetChronoDataPath(set.DATAPATH) my_system = chrono.ChSystemNSC() # Set the default outward/inward shape margins for collision detection, # this is especially important for very large or very small objects. chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001) chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001) # Maybe you want to change some settings for the solver. For example you # might want to use SetMaxItersSolverSpeed to set the number of iterations # per timestep, etc. # my_system.SetSolverType(chrono.ChSolver.Type_BARZILAIBORWEIN) # precise, more slow my_system.SetMaxItersSolverSpeed(70)
# # FEA for thin shells of Kirchhoff-Love type, with BST triangle finite elements # # ============================================================================= import pychrono.core as chrono import pychrono.irrlicht as chronoirr import pychrono.fea as fea import pychrono.mkl as mkl import os # Output directory out_dir = "./FEA_SHELLS" chrono.SetChronoDataPath('C:/codes/Chrono/Chrono_Source/data/') #GetLog() << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << "\n\n" # Create (if needed) output directory if not os.path.isdir(out_dir): os.mkdir(out_dir) # Create a Chrono::Engine physical system my_system = chrono.ChSystemNSC() # Create a mesh, that is a container for groups # of elements and their referenced nodes.