Development of cargo monitoring system for a rapid

  • Slides: 29
Download presentation
Development of cargo monitoring system for a rapid response team (disaster aid) Overview of

Development of cargo monitoring system for a rapid response team (disaster aid) Overview of concepts that you will demonstrate during Labs 3 and 4 / 28

Disaster Relief Issues n Disaster likely to be in remote areas q n Cargo

Disaster Relief Issues n Disaster likely to be in remote areas q n Cargo to be delivered by skid-air drop q n 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 q q n Roads are blocked, bridges destroyed – transportation very difficult Perishable goods (food) Delicate communication equipment (electronics) Need to know if cargo has been abused during transportation or delivery 2

Cargo Monitoring System n During transport q q q n Quick indication of health

Cargo Monitoring System n During transport q q q n Quick indication of health of product NOW Acceleration in range – accuracy of +- 1/16 G Temperature steady – accuracy of +- 1 / 32 C On delivery q Display of ranges that cargo has experienced n q Range of temperatures and accelerations Other cargo information 3

Overall design main( ) Initialize stuff (C++) Calculate Temperature Store temperature, calculate averages and

Overall design main( ) Initialize stuff (C++) Calculate Temperature Store temperature, calculate averages and ranges Calculate Acceleration Store acceleration, calculate averages and ranges General Purpose Timer controlling Display as ISR Temperature / Acceleration graphic (non-text) display Changes, actual temperatures Core timer ISR clock used for Temperature / Acceleration determination Communications with LCD MOSI / MISO format -- ISR Temperature / Acceleration information Text format 4

How is the project being split up? n Devices use pulse-width modulation q Acceleration

How is the project being split up? n Devices use pulse-width modulation q Acceleration – Handle through examples in the lectures q 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 n LCD display – SPI interface q Acceleration – Handle through examples in the lectures q Temperature – You are handling this in Lab. 4 q 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 5

Warning n n I plan to do these lectures to document the delivery of

Warning n n 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. q q 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 6

Overall design main( ) Initialize stuff (C++) Calculate Temperature Store temperature, calculate averages and

Overall design main( ) Initialize stuff (C++) Calculate Temperature Store temperature, calculate averages and ranges Calculate Acceleration Store acceleration, calculate averages and ranges General Purpose Timer controlling Display as ISR Temperature / Acceleration graphic (non-text) display Changes, actual temperatures Core timer ISR clock used for Temperature / Acceleration determination Communications with LCD MOSI / MISO format -- ISR Temperature / Acceleration information Text format 7

Do the easy part first n To calculate range q n How to calculate

Do the easy part first n To calculate range q n How to calculate acceleration average? q n max. Acc, min. Acc, now. Acc need to be determined? Store now. Acc in an array, update the array with new values, discard old values? Quick indicators needed q Acceleration stable, increasing, decreasing Calculate Acceleration Store acceleration, calculate averages and ranges 8

First problems – interpreting n Quick indicators requirements q Acceleration stable, increasing, decreasing What

First problems – interpreting n Quick indicators requirements q Acceleration stable, increasing, decreasing What do these requirements mean? n Most of the time the cargo will be experienced 1 G acceleration downwards due to gravity n Acceleration can occur in 3 dimensions 9

First problems – interpreting Quick indicators requirements n q Acceleration stable, increasing, decreasing What

First problems – interpreting Quick indicators requirements n q Acceleration stable, increasing, decreasing What do these requirements mean? n If we plan to use ADXL 213 Dual axis accelerometers, then we need 2 ADXL 213 Dual axis accelerometers q One doing x and y q One doing x and z q Could plan to use the two x-acceleration values as cross checks on each other to make sure that measuring equipment is working n How does the accelerometer behave if cargo experiences acceleration outside of design limits of accelerometer? q q 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? 10

Design details added main( ) Initialize stuff (C++) #define ACCELERATION_STEADY 1 #define ACCELERATION_DECREASING 2

Design details added main( ) Initialize stuff (C++) #define ACCELERATION_STEADY 1 #define ACCELERATION_DECREASING 2 #define ACCELERATION_INCREASING 3 volatile variable acceleration_changing Calculate Temperature Store temperature, calculate averages and ranges Calculate Acceleration Store acceleration, calculate averages and ranges Communication between main( ) and ISR means use volatile variables General Purpose Timer controlling Display as ISR Temperature / Acceleration graphic (non-text) display Changes, actual temperatures 11

Develop first test -- Requirements n n variable acceleration_changing is modified in main( )

Develop first test -- Requirements n n 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) 12

First Test concept TEST START acceleration_now == average_acceleration Set_Acceleration_Mode(acceleration_now , average_acceleration) CHECK(acceleration_changing signal shown

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 13

Three files are going to be needed Lab 3 directory – where product will

Three files are going to be needed Lab 3 directory – where product will end up being built n lab 3 prototypes. h #define ACCELERATION_STEADY 1 #define ACCELERATION_DECREASING 2 #define ACCELERATION_INCREASING 3 void Set_Acceleration_Mode(long int current_Acc, long int average_ACC); n Code. Acceleration. cpp Set_Acceleration_Mode( current_Acc, average_ACC) { All necessary code to make function work } Lab 3 tests directory – where all tests will be built n Tests. Acceleration. cpp TEST(Set_Acceleration_Mode, DEVELOPER_TEST) { All necessary code to test that function works } 14

Write the test code using E-TDD syntax #include “. . /Lab 3/lab 3 prototypes.

Write the test code using E-TDD syntax #include “. . /Lab 3/lab 3 prototypes. 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 15

Design details added Where is best to place this variable #define ACCELERATION_STEADY 1 #define

Design details added Where is best to place this variable #define ACCELERATION_STEADY 1 #define ACCELERATION_DECREASING 2 #define ACCELERATION_INCREASING 3 variable acceleration_changing 1. On the stack? 2. As an extern? 3. In. section L 1_data? Calculate Acceleration Store acceleration, calculate averages and ranges Communication between main( ) and ISR General Purpose Timer controlling Display as ISR Temperature / Acceleration graphic (non-text) display Changes, actual temperatures 16

Where to place variable CHOICE 1 – on the stack inside the test method

Where to place variable CHOICE 1 – on the stack inside the test method acceleration_changing? 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); 17

What is the correct design decision? Why is that the correct decision? n Decision

What is the correct design decision? Why is that the correct decision? n Decision n Now write the code that satisfies the test 18

Next test – Ability to calculate Average n Ability to calculate an average acceleration

Next test – Ability to calculate Average n Ability to calculate an average acceleration based on an array of previous acceleration values bool Calculate. Average(int *previous, int num, int *average_value) previous is the array of previous values num is the number of elements in the array average_value is the average acceleration calculated Returns true if the average value can be calculated 19

Design details added Where is best to place the arrays used in averaging previous

Design details added Where is best to place the arrays used in averaging previous acceleration measurements? Array information is not needed in any global sense THEREFORE PLACE THE ARRAY ON THE STACK (local variable) 1. On the stack? 2. As an extern? 3. In. section L 1_data? General Purpose Timer controlling Display as ISR Calculate Acceleration Store acceleration, calculate averages and ranges Temperature / Acceleration graphic (non-text) display Changes, actual temperatures 20

Write the test code using E-TDD syntax #include “. . /Lab 3/lab 3 prototypes.

Write the test code using E-TDD syntax #include “. . /Lab 3/lab 3 prototypes. h” TEST(Average. Calculation, DEVELOPER_TEST) int previous_values[10] = {0, 0, 2, 2, 1, 1, 10, 10}; int average_value = 0; bool result = true; // Empty array -- invalid number of points as array length result = Calculate. Average(previous_values, 0, &average_value); CHECK(result == false); // Average first two values average_value = 6; result = Calculate. Average(previous_values, 2, &average_value); CHECK(result == true); CHECK(average_value == 0); // Average first four values result = Calculate. Average(previous_values, 4, &average_value); CHECK(result == true); CHECK(average_value == 1); etc. Now write the code that satisfies the test 21

Next test – Ability to store previous acceleration values in a defined array n

Next test – Ability to store previous acceleration values in a defined array n n Need to store values into an array Problem – suppose array is of size 10 – how do you store the 11 th array entry? q q Answer – use circular buffers GUI note: Don’t use % function (modulus) as this involves a division – very slow on this processor. bool Add. To. Array(int *previous, int num, int new_acceleration_value) Returns true if the Add. To. Array( ) operation can be performed 22

Reminder How is the project being split up? n Devices use pulse-width modulation q

Reminder How is the project being split up? n Devices use pulse-width modulation q Acceleration – Handle through examples in the lectures q 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 n LCD display – SPI interface q Acceleration – Handle through examples in the lectures q Temperature – You are handling this in Lab. 4 q 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 23

Write the test code using E-TDD syntax (1) #include “. . /Lab 3/lab 3

Write the test code using E-TDD syntax (1) #include “. . /Lab 3/lab 3 prototypes. h” TEST(Add. To. Array, DEVELOPER_TEST) { #define MAX_ARRAY_SIZE 8 // WOULD THIS BE BETTER DEFINED INSIDE. . /Lab 3/lab 3 prototypes. h? int previous_values[MAX_ARRAY_SIZE] = {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}; result = Add. To. Array(previous_values, MAX_ARRAY_SIZE, 1); CHECK(result == true); ARRAYS_EQUAL(expected 1, previous_values, MAX_ARRAY_SIZE); // Have new acceleration values of 2 and then 3 – add those to the array int expected 2[MAX_ARRAY_SIZE] = {1, 2, 3, 0, 0, 0}; result = Add. To. Array(previous_values, MAX_ARRAY_SIZE, 2); CHECK(result == true); result = Add. To. Array(previous_values, MAX_ARRAY_SIZE, 3); CHECK(result == true); ARRAYS_EQUAL(expected 2, previous_values, MAX_ARRAY_SIZE); ……………MORE TEST CODE TO COME ………………. 24

Write the test code using E-TDD syntax (2) TEST(Add. To. Array, DEVELOPER_TEST) { ………

Write the test code using E-TDD syntax (2) TEST(Add. To. Array, DEVELOPER_TEST) { ……… TEST CODE CONTINUED ……… // Have new acceleration values of 2 and then 3 – add those to the array int expected 2[MAX_ARRAY_SIZE] = {1, 2, 3, 0, 0, 0}; result = Add. To. Array(previous_values, MAX_ARRAY_SIZE, 2); result = Add. To. Array(previous_values, MAX_ARRAY_SIZE, 3); ARRAYS_EQUAL(expected 2, 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 expected 2[MAX_ARRAY_SIZE] = {1, 2, 3, 0, 0, 0}; int expected 3[MAX_ARRAY_SIZE] = {9, 10, 11, 4, 5, 6, 7, 8}; for (int count = 4; count < 4 + MAX_ARRAY_SIZE; count++) { result = Add. To. Array(previous_values, MAX_ARRAY_SIZE, count); CHECK(result == true); } ARRAYS_EQUAL(expected 3, previous_values, MAX_ARRAY_SIZE); } NOW WRITE THE CODE THAT SATISFIES THE TEST 25

ADXL 213 Dual Axis Accelerometer PF 9 PF 8 26

ADXL 213 Dual Axis Accelerometer PF 9 PF 8 26

Calculation the acceleration using information from the hardware n n Let us assume that

Calculation the acceleration using information from the hardware n n Let us assume that we have measured the time (in clock pulses) for T 1 (T 1_high) and T 2 (T 2_period) Need to develop the tests to check that correctly calculate the acceleration when the acceleration is in the range +1. 7 G to -1. 7 G bool Calculate. Acceleration(int T 1_high, int T 2_period, int *new_acceleration_value) 27

Before tomorrow’s class n Write the tests needed to show that bool Calculate. Acceleration(int,

Before tomorrow’s class n Write the tests needed to show that bool Calculate. Acceleration(int, int *) correctly calculates the acceleration when the acceleration is in the range +1. 7 G to -1. 7 G Through this test design – identify the “design defect” in the current project design concept for the transportation monitoring device 28

Disaster Relief Issues n Disaster likely to be in remote areas q n Cargo

Disaster Relief Issues n Disaster likely to be in remote areas q n Cargo to be delivered by skid-air drop q n 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 q n Roads are blocked, bridges destroyed – transportation very difficult Perishable goods (food), delicate communication equipment (electronics) Need to know if cargo has been abused during transportation or delivery!!!!!! 29