During this week I have been looking for information on how windows work and what types are there and what strategies I can follow to know if a window is open or closed and how open it is.
VenTTracker's goal is to monitor natural ventilation routines. The design of the window has an impact on the effect of natural ventilation and also on the strategies to follow to know the state of the window.
The blog contains a summary of the types of windows and ideas to investigate to find out if the windows and doors are open and how open they are.
Many ideas in my head really wanting to try things. It's time to focus and not get too distracted.
Tracking System for Classroom Ventilation Routines
A STEM project for classrooms
the VenTTracker project - Blog #02 - Analyzing Window Types
Common Terms and Window Types
Common terms
- Operable vs. fixed. Windows that open are operable, while windows that do not open are fixed
- Panes. A pane is a sheet of glass.
- Sashes. The sash refers to a pane framed horizontally by rails and vertically by stiles. A window sash is the part of the window that you move when you want to open and close the window.
- Glazing. This term may refer to the part of the window that's made of glass or the process used to secure the glass into a window frame.
Windows types
- a. Fixed windows: are windows with a fixed frame that cannot be opened. The lack of window stiles and rails makes for a narrow frame and wide opening that lets in significantly more natural light.
- b. Single-hung windows: feature a single movable sash, raised from the bottom for ventilation, while the top stays stationary.
- c. Double-Hung windows: have two operating sash that move up and down allowing for ventilation on the top, bottom or both.
- d. Sliding windows: glide open horizontally from one side, providing easy access to fresh air.
- e. Casement windows: are windows that is attached to its frame by one or more hinges at the side. They are used singly or in pairs within a common frame, in which case they are hinged on the outside. Casement windows are often held open using a casement stay.
- f. Awning windows: are hinged on the top and open outward from the bottom, allowing for ventilation and protection from the rain. Often placed higher on walls for privacy or in combination with large stationary windows for a better view.
- g. Hopper window: is a small window that opens downward and inward. It is commonly installed as a bathroom or basement window. The upward tilt of the window glass pane blocks open dirt and debris from getting into your home. It usually can be opened with a crank or hinge.
- h. Vertical Pivot Windows: windows having a sash which pivots about a vertical axis at or near its center; when opened, the outside glass surface is conveniently accessible for cleaning.
- i. Horizontal pivot Window: The windows mechanism used allows the window to open both inwards and outwards to enable customers to benefit from optimum ventilation and light without compromising on security and heat conservation.
Measurement of door / window / shutter / blind opening ratios
For simplicity we are going to summarize the types of movements of door, window blind and shutter in two cases:
Problems to solve
The main problem is to know the actual state of the door, window, shutter or blind.
We are going to split the problem in three problems:
- Are the moving parts open or closed?
- How open are the moving parts?
- How to detect events as moving part changing state.
Is it the window open?
This is the simple part. We can use a plunger that activates a switch like in automatic door seals or something simpler like a reed sensor and magnet.
Our device can be on the moving part of the window, on the fixed part. If we are only concerned with whether the window is open or closed, as in an intrusion alarm, the fixed part is a good place for the device and the magnet would go in the moving part.
Device on window moving part:
Device on window fixed part
How open is the moving part?
For parts that slide, we need to know the amount of scrolling in the scroll direction to know how open it is.
For parts that tilt we need to know the tilt angle to know how open they are.
We define the open window opening ratio as the current opening percentage of the moving part, can be:
- a percentage of the total sliding length of the moving part,
- or a percentage of the maximum opening angle of the moving part .
As we don´t need to have precise measures but a ratio of the opening lets label our target opening ratios:
- Completely closed: open ratio = 0%
- Almost closed: 0 % < open ratio < 33%
- Semi-open 33% <= open ratio < 66%
- Fully open 66% <= open ratio < 100%
Strategies for knowing the moving part opening ratio.
My initial intention is to take advantage of the IMU chip included in the Arduino NANO 33 IoT development board to estimate the opening angle of the pivot, casement, and tilt-and-turn windows and the displacement of the sliding parts.
I know that I will not be able to obtain a precise measurement but I want to explore how far I can take advantage of the IMU.
Knowing if the moving part is in closed state will give us zero reference for our estimates.
In the strategies based on the accelerometer and / or on the gyroscope, the device must be on the moving part of the window in order to be able to detect the changes.
Let's explore some possible solutions. I will avoid those solutions that involve mechanical contact or modification of the structure of the window, door, blind or shutter to be monitored, as a linear resistive position sensor or a rotary encoder and a wheel.
Strategies for sliding parts:
- Accelerometer and reckoning algorithm for positioning
- A quadrature encoder made by two reed switches, or two hall sensors, aligned and several strategically placed magnets.
- Machine Learning??? Use TinyML to teach the device to classify different degrees of opening. Very open, semi-open, semi-closed, closed. Makes sense?
Strategies for pivoting parts:
- Accelerometer and gyroscope for window orientation, opening angle. Maybe with the aid of a complementary filter or a Kalman filter.
- Machine Learning??? Use TinyML to teach the device to classify different degrees of opening. Very open, semi-open, semi-closed, closed. Makes sense?
Can we use the accelerometer to determine the position of the moving part in the situations with sliding displacement?
Let's take samo data to see how the LSM6D3 accelerometer responds to left and right displacements
The IMU is located near the USB connector.
The circuit model. Use a breadboard to hold the arduino aligned with a ruler and connect via USB port to capture data with a serial port monitor.
Arduino sketch to capture data. Uses SparkFunLSM6DS3 library.
#include <SparkFunLSM6DS3.h> #define FREQUENCY_HZ 100 #define INTERVAL_MS (1000 / (FREQUENCY_HZ + 1)) signed long imuGetAccX(); void calibrateImu(void); void setupIMU(); LSM6DS3Core myIMU(I2C_MODE, 0x6A); signed long sstatex, sstatey; void setup() { Serial.begin(115200); delay(1000); // relax... Serial.println("Started"); setupIMU(); calibrateImu(); } void loop() { static unsigned long lastIntervalMs = 0; if (millis() > lastIntervalMs + INTERVAL_MS) { lastIntervalMs = millis(); signed long sampleX = imuGetAccX(); Serial.println(sampleX - sstatex); } } signed long imuGetAccX() { int16_t temp; myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTX_L_XL) ; return temp; } void calibrateImu(void) { unsigned int count1; count1 = 0; do { signed long sampleX = imuGetAccX(); sstatex = sstatex + sampleX; // Accumulate Samples count1++; } while (count1 != 0x0400); // 1024 times sstatex = sstatex >> 10; // division between 1024 } void setupIMU() { if (myIMU.beginCore() != 0) { Serial.print("Error at beginCore().\n"); } uint8_t dataToWrite = 0; // Temporary variable //Setup the accelerometer****************************** dataToWrite = 0; // Start Fresh! dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_100Hz; dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g; dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_104Hz; // Now, write the patched together data myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite); // Set the ODR bit myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C); dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED); }
Moving the device to the left.
First the acceleration on the x-axis is positive and its absolute value increases with time. The velocity of the part is also positive and its absolute increases with time. The moving part moves to the left.
Then the acceleration decreases and changes sign braking the device until the speed becomes zero and the device stops.
Moving the device to the right
First the acceleration on the x-axis is negative and its absolute value increases with time. The velocity of the part is also negative and its absolute value increases with time. The moving part moves to the right.
Then the acceleration increases and changes sign braking the device until the speed becomes zero and the device stops.
Some clarification about the sketch
What is doing calibrateImu() method?
A 'no movement' state is critical to obtain correct data. A calibration routine is needed at the beginning of the application. This calibration value must be as accurate as possible.
void calibrateImu(void) { unsigned int count1; count1 = 0; do { signed long sampleX = imuGetAccX(); sstatex = sstatex + sampleX; // Accumulate Samples count1++; } while (count1 != 0x0400); // 1024 times sstatex = sstatex >> 10; // division between 1024 }
The force of gravity is always influencing the measured acceleration. Therefore, to measure the real acceleration of the device, the contribution of the force of gravity must be removed from the accelerometer data. This can be achieved by applying a high-pass filter.
calibrateImu method obtains the x component of the acceleration when there is a no movement condition.
If the module is perfectly parallel to the earth's surface, the calibration value should be very close to 0.
Let's check the influence of the gravity for the board plane, x and y axes
Reading data in no movement condition
AX AY AZ
0.040410000 0.018800000 1.008420000
0.041020000 0.019650000 1.007320000
0.041380000 0.020750000 1.008420000
0.041990000 0.019650000 1.006840000
0.041630000 0.020750000 1.007810000
The accelerometer at resting on a table, it measure s 1G ( 9.81 m/s2) for the z-axis straight upwards.
The need for calibration is clear. The calibration will remove the acceleration offset component in the sensor output due to the earth's gravity (static acceleration).
Let's see the effect of the calibration. Make a new sketch the same as calibrateImu but for the two axes and with the Arduino LSM6DS3 library
The Arduino library is easier to use but lacks many of the methods needed to get more out of the IMU.
void calibrate(void) { uint32_t count1 = 0; float samplex = 0; float sampley = 0; float samplez = 0; do { if (IMU.accelerationAvailable()) { IMU.readAcceleration(samplex, sampley, samplez); staticx += samplex; // Accumulate Samples staticy += sampley; count1++; } } while (count1 < 10000); // 10 000 times staticx = staticx / 10000.0; // mean value staticy = staticy / 10000.0; }
The calibration routine averages samples when the accelerometer is in a no movement condition. The more samples that are taken, the more accurate the calibration results will be.
After applying the high pass filter, we simply subtract the values obtained during the calibration process. Notice that we are only applying the filter to x and y acceleration components.
After calibrating our values have been improved getting rid of earth's gravity but we can still see errors due to vibration and noise.
The real value of the acceleration is the sample minus the calibration value; it can be either positive or negative.
How can we obtain the velocity and the position from the accelerometer data?
Acceleration is the rate of change in the velocity of an object.
Velocity is the rate of change in the position of that same object.
In math we say that velocity is the derivative of position and acceleration is the derivative of velocity, like this:
a=ddt v and v=ddt x
Integration is the opposite of the derivative. If the acceleration of an object is known, we can obtain the position data by applying a double integration (assuming that the initial conditions are zero):
v=∫aba(t)dt+v0 x=∫abv(t)dt = ∫ab∫aba(t)dt
The integral computes the area below the curve, where the integration is the sum of very small areas whose width is almost zero.
In other words, the sum of the integration represents the magnitude of a physical variable.
Let makes some numbers to see how this work.
Sampling a signal gives us instantaneous values of its magnitude, so small areas can be created between two samples. This method introduces errors
velX(t)=velX(t−1)+a(t)·△t
PosX(t)=PosX(t−1)+v(t).△t
For this method to be correct, the time increment between samples would have to be zero. To reduce the error a bit we can divide the rectangular area into another rectangle and a triangle. The good news is that we can reduce the error by increasing the sampling frequency, but the bad news is that the velocity error accumulates and what is worse the position error increases quadratically.
velX(t)=velX(t−1)+(a(t−1)+a(t)−a(t−1)2 )×△t
posX(t)=posX(t−1)+(v(t−1)+v(t)−v(t−1)2 )×△t
Let's see what it looks like.
Moving the device to the left:
Moving the device to the right:
How to obtain movement direction
Average velocity < 0 going to the right
Average velocity >0 going to the left
Velocity = 0 stopped
Using a quadrature encoder to determine the position of the moving part in the situations with sliding displacement
Encoders
An encoder is a sensor which turns a position into an electronic signal. There are two forms: Absolute encoders give an absolute position value. Incremental encoders count movement rather than position.
With detection of a datum position and the use of a counter, an absolute position may be derived.
What is a quadrature encoder?
A quadrature encoder is an incremental encoder with 2 out-of-phase output channels used in many general automation applications where sensing the direction of movement is required. Each channel provides a specific number of equally spaced pulses per revolution (PPR) and the direction of motion is detected by the phase relationship of one channel leading or trailing the other channel.
The idea is very intuitive and when I came up with it, I didn't even know that they were called this way.
These blogs from element14 masters are a good introduction to understanding how it works.
Making a custom magnetic encoder for sliding windows.
We can make a quadrature encoder with two magnetic sensor to detect the out-phase and another one for detecting closed and open state.
But we are trying to do the same thing with only two reed sensors.
Let's try to design a quadrature encoder with open close detection.
The first two magnets are close enough to have the two magnetic sensors in phase so we can detect the open closed state, after that after the sensor 1 detects the second magnet the quadrature encoder will start.
In this case, the device can be located both on the mobile part and on the fixed part.
The encoder in action
When closed both switches are closed.
After switch 1 transitions from off to on without a switch 2 transition, the quadrature encoder is activated.
Timing diagrams
Breadboard diagram for testing.
The two push button switches in parallel with the reed sensors will allow us to simulate the transitions without the magnets.
Designing a model to make tests
I start to need a model to carry out the tests in a controlled environment.
I am going to have to design a wooden model to simulate sliding windows.
It should have
- a single degree of freedom,
- simulate small vibrations,
- have friction similar to a sliding window
- and some rollers to facilitate movement
- a surface where the device and / or magnets can be placed both on the fixed part and on the mobile part, enough to place a medium-sized breadboard
Next steps
- Continue with the study of the windows, strategies for the measurements in the pivoting parts.
- Design and build a mockup to simulate the behavior with the sliding parts.
- Design and build a mockup to simulate the behavior with the pivoting parts.
- Investigate what ML can contribute to our goals.
- Create a game to get familiar with the accelerometer and have fun along the way.
<< Previous VenTTracker Blog | Next VenTTracker Blog >> |
---|---|
VenTTracker #01 - Intro and motivation. | VenTTracker #03 - Analyzing window types II |
Top Comments