1

I am having a problem developing an object-orientated architecture to manage a network of sensors and controls. Currently, I am writing in Python, but this is more of a conceptual question.

I have an Arduino that is wired to a number of sensors. Several times a second, the Arduino sends data to a Raspberry Pi with information about the sensors using a ASCII-based serial communication scheme. An example of a response is below:

#POSITION 47 59203.008;

This response says that position sensor 47 is at position 59203.008 m.

I have a class in my Python program called Arduino that is constantly watching for serial data (on its own thread) and pushes that data to a thread-safe queue.

Each sensor type has a class (i.e. PositionSensor, TemperatureSensor, FlowRateSensor), an address property, and a value property--along with a number of useful methods to perform computations on the data.

My problem is getting the data from the Arduino object to the proper sensor objects. What would be a good pattern for this type of programming problem?

I have considered having my sensors subscribe to the queue, and listen for their sensor-type and address (ignoring anything else), but how do I then tell the sensors that they should check the queue? What class would contain the queue? I feel like there is a model that fits my exact situation.

1 Answer 1

1

My experience with something like this comes from programming a controller for a quadcopter and we had a loop that polled all the sensors at something like 250Hz. We simply updated a massive struct of the state of the quad and passed that to the flight controller.

I assume your Arduino code is doing the polling in its main loop then sending the data to the RPi. Do you have enough bandwidth to just send all the sensor values with every message from the Arduino to the RPi? You can build a map of the latest sensor values and let the individual sensor classes read this map and take actions based on the latest value.

If you don't have enough bandwidth, consider using a binary protocol instead of an ASCII protocol but only if you need to.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.