SimObject

Pose

class pose.Pose(*args, **kwargs)[source]

The pose class allows for a posing of objects in 2D space. The pose uses a right-hand coordinate system with counter-clockwise measurement of theta from the x-axis

There are several ways to create a pose:

Pose(x,y,theta) A pose at x,y and orientation theta
Pose(x,y) Same as Pose(x,y,0)
Pose() Same as Pose(0,0,0)
Pose([x,y,theta]) Same as Pose(x,y,theta)

There are several ways to access pose parameters:

x, y, theta = pose
x, y, theta = pose.get_list()
x = pose.x; y = pose.y; theta = pose.theta
get_list()[source]

Get the pose as a list [x, y, theta]. Equivalent to list(pose).

get_transformation()[source]

Get the 3x3 transformation matrix associated with the pose.

iscloseto(other, epsilon)[source]

Compare this pose to other. Returns True if the relative distance in x, y and theta is smaller than epsilon

set_pose(*args, **kwargs)[source]

Set all or some pose parameters.

Possible arguments are:

set_pose(x, y, theta) Set all of x, y and theta
set_pose(another_pose) Use x, y and theta from another pose
set_pose(x = 3.0) Only change the x position
set_pose(theta = pi, y = 3.0) Only change the y position and orientation
set_pose(another_pose, y = 1) Use x and theta from another pose, use y=1

SimObject and simple shapes

class simobject.SimObject(pose, color=0)[source]

The base class for all objects that can be drawn in the simulator. Every SimObject has a pose, an envelope and a color.

Parameters:
  • pose (Pose) – The position of the object.
  • color (int) – The internal color of the object (0xAARRGGBB or 0xRRGGBB). The default color is black.
get_color()[source]

Get the internal color of the object

set_color(color)[source]

Set the internal color of the object

get_pose()[source]

Get the pose of the object in world coordinates

set_pose(pose)[source]

Set the pose of the object in world coordinates

draw(renderer)[source]

Draws the object using renderer (see Renderer).

The object doesn’t have to use only one color. It doesn’t even have to use its internal color while drawing.

get_envelope()[source]

Get the envelope of the object in object’s local coordinates.

The envelope is a list of xy pairs, describing the shape of the bounding polygon.

get_world_envelope(recalculate=False)[source]

Get the envelope of the object in world coordinates. Used for checking collision.

The envelope is cached, and will be recalculated if recalculate is True.

get_bounding_rect()[source]

Get the smallest rectangle that contains the object as a tuple (x, y, width, height).

has_collision(other)[source]

Check if the object has collided with other. Return True or False

get_contact_points(other)[source]

Get a list of contact points with other object. Returns a list of (x, y)

get_bounds()[source]

Get the smallest rectangle that contains the object as a tuple (xmin, ymin, xmax, ymax)

class simobject.Polygon(pose, shape, color)[source]

The polygon is a simobject that gets the envelope supplied at construction. It draws itself as a filled polygon.

Parameters:
  • pose (Pose) – The position of the polygon.
  • shape (list((int,int))) – The list of points making up the polygon.
  • color (int) – The color of the polygon (0xAARRGGBB or 0xRRGGBB).
draw(r)[source]

Draw the envelope (shape) filling it with the internal color.

class simobject.Cloud(color)

The cloud is a collection of points.

add_point(pose)

Append a point at pose to the collection. The orientation of the pose is ignored

draw(r)

Draw a polyline with modes at all added points, using the internal color

class simobject.Path(start, color)[source]

The path is a simobject that draws itself as a polyline. The line starts at start, and can be continued by adding points using add_point().

Parameters:
  • start (Pose) – The starting point of the polyline in world coordinates.
  • color (int) – The color of the line (0xAARRGGBB or 0xRRGGBB).

The path is used by the simulator to track the history of robot motion

reset(start)[source]

Set the start point to start.x and start.y and remove all other points

draw(r)[source]

Draw a polyline with modes at all added points, using the internal color

Table Of Contents

Previous topic

Simulator

Next topic

Robots and the world

This Page