Hydroplant Subsystems – Week 4


Introduction to This Week’s Update on Smart Systems

We have now started to test the whole system. This week has been filled with a lot of collaboration between all the members of the team to discuss how the whole system works and to make sure that we all understand the system architecture within all the disciplines. Besides the group members in Smart Systems, we have collaborated with other students in Hydroplant who handle both electrical and physical parts of the system. It is important for the group to communicate the interfaces between the different subsystems, physical components, robotics, and the electrical system.

We have tested the communication between Nodes, Master Controller, Autonomy, and GUI this week, and we were able to make the system work properly. You can see in the video that the Climate node connects to the broker and presents itself to the Master Controller. Then, when the GUI connects to the Broker, it receives the information about the system and creates the visual elements. We tested by sending commands from the GUI and Autonomy; both worked properly. We were also able to synchronize the GUI when the Autonomy algorithm sent commands to the system.


Shahin Ostadahmadi

This week, I spent some time with the whole group to discuss the system architecture for software, how the whole system works together, and how different processes have to be handled in parallel, such as moving a plant from one stage to another while listening to new commands. We also spent some time discussing different electrical components for the circuit board and ideas to save some “pins” on the Arduino by using a Multiplexer for some of the components. Among other things, we have two servos, one for moving plants and one for analyzing the plants with a camera. To keep track of the positions of the servos, we are using 14 micro switches for each servo. We will use a multiplexer to connect all the switches together and just use 3 pins on the Arduino instead of 14.

I also planned our next purchase and budget review to ensure we have enough resources to buy everything we need later this year.

GUI

Logging system

Last week I tested the internal logging system. This week, along with Oscar, we tested the logging system from all devices. The logging system worked well on all the devices. I also refactored some of the logging code. The logging system is quite important for us to gather all the system behavior in one place both for system control and debugging.

Synchronization

I implemented the synchronization on the GUI side to ensure the GUI accurately represents the actual system. The GUI now takes sync messages from the Master Controller to update a system state for one or more visual elements whenever there is a state change in the physical system. The GUI also deletes visual elements when a node is inactive or loses connection and recreates the visual elements when it becomes active again. One important part of creating and destroying visual elements is memory management. Since the container that represents the physical system is dynamically created (heap-allocated pointers, C++), it is crucial to track the pointers and delete them when we are destroying the objects to avoid memory leaks and the so-called “dangling pointers”.

Microcontroller

Updating Library

I updated some of the library code to add more functionalities for actuators, sensors, and LogicController.

Debugging

Earlier this week, we encountered problems with the communication and message exchange between all the subsystems. We spent a lot of time debugging. We repeatedly reviewed the code in the Master Controller, Microcontroller, GUI, and Autonomy. We also looked into the MQTT-library source code with Oscar to find the system’s unusual behavior. We invited other people to review the code since we had tunnel vision at the time. In the end, the only issue was that when we created JSON messages to send from the Arduino, we allocated too large a JSON document for the Arduino, causing it to crash. It was a simple mistake that we’ll never forget, but it had a happy ending.

Job Handling

I implemented the job management logic for Arduino nodes to receive commands. Now, all the commands that the nodes receive are added to a command queue container, and they are handled sequentially in the main Arduino loop. The only task the different nodes have is to write a function to handle specific commands related to the services they offer, and all communication and job handling are managed in the background.

The logic has been tested and works well. In the following weeks, I will refactor the code and add some abstract levels to generalize functionalities and incorporate them into the library code.

Receipt logic

We began work on the receipt logic. Oscar made good progress in the Master Controller, and I implemented some of the code. We tested some functionalities with Oscar, and we plan to conduct more testing and finalize the implementation next week.

Climate node

We’ve successfully set up the Climate node and conducted initial tests using lights. Over the coming weeks, we plan to add additional actuators and sensors.

Commits

Only members of the organization can see these commits.

https://github.com/hydroplantno/mqtt-nodes/commit/0b35b0be3fa75cab9f483abce4afa57e73863742 – Connect your Github account

https://github.com/hydroplantno/library/commit/ee872267b300b420b97adbcba53ba0a2c3207639 – Connect your Github account


Oscar Melby

Communication testing

Worked together with Shahin as mentioned above, and tested a lot this week, and seems like we finally are where we want to be regarding MQTT communication between devices. Still have to discuss more about interfaces between nodes, but will take this as we go along. Since we use JSON, it’s as easy as adding a new key-value pair. While Shahin mostly worked with the GUI and node side of things I did a bit more on the master-controller and autonomy.

Autonomy

Got dummy logic working, which was turning lights on/off based on the time of day. Might need to rewrite parts of it, since I’m unsure how time-events differ from sensor events, but we’ll figure this out.

Added states to data that starts off “unchecked” goes to “checked” and then deleted.

Added job states which starts off “queued” goes to “pending” then “done” → deleted.

Refactored autonomy class a bit to use master’s data directly instead of storing duplicates. Still debating with myself if some parts like sensor data should still be duplicated, as we don’t care about all data saved to master-class.

Master-controller

Implemented logging using a readable format. Prints both to terminal and local files, which makes debugging a lot easier as you can always check the log file.

Added the receipt system Shahin talked about on master’s side. This is done in order to be sure if a job has been done, and will in turn change the states of data in autonomy, so we know when we can do the next thing. It works as of now, still need to test it more with the autonomy.

Added state, which uses the receipt system to remember where it left off when shutting down. This is used in order to synchronize the GUI so if we have turned LED1 on, turned off the GUI, and then GUI on again, it will say that LED1 is on. This is also saved to the database, so if the master shuts down, it will remember that it was on before crashing or being terminated.

Made other small improvements like deleting keys in the JSON we don’t care about before sending, making code more readable, and being able to turn autonomy on/off using the GUI.

GitHub Actions runner

After moving the runner to our LAMP server it still dies randomly, no idea why. It’s also a pain in the ass to work with since the server or something required sudo permission all the time. Even touching a file or running something requires sudo, and the user has sudo permission. But conveniently (not) the runner doesn’t want to run if it’s run using sudo. Got this working last week by commenting out all exit(1) tied to this if-check. But for some reason when I try to edit the files now, using sudo nano, it saves as usual, ls -la shows that the file has been changed, but cat’ing the file shows that it has been reverted. No clue why, might just not care about checks going forward.

Commits

Only members of the organization can see these commits.

https://github.com/hydroplantno/master-controller/commit/2dced01f35d7c302761ebdb2b80feb4301a6a552 – Connect your Github account

https://github.com/hydroplantno/master-controller/commit/32c85b523396f7bce08547f9777c136c395e831c – Connect your Github account

https://github.com/hydroplantno/master-controller/commit/a811f33641fcea39c8352f34d08d39cfab166c5d – Connect your Github account


Aditi Deshpande

All you curious readers out there, I have some good news. I finally got PlatformIO to work perfectly! Therefore I was able to work effectively this week, and we got a lot done. Firstly on Monday, Theo and I tested the final iteration of the Mover class and it worked very well. The exact place the placeholder ended up after moving was not very accurate since we had not incorporated switches in our system, but we expected this and we were satisfied as we know the logic was correct. We also got the circuit diagram of how switches work with multiplexes from Mustafa, an electronics engineering student who works on the project. So we discussed a bit on how we would program the switches, and I am looking forward to doing that.

On Friday I started to write the code for the Plant Information Node. I added simple functions and variables and I got an explanation from our team leader Shahin on how the code should look. Since Arduino has only one thread and can only do one thing at a time, using a while loop() to move the PIN would be a bad idea, because we also need to check if there are jobs that need to be added to a job queue for communication. So he suggested using a switch that switches between states. Therefore I first created a state machine diagram for planning how the structure will look like:

There are going to be two states, a go state, and a picture state. The go state is when the stepper will move forward, most probably by one switch. So, we go through the function(which contains the switch states) only once, and we check if there are any available jobs, add them, and go through the function again. If that switch is the target switch, we break out of the go state and move to the picture state where we take the picture. Otherwise, we do the whole process again. So I have started to code this function.

Here are the code commits:

  1. Changes made to the Stepper function so that the stepper could run smoothly -added a Go function-https://github.com/hydroplantno/library/commit/3374cdcd928a099d0331ac09d349446e2fe1d968 – Connect your Github account
  2. Changes made to the Mover class, replacing move function with go and removing calc_switch function- https://github.com/hydroplantno/library/commit/2b9cbdc4994729113e7fa3bb58ee1b94bb0dfe48 – Connect your Github account
  3. Created the Plant Information Node class with the backbone structure- https://github.com/hydroplantno/library/commit/933b083c0a8bf9fa4b3c44de3afa1ea453918d5d – Connect your Github account

Things to work on next week:

  1. Program the switches as we have the circuit diagram. Even though we cannot test them yet as we have not connected them to the system at least we will have the code ready
  2. Finish coding the function that has the switch states for the PIN, both Go state and picture state
  3. Integrate it to the MQTT client

Theo Magnor

This week we have done testing of the Mover class and made corresponding changes to the code.
https://github.com/hydroplantno/library/tree/aditi-theo/mover/LogicController/Mover – Connect your Github account

I have also made changes to the plantMoverController class, it now has a switch case and will enter the different cases depending on what logic the masterController wants executed. The logic that will be in each case and for switching cases, I will work on next week.
https://github.com/hydroplantno/library/tree/aditi-theo/mover/LogicController/plantMoverController – Connect your Github account

I have also started making the armController class which is responsible for moving the arm that will attach to the plantMover to the plant rows.
https://github.com/hydroplantno/library/commit/ddaecc0c71defa21d2b7ea8230e30a7fb010e095 – Connect your Github account


Ivan Bergmann Maronsson

This week has been spent on more alterations to the PCB and figuring out how to use a step-down transformer to get desired voltages. The PCB now has LED’s to show when certain components are being used. And capacitors have been added. There might be to many capacitors, but this will be fixed later down the line.


Have a lovely week with smart systems!


Leave a Reply