API Documentation

PutObjectInBox Simulator

class simulators.sim_discrete.Item(*values)[source]

Bases: Enum

Types of objects.

class simulators.sim_discrete.LTMSim(*args: Any, **kwargs: Any)[source]

Bases: Node

ObjectInBox simulator class.

ask_nicely_policy()[source]

Ask someone to bring the object closer to the robot.

avoid_reward_by_chance(distance, angle)[source]

Avoid a reward situation obtained by chance. This is necessary so sweep never puts the object close to the robot or colliding with a box.

Parameters:
  • distance (float) – The distance to the object.

  • angle (float) – The angle to the object.

Returns:

The distance value to avoid the reward.

Return type:

float

ball_and_box_on_the_same_side()[source]

Check if an object and a box are on the same side.

Returns:

A value that indicates if the object is in the same side or not.

Return type:

bool

calculate_closest_position(ang)[source]

Calculate the closest feasible position for an object taking into account the angle.

Parameters:

ang (float) – The angle to the object.

Returns:

The closest distance and angle.

Return type:

tuple

calculate_closest_position_callback(request, response)[source]

The callback to calculate the closest feasible position with a given object angle.

Parameters:
  • request (simulators_interfaces.srv.CalculateClosestPosition.Request) – The Request that includes the angle to the object.

  • response (simulators_interfaces.srv.CalculateClosestPosition.Response) – The Response that includes the closest distance and angle.

Returns:

The Response that includes the closest distance and angle.

Return type:

simulators_interfaces.srv.CalculateClosestPosition.Response

change_hands_policy()[source]

Exchange an object from one hand to the other one.

check_object_pickable()[source]

Check if an object is within the robot’s reachable area.

Returns:

A value that indicates if the object can be moved or not.

Return type:

bool

check_object_pickable_with_two_hands()[source]

Check if an object can be hold with two hands.

Returns:

A value that indicates if the object can be hold or not.

Return type:

bool

grasp_object_policy()[source]

Grasp an object with a gripper.

grasp_with_two_hands_policy()[source]

Grasp an object using both arms.

load_configuration()[source]

Load configuration from a file.

load_experiment_file_in_commander()[source]

Load the configuration file in the commander node.

Returns:

Response from the commander node indicating the success of the loading.

Return type:

core_interfaces.srv.LoadConfig.Response

new_action_callback(data)[source]

Execute a policy and publish new perceptions.

Parameters:

data (ROS msg defined in the config file.) – The message that contains the policy to execute.

new_action_service_callback(request, response)[source]

Execute a policy and publish new perceptions.

Parameters:
  • request (ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.Policy.Request) – The message that contains the policy to execute.

  • response (ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.Policy.Response) – Response of the success of the execution of the action.

Returns:

Response indicating the success of the action execution.

Return type:

ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.Policy.Response

new_command_callback(data)[source]

Process a command received.

Parameters:

data (ROS msg defined in the config file. Typically cognitive_processes_interfaces.msg.ControlMsg) – The message that contais the command received.

object_held()[source]

Check if an object is held with one hand.

Returns:

A value that indicates if the object is held or not.

Return type:

bool

object_held_with_left_hand()[source]

Check if an object is held with the left hand.

Returns:

A value that indicates if the object is held or not.

Return type:

bool

object_held_with_right_hand()[source]

Check if an object is held with the right hand.

Returns:

A value that indicates if the object is held or not.

Return type:

bool

object_held_with_two_hands()[source]

Check if an object is held with two hands.

Returns:

A value that indicates if the object is held or not

Return type:

bool

object_in_close_box(dist, ang)[source]

Check if there is an object inside of a box.

Parameters:
  • dist (float) – The distance to the object.

  • ang (float) – The angle to the object.

Returns:

The value that indicates if the object is inside of the box or not.

Return type:

bool

object_in_far_box(dist, ang)[source]

Check if there is an object inside of a box.

Parameters:
  • dist (float) – The distance to the object.

  • ang (float) – The angle to the object.

Returns:

The value that indicates if the object is inside of the box or not.

Return type:

bool

static object_is_small(rad)[source]

Return True if the ball is small, False if it is big. Right now, small is 0.03 and big 0.07.

Parameters:

rad (float) – Radius of the ball.

Returns:

The value that indicates if the ball is small or not.

Return type:

bool

static object_outside_table(dist, ang)[source]

Return True if the object is outside the table. This is used in some scripts…

Parameters:
  • dist (float) – The distance to the object.

  • ang (float) – The angle to the object.

Returns:

Value that indicates if the object is outside of the table or not.

Return type:

bool

object_pickable()[source]

Check if an object is in a place where it can be picked.

Returns:

A value that indicates if the object is in a place where it can be picked or not.

Return type:

bool

static object_pickable_with_two_hands(dist, ang)[source]

Return True if the object is in a place where it can be picked with two hands.

Parameters:
  • dist (float) – The distance to the object.

  • ang (float) – The angle to the object.

Returns:

Value that indicates if the object is pickable or not.

Return type:

bool

object_pickable_with_two_hands_callback(request, response)[source]

The callback to calculate if an object can be pickable with two hands.

Parameters:
  • request (simulators_interfaces.srv.ObjectPickableWithTwoHands.Request) – The Request that includes the distance and angle to the object.

  • response (simulators_interfaces.srv.ObjectPickableWithTwoHands.Response) – The Response that indicates if the object is pickable or not.

Returns:

The Response that indicates if the object is pickable or not.

Return type:

simulators_interfaces.srv.ObjectPickableWithTwoHands.Response

object_too_close(dist, ang)[source]

Return True if the object is too close to the robot to be caught.

Parameters:
  • dist (float) – The distance to the object.

  • ang (float) – The angle to the object.

Returns:

Value that indicates if the object is too close or not.

Return type:

bool

object_too_far(dist, ang)[source]

Return True if the object is out of range of the robot.

Parameters:
  • dist (float) – The distance to the object.

  • ang (float) – The angle to the object.

Returns:

Value that indicates if the object is out of range or not.

Return type:

bool

object_too_far_callback(request, response)[source]

The callback to calculate if and object is out of range of the robot.

Parameters:
  • request (simulators_interfaces.srv.ObjectTooFar.Request) – The Request that includes the distance and angle to the object.

  • response (simulators_interfaces.srv.ObjectTooFar.Response) – The Response that indicates if the object if out of the range or not.

Returns:

The Response that indicates if the object if out of the range or not.

Return type:

simulators_interfaces.srv.ObjectTooFar.Response

object_with_robot(dist, ang)[source]

Check if there is an object adjacent to the robot.

Parameters:
  • dist (float) – The distance to the object.

  • ang (float) – The angle to the object.

Returns:

The value that indicates if the object is adjacent or not.

Return type:

bool

publish_perceptions()[source]

Publish the current perceptions to the corresponding topics.

put_object_in_box_policy()[source]

Put an object into the box.

put_object_with_robot_policy()[source]

Put an object as close to the robot as possible.

random_perceptions()[source]

Randomize the state of the environment. This method is called when the world is initialized or reset.

random_position(in_valid=True, out_valid=True)[source]

Return a random position in the table.

Parameters:
  • in_valid (bool) – True if the position can be generated close to the robot.

  • out_valid (bool) – True if the position can be generated away to the robot.

Returns:

The distance and angle to the random position generated.

Return type:

tuple

reset_world(data)[source]

Reset the world to a random state.

Parameters:

data (ROS msg defined in the config file. Typically cognitive_processes_interfaces.msg.ControlMsg or cognitive_processes_interfaces.srv.WorldReset.Request) – The message that contains the command to reset the world. It is not used.

reward_ball_in_box()[source]

Reward for object in box goal.

Returns:

True if there is reward or False if not.

Return type:

bool

reward_ball_in_box_goal()[source]

Gives a reward of 1.0 if the ball is in the box.

reward_ball_with_robot()[source]

Gives a reward for object with robot goal.

Returns:

True if there is reward or False if not

Return type:

bool

reward_clean_area()[source]

Gives a reward for cleaning the table goal.

Returns:

True if there is reward or False if not

Return type:

bool

reward_progress_ball_in_box()[source]

Gives a larger reward the closer the robot is to the goal of putting the ball in the box. If the ball is in the box, the reward is 1.0.

send_object_outofreach(ang)[source]

Calculate the coordinates of the object when moving it out of reach.

Parameters:

ang (float) – The angle to the object.

Returns:

The calculated coordinates.

Return type:

tuple

static send_object_twohandsreachable(dist)[source]

Calculate the coordinates of the object when moving it to a place where it can be picked with two hands.

Parameters:

dist (float) – The distance to the object.

Returns:

The calculated coordinates.

Return type:

tuple

setup_control_channel(simulation)[source]

Configure the ROS topic/service where listen for commands to be executed.

Parameters:

simulation (dict) – The params from the config file to setup the control channel.

setup_perceptions(perceptions)[source]

Configure the ROS publishers where publish perception values.

Parameters:

perceptions (dict) – The params from the config file to setup the perceptions.

sweep_object_policy()[source]

Sweep an object to the front of the robot.

throw_policy()[source]

Throw an object towards a box.

update_reward_sensor()[source]

Update goal sensors’ values.

world_reset_service_callback(request, response)[source]

Callback for the world reset service.

Parameters:
  • request (ROS msg defined in the config file Typically cognitive_processes_interfaces.srv.WorldReset.Request) – The message that contains the request to reset the world.

  • response (ROS msg defined in the config file. Typically cognitive_processes_interfaces.srv.WorldReset.Response) – Response of the world reset service.

Returns:

Response indicating the success of the world reset.

Return type:

ROS msg defined in the config file. Typically cognitive_processes_interfaces.srv.WorldReset.Response

class simulators.sim_discrete.World(*values)[source]

Bases: Enum

Worlds to be simulated.

FruitShop Simulator

class simulators.fruit_shop_sim_discrete.FruitShopSim(*args: Any, **kwargs: Any)[source]

Bases: Node

FruitShopSim simulator class.

accept_fruit_policy()[source]

Put the fruit into the accepted fruit box if the fruit is valid.

ask_nicely_policy()[source]

Ask the experimenter to provide more fruits if there are none available.

change_hands_policy()[source]

Change the fruit from one gripper to the other if the fruit is small enough.

discard_fruit_policy()[source]

Put the fruit into the discarded fruit box if the fruit is not valid.

fruit_in_placed_pos()[source]

Check if the fruit is in the center of the table.

Returns:

True if the fruit is in the center of the table, False otherwise.

Return type:

bool

generate_fruits(n_fruits, scale=None)[source]

Generate a number of fruits with random positions and dimensions.

Parameters:
  • n_fruits (int) – Number of fruits to generate.

  • scale (simulators_interfaces.msg.ScaleListMsg or NoneType) – If it is None, fruit will only be generated in the collection area. Otherwise, fruits could be generated anywhere.

load_configuration()[source]

Load the configuration file and setup the simulator. It is configured the random number generator, the stages of the experiment, the perceptions, and the control channel.

load_experiment_file_in_commander()[source]

Load the configuration file in the commander node.

Returns:

Response from the commander node indicating the success of the loading.

Return type:

core_interfaces.srv.LoadConfig.Response

new_action_service_callback(request, response)[source]

Execute a policy and publish new perceptions.

Parameters:
  • request (ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.Policy.Request) – The message that contains the policy to execute.

  • response (ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.Policy.Response) – Response of the success of the execution of the action.

Returns:

Response indicating the success of the action execution.

Return type:

ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.Policy.Response

new_command_callback(data)[source]

Process a command received

Parameters:

data (ROS msg defined in the config file. Typically cognitive_processes_interfaces.msg.ControlMsg) – The message that contais the command received.

perceive_closest_fruit()[source]

Choose the closest fruit from the list of fruits and update the fruit perceptions accordingly. Remember that, in this case, the robot is only able to perceive the fruit that is closest to it.

pick_fruit_policy()[source]

Pick the closest fruit to the robot.

Raises:

RuntimeError – If the closest fruit is not the fruit on the scale when the scale is active.

place_fruit_policy()[source]

Place the fruit in the center of the table. If the fruit is in the left hand, it will be placed slightly on the right side of the table, and vice versa. It is a way to change the side of the table where the fruit is placed.

press_button_policy()[source]

Toggle the light of the button.

publish_perceptions()[source]

Publish the current perceptions to the corresponding topics.

random_perceptions()[source]

Generate random perceptions when the world is reset.

random_position(area)[source]

Generate a random position within the specified area.

Parameters:

area (dict) – The area where the position should be generated.

Returns:

A tuple containing the distance and angle of the generated position.

Return type:

tuple

reset_world(data)[source]

Reset the world to a new state.

Parameters:

data (ROS msg defined in the config file. Typically cognitive_processes_interfaces.msg.ControlMsg or cognitive_processes_interfaces.srv.WorldReset.Request) – The message that contains the command to reset the world. It is not used.

reward_classify_fruit_goal()[source]

Gives a reward of 1.0 if the fruit is correctly classified.

reward_place_fruit_goal()[source]

Gives a reward of 1.0 if the fruit is placed in the center of the table.

reward_progress_classify_fruit_goal()[source]

Gives a larger reward the closer the robot is to correctly classifying a fruit. If the fruit is correctly accepted or discarded, the reward is 1.0.

setup_control_channel(simulation)[source]

Configure the ROS topic/service where listen for commands to be executed.

Parameters:

simulation (dict) – The params from the config file to setup the control channel.

setup_experiment_stages(stages)[source]

Setup the stages of the experiment with their corresponding iterations.

Parameters:

stages (dict) – A dictionary where keys are stage names and values are the iterations at which the stage starts.

setup_perceptions(perceptions)[source]

Configure the ROS topics where the simulator will publish the perceptions.

Parameters:

perceptions (list) – A list of dictionaries where each dictionary contains the name, perception topic, and perception message class.

test_fruit_policy()[source]

Put the fruit on the scale in order to test it.

update_reward_sensor()[source]

Update goal sensors’ values.

world_reset_service_callback(request, response)[source]

Callback for the world reset service.

Parameters:
  • request (ROS msg defined in the config file Typically cognitive_processes_interfaces.srv.WorldReset.Request) – The message that contains the request to reset the world.

  • response (ROS msg defined in the config file. Typically cognitive_processes_interfaces.srv.WorldReset.Response) – Response of the world reset service.

Returns:

Response indicating the success of the world reset.

Return type:

ROS msg defined in the config file. Typically cognitive_processes_interfaces.srv.WorldReset.Response

PumpPanel Simulator

class simulators.pump_panel_sim_discrete.PumpObjects(*args: Any, **kwargs: Any)[source]

Bases: EncodableDecodableEnum

This class defines the objects that can be found in the pump panel.

class simulators.pump_panel_sim_discrete.PumpPanelSim(*args: Any, **kwargs: Any)[source]

Bases: Node

PumpPanelSim simulator class.

deliver_object_policy(obj=None)[source]

Policy to deliver to the user the object that was caught.

Parameters:

obj (str) – The object to deliver. It is not necessary to specify it, as the simulator will always deliver the tool that was caught.

grasp_object_policy(obj=None)[source]

Parametrized policy to grasp an object.

Parameters:

obj (str) – The object to grasp.

initial_perceptions()[source]

Initialize the perceptions of the pump panel simulator. The initial state is with all indicators off, all valves closed and the tools stored.

load_configuration()[source]

Load the configuration file and setup the simulator. It is configured the random number generator, the stages of the experiment, the perceptions, and the control channel.

load_experiment_file_in_commander()[source]

Load the configuration file in the commander node.

Returns:

Response from the commander node indicating the success of the loading.

Return type:

core_interfaces.srv.LoadConfig.Response

new_action_service_callback(request, response)[source]

Execute a policy and publish new perceptions.

Parameters:
  • request (ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.PolicyParametrized.Request) – The message that contains the policy execute and its parameter.

  • response (ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.PolicyParametrized.Response) – Response of the success of the execution of the action.

Returns:

Response indicating the success of the action execution.

Return type:

ROS srv defined in the config file. Typically cognitive_node_interfaces.srv.PolicyParametrized.Response

new_command_callback(data)[source]

Process a command received

Parameters:

data (ROS msg defined in the config file. Typically cognitive_processes_interfaces.msg.ControlMsg) – The message that contais the command received.

press_object_policy(obj=None)[source]

Parametrized policy to press an object.

Parameters:

obj (str) – The object to press.

publish_perceptions()[source]

Publish the current perceptions to the corresponding topics.

reset_world(data)[source]

Reset the world to the initial state.

Parameters:

data (ROS msg defined in the config file. Typically cognitive_processes_interfaces.msg.ControlMsg or) – The message that contains the command to reset the world. It is not used.

cognitive_processes_interfaces.srv.WorldReset.Request

reward_start_pump_goal()[source]

Gives a reward of 1.0 if the pump has been started.

setup_control_channel(simulation)[source]

Configure the ROS topic/service where listen for commands to be executed.

Parameters:

simulation (dict) – The params from the config file to setup the control channel.

setup_perceptions(perceptions)[source]

Configure the ROS topics where the simulator will publish the perceptions.

Parameters:

perceptions (list) – A list of dictionaries where each dictionary contains the name, perception topic, and perception message class.

simulate_values()[source]

Simulate the valuas of some indicators of the pump panel.

store_object_policy(obj=None)[source]

Policy to store in its respective box the object that was caught.

Parameters:

obj (str) – The object to store. It is not necessary to specify it, as the simulator will always store the tool that was caught.

update_reward_sensor()[source]

Update goal sensors’ values.

world_reset_service_callback(request, response)[source]

Callback for the world reset service.

Parameters:
  • request (ROS msg defined in the config file Typically cognitive_processes_interfaces.srv.WorldReset.Request) – The message that contains the request to reset the world.

  • response (ROS msg defined in the config file. Typically cognitive_processes_interfaces.srv.WorldReset.Response) – Response of the world reset service.

Returns:

Response indicating the success of the world reset.

Return type:

ROS msg defined in the config file. Typically cognitive_processes_interfaces.srv.WorldReset.Response

2D Manipulation

class simulators.scenarios_2D.Ball(name, x=0.0, y=0.0, angle=0.0, radius=40.0, color='red')[source]

Bases: Entity

Class that implements a Ball entity in the simulator.

register_visual(ax: matplotlib.axes.Axes)[source]

Register the visual representation of the ball in the given Axes.

Parameters:

ax (matplotlib.axes.Axes) – Axes where the visual representation will be registered.

set_alpha(alpha)[source]

Set the transparency of the ball entity in the visual representation.

Parameters:

alpha (float) – Transparency of the ball, between 0 (transparent) and 1 (opaque).

set_color(color)[source]

Set the color of the ball.

Parameters:

color (str) – Color of the ball.

update_visual()[source]

Update the visual representation of the ball.

class simulators.scenarios_2D.Baxter2Arms(x_size=(0, 2500), y_size=(0, 1000), x_bounds=(100, 2400), y_bounds=(50, 800), grasp_range=80.0, visualize=True, verbose=False)[source]

Bases: Sim

Class that simulates the Baxter robot.

apply_action(rel_angle_l=0.0, rel_angle_r=0.0, vel_left=0.0, vel_right=0, gripper_left=False, gripper_right=False)[source]

Move arms with a specific angle and velocity (default 0).

Parameters:
  • rel_angle_l (float) – Relative angle to move the left arm.

  • rel_angle_r (float) – Relative angle to move the right arm.

  • vel_left (float) – Velocity to move the left arm.

  • vel_right (float) – Velocity to move the right arm.

  • gripper_left (bool) – Gripper state of the left arm (True if closed, False otherwise).

  • gripper_right (bool) – Gripper state of the right arm (True if closed, False otherwise).

move_robot_arm(arm: Robot, vel)[source]

Move robot arm wih a specific velocity.

Parameters:
robot_arm_action(arm: Robot, relative_angle, vel, step_world=True)[source]

Move robot arm with a specific angle and velocity.

Parameters:
  • arm (simulators.scenarios_2D.Robot) – Robot entity to move.

  • relative_angle (float) – Relative angle to move the arm.

  • vel (float) – Velocity to move the arm.

class simulators.scenarios_2D.Box(name, x=0.0, y=0.0, angle=0.0, color='blue', w=100.0, h=100.0)[source]

Bases: Entity

Class that implements a Box entity in the simulator.

register_visual(ax: matplotlib.axes.Axes)[source]

Register the visual representation of the box in the given Axes.

Parameters:

ax (matplotlib.axes.Axes) – Axes where the visual representation will be registered.

set_alpha(alpha)[source]

Set the transparency of the box entity in the visual representation.

Parameters:

alpha (float) – Transparency of the box, between 0 (transparent) and 1 (opaque).

set_color(color)[source]

Set the color of the box.

Parameters:

color (str) – Color of the box.

update_visual()[source]

Update the visual representation of the box.

class simulators.scenarios_2D.ComplexScenario(x_size=(0, 2500), y_size=(0, 1000), x_bounds=(100, 2400), y_bounds=(50, 800), visualize=True)[source]

Bases: Baxter2Arms

Class that implements a complex scenario with a Baxter robot and multiple balls and boxes.

world_rules()[source]

Establish the ball position in the scenario.

class simulators.scenarios_2D.Entity(name, x=0.0, y=0.0, angle=0.0, type=EntityType.DEFAULT)[source]

Bases: object

Class that implements an Entity in the simulator.

get_angle()[source]

Get the angle of the entity.

Returns:

Angle of the entity in degrees.

Return type:

float

get_pos()[source]

Get the position of the entity.

Returns:

Tuple with the x and y position of the entity.

Return type:

tuple

register_visual(ax: matplotlib.axes.Axes)[source]

Register the visual representation of the entity in the given Axes. This method should be implemented in the subclasses.

Parameters:

ax (matplotlib.axes.Axes) – Axes where the visual representation will be registered.

Raises:

NotImplementedError – If the method is not implemented in the subclass.

set_alpha(alpha)[source]

Set the transparency of the entity. This method should be implemented in the subclasses.

Parameters:

alpha (float) – Transparency of the entity, between 0 (transparent) and 1 (opaque).

Raises:

NotImplementedError – If the method is not implemented in the subclass.

set_angle(angle)[source]

Set the angle of the entity. The angle is bounded in the range [-180, 180] degrees.

Parameters:

angle (float) – Angle of the entity in degrees.

set_color(color)[source]

Set the color of the entity. This method should be implemented in the subclasses.

Parameters:

color (str) – Color of the entity.

Raises:

NotImplementedError – If the method is not implemented in the subclass.

set_pos(x=None, y=None)[source]

Set the position of the entity. If x or y is not provided, it will not be changed.

Parameters:
  • x (float) – x position of the entity.

  • y (float) – y position of the entity.

Raises:

TypeError – If x or y is not a number.

update_visual()[source]

Update the visual representation of the entity. This method should be implemented in the subclasses.

Raises:

NotImplementedError – If the method is not implemented in the subclass.

class simulators.scenarios_2D.EntityType(*values)[source]

Bases: Enum

Class that defines the different types of entities in the simulator.

class simulators.scenarios_2D.Robot(name, x=0.0, y=0.0, angle=0.0)[source]

Bases: Entity

Class that implements a Robot entity in the simulator.

register_visual(ax: matplotlib.axes.Axes)[source]

Register the visual representation of the robot in the given Axes.

Parameters:

ax (matplotlib.axes.Axes) – Axes where the visual representation will be registered.

set_alpha(alpha)[source]

Set the transparency of the robot entity in the visual representation.

Parameters:

alpha (float) – Transparency of the robot, between 0 (transparent) and 1 (opaque).

set_color(color)[source]

Set the color of the robot.

Parameters:

color (str) – Color of the robot.

set_gripper(value)[source]

Set the gripper state of the robot.

Parameters:

value (bool) – True if the gripper is closed, False otherwise.

update_visual()[source]

Update the visual representation of the robot.

class simulators.scenarios_2D.Sim(x_size=(0, 2500), y_size=(0, 1000), x_bounds=(100, 2400), y_bounds=(50, 800), visualize=True, verbose=False)[source]

Bases: object

Class that implements a Simulator

This simulator makes possible to make/test different experiments in a virtual scenario. It contains the two arms of the Baxter robot, the Robobo! robot, some boxes and a ball.

The implemented methods allow the user to move both robots throw the scenario (with and without the ball), get distances and relative angles between the different objects and get/set the position of all of them.

apply_action(**params)[source]

Placeholder method: Implement the action logic according to the desired scenario.

enforce_limits(entity: Entity, limits)[source]

Check if the next position of one of the entities is inside its movement limits.

Parameters:
  • entity (simulators.scenarios_2D.Entity) – Entity to check the limits.

  • limits (tuple of tuples) – Movement limits of the entity, in the form ((x_min, x_max), (y_min, y_max)).

filter_entities(entities, type)[source]

Filter entities by type.

Parameters:
Returns:

List of entities of the specified type.

Return type:

list of simulators.scenarios_2D.Entity

get_close_entities(entity: Entity, threshold)[source]

Get a list of entities that are close to the given entity within a certain threshold.

Parameters:
  • entity (simulators.scenarios_2D.Entity) – Entity to which we want to find close entities.

  • threshold (float) – Distance threshold to consider an entity as close.

Returns:

List of entities that are close to the given entity.

Return type:

list of simulators.scenarios_2D.Entity

static get_distance(x1_y1, x2_y2)[source]

Return the Euclidean distance between two points.

Parameters:
  • x1_y1 (tuple) – Tuple with the coordinates of the first point (x1, y1).

  • x2_y2 (tuple) – Tuple with the coordinates of the second point (x2, y2).

Returns:

Euclidean distance between the two points.

Return type:

float

static get_relative_angle(x1_y1, x2_y2)[source]

Return the relative angle between two points

Parameters:
  • x1_y1 (tuple) – Tuple with the coordinates of the first point (x1, y1).

  • x2_y2 (tuple) – Tuple with the coordinates of the second point (x2, y2).

Returns:

Relative angle in degrees between the two points. If both positions are equal, returns 0.0.

Return type:

float

get_scenario_data()[source]

Scenario data needed to predict future states using the world model.

Raises:

NotImplementedError – If the method is not implemented in the subclass.

get_sensorization()[source]

Return a sensorization vector with the distance between the object in which the robot is focused and its actuator, the color of this object…

Raises:

NotImplementedError – If the method is not implemented in the subclass.

static normalize_value(value, max_value, min_value=0.0)[source]

Normalize a value between 0 and 1, given a maximum and minimum value.

Parameters:
  • value (float) – Value to normalize.

  • max_value (float) – Maximum value for normalization.

  • min_value (float) – Minimum value for normalization.

Returns:

Normalized value.

Return type:

float

plot_entities()[source]

Plot the generated entities.

restart_scenario()[source]

Set the scenario to the desired initial conditions.

Raises:

NotImplementedError – If the method is not implemented in the subclass.

restart_scenario_partially()[source]

Partially reinitialize the scenario.

Raises:

NotImplementedError – If the method is not implemented in the subclass.

world_rules()[source]

Placeholder method: Implement the desired world logic according to the desired scenario.

Raises:

NotImplementedError – If the method is not implemented in the subclass.

class simulators.scenarios_2D.SimpleScenario(x_size=(0, 2800), y_size=(0, 1550), x_bounds=(100, 2700), y_bounds=(50, 1350), grasp_range=80.0, place_range=80.0, visualize=True, logger=None)[source]

Bases: Baxter2Arms

Class that implements a simple scenario with a Baxter robot and a ball.

restart_scenario(rng: numpy.random.Generator)[source]

Set the scenario to random initial conditions.

Parameters:

rng (numpy.random.Generator) – Random number generator.

world_rules()[source]

Establish the ball position in the scenario