GraspSimulation

The GraspSimulation module runs batch simulations of hands grasping objects. It uses Klamp’t to control the physics simulation.

class GraspSimulation.GraspSimulation(self, batchSim, files=[PATH_TO_WORLD_FILE])

GraspSimulation is the core framework of the simulator. It interfaces with the Design and HandController modules to simulate hands grasping objects.

The constructor loads the world and sets up the hand and grasp objects before beginning the batch simulation.

Note: control_loop(), display(), motionfunc(), and mousefunc() will be called in every simulation step.

Parameters:
  • batchSim (GraspSimulation.BatchSim) – The batch of simulations to simulate.
  • files (list[str]) – The Klamp’t world files to use for the simulation.
control_loop()

Continually updates the simulation and resets the simulation when it is over. The Klamp’t simulation is managed here.

reinitSim()

Reinitialize the simulation with the next design and control parameters from the GraspSimulation.BatchSim.

display()

Draws the simulation and displays information on the screen using OpenGL.

mousefunc(button, state, x, y)

Acts upon mouse clicks. Currently only prints mouse events and passes mouse clicks to Klamp’t.

Parameters:
  • button (int) – The number of the mouse button whose state changed. 0 is the left button, 1 is the right, and 2 is the middle button.
  • state (in) – The number for the new state of the button. 0 for released, 1 for pressed.
  • x (int) – The X-coordinate of the mouse.
  • y (int) – The Y-coordinate of the mouse.
motionfunc(x, y, dx, dy)

Acts upon mouse movements. Rotates the world with click and drag, pans with with ctrl click and drag, and zooms with shift click and drag. All events are passed to Klamp’t.

Parameters:
  • x (int) – The X-coordinate of the mouse.
  • y (int) – The Y-coordinate of the mouse.
  • dx (int) – The distance the mouse moved along the X-axis.
  • dy (int) – The distance the mouse moved along the Y-ayis.
class GraspSimulation.GraspStateMachine(graspTorque=1)

The state machine framework for simulation logic in a single run of simulation. runStateMachine() contains all of the grasp logic. This class also contains a grasp logic example: measuring the maximum pullout force of a grasp.

Parameters:graspTorque (int) – The amount of torque to apply while grasping.
runStateMachine(currentTime, handController, graspObject)

Runs the state machine by one step and manages which state the simulation is in. You should override this with your own state machine code.

Parameters:
enterState(newState)

Change to a new state and verify that the new state exists.

Parameters:newState (str) – The new state to enter.
objHasEscaped(objPos)

Helper function to query if the object has escaped from the hand.

Parameters:objPos (list[float]) – The position of the Design.GraspObject in 3D space.
objIsStill(objAnguVel, objTranVel)

Helper function to query if the object becomes still.

Parameters:
  • objAnguVel (numpy.array[float]) – The angular velocity of the Design.GraspObject in vector form.
  • objTranVel (numpy.array[float]) – The transverse velocity of the Design.GraspObject in vector form.
objIsMoving(objAnguVel, objTranVel)

Helper function to query if the object starts to move.

Parameters:
  • objAnguVel (numpy.array[float]) – The angular velocity of the Design.GraspObject in vector form.
  • objTranVel (numpy.array[float]) – The transverse velocity of the Design.GraspObject in vector form.
class GraspSimulation.BatchSim(autoStart=True, logFileName='logFile_default.txt')

Framework for runing batch simulation. This class provides an interface for interacting with GraspSimulation for batch simulations.

Note: if autoStart is set to False, you will need to press “S” at each simulation to start

Parameters:
  • autoStart (bool) – Whether or not to start the simulation automatically after Klamp’t is finished loading.
  • logFileName (str) – The file to output the simulation data to.
importNewSim()

This function will be called by the GraspSimulation when a simulation is finished. Refresh your simulation parameters here according to the self.iterNum. You should override this to generate your own simulations.

deleteOldSim()

Delete all of the objects and the state machine from the previous simulation.

endBatchSim()

Save the log and end the simulation.

Previous topic

HandController

This Page