This provides a basic Message protocol for robot communication. Each message contains the ID of the sender and a dictionary of message contents. The values of the message contents may be any type, so the receiver must know how to process the data.

Additionally, Messages can optionally include a receiver type (rx_type). This is only needed if there are multiple types of robots in the World, and you only want certain types of robots to receive the message.

If no arguments are provided when a Message is created, it creates a null message, which signals that the robot is not broadcasting anything.

While it is possible to extend this class, the default Message class should meet most needs.

class gridsim.message.Message(tx_id: Optional[int] = None, content: Dict[str, Any] = {}, rx_type: Type[gridsim.robot.Robot] = <class 'gridsim.robot.Robot'>)
__init__(tx_id: Optional[int] = None, content: Dict[str, Any] = {}, rx_type: Type[gridsim.robot.Robot] = <class 'gridsim.robot.Robot'>)

A message sent by robots. Can be either a null (empty) message if no arguments are provided to the constructor. Or it contains the sender’s ID, a dictionary of content, and (optionally) the type of robot that receives the message.

  • tx_id (Optional[int], optional) – ID of the sending (transmitting) robot, by default None

  • content (Dict[str, Any]] optional) – Dictionary of message keys and values, by default an empty dictionary. Keys must be strings, but values can be of any type (incumbent on receiver to correctly interpret incoming data)

  • rx_type (Type[Robot], optional) – Type of the receiving robot, by default Robot (i.e., message will be processed by any Robot.)

get(key: Optional[str] = None) → Optional[Dict[str, Any]]

Get the contents of the message


key (Optional[str], optional) – Name of the parameter to retrieve, by default None. If not specified, a dictionary of all parameters will be returned.


Dictionary of the message contents

Return type

Optional[Dict[str, Any]]


KeyError – If a key is provided but is not in the message contents

sender() → Optional[int]

Get the ID (32-bit integer) of the robot that sent the message


ID of the sending (transmitting) robot

Return type