deepbots.robots.controllers

class deepbots.robots.EmitterReceiverRobot(*args: Any, **kwargs: Any)[source]

Bases: Robot

This EmitterReceiverRobot implements only the most basic run method, that steps the robot and calls the handle_emitter, handle_receiver methods that are needed for communication with the supervisor.

This class must be inherited by all robot controllers created by the user and the handle_emitter, handle_receiver, initialize_comms methods are all abstract and need to be implemented according to their docstrings. For a simpler RobotController that implements the methods in a basic form inherit the CSVRobot subclass or other emitter-receiver subclasses.

get_timestep()[source]
property timestep

Getter of _timestep field. Timestep is defined in milliseconds

Returns

The timestep of the controller in milliseconds

initialize_comms(emitter_name, receiver_name)[source]

This method should initialize and return the emitter and receiver in a tuple as expected by the constructor.

A basic example implementation can be:

emitter = self.getDevice(“emitter”) receiver = self.getDevice(“receiver”) receiver.enable(self.timestep) return emitter, receiver

Returns

(emitter, receiver) tuple, as initialized

handle_emitter()[source]

This method should take data from the robot, eg. sensor data, parse it into a message and use the robot’s emitter to send it to the supervisor. This message will be used as the observation of the robot.

handle_receiver()[source]

This method should take data through the receiver in the form of a message and parse into data usable by the robot.

For example the message might include a motor speed, which should be parsed and applied to the robot’s motor.

run()[source]

This method is required by Webots to update the robot in the simulation. It steps the robot and in each step it runs the two handler methods to use the emitter and receiver components.

This method should be called by a robot manager to run the robot.

class deepbots.robots.CSVRobot(*args: Any, **kwargs: Any)[source]

Bases: EmitterReceiverRobot

Basic implementation of a robot that can emit and receive messages to/from the supervisor in string utf-8 form that are Comma Separated Values, i.e. a list.

initialize_comms(emitter_name, receiver_name)[source]

This method implements the basic emitter/receiver initialization that assumes that an emitter and a receiver component are present on the Webots robot with appropriate DEFs (“emitter”/”receiver”).

Parameters
  • emitter_name – The name of the emitter device on the supervisor node

  • receiver_name – The name of the receiver device on the supervisor node

Returns

The initialized emitter and receiver references

handle_emitter()[source]

This emitter uses the user-implemented create_message() method to get whatever data the robot gathered, convert it to a string if needed and then use the emitter to send the data in a string utf-8 encoding to the supervisor.

handle_receiver()[source]

This receiver uses the basic Webots receiver-handling code. The use_message_data() method should be implemented to actually use the data received from the supervisor.

create_message()[source]

This method should be implemented to convert whatever data the robot has, eg. sensor data, into a message to be sent to the supervisor via the emitter.

Returns

a list or a comma-separated string containing all data

use_message_data(message)[source]

This method should be implemented to apply whatever actions the message (received from the supervisor) contains.

Parameters

message – list containing data received from the supervisor