robot module

This module contains a class representing the robot.

class robot.IDPRobot

Bases: controller.Robot

Class representing the robot

compass

The compass

Type

IDPCompass

gps

The GPS

Type

IDPGPS

motors

The two motors

Type

IDPMotorController

default_target_bearing_threshold

Threshold determining whether the target bearing is reached

Type

float

default_target_distance_threshold

Threshold determining whether the target coordinate is reached

Type

float

timestep

Time step of the current world

Type

float

ultrasonic_left

The ultrasonic sensor on the left

Type

IDPDistanceSensor

ultrasonic_right

The ultrasonic sensor on the right

Type

IDPDistanceSensor

infrared

The IR sensor (long range)

Type

IDPDistanceSensor

color_detector

The colour detector, containing two light sensors with red and green filters

Type

IDPColorDetector

angle_from_bot_from_bearing(bearing: float)float

The clockwise angle from the direction our bot is facing to the bearing in radians

Parameters

bearing (float) – Bearing from north

Returns

Angle measured clockwise from direction bot is facing, [-pi, pi]

Return type

float

angle_from_bot_from_position(position: list)float

The clockwise angle from the direction our bot is facing to the position in radians

Parameters

position ([float, float]) – Positions co-ordinates, East-North, m

Returns

Angle measured clockwise from direction bot is facing, [-pi, pi]

Return type

float

property angular_velocity

The current angular velocity of the robot measured by bearings

Returns

Angular velocity, rad/s

Return type

float

property bearing

The current bearing of the robot in radians

Returns

Bearing measured clockwise from North, [0, 2pi]

Return type

float

brake()
check_target_valid(target: Optional[modules.targeting.Target])bool
collect_block()bool

Collect block at the best position possible

Returns

If the collect action is completed

Return type

bool

coordtransform_bot_cartesian_to_world(vec: numpy.ndarray)numpy.ndarray

Transform a position vector of a point in the robot frame (relative to the robot center) to the absolute position vector of that point in the world frame

Parameters

vec (np.ndarray) – A vector relative to the centre of the robot

Returns

The absolute position vector of the point in the world frame

Return type

np.ndarray

coordtransform_bot_polar_to_world(distance: float, angle: float)numpy.ndarray

Given a distance and angle from our bot, return the objects position

Parameters
  • distance (float) – Distance to object in m

  • angle (float) – Angle from bot to object in rads

Returns

Positions co-ordinates, East-North, m

Return type

[float, float]

distance_from_bot(position)float

The Euclidean distance between the bot and a position

Parameters

position ([float, float]) – Positions co-ordinates, East-North, m

Returns

Distance between bot and target in metres

Return type

float

do(*args)

Small wrapper to make telling robot to do something a little cleaner

drive_to_position(target_pos: Union[list, numpy.ndarray], max_forward_speed=None, max_rotation_rate=None, reverse=False, passive_collision_avoidance=True, accuracy_threshold=None)bool

Go to a position

Parameters
  • target_pos ([float, float]) – The East-North co-ords of the target position

  • max_forward_speed (float) – Maximum speed to travel at m/s

  • max_rotation_rate (float) – Maximum rate to rotate at, rad/s

  • reverse (bool) – Whether to reverse there

  • passive_collision_avoidance (bool) – Whether to try and avoid the other bot and known blocks

  • accuracy_threshold (float) – Threshold determining whether the target coordinate is reached

Returns

If we are at our target

Return type

bool

execute_next_action()bool

Execute the next action in self.action_queue

When each action is completed it’s removed from the list. Using list mutability this allows us to alter / check the action list elsewhere in the code to see the bots progress and also change its objectives. If people have better ideas on how to do this I’m all ears. Execute_action was only ever supposed to be about motion

Returns

Whether action list is completed or not

Return type

bool

face_bearing(target_bearing: float)bool

Face a given bearing

Parameters

target_bearing (float) – Desired bearing of our robot

Returns

If we are at our target

Return type

bool

filter_targets(targets: list)list

Filter a given list of targets, returns targets the robot can drive to without hitting other targets or the other robot on the way.

Parameters

targets ([Target]) – List of targets

Returns

Filtered list of targets

Return type

[Target]

getDevice(name: str)
getTime()

This function is used by PIDs to see what the current robot time is for accurate data recording

get_best_target()Optional[modules.targeting.Target]

Decide on a new target block for robot, which is the cloest valid target on the way to which there won’t involve any collision

Returns

Targets co-ordinates, East-North, m

Return type

[float, float]

get_bot_front(distance: float)numpy.ndarray

Get the coordinates of a point a certain distance in front of the center of the robot

Parameters

distance (float) – Distance in front of the center

Returns

The coordinate

Return type

np.ndarray

get_bot_vertices()list

Get the coordinates of vertices of the bot in world frame (i.e. in meters)

The robot is assumed to be a rectangle.

Returns

List of coordinates

Return type

[np.ndarray]

get_imminent_collision()Optional[tuple]
get_min_distance_bot_to_bot(other_bot_vertices: list)float

Get the minimum distances between two robots

Parameters
  • other_bot_vertices ([np.ndarray]) – List of vertices of the other robot, needs to be specified in

  • clockwise order (a) –

Returns

The minimum distance between the two robots

Return type

float

get_min_distance_point_to_bot(position: Union[list, numpy.ndarray])float

Get the minimum distance between a point and the bounding box of the robot

Parameters

position (list, np.ndarray) – The coordinate of the point

Returns

The minimum distance

Return type

float

get_min_distance_vertex_to_wall()

Get the minimum distance from any of the vertices of the robot to the wall

Returns

The minimum distance

Return type

float

get_sensor_distance_to_wall()

Get the distance the sensor should measure if there is nothing between it and the wall

Note that the sensor is assumed to be at the centre of the robot.

Returns

The distance

Return type

float

hold(time=None)
property linear_speed

The current speed of the robot measured by the GPS

Returns

Current speed (ms^-1)

Return type

float

plot_all_graphs()
plot_motion_history()
property position

The current position of the robot

Returns

Position (East, North) in meters

Return type

[float, float]

reset_action_variables()

Cleanup method to be called when the current action changes. If executing bot commands manually (i.e. robot.drive_to_position), call this first.

reverse_to_position(target_pos: Union[list, numpy.ndarray])bool

Go to a position in reverse

Parameters

target_pos ([float, float]) – The East-North co-ords of the target position

Returns

If we are at our target

Return type

bool

rotate(angle: float, max_rotation_rate=None, accuracy_threshold=None)bool

Rotate the bot a fixed angle at a fixed rate of rotation

Parameters
  • angle (float) – Angle to rotate in radians, positive is clockwise

  • max_rotation_rate (float) – Maximum rate to rotate at, rad/s

  • accuracy_threshold (float) – Threshold determining whether the target angle is reached

Returns

If we completed rotation

Return type

bool

scan()bool

Rotate 360 degrees to scan for blocks

Returns

Whether the scan is completed

Return type

bool

step(timestep)

A wrapper for the step call that allows us to keep our last bearing and keep track of time. Furthermore, tasks that needs to be ran every timestep are also put here.

update_motion_history(**kwargs)
class robot.IDPRobotState(value)

Bases: enum.Enum

An enumeration.

COLLECTING_TARGET = 6
CORRECT_COLOUR = 5
DETECTING_COLOUR = 3
DRIVING_TO_TARGET = 0
FACING_TARGET = 2
GET_TO_COLLECT_DISTANCE_FROM_BLOCK = 4
ROTATE_TO_FACE_TARGET = 1
TARGET_COLLECTED = 7