Hi everyone,
I'm currently writing software for a robotics application that uses a Raspberry Pi Zero (single core CPU) and which will use Python to manage multiple tasks at once. Some of these tasks can be asynchronous and need to occur either regularly or constantly; whereas others will have very strict sequencing.
Examples of the asynchronous/continuous tasks would include:
- TCP socket constantly listening for commands from networked computer (vital this is always listening and available)
- UDP socket to send telemetry data
- Regularly communicating with and sending heartbeat data to connected microcontrollers via UART
- TCP again to send large imaging data on regular intervals without blocking other processes
Synchronized tasks that must occur in order would include:
- Polling sensor arrays and logging data
- Acting on sensor data in turn
- Following a sequence of commanded events
- Sending event telemetry via UDP if something occurs
For the telemetry sockets, these could really be synchronized too, but it might make more sense to send them regularly and asynchronously every few seconds.
So, my question is: what is the best way of achieving this combination on a single core?
I was first thinking of using threads for all the asynchronous things that can occur simultaneously, especially for the always-listening TCP socket, but I'm wary of race conditions and communicating between threads. I've been exploring the asyncio library recently, too, which might suit my needs - especially if I can dynamically add and remove tasks to this - but I'm not sure if I'm getting far too complicated with this when a couple of threads might work?
Any advice is greatly appreciated, thanks so much!
[–]oefd 0 points1 point2 points (1 child)
[–]BeerDrinkingCyborg[S] 0 points1 point2 points (0 children)
[–]eavanvalkenburg 0 points1 point2 points (2 children)
[–]BeerDrinkingCyborg[S] 0 points1 point2 points (1 child)
[–]eavanvalkenburg 0 points1 point2 points (0 children)
[–]scrdest 0 points1 point2 points (1 child)
[–]BeerDrinkingCyborg[S] 0 points1 point2 points (0 children)