![Page 1: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/1.jpg)
Development of cargo monitoring system for arapid response team (disaster aid)Overview of concepts for a “real”
embedded system
![Page 2: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/2.jpg)
2 / 28
Disaster Relief Issues
Disaster likely to be in remote areas Roads are blocked, bridges destroyed – transportation very
difficult Cargo to be delivered by skid-air drop
Basically, fly very low over the area, throw out a small parachute, cargo-skid is pulled out of the aircraft and falls to ground – not parachuted down
Mixed cargo Perishable goods (food) Delicate communication equipment (electronics)
Need to know if cargo has been abused during transportation or delivery
![Page 3: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/3.jpg)
3 / 28
Cargo Monitoring System
During transport Quick indication of health of product NOW Acceleration in range – accuracy of +- 1/16 G Temperature steady – accuracy of +- 1 / 32 C
On delivery Display of ranges that cargo has experienced
Range of temperatures and accelerations Other cargo information
![Page 4: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/4.jpg)
4 / 28
Overall designInitialize stuff (C++)
Calculate Temperature
Store temperature, calculate averages
and ranges
Calculate Acceleration
Store acceleration, calculate averages
and ranges
General Purpose Timercontrolling Display as
ISR
Temperature / Accelerationgraphic (non-text) display
Changes, actual temperatures
Core timerISR clockused for
Temperature / Accelerationdetermination
Communications with LCDMOSI / MISO format -- ISR
Temperature / AccelerationinformationText format
main( ) Play music and monitor light
levels might be nice too
![Page 5: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/5.jpg)
5 / 28
How is the project being split up? Devices use pulse-width modulation
Acceleration – Handle through examples in the lectures Temperature – You are handling this in Lab. 3.
This means that all the tests and functions developed in the lectures for handling acceleration using a pulse-width modulated device will need to be modified by you for handling temperature
LCD display – SPI interface Acceleration – Handle through examples in the lectures Temperature – You are handling this in Lab. 4 This means that all the tests and functions developed in the
lectures for displaying acceleration using am SPI display device will need to be modified by you for handling temperature
![Page 6: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/6.jpg)
6 / 28
Warning
I plan to do these lectures to document the delivery of a design using a test driven development approach
I don’t know where the final project (code etc) will end up at this moment. Design decisions may change as I go along. If design decisions change, then I will have to change some
of my tests and code.
HOWEVER, I HAVE NO INTENTION OF GOING TO BACK AND MODIFYING THE EARLIER LECTURE NOTES. SO KEEP THAT IN MIND IF YOU DON’T ATTEND ALL THE CLASSES
![Page 7: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/7.jpg)
7 / 28
Overall designInitialize stuff (C++)
Calculate Temperature
Store temperature, calculate averages
and ranges
Calculate Acceleration
Store acceleration, calculate averages
and ranges
General Purpose Timercontrolling Display as
ISR
Temperature / Accelerationgraphic (non-text) display
Changes, actual temperatures
Core timerISR clockused for
Temperature / Accelerationdetermination
Communications with LCDMOSI / MISO format -- ISR
Temperature / AccelerationinformationText format
main( )
![Page 8: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/8.jpg)
8 / 28
Do the easy part first To calculate range
maxAcc, minAcc, nowAcc need to be determined? How to calculate acceleration average?
Store nowAcc in an array, update the array with new values, discard old values?
Quick indicators needed Acceleration stable, increasing, decreasing
Calculate Acceleration
Store acceleration, calculate averages
and ranges
![Page 9: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/9.jpg)
9 / 28
First problems – interpreting requirements Quick indicators
Acceleration stable, increasing, decreasing
What do these requirements mean? Most of the time the cargo will be experienced 1G
acceleration downwards due to gravity Acceleration can occur in 3 dimensions
![Page 10: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/10.jpg)
10 / 28
First problems – interpreting requirements Quick indicators
Acceleration stable, increasing, decreasing
What do these requirements mean? If we plan to use ADXL213 Dual axis accelerometers, then we need 2
ADXL213 Dual axis accelerometers One doing x and y One doing x and z Could plan to use the two x-acceleration values as cross checks on each
other to make sure that measuring equipment is working
How does the accelerometer behave if cargo experiences acceleration outside of design limits of accelerometer? Saturation – if bigger acceleration is experienced than biggest than can
be measured, then returns biggest acceleration allowed Aliasing – wrap-around -- if bigger than biggest that can be measured,
then looks like smallest allowed or perhaps even big in the wrong direction – like a car odometer (distance) that goes to 999999 and then 000000
Need to find out -- Do some experiments? Manual has the information?
![Page 11: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/11.jpg)
11 / 28
Design details addedInitialize stuff (C++)
Calculate Temperature
Store temperature, calculate averages
and ranges
Calculate Acceleration
Store acceleration, calculate averages
and ranges
General Purpose Timercontrolling Display as
ISR
Temperature / Accelerationgraphic (non-text) display
Changes, actual temperatures
#define ACCELERATION_STEADY 1#define ACCELERATION_DECREASING 2#define ACCELERATION_INCREASING 3
volatile variable acceleration_changing
Communicationbetweenmain( )
and ISR
means use
volatile
variables
main( )
![Page 12: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/12.jpg)
12 / 28
Develop first test -- Requirements variable acceleration_changing is modified in
main( ) depending on whether current acceleration is greater than, equal to, or less than the average acceleration
Display ISR uses this information to modify how the LED flash (flicker the lights up (acceleration increasing), flicker the lights down (acceleration decreasing)), steady lights (acceleration reasonably stable – within some limits), )
Set_Acceleration_Mode( current_Acc, average_ACC)
![Page 13: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/13.jpg)
13 / 28
First Test concept
TEST START
acceleration_now == average_acceleration Set_Acceleration_Mode(acceleration_now , average_acceleration) CHECK(acceleration_changing signal shown as steady)
acceleration_now < average_acceleration Set_Acceleration_Mode(acceleration_now , average_acceleration) CHECK(acceleration_changing signal shown as decreasing)
acceleration_now > average_acceleration Set_Acceleration_Mode(acceleration_now , average_acceleration) CHECK(acceleration_changing signal shown as increasing)
TEST END
![Page 14: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/14.jpg)
14 / 28
Three files are going to be neededLab3 directory – where product will end up being built lab3prototypes.h
#define ACCELERATION_STEADY 1 Lab. 3 TEMPERATURE_STEADY#define ACCELERATION_DECREASING 2 #define ACCELERATION_INCREASING 3
void Set_Acceleration_Mode(long int current_Acc, long int average_ACC);
CodeAcceleration.cpp Set_Acceleration_Mode( current_Acc, average_ACC) {
All necessary code to make function work }
Lab3 tests directory – where all tests will be built TestsAcceleration.cpp
TEST(Set_Acceleration_Mode, DEVELOPER_TEST) {
All necessary code to test that function works }
![Page 15: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/15.jpg)
15 / 28
Write the test code using E-TDD syntax#include “../Lab3/lab3prototypes.h”
TEST(Set_Acceleration_Mode, DEVELOPER_TEST)
// acceleration_now == average_acceleration Set_Acceleration_Mode(6 , 6); CHECK(acceleration_changing == ACCELERATION_STEADY);
// acceleration_now < average_acceleration Set_Acceleration_Mode(0 , 6); CHECK(acceleration_changing == ACCELERATION_DECREASING);
// acceleration_now > average_acceleration Set_Acceleration_Mode(acceleration_now , average_acceleration) CHECK(acceleration_changing == ACCELERATION_INCREASING);
}
Now write the code that satisfies the test
![Page 16: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/16.jpg)
16 / 28
Design details added
Calculate Acceleration
Store acceleration, calculate averages
and ranges
General Purpose Timercontrolling Display as
ISR
Temperature / Accelerationgraphic (non-text) display
Changes, actual temperatures
#define ACCELERATION_STEADY 1#define ACCELERATION_DECREASING 2#define ACCELERATION_INCREASING 3
variable acceleration_changing
Communicationbetweenmain( )
and ISR
Where is best to place thisvariable
1. On the stack?
2. As an extern?
3. In .section L1_data?
![Page 17: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/17.jpg)
17 / 28
Where to place variable acceleration_changing? CHOICE 1 – on the stack inside the test method
TEST(Set_Acceleration_Mode, DEVELOPER_TEST)
int acceleration_changing = 0;
Set_Acceleration_Mode(6 , 6); CHECK(acceleration_changing == ACCELERATION_STEADY);
CHOICE 2 – as an external global variable, with the variable declared in another file
extern int acceleration_changing;
TEST(Set_Acceleration_Mode, DEVELOPER_TEST)
Set_Acceleration_Mode(6 , 6); CHECK(acceleration_changing == ACCELERATION_STEADY);
CHOICE 3 – as a global variable, declared in this file but used by functions in other files
int acceleration_changing = 0;
TEST(Set_Acceleration_Mode, DEVELOPER_TEST)
Set_Acceleration_Mode(6 , 6); CHECK(acceleration_changing == ACCELERATION_STEADY);
![Page 18: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/18.jpg)
18 / 28
What is the correct design decision?Why is that the correct decision? Decision
Now write the code that satisfies the test
![Page 19: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/19.jpg)
19 / 28
Next test – Ability to calculate Average
Ability to calculate an average acceleration based on an array of previous acceleration values
bool CalculateAverage(int *previous, int num, int *average_value)
previous is the array of previous valuesnum is the number of elements in the arrayaverage_value is the average acceleration calculatedReturns true if the average value can be calculated
![Page 20: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/20.jpg)
20 / 28
Design details added
Calculate Acceleration
Store acceleration, calculate averages
and ranges
General Purpose Timercontrolling Display as
ISR
Temperature / Accelerationgraphic (non-text) display
Changes, actual temperatures
Array information is not needed in any global sense
THEREFORE PLACE THE ARRAYON THE STACK (local variable)
Where is best to place thearrays used in averagingprevious accelerationmeasurements?
1. On the stack?
2. As an extern?
3. In .section L1_data?
![Page 21: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/21.jpg)
21 / 28
Write the test code using E-TDD syntax#include “../Lab3/lab3prototypes.h”
TEST(AverageCalculation, DEVELOPER_TEST) LAB3 – Equivalent with Temperature
int previous_values[10] = {0, 0, 2, 2, 1, 1, 10, 10, 10, 10}; int average_value = 0; bool result = true;
// Empty array -- invalid number of points as array length result = CalculateAverage(previous_values, 0, &average_value); CHECK(result == false);
// Average first two values
average_value = 6; result = CalculateAverage(previous_values, 2, &average_value); CHECK(result == true); CHECK(average_value == 0);
// Average first four values result = CalculateAverage(previous_values, 4, &average_value); CHECK(result == true); CHECK(average_value == 1);
etc.
Now write the code that satisfies the test
![Page 22: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/22.jpg)
22 / 28
Next test – Ability to store previous acceleration values in a defined array
Need to store values into an array Problem – suppose array is of size 10 – how do you
store the 11th array entry? Answer – use circular buffers GUI note: Don’t use % function (modulus) as this involves a
division – very slow on this processor.
bool AddToArray(int *previous, int num, int new_acceleration_value)
Returns true if the AddToArray( ) operation can be performed
![Page 23: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/23.jpg)
23 / 28
ReminderHow is the project being split up? Devices use pulse-width modulation
Acceleration – Handle through examples in the lectures Temperature – You are handling this in Lab. 3.
This means that all the tests and functions developed in the lectures for handling acceleration using a pulse-width modulated device will need to be modified by you for handling temperature
LCD display – SPI interface Acceleration – Handle through examples in the lectures Temperature – You are handling this in Lab. 4 This means that all the tests and functions developed in the
lectures for displaying acceleration using am SPI display device will need to be modified by you for handling temperature
![Page 24: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/24.jpg)
24 / 28
Write the test code using E-TDD syntax (1)#include “../Lab3/lab3prototypes.h”
TEST(AddToArray, DEVELOPER_TEST) { LAB3 – Equivalent with Temperature
#define MAX_ARRAY_SIZE 8 // WOULD THIS BE BETTER DEFINED INSIDE ../Lab3/lab3prototypes.h? int previous_values[MAX_ARRAY_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0}; bool result;
// Have a new acceleration value of 1 – add to the array int expected [MAX_ARRAY_SIZE] = {1, 0, 0, 0, 0, 0, 0, 0}; result = AddToArray(previous_values, MAX_ARRAY_SIZE, 1); CHECK(result == true); ARRAYS_EQUAL(expected1, previous_values, MAX_ARRAY_SIZE);
// Have new acceleration values of 2 and then 3 – add those to the array int expected2[MAX_ARRAY_SIZE] = {1, 2, 3, 0, 0, 0, 0, 0}; result = AddToArray(previous_values, MAX_ARRAY_SIZE, 2); CHECK(result == true);
result = AddToArray(previous_values, MAX_ARRAY_SIZE, 3); CHECK(result == true); ARRAYS_EQUAL(expected2, previous_values, MAX_ARRAY_SIZE);
…………………………MORE TEST CODE TO COME …………………………….
![Page 25: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/25.jpg)
25 / 28
Write the test code using E-TDD syntax (2)TEST(AddToArray, DEVELOPER_TEST) { LAB3 – Equivalent with Temperature Array
……… TEST CODE CONTINUED ………
// Have new acceleration values of 2 and then 3 – add those to the array int expected2[MAX_ARRAY_SIZE] = {1, 2, 3, 0, 0, 0, 0, 0}; result = AddToArray(previous_values, MAX_ARRAY_SIZE, 2); result = AddToArray(previous_values, MAX_ARRAY_SIZE, 3); ARRAYS_EQUAL(expected2, previous_values, MAX_ARRAY_SIZE);
// Now add eight new values to the array – that will force a wrap-around of the array value// Now the three oldest values have been overwritten
// int expected2[MAX_ARRAY_SIZE] = {1, 2, 3, 0, 0, 0, 0, 0}; int expected3[MAX_ARRAY_SIZE] = {9, 10, 11, 4, 5, 6, 7, 8}; for (int count = 4; count < 4 + MAX_ARRAY_SIZE; count++) { result = AddToArray(previous_values, MAX_ARRAY_SIZE, count); CHECK(result == true); } ARRAYS_EQUAL(expected3, previous_values, MAX_ARRAY_SIZE);
}
NOW WRITE THE CODE THAT SATISFIES THE TEST
![Page 26: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/26.jpg)
26 / 28
ADXL213 Dual Axis Accelerometer
PF9
PF8
![Page 27: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/27.jpg)
27 / 28
Calculation the acceleration using information from the hardware
LAB3 – Equivalent with Temperature Sensor
Let us assume that we have measured the time (in clock pulses) for T1 (T1_high) and T2 (T2_period)
Need to develop the tests to check that correctly calculate the acceleration when the acceleration is in the range +1.7G to -1.7G
bool CalculateAcceleration(int T1_high, int T2_period, int *new_acceleration_value)
![Page 28: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/28.jpg)
28 / 28
Before tomorrow’s class
Write the tests needed to show that
bool CalculateAcceleration(int, int, int *)
correctly calculates the acceleration when the acceleration is in the range +1.7G to -1.7G
Through this test design – identify the “design defect” in the current project design concept for the transportation monitoring device
![Page 29: Development of cargo monitoring system for a rapid response team (disaster aid)](https://reader034.vdocuments.mx/reader034/viewer/2022042822/5681333e550346895d9a3487/html5/thumbnails/29.jpg)
29 / 28
Disaster Relief Issues
Disaster likely to be in remote areas Roads are blocked, bridges destroyed – transportation very
difficult Cargo to be delivered by skid-air drop
Basically, fly very low over the area, throw out a small parachute, cargo-skid is pulled out and falls to ground – not parachuted down
Mixed cargo Perishable goods (food), delicate communication
equipment (electronics) Need to know if cargo has been abused during
transportation or delivery!!!!!!