mr = chrono.ChMatrix33D() mr[0,0]=-0.841992572625772; mr[1,0]=0; mr[2,0]=0.539489117260983 mr[0,1]=-0.539489117260985; mr[1,1]=0; mr[2,1]=-0.841992572625771 mr[0,2]=0; mr[1,2]=-1; mr[2,2]=0 body_2.GetCollisionModel().AddBox(0.00239999309720335,0.00250923730353967,0.00280857758415823,chrono.ChVectorD(-0.0401200925870508,0.0350388268103799,-0.178717071200898),mr) mr = chrono.ChMatrix33D() mr[0,0]=0.529523859525646; mr[1,0]=0; mr[2,0]=0.848295044305379 mr[0,1]=-0.848295044305379; mr[1,1]=0; mr[2,1]=0.529523859525645 mr[0,2]=0; mr[1,2]=-1; mr[2,2]=0 body_2.GetCollisionModel().AddBox(0.00250923730353971,0.00239999309720335,0.00280857758415823,chrono.ChVectorD(-0.0494110785736743,0.0350388268103799,-0.172841038928428),mr) mr = chrono.ChMatrix33D() mr[0,0]=0.845149386603263; mr[1,0]=0; mr[2,0]=-0.53453018092913 mr[0,1]=0.534530180929129; mr[1,1]=0; mr[2,1]=0.845149386603264 mr[0,2]=0; mr[1,2]=-1; mr[2,2]=0 body_2.GetCollisionModel().AddBox(0.00350000000000001,0.0243835708612008,0.00280857758415823,chrono.ChVectorD(-0.0224331359558976,0.0350388268103799,-0.140469187277248),mr) pt_vect = chrono.vector_ChVectorD() pt_vect.push_back(chrono.ChVectorD(0.0521295297003961,0.0258474043945381,-0.109787208704166)) pt_vect.push_back(chrono.ChVectorD(0.0585680663475354,0.0258474043945381,-0.13676931754083)) pt_vect.push_back(chrono.ChVectorD(0.0702403529187583,0.0258474043945381,-0.133984048038744)) pt_vect.push_back(chrono.ChVectorD(0.0633542807043835,0.0258474043945381,-0.10512644263427)) pt_vect.push_back(chrono.ChVectorD(0.0521295297003961,0.0398474043945381,-0.109787208704166)) pt_vect.push_back(chrono.ChVectorD(0.0585680663475354,0.0398474043945381,-0.13676931754083)) pt_vect.push_back(chrono.ChVectorD(0.0702403529187583,0.0398474043945381,-0.133984048038744)) pt_vect.push_back(chrono.ChVectorD(0.0633542807043835,0.0398474043945381,-0.10512644263427)) body_2.GetCollisionModel().AddConvexHull(pt_vect) pt_vect = chrono.vector_ChVectorD() pt_vect.push_back(chrono.ChVectorD(-0.0448398581045523,0.0258474043945381,-0.0794862238349664)) pt_vect.push_back(chrono.ChVectorD(-0.0362924460942842,0.0258474043945381,-0.0879089162742476)) pt_vect.push_back(chrono.ChVectorD(-0.0169874992605579,0.0258474043945381,-0.0683181101735014)) pt_vect.push_back(chrono.ChVectorD(-0.026134463034664,0.0258474043945381,-0.0605038474001435)) pt_vect.push_back(chrono.ChVectorD(-0.0448398581045523,0.0398474043945381,-0.0794862238349664))
# Chrono::Engine Python script from SolidWorks # Assembly: C:\tasora\code\dynamics\papers\contact_rolling\plots\conveyor\assembly_conveyor.SLDASM import ChronoEngine_PYTHON_core as chrono import builtins shapes_dir = 'cad_conveyor_shapes/' if hasattr(builtins, 'exported_system_relpath'): shapes_dir = builtins.exported_system_relpath + shapes_dir exported_items = [] body_0= chrono.ChBodyAuxRefShared() body_0.SetName('ground') body_0.SetBodyFixed(1) exported_items.append(body_0) # Rigid body part body_1= chrono.ChBodyAuxRefShared() body_1.SetName('conveyor^assembly_conveyor-1') body_1.SetPos(chrono.ChVectorD(-1.5,1,0)) body_1.SetRot(chrono.ChQuaternionD(1,0,0,0)) body_1.SetMass(62.5596464664722) body_1.SetInertiaXX(chrono.ChVectorD(2.4969698065779,43.2055331519538,41.4723890032672)) body_1.SetInertiaXY(chrono.ChVectorD(-0.00109264755200904,4.73037407855426e-16,-5.11743425413158e-17)) body_1.SetFrame_COG_to_REF(chrono.ChFrameD(chrono.ChVectorD(-0.000365893287965613,-0.0560030560102842,-3.54932640234839e-18),chrono.ChQuaternionD(1,0,0,0))) body_1.SetBodyFixed(1) # Visualization shape
# Chrono::Engine Python script from SolidWorks # Assembly: C:\Program Files\SolidWorks Corp\SolidWorks\chronoengine\examples\collisions\portal.SLDASM import ChronoEngine_PYTHON_core as chrono import builtins shapes_dir = 'collisions_shapes/' if hasattr(builtins, 'exported_system_relpath'): shapes_dir = builtins.exported_system_relpath + shapes_dir exported_items = [] body_0 = chrono.ChBodyAuxRefShared() body_0.SetName('ground') body_0.SetBodyFixed(1) exported_items.append(body_0) # Rigid body part body_1 = chrono.ChBodyAuxRefShared() body_1.SetName('column-1') body_1.SetPos(chrono.ChVectorD(0.1, 0.1, -2.77555756156289e-17)) body_1.SetRot(chrono.ChQuaternionD(1, 0, 0, 0)) body_1.SetMass(5.94162890340754) body_1.SetInertiaXX( chrono.ChVectorD(0.0828656280407889, 0.0140634491293917, 0.0828656280407889)) body_1.SetInertiaXY( chrono.ChVectorD(7.3359262007676e-38, -3.61798264958413e-19, -2.89120579226739e-18)) body_1.SetFrame_COG_to_REF(
print(" file to load is ", m_filename) print(" timestep is ", m_timestep) print(" length is ", m_length) # --------------------------------------------------------------------- # # load the file generated by the SolidWorks CAD plugin # and add it to the ChSystem. # # This is usually done as # from my_module import exported_items # but here is 'my_module' is a string, so there's a workaround with 'exec' print("Loading C::E scene...") exported_items = chrono.ImportSolidWorksSystem(modulename) print("...loading done!") # Print exported items for my_item in exported_items: print(my_item.GetName()) # Add items to the physical system my_system = chrono.ChSystem() for my_item in exported_items: my_system.Add(my_item) # --------------------------------------------------------------------- # # Render a short animation by generating scripts
def main(): pass if __name__ == '__main__': main() print ("First tutorial about Chrono::Engine in Python"); # Load the Chrono::Engine unit!!! import ChronoEngine_PYTHON_core as chrono # Test logging chrono.GetLog().Bar() chrono.GetLog() << "result is: " << 11+1.5 << "\n" chrono.GetLog().Bar() # Test vectors my_vect1 = chrono.ChVectorD() my_vect1.x=5 my_vect1.y=2 my_vect1.z=3 my_vect2 = chrono.ChVectorD(3,4,5) my_vect4 = my_vect1*10 + my_vect2 my_len = my_vect4.Length() print ('vect sum =', my_vect1 + my_vect2) print ('vect cross =', my_vect1 % my_vect2) print ('vect dot =', my_vect1 ^ my_vect2)
# Load the Chrono::Engine unit and the postprocessing unit!!! import ChronoEngine_PYTHON_core as chrono import ChronoEngine_PYTHON_postprocess as postprocess import ChronoEngine_PYTHON_irrlicht as chronoirr # We will create two directories for saving some files, we need this: import os import math # --------------------------------------------------------------------- # # Create the simulation system and add items # my_system = chrono.ChSystem() # Set the default outward/inward shape margins for collision detection, # this is epecially 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 SetIterLCPmaxItersSpeed to set the number of iterations # per timestep, etc. #my_system.SetLcpSolverType(chrono.ChSystem.LCP_ITERATIVE_BARZILAIBORWEIN) # precise, more slow my_system.SetIterLCPmaxItersSpeed(70) # Create a contact material (surface property)to share between all objects. # The rolling and spinning parameters are optional - if enabled they double
if __name__ == '__main__': main() import os import math import ChronoEngine_PYTHON_core as chrono import ChronoEngine_PYTHON_postprocess as postprocess # --------------------------------------------------------------------- # # Create the simulation system. # (Do not create parts and constraints programmatically here, we will # load a mechanism from file) my_system = chrono.ChSystem() # Set the collision margins. This is expecially important for very large or # very small objects (as in this example)! Do this before creating shapes. chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001) chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001) # --------------------------------------------------------------------- # # load the file generated by the SolidWorks CAD plugin # and add it to the ChSystem # print("Loading C::E scene...") exported_items = chrono.ImportSolidWorksSystem(
import os import imp import math import matplotlib import csv import random import numpy as np import matplotlib.cm as cm import matplotlib.mlab as mlab import matplotlib.pyplot as plt import sys #from PyQt4 import QtGui, QtCore # Create a physical system, my_system = chrono.ChSystem() # Set the default outward/inward shape margins for collision detection, # this is epecially important for very large or very small objects. chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.005) chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.005) # Load the CAD file exported_items = chrono.ImportSolidWorksSystem('cad_conveyor') # Add items to the physical system my_system = chrono.ChSystem() for my_item in exported_items: my_system.Add(my_item)
main() import os import math import ChronoEngine_PYTHON_core as chrono import ChronoEngine_PYTHON_postprocess as postprocess import ChronoEngine_PYTHON_irrlicht as chronoirr print("Example: create a system and visualize it in realtime 3D") # --------------------------------------------------------------------- # # Create the simulation system and add items # mysystem = chrono.ChSystem() # Create rigid body mbody1 = chrono.ChBodyShared() mbody1.SetBodyFixed(False) mysystem.Add(mbody1) mboxasset = chrono.ChBoxShapeShared() mboxasset.GetBoxGeometry().Size = chrono.ChVectorD(0.2, 0.5, 0.1) mbody1.AddAsset(mboxasset) mboxtexture = chrono.ChTextureShared() mboxtexture.SetTextureFilename('../data/concrete.jpg') mbody1.GetAssets().push_back(mboxtexture)
m_filename = "" m_timestep = 0.001 m_length = 4.0 # --------------------------------------------------------------------- # # load the file generated by the SolidWorks CAD plugin # and add it to the ChSystem. # # This is usually done as # from my_module import exported_items # but here is 'my_module' is a string, so there's a workaround with 'exec' print("Loading C::E scene...") exported_items = chrono.ImportSolidWorksSystem('collisions') print("...loading done!") # Print exported items for my_item in exported_items: print(my_item.GetName()) # Add items to the physical system my_system = chrono.ChSystem() for my_item in exported_items: my_system.Add(my_item) # TRICKS # Set the default outward/inward shape margins for collision detection,
pass if __name__ == '__main__': main() # Load the Chrono::Engine unit and the postprocessing unit!!! import ChronoEngine_PYTHON_core as chrono import ChronoEngine_PYTHON_postprocess as postprocess # We will create two directories for saving some files, we need this: import os # Create a physical system, my_system = chrono.ChSystem() # Set the default margins for collision detection, this is epecially # important for very large or very small objects. chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001) chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001) # Create the set of the particle clones (many rigid bodies that # share the same mass and collision shape, so they are memory efficient # in case you want to simulate granular material) body_particles = chrono.ChParticlesClonedShared() body_particles.SetMass(0.01);
#------------------------------------------------------------------------------- #!/usr/bin/env python def main(): pass if __name__ == '__main__': main() # Load the Chrono::Engine unit!!! import ChronoEngine_PYTHON_core as chrono # Create a physical system, my_system = chrono.ChSystem() # Add two bodies my_shbodyA = chrono.ChBodyShared() my_shbodyA.SetMass(20) my_shbodyA.SetInertiaXX(chrono.ChVectorD(10, 10, 10)) print(my_shbodyA.GetXInertia()) my_shbodyA.SetPos(chrono.ChVectorD(1, -1, 0)) my_shbodyA.GetCollisionModel().AddBox(10, 1, 10) my_shbodyA.SetBodyFixed(1) my_shbodyA.SetCollide(1) my_shbodyB = chrono.ChBodyShared() my_shbodyB.SetPos(chrono.ChVectorD(0, 2, 0)) my_shbodyB.GetCollisionModel().AddBox(1, 1, 1) my_shbodyB.SetCollide(1)
# Chrono::Engine Python script from SolidWorks # Assembly: C:\tasora\lavori\orologio_audemar\CAD_swiss_escapement\escapement.SLDASM import ChronoEngine_PYTHON_core as chrono import builtins shapes_dir = 'swiss_escapement_shapes/' if hasattr(builtins, 'exported_system_relpath'): shapes_dir = builtins.exported_system_relpath + shapes_dir exported_items = [] body_0= chrono.ChBodyAuxRefShared() body_0.SetName('ground') body_0.SetBodyFixed(1) exported_items.append(body_0) # Rigid body part body_1= chrono.ChBodyAuxRefShared() body_1.SetName('escape_wheel^escapement-1') body_1.SetPos(chrono.ChVectorD(0,0.000381819559584939,0)) body_1.SetRot(chrono.ChQuaternionD(0,0,0.707106781186548,0.707106781186547)) body_1.SetMass(0.385093622816182) body_1.SetInertiaXX(chrono.ChVectorD(0.000614655341550614,0.00114774663635329,0.000614655341550614)) body_1.SetInertiaXY(chrono.ChVectorD(1.04945260437012e-19,-5.29910899706164e-19,5.85921324575995e-19)) body_1.SetFrame_COG_to_REF(chrono.ChFrameD(chrono.ChVectorD(-1.29340068058665e-17,4.10138104133823e-17,0.00633921901294084),chrono.ChQuaternionD(1,0,0,0))) # Visualization shape body_1_1_shape = chrono.ChObjShapeFileShared()
def main(): pass if __name__ == '__main__': main() # Load the Chrono::Engine unit and the postprocessing unit!!! import ChronoEngine_PYTHON_core as chrono import ChronoEngine_PYTHON_postprocess as postprocess # We will create two directories for saving some files, we need this: import os # Create a physical system, my_system = chrono.ChSystem() my_systemB = my_system my_system.SetTol(2) print(my_systemB.GetTol()) # Create a body body_1 = chrono.ChBodyAuxRefShared() my_system.Add(body_1) # Attach a visualization asset to the body (a Wavefront .obj mesh) myasset = chrono.ChSphereShapeShared() myasset.GetSphereGeometry().rad = 0.2 body_1.GetAssets().push_back(myasset) # Assets can be shared, ex. to save memory... body_2 = chrono.ChBodyAuxRefShared()
import sys, getopt, imp import ChronoEngine_PYTHON_core as chrono import ChronoEngine_PYTHON_postprocess as postprocess m_timestep = 0.01 m_length = 1.0 # --------------------------------------------------------------------- # # load the file generated by the SolidWorks CAD plugin # and add it to the ChSystem. # print("Loading C::E scene...") exported_items = chrono.ImportSolidWorksSystem('engine4c') print("...loading done!") # Print exported items for my_item in exported_items: print(my_item.GetName()) # Add items to the physical system my_system = chrono.ChSystem() for my_item in exported_items: my_system.Add(my_item) # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # SOME MODIFICATIONS....