soar.sim.world

Soar World and WorldObject classes/subclasses, for simulating and drawing worlds.

class soar.sim.world.Block(p1, p2, thickness=0.002, **options)

Bases: soar.sim.world.Polygon

An arbitrarily thick wall centered on a line.

Useful when infinitely-thin lines are causing issues with collision detection.

Parameters:
  • p1 – An (x, y) tuple or soar.sim.geometry.Point as the first endpoint of the line segment.
  • p1 – An (x, y) tuple or soar.sim.geometry.Point as the second endpoint of the line segment.
  • thickness (float) – The thickness of the block to expand out from the line on which it is centered.
  • **options – Tkinter options.
borders
draw(canvas)

Draw the object on a canvas.

Parameters:canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
class soar.sim.world.Polygon(points, center=None, **options)

Bases: soar.sim.geometry.PointCollection, soar.sim.world.WorldObject

A movable polygon with Tkinter options.

Parameters:
borders
collision(other, eps=1e-08)

Determine whether the polygon intersects with another WorldObject.

Parameters:
  • other – Either a Polygon or a Wall as the other object.
  • eps (float, optional) – The epsilon within which to consider a collision to have occurred.
draw(canvas)

Draw the object on a canvas.

Parameters:canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
class soar.sim.world.Ray(pose, length, eps=1e-08, **options)

Bases: soar.sim.world.Wall

A ray of a specified length, origin and direction.

Parameters:
  • pose – An (x, y, theta) tuple or soar.sim.geometry.Pose as the origin of the ray.
  • length (float) – The length of the ray.
  • **options – Tkinter options.
class soar.sim.world.Wall(p1, p2, eps=1e-08, **options)

Bases: soar.sim.world.WorldObject, soar.sim.geometry.LineSegment

A straight wall with Tk options and collision detection.

Note that these walls are infinitely thin, so on-edge collision cannot occur.

Parameters:
  • p1 – An (x, y) tuple or a soar.sim.geometry.Point as the first endpoint of the wall.
  • p1 – An (x, y) tuple or a soar.sim.geometry.Point as the second endpoint of the wall.
  • eps (float) – The epsilon within which to consider a wall vertical or horizontal.
  • **options – Tkinter options.
collision(other, eps=1e-08)

Determine whether two walls intersect.

Parameters:
  • other – A Wall, or other LineSegment subclass.
  • eps (float) – The epsilon within which to consider two parallel lines the same line.
Returns:

A list of (x, y) tuples consisting of the intersection(s), or None if the segments do not intersect.

draw(canvas)

Draw the object on a canvas.

Parameters:canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
class soar.sim.world.World(dimensions, initial_position, objects=None)

Bases: object

A simulated world containing objects that can be simulated stepwise and drawn on a soar.gui.canvas.SoarCanvas.

dimensions

tuple – An (x, y) tuple representing the worlds length and height.

initial_position

An (x, y, theta) or soar.sim.geometry.Pose representing the robot’s initial position in the world.

objects

list – A list of (WorldObject, layer) tuples containing all of the world’s objects.

layer_max

int – The highest layer currently allocated to an object in the world.

canvas

An instance of soar.gui.canvas.SoarCanvas, if the world is being drawn, otherwise None.

Parameters:
  • dimensions (tuple) – An (x, y) tuple representing the worlds length and height.
  • initial_position – An (x, y, theta) or soar.sim.geometry.Pose representing the robot’s initial position in the world.
  • objects (list) – The initial WorldObject (s) to add to the world
add(obj, layer=None)

Add an object to the world, with an optional layer specification.

Parameters:
  • obj – A WorldObject (or a subclass instance).
  • layer (int) – The layer on which the object is to be drawn. Objects are drawn in order from smallest to largest layer. If this argument is None, the object’s layer will be set to one higher than the highest layer in the objects list.
delete(canvas)

Delete the world from a canvas, by deleting each object at a time.

Parameters:canvas – The soar.gui.canvas.SoarCanvas from which to delete.
draw(canvas)

Draw the world on a canvas.

Objects are drawn in order from the lowest to highest layer if their do_draw attribute is True.

Parameters:canvas – The soar.gui.canvas.SoarCanvas on which to draw the world. How each object is drawn is up to the object.
find_all_collisions(obj, eps=1e-08, condition=None)

Finds all the collisions of a WorldObject subclass with objects in the world.

Parameters:
  • obj – A WorldObject or subclass instance. Objects in the world must know how to collide with it.
  • eps (float, optional) – An optional epsilon within which to consider a collision to have occurred. What that means differs between WorldObject subclasses.
  • condition (optional) – A function to apply to each object in the world that must be True in order for it to be considered.
Returns:

A list of (world_obj, p) tuples, where world_obj is the object that collided and p is the soar.sim.geometry.Point at which the collision occurred. If multiple collision points occurred with the same object, each will be listed separately. If no collisions occurred, returns None.

Return type:

list

on_step(step_duration)

Perform a single step on the world’s objects.

Parameters:step_duration (float) – The duration of the step in seconds.
class soar.sim.world.WorldObject(do_draw, do_step, dummy=False, **options)

Bases: object

An object that can be simulated and drawn in a soar.sim.world.World on a soar.gui.canvas.SoarCanvas.

Classes that are designed to work with a World in Soar may either subclass from this class or implement its methods and attributes to be considered valid.

do_draw

bool – Used by a World to decide whether to draw the object on a canvas.

do_step

bool – Used by a World to decide whether to step the object in simulation.

Parameters:
  • do_draw (bool) – Sets the value of the do_draw attribute.
  • do_step (bool) – Sets the value of the do_step attribute.
  • dummy (bool) – Whether the object is a dummy–that is, not intended to be drawn or stepped, but used for some intermediate calcuation (usually collision).
  • **options – Tkinter options. This may include ‘tags’, for drawing on a canvas, line thickness, etc.
collision(other, eps=1e-08)

Determine whether two WorldObject (s) collide.

Objects that subclass WorldObject should implement collision detection for every applicable class from which they inherit.

Parameters:
  • other – A supported WorldObject subclass with which this object could potentially collide.
  • eps (float, optional) – The epsilon within which to consider a collision to have occurred, different for each subclass.
Returns:

A list of (x, y) tuples consisting of all the collision points with other, or None if there weren’t any.

Return type:

list

delete(canvas)

Delete the object from a canvas.

Parameters:canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, from which the object will be deleted.
draw(canvas)

Draw the object on a canvas.

Parameters:canvas – A Tkinter Canvas or a subclass, typically a soar.gui.canvas.SoarCanvas, on which the object will be drawn.
on_step(step_duration)

Simulate the object for a step of a specified duration.

Parameters:step_duration – The duration of the step, in seconds.