Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplified version of smart interaction explorer #35

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ channels:
- defaults
dependencies:
- python=3.9.12
- irrlicht=1.8.5
- irrlicht
- numpy
- yapf
- mypy
- pylint
- pip
- pip:
- networkx==2.8.6
- matplotlib==3.6.0
- scipy
- mcts==1.0.4
- open3d
- lxml
67 changes: 67 additions & 0 deletions examples/intexp_external_forces_on_testee_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pychrono as chrono
import pychrono.irrlicht as irr
from rostok import intexp

""" Testee object is dumbbell """
obj_db = intexp.chrono_api.ChTesteeObject() # Create Chrono Testee Object
obj_db.createChronoBodyMeshFromFile('./examples/models/custom/body1.obj',
'./examples/models/custom/body1.xml') # create 3D mesh and parameters (grasping poses read from file)
obj_db.setChronoBodyMeshRefFrameInPoint(chrono.ChFrameD(chrono.ChVectorD(0,0.2,0), chrono.ChQuaternionD(1,0,0,0)))

''' Impact on Testee Object'''
impact = chrono.ChForce() # Create Impact
obj_db.chrono_body_mesh.AddForce(impact) # Attach to ChBody

IMPACTS_M = [1, 1, 1, 2, 2, 2] # Exam with 6 constant forces and different directions
IMPACTS_DIR = [chrono.ChVectorD(1,0,0),
chrono.ChVectorD(0,1,0),
chrono.ChVectorD(0,0,1),
chrono.ChVectorD(-1,0,0),
chrono.ChVectorD(0,-1,0),
chrono.ChVectorD(0,0,-1)]
IMPACTS_APPLICATION_POINT = [chrono.ChVectorD(0, 0, 0),
chrono.ChVectorD(0, 0, 0),
chrono.ChVectorD(0, 0, 0),
chrono.ChVectorD(0, 0, 0),
chrono.ChVectorD(0, 0, 0),
chrono.ChVectorD(0, 0, 0)]

tracking_timer = intexp.chrono_api.ImpactTimerParameters(test_bound=len(IMPACTS_DIR),
clock_bound=2.0, step = 1e-3) # Switch timer of impact every 2 sec


''' Floor added for clarity '''
floor = chrono.ChBodyEasyBox(1,0.005,1, 1000, True, True, chrono.ChMaterialSurfaceNSC())
floor.SetPos(chrono.ChVectorD(0,-0.005,0))
floor.SetBodyFixed(True)
floor.SetName('Floor')
floor.GetVisualShape(0).SetColor(chrono.ChColor(80/255, 80/255, 80/255))

''' Simulation Solver '''
system = chrono.ChSystemNSC()
system.Set_G_acc(chrono.ChVectorD(0,0,0))
system.Add(obj_db.chrono_body_mesh) # Chrono Testee Object added to simulation
system.Add(floor)

''' PyChrono Visualisation '''
vis = irr.ChVisualSystemIrrlicht()
vis.AttachSystem(system)
vis.SetWindowSize(1028,768)
vis.SetWindowTitle('Impacts')
vis.SetSymbolScale(3)
vis.Initialize()
vis.AddLight(chrono.ChVectorD(0,10,0), 15)
vis.AddSkyBox()
vis.AddCamera(chrono.ChVectorD(1,0.5,1))
vis.EnableCollisionShapeDrawing(True)
vis.EnableBodyFrameDrawing(True)

while vis.Run():
system.Update()
vis.BeginScene()
vis.Render()
vis.EndScene()
system.DoStepDynamics(1e-3)

intexp.chrono_api.updateImpact(obj_db, impact, tracking_timer,
IMPACTS_APPLICATION_POINT, IMPACTS_DIR, IMPACTS_M) # Update timer and go through the list of impacts
61 changes: 61 additions & 0 deletions examples/intexp_load_and_show_testee_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pychrono as chrono
import pychrono.irrlicht as irr

from rostok import intexp

''' Testee object is dumbbell '''
obj_db = intexp.chrono_api.ChTesteeObject() # Create Chrono Testee Object
error = obj_db.createChronoBodyMeshFromFile('./examples/models/custom/body1.obj',
'./examples/models/custom/body1.xml') # create 3D mesh and parameters (grasping poses read from file)
print('Uploded mesh with code error:', error)
# Uncomment the line below for generate new poses
# obj_db.rewriteGraspingPosesList(intexp.poses_generator.genRandomPosesAroundLine(20, 0.04, 0.06, 0.015, 0.18))
obj_db.rewriteGraspingPosesList(intexp.poses_generator.genCylindricalSurfaceFromPoses(20, 0.07, 0.015, 0.18))
obj_db.showObjectWithGraspingPoses()
desired_poses = obj_db.getChronoGraspingPosesList() # List of all grasping poses
hand_power_grasp_frame = chrono.ChFrameD(chrono.ChVectorD(0, 0, 0), chrono.Q_ROTATE_Z_TO_Y) # Power grasp point in the ABS
obj_db.setChronoBodyMeshOnPose(desired_poses[0], hand_power_grasp_frame) # Position object for grasp pose into point

''' Floor added for clarity '''
floor = chrono.ChBodyEasyBox(1,0.005,1, 1000, True, False, chrono.ChMaterialSurfaceNSC())
floor.SetPos(chrono.ChVectorD(0,-0.005,0))
floor.SetBodyFixed(True)
floor.SetName('Floor')
floor.GetVisualShape(0).SetColor(chrono.ChColor(80/255, 80/255, 80/255))

''' Simulation Solver '''
system = chrono.ChSystemNSC()
system.Set_G_acc(chrono.ChVectorD(0,0,0))
system.Add(obj_db.chrono_body_mesh) # Chrono Testee Object added to simulation
system.Add(floor)
''' PyChrono Visualisation '''
vis = irr.ChVisualSystemIrrlicht()
vis.AttachSystem(system)
vis.SetWindowSize(1028,768)
vis.SetWindowTitle('Grasping positions generation example')
vis.SetSymbolScale(3)
vis.Initialize()
vis.AddLight(chrono.ChVectorD(0,10,0), 15)
vis.AddSkyBox()
vis.AddCamera(chrono.ChVectorD(1,0.5,1))
vis.EnableCollisionShapeDrawing(True)
vis.EnableBodyFrameDrawing(True)

counter = 0
i = 1

while vis.Run():
system.Update()
vis.BeginScene()
vis.Render()
vis.EndScene()
system.DoStepDynamics(1e-3)

if counter > 0.5: #Demonstration all poses every 0.5 seconds
obj_db.setChronoBodyMeshOnPose(desired_poses[i], hand_power_grasp_frame)
counter = 0
i += 1
if i >= len(desired_poses):
i = 0
else:
counter += 1e-3
5 changes: 5 additions & 0 deletions examples/models/custom/body1.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WaveFront *.mtl file (generated by Autodesk ATF)

newmtl Steel_-_Satin
Kd 0.627451 0.627451 0.627451

Loading