River System Control Software (2017)

Sub-forum for general software improvements threads
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

River System Control Software (2017)

Post by hamishmb »

Hi all,

I'm about to make a start on the river system control software, and I'll also try to fix the fault-detection system for the Resistance probe.

I'm thinking about making a "Motor" class that holds private (or as close as you can get) properties such as "IsVariableSpeed", "State (on=True, off=False)", and so on, and some getter and setter function so we can control it without the potential for setting stuff wrong (I can build tests in to throw errors if we eg request something impossible). All of this would go in a separate module, to be imported from the "Main" file to keep it all tidy. I might use a main loop for control and monitoring that can be exited if we request manual control, and re-entered when manual control is disabled.

Any thoughts? I might not finish it before I go on holiday, but I have plenty of time for now so we'll see :)

Hamish
Last edited by hamishmb on 06/11/2020, 19:14, edited 1 time in total.
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: River System Control Software

Post by TerryJC »

Sounds like a plan. Probably not needed yet, but you may want to consider running this module as a standalone program and using inter-process communication between this and the sensor software to trigger motor on-off etc.

The reason for this suggestion is that Python has the 'global interpreter lock' which prevents more than two processes running at the same time within any program. For the Bells software I didn't want to get into inter-process communication or multi-processing so I made use of external programs such as the mpg321 MP3 player, which ran as a separate process to Python. For this though you may be better to look at running each River System 'capability' (eg sensors, control etc) as a separate process, to reduce that limitation.
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: River System Control Software

Post by hamishmb »

I have some experience with IPC - we could use pipes, or sockets to do this. However, we could also use threads - I'm very experienced with threading and can engineer a fast, efficient solution for that. Then we wouldn't need IPC at all - we could just pass messages between threads with something like a queue, or list.

I propose incorporating all of the smaller sensor programs we wrote into this program, making them importable modules, at the same time as allowing them to run standalone for eg testing new installations.

I also propose that we make a repository on github to track this, though how we can give multiple users commit permissions in unknown to me. Have you done that before Terry? If not I'm sure I can figure it out :)

Hamish
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: River System Control Software

Post by TerryJC »

You obviously know more about this than I, but from what I was told when I was doing in the bells software, the 'global interpreter lock' will prevent you running more than two threads or processes within a single Python program. So if we had 3 sensors connected to a single Pi, then importing 3 modules (or using the same module three times), is likely to cause problems.

Please don't take my word for it, but the source of my info was the Dorset Linux User Group and various forums on the web.

I agree about Github, it just needs some time to get it set up. I think it will only become important when we open the project up to the QE 6th Formers.
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: River System Control Software

Post by hamishmb »

I had a quick look, and you're sort-of right :)

The lock means that while we can have as many threads as we want (I've written programs that use 3 at a time so I know we can do 2+), they can't effectively make full use of the CPU, and will (mostly) just run on a single core. In our case this is probably quite helpful - our program will use next to no CPU power, and it will keep other cores free for nginx and the OS to use. Apparently it matters less in Python than in eg Cython. If this becomes an issue for us (I'm confident it won't), I'll just rewrite the code in C++ or something instead I guess. Multiprocessing seems a bit over the top.

Shall I have a go at setting it up or shall we wait?

Hamish
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: River System Control Software

Post by hamishmb »

^ The github repository, that is. I'll need your github username to do that, I'd assume.
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: River System Control Software

Post by TerryJC »

hamishmb wrote:^ The github repository, that is. I'll need your github username to do that, I'd assume.
I don't have one, I've never needed to use it until now.
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: River System Control Software

Post by hamishmb »

Ah okay. I'll have a quick go now :)
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: River System Control Software

Post by hamishmb »

Okay, our github page is now created. From now on, I will be committing the code for this software to there. I will bump the version number and add an attachment here at relevant points.

The repository is at: https://github.com/wmtprojectsteam/rivercontrolsystem

As with the forum, I have the admin details, but anyone else can have them if they want. I don't know if any of you want to create a github account, but if you've done so let me know and I'll add you to the team so you have push permissions :)

Hamish
Hamish
Penri
Posts: 1284
Joined: 18/05/2017, 21:28

Re: River System Control Software

Post by Penri »

Hello

I’m sure this is the wrong place but I can’t find river status with my phone, however, I came in this morning to find the sump empty, butts pump groaning and river not flowing. Water was still flowing back from the butts, the probe was lit at around 200mm. I turned off the SSR and circulation pump, filled the sump and restarted the river, that did not take long to start flowing. Put SSR back on auto watched level drop below 400mm pump kept going, then lifted float switch, pump still going.
Have left Butts pump off and shut return valve so river is now just circulating.

Hwyl

Penri
Post Reply