obstacle - Obstacle and robot definition

class gym_ultrasonic.envs.obstacle.Obstacle(position, width, height, angle=0)[source]

Bases: object

A static rectangular obstacle.

property polygon
Returns
Polygon

Minimum rotated bounding box polygon.

get_polygon_parallel_coords(self)[source]
Returns
np.ndarray

Clock-wise vertices of the bounding box polygon, parallel to the world axes.

set_position(self, position)[source]

Sets the object global position.

Parameters
position: List[float]

Obstacle center position in world coordinates, (x, y).

extra_repr(self)[source]
class gym_ultrasonic.envs.obstacle.Servo(width, height, sonar_direction_angles=(0, ), angle_range=(-0.5235987755982988, 0.5235987755982988), angular_vel=0)[source]

Bases: gym_ultrasonic.envs.obstacle.Obstacle

Servo that holds sonar(s) on board. Servo has only one function - rotate the sonar(s).

property sonar_angles_world
rotate(self, sim_time=None, angle_turn=None)[source]

Rotates the servo.

Parameters
sim_time: float

Simulation time step, sec.

angle_turn: float

Angle to rotate the servo. If set to None, it’s calculated by the time spent, multiplied by the angular velocity.

reset(self)[source]

Resets the servo.

extra_repr(self)[source]
class gym_ultrasonic.envs.obstacle.Robot(width, height, sonar_direction_angles=(0, ), sensor_max_dist=2000)[source]

Bases: gym_ultrasonic.envs.obstacle.Obstacle

Robot with a mounted servo and ultrasonic range sensor.

property servo_shift
Returns
float

Shift of the servo along robot’s main axis, mm

property n_sonars
Returns
int

Num. of sonars on board.

move_forward(self, move_step)[source]
Parameters
move_step: float

Move step, mm.

diffdrive(self, vel_left, vel_right, sim_time)[source]

Differential drive. Adapted from http://ais.informatik.uni-freiburg.de/teaching/ss17/robotics/exercises/solutions/03/sheet03sol.pdf

Parameters
vel_left: float

Left wheel tangential speed, mm / sec.

vel_right: float

Right wheel tangential speed, mm / sec.

sim_time: float

Simulation time step, sec.

Returns
move_step: float

Performed move step in mm along robot’s main axis.

angle_rotate: float

Performed rotation in radians.

trajectory: LineString

Trajectory of this step.

turn(self, angle_step)[source]
Parameters
angle_step: float

CCW angle turn in radians.

collision(self, obj)[source]
Parameters
obj: Obstacle or List[Obstacle]

An obstacle(s) to check for a collision.

Returns
bool

If robot’s minimum rotated bounding box collides with an obstacle(s).

property direction_vector
Returns
np.ndarray

Robot’s direction vector, (x, y)

property servo_position
Returns
np.ndarray

World coordinates of Servo with embedded Ultrasonic sensor, (x, y)

ray_cast(self, obstacles)[source]

Casts a ray along servo sensor direction and checks if there an intersection with obstacles. Simulates Ultrasonic range sonar, mounted on top of the servo, in a real robot.

Parameters
obstacles: List[Obstacle]

List of obstacles in the scene.

Returns
min_dist: List[float]

Min dist to an obstacle. If no obstacle is found at the ray intersection, max_dist is returned.

intersection_xy: List[np.ndarray]

X and Y of the intersection point with an obstacle.

reset(self, box)[source]

Sets the current position to a random point from a box.

Parameters
box: Box

Allowed box space to sample a point from.

extra_repr(self)[source]