Skip to main content

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 NodeDescriptionEventDataSubscriberNotes
DisplayNodeDisplay ManagementshutdownNoneUbermenschSignals shutdown
motor-stopNoneMotorNodeStop all motion
motor-translate-forward-leftspeed: int
duration:float
MotorNodeSlide Forwards Left
motor-forwardsspeed: int
duration:float
MotorNodeMove Forwards
motor-translate-forward-rightspeed: int
duration:float
MotorNodeSlide Forwards Right
motor-pan-leftspeed: int
duration:float
MotorNodeMove Left
motor-pan-rightspeed: int
duration:float
MotorNodeMove Right
motor-translate-back-leftspeed: int
duration:float
MotorNodeSlide Backwards Left
motor-backwardsspeed: int
duration:float
MotorNodeMove Backwards
motor-translate-back-rightspeed: int
duration:float
MotorNodeSlide Backwards right
motor-rotate-leftspeed: int
duration:float
MotorNodeRotate Left
motor-rotate-rightspeed: int
duration:float
MotorNodeRotate Right
servo-commandcommand: CameraCommandServoNodeExecute Camera Command
FaceRecognitionMonitors camera stream
AI Face recognition
display-node-frameframe: np.ndarrayDisplayNodeFrame data to be displayed
person-detectedperson: PersonPersonNodeSent when a person is recognized
MotionNodeResponsible for intelligent motion behaviourservo-execute-sequencesequence: ListServoNodeSequence of steps for camera to follow
servo-commandcommand: CameraCommandServoNodeStop moving
PersonNodeHandles identified personspeech-node-speakphrase: strSpeechNodeSends greeting for person to speech node
centre-thingthing: ThingMotionNodeMove robot to centre an object in the frame
Triggered when a thing has been detected
start-looking-aroundNoneMotionNodeStart camera motion to look around for something
Triggered when the person node gets bored
stop-looking-aroundNoneMotionNodeStop camera motion to look around for something
Triggered when the person has been detected
StatusNodeMonitors System Statussystem-statusstatus: SystemStatusOledNodeDisplay the current system status
system-statusstatus: SystemStatusDisplayNodeDisplay the current system status
under-voltage-detectedNoneUbermenschUsed to shutdown main process
UPSNodeMonitors UPSups-battery-percentpercent: intStatusNodeReports the current UPS Battery Percentage
under-voltage-detectedNoneUbermenschUsed 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 NodeDescriptionEventDataPublisherNotes
BuzzerI2C Buzzer Managementbuzzer-node-soundduration: floatNoneSound buzzer for duration seconds
DisplayNodeDisplay Managementdisplay-node-frameframe: np.ndarrayFaceRecognitionDisplay the current frame
system-statusstatus: SystemStatusStatusNodeDisplay the current status
MotionNodeManages intelligent movements of the robotstart-looking-aroundNonePersonNodeStart looking around with the camera for something interesting
stop-looking-aroundNonePersonNodeStop looking around with the camera
centre-thingthing: ThingPersonNodeMove robot to centre an object in the camera frame
MotorNodeI2C Motorsmotor-stopNoneDisplayNodeStop all motors
motor-forwardsspeed: int
duration:float
DisplayNodeMove forwards
motor-backwardsspeed: int
duration:float
DisplayNodeMove backwards
motor-pan-leftspeed: int
duration:float
DisplayNodePan left
motor-pan-rightspeed: int
duration:float
DisplayNodePan right
motor-translate-forward-leftspeed: int
duration:float
DisplayNodeSlide Forwards Left
motor-translate-forward-rightspeed: int
duration:float
DisplayNodeSlide Forwards Right
motor-translate-backwards-leftspeed: int
duration:float
DisplayNodeSlide Backwards Left
motor-translate-backwards-rightspeed: int
duration:float
DisplayNodeSlide Backwards Right
motor-rotate-leftspeed: int
duration:float
DisplayNodeRotate Left
motor-rotate-rightspeed: int
duration:float
DisplayNodeRotate Right
OledNodeAdafruit SSD1306 Display Managementsystem-statusstatus: SystemStatusStatusNodeDisplay the current status
PersonNodeHandles identified person
Manages searching for a person
person-detectedperson: PersonFaceRecognitionSends greeting for person to speech node
ServoNodeI2C Camera Servo Managementservo-execute-sequencesequence: ListMotionNodeStart executing a sequence of camera moves
servo-commandcommand: CameraCommandDisplayNodeExecute a single Camera Command
SpeechNodeAI Speech Generatorspeech-node-speakphrase: strPersonNodePerson greeting
StatusNodeMonitors System Statusups-battery-percentpercent: intUPSNodeInformed on UPS Battery Percentage
UbermenschTop level controllerunder-voltage-detectedNoneStatusNodeUnder voltage detected
shutdownNoneDisplayNodeShutdown request

Node Class

This is the base class for all nodes:

node.py
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:

i2cnode.py
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:

Personal Greeting
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:

Subscribing to speech-node-speak
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:

Speech handling
loading...