Triple redundancy sensor matlab code

Click For Summary

Discussion Overview

The discussion revolves around a homework problem related to implementing a control logic for a scientific telescope that uses triple redundancy in sensor measurements. Participants explore how to handle NaN values in sensor data, calculate averages from valid measurements, and manage conditions for exiting loops based on sensor failures.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant expresses uncertainty about how to compute the mean of an array while ignoring NaN values, noting that using the mean function directly results in NaN if any elements are NaN.
  • The same participant seeks clarification on how to implement a condition to break a loop only after detecting 30 consecutive rows of all NaN values, questioning the effectiveness of their current approach.
  • There are concerns about correctly implementing the logic for previous estimates when all sensors fail, with a participant unsure about how to manage this within their code.
  • Another participant indicates that they have resolved their issues and suggests disregarding the previous posts.
  • A further inquiry is made about how the problem was solved, indicating a desire for insight into the resolution process.
  • One participant recommends seeking help from a teaching assistant (TA) for additional support.

Areas of Agreement / Disagreement

The discussion reflects a lack of consensus, as one participant has resolved their issues while others continue to seek clarification on specific coding challenges. There are no definitive solutions presented, and multiple viewpoints on the approach to the problem exist.

Contextual Notes

Participants express uncertainty about handling NaN values and managing loop conditions, indicating potential limitations in their understanding of MATLAB functions and control structures. The discussion does not resolve these uncertainties.

gfd43tg
Gold Member
Messages
949
Reaction score
48

Homework Statement


Hardware redundancy is important in many real-world engineering systems. Specifically, installing
multiple sensors that measure the same quantity provides a level of safety in the event that one
instrument fails during the mission lifetime. You do not want an expensive project to become a
complete failure simply due to the malfunction of one small part.

Suppose you are an engineer designing the control logic for a scientific telescope that will be
launched into space to study the sun. In order to provide a reasonable layer of safety, a triple
redundancy in the measurement of the telescope's elevation angle with respect to the horizon of
the Earth has been put into place (i.e. these three sensors measure the same quantity). Your task
is to program the software logic that will determine how the three independent measurements
will be combined in real-time, in order to provide the on-board computer with the best possible
estimate of the true elevation angle.

The following is known about the sensors:
- If a sensor fails, its measurement will read as NaN;
- Otherwise, working sensors provide measurements that will read as finite double values;
- Faulty/loose wiring may cause a measurement to read as NaN for a few samples, but can
return to valid measurements.

The estimator code must incorporate the following logic:
- On startup, the estimator logic defines the "previous estimate" to be NaN
- If there are any working sensors, define the elevation estimate as the average of the mea-
surements from all working sensors
- if all three sensors fail, the elevation estimate should be set to the previous estimate
- if all three sensors read NaN for 30 consecutive samples, then exit the sensor loop.

Load the sensorData.mat file which contains measurements, a Nx3 double array of sensor
measurements. Write code to "simulate" your sensor logic by looping through measurements
one row at a time to mimic the real-time sensor readings. Store the elevation estimates for each
loop iteration in a column vector called elevationEstimates.


Homework Equations





The Attempt at a Solution


This problem has a lot of information, so I am trying to break it down into 'subsystems' and solve the individual subsystems. I have a few problems right now with my code that I haven't been able to reconcile. I will list them out right now as I see them. This is a 150x3 array

1. I don't know how to find the mean of only the components of an array that are not NaN. If I do the mean of a row that has any components that are NaN, the mean is NaN. This problem becomes apparent in my code at the elevationEstimate lines, where I have a [ ] which is where I want to somehow specify to take the mean of the elements that are not NaN.

If I do isnan(measurements(4,:)) for example, I get an array [0 0 1]. Now, I want to go back to the elements of the array where isnan(measurements(i,:)) = 0 and take the mean of those.

2. I want the code to break when I get 30 rows consecutively that have all columns = NaN. I thought to do a while loop with failcounter(i:i+29) == 30. If I add break after that, will that let MATLAB know only to break if that condition is meant, or is it just going to break at that line no matter what. If it does break no matter what, how do I set it so that it will only break the loop if I get 30 consecutive rows of all NaN.

3. I am having some problems implementing this previousEstimates



Code:
failcounter = 0;
counter = 0;
previousEstimate = NaN;
for i = 1:length(measurements)
    while failcounter(i:i+29) == 30
break
if sum(isnan(measurements(i,:))) == 0
    counter = counter + 1;
    failcounter = 0;
    elevationEstimates = mean(measurements(i,:));
elseif sum(isnan(measurements(i,:))) == 1
    counter = counter + 1;
    failcounter = 0;
    elevationEstimates = mean(measurements(i,[ ]));
elseif sum(isnan(measurements(i,:))) == 2
    counter = counter + 1;
    failcounter = 0;
    elevationEstimates = mean(measurements(i, [ ]))
else
    failcounter = failcounter + 1;
    previousEstimate = elevationEstimates(counter);
end 
if sum(measurements(1,:)) == 3
    previousEstimates = NaN;
end 

    end
end
 
Physics news on Phys.org
solved, disregard
 
How did you solve this problem?
 
Get help from the TA, good luck with E7!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K