The simulator manages simobjects and their collisions, commands supervisors and draws the world using the supplied renderer.
The simulator runs in a separate thread. None of its functions are threadsafe, and should never be called directly from other objects (except for the functions inherited from threading.Thread). The communication with the simulator should be done through its in_queue and out_queue. See Interaction between GUI and the Simulator.
Parameters: 


A plotable is an expression that yields a numerical value. It is evaluated every cycle and the values are announced by the simulator in the plot_update signal.
The expression has access to the following variables: robot  the first robot in the scene supervisor  the supervisor of this robot math  the math module
Apply parameters to the supervisor of robot.
The parameters have to correspond to the requirements of the supervisor, as specified in supervisor.Supervisor.get_ui_description()
Center the view on the (first) robot and follow it.
If rotate is true, also follow the robot’s orientation.
Start the thread. In the beginning there’s no world, no obstacles and no robots.
The simulator will try to draw the world undependently of the simulation status, so that the commands from the UI get processed.
pySimiam loads user code dynamically. This includes robot definitions, supervisors and controllers. It is important to specify the type of the robot and its supervisor in the world XML file (see World files), and the type of a controller in supervisor.Supervisor.add_controller()
The type is specified as a single string with the format "mymodule.MyClass". It is equivalent to a python construct from mymodule import MyClass. If mymodule is omitted, like in "MyClass", the corresponding statement is from myclass import MyClass (note the lowercase module name). If there is more than one point in the string, the class name is taken to be everything after the last point.
The file mymodule.py is expected to reside in the appropriate folder: ./robots/ for robots, ./controllers/ for controllers and ./supervisors/ for supervisors.
Load a class from a module, specified by module_string.
The path is an additional path that is prepended to the module string.
E.g. C = load_by_name('mymodule.MyClass','path.to.module') is equivalent to from path.to.module.mymodule import MyClass as C.
Unload all modules loaded so far with load_by_name()
This class describes structures with arbitrary fields. It is used, e.g. for the communication between the supervisor and the UI.
Example:
p = Struct()
p.goal = Struct()
p.goal.x = 0.0
p.goal.y = 0.5
p.velocity = Struct()
p.velocity.v = 0.2
p.gains = Struct()
p.gains.kp = 10.0
p.gains.ki = 2.0
p.gains.kd = 0.0
Alternatives:
p = Struct({'goal':{'x':0.0, 'y':0.5}, 'velocity':{'v':0.2}, 'gains':{'kp':10.0, 'ki':2.0, 'kd':0.0}})
p = Struct("{'goal':{'x':0.0, 'y':0.5}, 'velocity':{'v':0.2}, 'gains':{'kp':10.0, 'ki':2.0, 'kd':0.0}}")
In the second case, the string has to be a valid JSON object. It is also impossible to use dictionaries as values in the Struct in these cases.
polygon object
polygon object
test if point x_y = (x, y) is outside, on the boundary, or inside polygon uses raytracing algorithm
returns 0 if outside returns 1 if on boundary returns 1 if inside
test if other polygon collides with self using seperating axis theorem if collision, return projections
arguments: other – a polygon object
returns: an array of projections
return distance between self and other uses GJK algorithm. for details see:
Bergen, Gino Van Den. (1999). A fast and robust GJK implementation for collision detection of convex objects. Journal of Graphics Tools 4(2).
arguments: other – a Polygon object
keyword arguments r – initial search direction; setting r to the movement vector of self  other may speed convergence
Determine contact (intersection) points between self and other.
returns Empty list if no collisions found returns List of intersection points
return the hit scalar, hit vector, and hit normal from self to other in direction r uses GJKbased raycast[1] modified to accomodate constant angular rotation[2][3] without needing to recompute the Minkowski Difference after each iteration[4].
[1] Bergen, Gino Van Den. (2004). Ray casting against general convex objects with application to continuous collision detection. GDC 2005. retrieved from http://www.bulletphysics.com/ftp/pub/test/physics/papers/ jgt04raycast.pdf on 6 July 2011.
[2] Coumans, Erwin. (2005). Continuous collision detection and physics. retrieved from http://www.continuousphysics.com/ BulletContinuousCollisionDetection.pdf on 18 January 2012
[3] Mirtich, Brian Vincent. (1996). Impulsebased dynamic simulation of rigid body systems. PhD Thesis. University of California at Berkely. retrieved from http://www.kuffner.org/james/software/dynamics/mirtich/ mirtichThesis.pdf on 18 January 2012
[4] Behar, Evan and JyhMing Lien. (2011). Dynamic Minkowski Sum of convex shapes. In proceedings of IEEE ICRA 2011. retrieved from http://masc.cs.gmu.edu/wiki/uploads/GeneralizedMsum/ icra11dynsumconvex.pdf on 18 January 2012.
arguments: other – Polygon object r – direction vector NOTE: GJK searches IN THE DIRECTION of r, thus r needs to point towards the origin with respect to the direction vector of self; in other words, if r represents the movement of self then client code should call raycast with r.
keyword arguments: s – initial position along r, (0, 0) by default theta – angular velocity in radians
returns: if r does not intersect other, returns False else, returns the hit scalar, hit vector, and hit normal hit scalar – the scalar where r intersects other hit vector – the vector where self intersects other hit normal – the edge normal at the intersection
Returns an array of the points in convex hull of P in CCW order.
arguments: P – a Polygon object or an numpy.array object of points
polygon object
returns the centroid of the polygon
test if point x_y = (x, y) is outside, on the boundary, or inside polygon uses raytracing algorithm
returns 0 if outside returns 1 if on boundary returns 1 if inside
test if other polygon collides with self using seperating axis theorem if collision, return projections
arguments: other – a polygon object
returns: an array of projections
return distance between self and other uses GJK algorithm. for details see:
Bergen, Gino Van Den. (1999). A fast and robust GJK implementation for collision detection of convex objects. Journal of Graphics Tools 4(2).
arguments: other – a Polygon object
keyword arguments r – initial search direction; setting r to the movement vector of self  other may speed convergence
return the AABB, as a pygame rect, of the polygon
Determine contact (intersection) points between self and other.
returns Empty list if no collisions found returns List of intersection points
return a new polygon moved by x, y
move the polygon by x, y
project self onto axis
return the hit scalar, hit vector, and hit normal from self to other in direction r uses GJKbased raycast[1] modified to accomodate constant angular rotation[2][3] without needing to recompute the Minkowski Difference after each iteration[4].
[1] Bergen, Gino Van Den. (2004). Ray casting against general convex objects with application to continuous collision detection. GDC 2005. retrieved from http://www.bulletphysics.com/ftp/pub/test/physics/papers/ jgt04raycast.pdf on 6 July 2011.
[2] Coumans, Erwin. (2005). Continuous collision detection and physics. retrieved from http://www.continuousphysics.com/ BulletContinuousCollisionDetection.pdf on 18 January 2012
[3] Mirtich, Brian Vincent. (1996). Impulsebased dynamic simulation of rigid body systems. PhD Thesis. University of California at Berkely. retrieved from http://www.kuffner.org/james/software/dynamics/mirtich/ mirtichThesis.pdf on 18 January 2012
[4] Behar, Evan and JyhMing Lien. (2011). Dynamic Minkowski Sum of convex shapes. In proceedings of IEEE ICRA 2011. retrieved from http://masc.cs.gmu.edu/wiki/uploads/GeneralizedMsum/ icra11dynsumconvex.pdf on 18 January 2012.
arguments: other – Polygon object r – direction vector NOTE: GJK searches IN THE DIRECTION of r, thus r needs to point towards the origin with respect to the direction vector of self; in other words, if r represents the movement of self then client code should call raycast with r.
keyword arguments: s – initial position along r, (0, 0) by default theta – angular velocity in radians
returns: if r does not intersect other, returns False else, returns the hit scalar, hit vector, and hit normal hit scalar – the scalar where r intersects other hit vector – the vector where self intersects other hit normal – the edge normal at the intersection
return an array of vectors of edges rotated theta radians
returns an array of points rotated theta radians around the centroid
The Rect class is used for storing and manipulating rectangular areas.
It has left, bottom, width and height attributes, which are automatically changed by assignment to the right, top, topleft, topright, bottomleft, bottomright or center properties.
Rects can be added to greater a greater containing rectangle, or a Rect.union classmethod is available to sum a list of Rect objects.
The collidepoint and intersects methods are used for collision testing.
Eg: >> Rect((0,0,10,10)).collidepoint((2,2)) >> True >> Rect((0,0,10,10)).collidepoint((20,20)) >> False
This Rect class is different to the Pygame Rect class, in that is stores coordinates internally as floats, and uses a lefthanded coordinate system.
The Rect class is used for storing and manipulating rectangular areas.
It has left, bottom, width and height attributes, which are automatically changed by assignment to the right, top, topleft, topright, bottomleft, bottomright or center properties.
Rects can be added to greater a greater containing rectangle, or a Rect.union classmethod is available to sum a list of Rect objects.
The collidepoint and intersects methods are used for collision testing.
Eg: >> Rect((0,0,10,10)).collidepoint((2,2)) >> True >> Rect((0,0,10,10)).collidepoint((20,20)) >> False
This Rect class is different to the Pygame Rect class, in that is stores coordinates internally as floats, and uses a lefthanded coordinate system.
Add another rect to this rect, expanding as needed.
Test if a point intersects with this rect.
Return True if other contains self
Return the intersection of this rect and other rect. Return None if no intersection.
Test if a rect intersects with this rect.
Return a rect which covers all rects in others.
QuadTree data structure of simulated objects
QuadTree data structure of simulated objects
Returns the items that overlap a bounding rectangle.
Returns the set of all items in the quadtree that overlap with a bounding rectangle.
Insert a list of SimObject items