Nodes and Events
Nodes are independent services that support background processing. Each node is responsible for a physical device like the Buzzer or system process like actions related to detecting a person.
Nodes communicate via pub-sub events and will be responsible for publishing events, subscribing to events or both.
The diagram above show the currently implemented nodes and their events:
Publishing Nodes
The table below describes the node and the events published by the node:
Publishing Node | Description | Event | Data | Subscriber | Notes |
---|---|---|---|---|---|
DisplayNode | Display Management | shutdown | None | Ubermensch | Signals shutdown |
motor-stop | None | MotorNode | Stop all motion | ||
motor-translate-forward-left | speed: int duration:float | MotorNode | Slide Forwards Left | ||
motor-forwards | speed: int duration:float | MotorNode | Move Forwards | ||
motor-translate-forward-right | speed: int duration:float | MotorNode | Slide Forwards Right | ||
motor-pan-left | speed: int duration:float | MotorNode | Move Left | ||
motor-pan-right | speed: int duration:float | MotorNode | Move Right | ||
motor-translate-back-left | speed: int duration:float | MotorNode | Slide Backwards Left | ||
motor-backwards | speed: int duration:float | MotorNode | Move Backwards | ||
motor-translate-back-right | speed: int duration:float | MotorNode | Slide Backwards right | ||
motor-rotate-left | speed: int duration:float | MotorNode | Rotate Left | ||
motor-rotate-right | speed: int duration:float | MotorNode | Rotate Right | ||
servo-command | command: CameraCommand | ServoNode | Execute Camera Command | ||
FaceRecognition | Monitors camera stream AI Face recognition | display-node-frame | frame: np.ndarray | DisplayNode | Frame data to be displayed |
person-detected | person: Person | PersonNode | Sent when a person is recognized | ||
MotionNode | Responsible for intelligent motion behaviour | servo-execute-sequence | sequence: List | ServoNode | Sequence of steps for camera to follow |
servo-command | command: CameraCommand | ServoNode | Stop moving | ||
PersonNode | Handles identified person | speech-node-speak | phrase: str | SpeechNode | Sends greeting for person to speech node |
centre-thing | thing: Thing | MotionNode | Move robot to centre an object in the frame Triggered when a thing has been detected | ||
start-looking-around | None | MotionNode | Start camera motion to look around for something Triggered when the person node gets bored | ||
stop-looking-around | None | MotionNode | Stop camera motion to look around for something Triggered when the person has been detected | ||
StatusNode | Monitors System Status | system-status | status: SystemStatus | OledNode | Display the current system status |
system-status | status: SystemStatus | DisplayNode | Display the current system status | ||
under-voltage-detected | None | Ubermensch | Used to shutdown main process | ||
UPSNode | Monitors UPS | ups-battery-percent | percent: int | StatusNode | Reports the current UPS Battery Percentage |
under-voltage-detected | None | Ubermensch | Used to shutdown main process when battery falls below threshold |
Subscribing Nodes
The table below describe the node and the events subscribed to by the node
Subscribing Node | Description | Event | Data | Publisher | Notes |
---|---|---|---|---|---|
Buzzer | I2C Buzzer Management | buzzer-node-sound | duration: float | None | Sound buzzer for duration seconds |
DisplayNode | Display Management | display-node-frame | frame: np.ndarray | FaceRecognition | Display the current frame |
system-status | status: SystemStatus | StatusNode | Display the current status | ||
MotionNode | Manages intelligent movements of the robot | start-looking-around | None | PersonNode | Start looking around with the camera for something interesting |
stop-looking-around | None | PersonNode | Stop looking around with the camera | ||
centre-thing | thing: Thing | PersonNode | Move robot to centre an object in the camera frame | ||
MotorNode | I2C Motors | motor-stop | None | DisplayNode | Stop all motors |
motor-forwards | speed: int duration:float | DisplayNode | Move forwards | ||
motor-backwards | speed: int duration:float | DisplayNode | Move backwards | ||
motor-pan-left | speed: int duration:float | DisplayNode | Pan left | ||
motor-pan-right | speed: int duration:float | DisplayNode | Pan right | ||
motor-translate-forward-left | speed: int duration:float | DisplayNode | Slide Forwards Left | ||
motor-translate-forward-right | speed: int duration:float | DisplayNode | Slide Forwards Right | ||
motor-translate-backwards-left | speed: int duration:float | DisplayNode | Slide Backwards Left | ||
motor-translate-backwards-right | speed: int duration:float | DisplayNode | Slide Backwards Right | ||
motor-rotate-left | speed: int duration:float | DisplayNode | Rotate Left | ||
motor-rotate-right | speed: int duration:float | DisplayNode | Rotate Right | ||
OledNode | Adafruit SSD1306 Display Management | system-status | status: SystemStatus | StatusNode | Display the current status |
PersonNode | Handles identified person Manages searching for a person | person-detected | person: Person | FaceRecognition | Sends greeting for person to speech node |
ServoNode | I2C Camera Servo Management | servo-execute-sequence | sequence: List | MotionNode | Start executing a sequence of camera moves |
servo-command | command: CameraCommand | DisplayNode | Execute a single Camera Command | ||
SpeechNode | AI Speech Generator | speech-node-speak | phrase: str | PersonNode | Person greeting |
StatusNode | Monitors System Status | ups-battery-percent | percent: int | UPSNode | Informed on UPS Battery Percentage |
Ubermensch | Top level controller | under-voltage-detected | None | StatusNode | Under voltage detected |
shutdown | None | DisplayNode | Shutdown request |
Node Class
This is the base class for all nodes:
loading...
The class provides base behaviour for all nodes:
- Logging Context - Every node is able to call logging functions with context and controlled by configuration. Last node logging is also managed and made available to the DisplayNode
- Running state - Orchestrated and controlled start and stop. Running state is also available for reporting by DisplayNode
- Background Running - Method for running a task every trigger period or timeout on an event channel.
I2C Node Class
This is a special class used as a base for all I2C nodes:
loading...
This class provides methods for reading and writing using the I2C ports on the Raspberry PI. The class also handles errors when accessing the I2C register, logging the failure and automatically shutting down the node.
Publish / Subscribe
A key principle of the design is the communication between nodes. All nodes have access to a common publish-subscribe bus and use this bus to publish events for the other nodes.
An example of this is can be seen in the person node. When this node detects a new person it sends that person a greeting by publishing this greeting against a event called speech-node-speak:
loading...
The node property self.node_event_channel is used by nodes to publish and subscribe to event is a fast and asynchronous manner.
This event is handled by the speech node. It is responsible for converting the message text to speech and playing that speech to any attached audio device. To handle this event, the speech node first subscribes to the event:
loading...
When a speech-node-speak event is raise it is passed to the speech node speak callback with the arguments pass by the person node. The speech node then plays the phrase passed in the event:
loading...