Skip to content

Software

Boris Yanchev edited this page Apr 19, 2020 · 16 revisions

User Stories

Use Cases

Structure

The software consists of mainly 5 steps.

  1. Turn on/off the heater (Relay)
  2. Dispense tea leaves (Stepper Motor)
  3. Measure water temperature (Temperature Sensor)
  4. Dispense hot water (Valve 1)
  5. Dispense tea (Valve 2)

Motor and Sensor correspond to 'stepper motor' and 'temperature sensor' operations respectively. Switch contains 3 operations including 'relay', 'valve 1' and 'valve 2'.

Stepper Motor

The stepper motor chosen was operated with 3 input pins using the WiringPi library. One low to high transition gives 1.8 degrees rotation. Direction, angle and speed are passed on to Motor class, then the number of steps and frequency were specified. Suitable speed and angle were chosen depending on the amount of tea leaves required.

This operation runs in a different thread from the main thread so that the Tea Maker can dispense tea leaves while it is waiting for water to boil. CppThread library by Bernd Porr was used to implement the operation in a thread. CppThread class was inherited by Motor class, and the actual motor operation was written in the inherited function run().

Temperature Sensor

The temperature sensor chosen communicates with RPI via 1-wire configuration. CppTimer library by Bernd Porr was used to sample temperature periodically with precise frequency in real time. CppTimer class was inherited by Sensor class, and the sampling operation was implemented in the inherited function timerevent(). Once the water temperature reaches the target temperature, the sampling loop breaks and an LED is illuminated.

Switches

Similarly, the CppTimer library was used to dispense precise amount of liquid. CppTimer class was inherited by Relay, Valve1 and Valve2 classes, and operations of closing valves or switching off the relay were written in the inherited function timerevent() in each class. Once the valves are opened or the relay is switched on, timerevent() occurs only once after specified time elapses. Whether timerevent() occurs once or multiple times (ONESHOT or PERIODIC) can be determined by cppTimerType_t.

GUI

The GUI (Graphical User Interface) has been developed using Qt. The 3 components of the software (Motor, Sensor, Switch) were integrated and interfaced. Please see the TeaMaker repository for the GUI with integrated software. The GUI is still under development and currently contains a few buttons to specify a kind of tea (green tea, black tea, etc.). Depending on the tea selected, suitable water temperature, brew time, amount of tea leaves and water are passed on to the program. The temperature sensor starts sampling as soon as the heater is switched on. The stepper motor operates in another thread to dispense tea leaves to utilise the waiting time for the water to be boiled. While the temperature sensor is sampling, a LED is on. The LED turns off once the water temperature reaches the target temperature and the sensor stops sampling. Then the relay switches off the heater and valve 1 dispenses specified amount of heated water. After waiting for the tea brew time, finally valve 2 dispenses the tea into a cup.

Unit tests

Unit tests were designed based on SourceCode to make sure if the each software component works with the hardware properly. Initial tests were done using TestCode without real time coding. Afterwards, RealTimeCode was developed with implementation of real time operation including threads and timers.

Libraries

  • C++ thread library by Bernd Porr, CppThread
  • C++ Linux timer library by Bernd Porr, CppTimer
  • C source code for the 1-wire temperature sensor, DS18B20
  • C GPIO access library for Raspberry Pi, WiringPi

More Information

For further reading and detailed documentation on the classes, their functions and their members please click here.