Messages¶
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: Optional[Dict[str, Any]] = None, rx_type: Type[gridsim.robot.Robot] = <class 'gridsim.robot.Robot'>)¶ -
__init__
(tx_id: Optional[int] = None, content: Optional[Dict[str, Any]] = None, 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.
- Parameters
tx_id (Optional[int], optional) – ID of the sending (transmitting) robot, by default None
content (Optional[Dict[str, Any]], optional) – Dictionary of message keys and values, by default None. Keys must be strings, but values can be of any type (incumbent on receiver for interpretation)
rx_type (Type[Robot], optional) – Type of the receiving robot, by default Robot (i.e., message will be processed by any Robot.)
-
get
() → Optional[Dict[str, Any]]¶ Get the contents of the message
- Returns
Dictionary of the message contents
- Return type
Optional[Dict[str, Any]]
-
tx_id
() → Optional[int]¶ Get the ID (32-bit integer) of the robot that sent the message
- Returns
ID of the sending (transmitting) robot
- Return type
Optional[int]
-