Question
Your program will calculate the resultant saturated pressure of our mythical vessel of special fluid and air to a global variable vesselPress_psia, from a temperature
Your program will calculate the resultant saturated pressure of our mythical vessel of special fluid and air to a global variable vesselPress_psia, from a temperature (degrees Celsius, global variable vesselTemp_C). This temperature represents an electrical sensor input converted to engineering units. The linear interpolation algorithm is based on degrees Fahrenheit.
Requirements
Reuse your Hw5 or baseline from the solution code of Hw5. If you use the solution code, change all appropriate comments and assume ownership. This homework will use a stub function which mimics an API to a sensor. A stub function is used for testing and is replaced after verification of the application code is completed. The function descriptions are as follows:
HW5 Code:
SCOPE:
By using linear interpolation algorithm and followed HW3 we can create C program of pressure for provided temperatur.
*/
#include
#include
//global constant temperature and pressure arrays
const float tempF[] = { 35, 40, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200, 212, 220, 240, 260, 280, 300, 350, 400, 450, 500, 550, 600, 650, 700 };
const float psi[] = { 0.0885, 0.1217, 0.1781, 0.2563, 0.3631, 0.5069, 0.6979, 0.9493, 1.692, 2.888, 4.736, 7.507, 11.52, 14.69, 17.19, 24.97, 35.43, 49.20, 67.01, 134.60, 247.26, 422.55, 680.86, 1045.43, 1543.20, 2208.40, 3094.30 };
const int size = 27; // size of the above arrays
int main(void)
{
float vesselTemp_C = 18, vesselTemp_F, fah_lower = 0, fah_upper = 0, psi_lower, psi_upper, res_psi;
// loop that continues till user input is within the range
while (1)
{
vesselTemp_F = ((vesselTemp_C * 9) / 5) + 32;
if (vesselTemp_F >= 35 && vesselTemp_F <= 700)
break;
else
{
printf(" Vessel temperature out of range. ");
}
}
int tempFound = 0;
// loop to find the psi if vesselTemp_F is present in array or find the metrics used to calculate the pressure for given temperature
for (int i = 0; i < size; i++)
{
if (vesselTemp_F == tempF[i])
{
res_psi = psi[i];
tempFound = 1;
break;
}
else if (vesselTemp_F > tempF[i])
{
fah_lower = tempF[i];
psi_lower = psi[i];
}
else if (vesselTemp_F < tempF[i])
{
fah_upper = tempF[i];
psi_upper = psi[i];
break;
}
}
if (tempFound == 0)
{
res_psi = psi_lower + (((vesselTemp_F - fah_lower) / (fah_upper - fah_lower)) * (psi_upper - psi_lower));
}
printf(" Result of hand test is psi ~= %f", res_psi);
return EXIT_SUCCESS;
}
Function MslTemp():
Input: No input arguments and no global data references
Returns: Pointer to next test data, NULL when no more test data
Arguments: None
Description:
Defines and retains the test input data representing a thermocouple sensor through and Analog Input (AI) port. The Thermocouple voltage is in units of degree Celsius.
Function Interpolate():
Input: There could be four arguments and no global data references Returns: Float value from the interpolation algorithm.
Arguments: You define the arguments for the function: at least two tables, a set point and
something else.
Description:
Calculates the resultant value from a set point and associated tables, limiter values,
through the use of lookup tables and interpolation. Saturation (limitation) is based on the first and last table entries.
The main() function will loop until MslTemp() returns NULL. For each loop MslTemp() returns the voltage of the sensor (test data). The voltage and appropriate tables are passed through the arguments to the function Interpolate() which will return the resultant Celsius temperature. The temperature is converted to Fahrenheit then Fahrenheit and appropriate tables are passed to Interpolate() which will return the resultant vesselPress_psia.
The test data for the function MslTemp() is in Appendix C, must be referenced only in MslTemp().
The code must perform Saturation testing. Provide your test plan for verifying Saturation testing in your header comment.
Design considerations:
1- Hw7 variation
a- If your Hw5 was buggered, you may use the Hw5 solution as a baseline for Hw7.(already given)
b- Not much changed, except initial data from a random number, it is replaced with a function and a test array, so you do not have to setup a breakpoint and change the data manually for each test step.
c- Main loop stops when a pointer becomes NULL.
2- Notice I added Function declaration information
a- These are requirements for the two function you must develop
b- The main() will call Interpolate() twice with different arguments for each loop.
c- The main() will call MslTemp() once a loop
Deliverables
1- You are to follow the Programming Standards for this class.
2- Submit as Hw7.c
Appendix A
Temperature - t - (oF) | Pressure - pv - (psia, lb/in2) |
35 | 0.0885 |
40 | 0.1217 |
50 | 0.1781 |
60 | 0.2563 |
70 | 0.3631 |
80 | 0.5069 |
90 | 0.6979 |
100 | 0.9493 |
120 | 1.692 |
140 | 2.888 |
160 | 4.736 |
180 | 7.507 |
200 | 11.52 |
212 | 14.69 |
220 | 17.19 |
240 | 24.97 |
260 | 35.43 |
280 | 49.20 |
300 | 67.01 |
350 | 134.60 |
400 | 247.26 |
450 | 422.55 |
500 | 680.86 |
550 | 1045.43 |
600 | 1543.20 |
650 | 2208.40 |
700 | 3094.30 |
Appendix B
Voltage VDC | Temperature (oC) |
1.2 | 1 |
1.5 | 20 |
1.8 | 45 |
2.1 | 90 |
2.4 | 120 |
2.7 | 185 |
3.0 | 205 |
3.4 | 275 |
3.8 | 300 |
4.4 | 350 |
4.8 | 390 |
Appendix C
Test data for function MslTemp(): float vdc [ ] = { 5.0, 1.1, 1.469 }
This data came from Hw5 Test plan for AI.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started