Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
cdEvaluation.c
Go to the documentation of this file.
1/*
2 * Academic License - for use in teaching, academic research, and meeting
3 * course requirements at degree granting institutions only. Not for
4 * government, commercial, or other organizational use.
5 * File: cdEvaluation.c
6 *
7 * MATLAB Coder version : 24.2
8 * C/C++ source code generated on : 06-May-2025 18:24:48
9 */
10
11/* Include Files */
12#include "cdEvaluation.h"
13#include "eml_mtimes_helper.h"
14#include "find.h"
15#include "mrdivide_helper.h"
16#include "mtimes.h"
17#include "rt_nonfinite.h"
18
19/* Function Definitions */
20/*
21 * Find indices of the surrounding x-coordinates
22 *
23 * Arguments : const double dep_states[6]
24 * const double mach_states[5]
25 * const double cd_table[30]
26 * double dep
27 * double mach
28 * Return Type : double
29 */
30double cdEvaluation(const double dep_states[6], const double mach_states[5],
31 const double cd_table[30], double dep, double mach)
32{
33 double b_b_tmp_data;
34 double b_tmp_data;
35 double c_b_tmp_data;
36 double cd;
37 double cd_table_data;
38 double d_b_tmp_data;
39 double tmp_data;
40 double x1_data;
41 double x2_data;
42 double y1_data;
43 double y2_data;
44 double y2_idx_data;
45 int cd_table_size[2];
46 int tmp_size[2];
47 int i;
48 int i1;
49 int loop_ub;
50 int x1_idx_data;
51 int y1_idx_data;
52 int y1_size;
53 int y2_size;
54 bool b_dep_states[6];
55 bool b_mach_states[5];
56 for (i = 0; i < 6; i++) {
57 b_dep_states[i] = (dep_states[i] <= dep);
58 }
59 i1 = eml_find(b_dep_states, (int *)&y1_idx_data);
60 loop_ub = i1;
61 for (i = 0; i < i1; i++) {
62 x1_idx_data = y1_idx_data;
63 }
64 for (i = 0; i < i1; i++) {
65 cd = (double)x1_idx_data + 1.0;
66 }
67 /* Find indices of the surrounding y-coordinates */
68 for (i = 0; i < 5; i++) {
69 b_mach_states[i] = (mach_states[i] <= mach);
70 }
71 i1 = b_eml_find(b_mach_states, (int *)&y1_idx_data);
72 for (i = 0; i < i1; i++) {
73 y2_idx_data = (double)y1_idx_data + 1.0;
74 }
75 /* Extract the surrounding x and y coordinates */
76 for (i = 0; i < loop_ub; i++) {
77 x1_data = dep_states[x1_idx_data - 1];
78 x2_data = dep_states[(int)cd - 1];
79 }
80 for (i = 0; i < i1; i++) {
81 y1_data = mach_states[y1_idx_data - 1];
82 y2_data = mach_states[(int)y2_idx_data - 1];
83 }
84 /* Extract the corresponding z-values */
85 /* Perform bilinear interpolation */
86 for (i = 0; i < loop_ub; i++) {
87 b_tmp_data = x2_data - dep;
88 }
89 for (i = 0; i < i1; i++) {
90 b_b_tmp_data = y2_data - mach;
91 }
92 for (i = 0; i < loop_ub; i++) {
93 c_b_tmp_data = dep - x1_data;
94 }
95 for (i = 0; i < i1; i++) {
96 d_b_tmp_data = mach - y1_data;
97 y2_data -= y1_data;
98 }
99 cd_table_size[0] = i1;
100 cd_table_size[1] = loop_ub;
101 if (loop_ub - 1 >= 0) {
102 for (i = 0; i < i1; i++) {
103 cd_table_data = cd_table[(y1_idx_data + 5 * (x1_idx_data - 1)) - 1];
104 }
105 }
106 for (i = 0; i < loop_ub; i++) {
107 x2_data = (x2_data - x1_data) * y2_data;
108 }
109 mrdiv_2((double *)&x2_data, loop_ub, (double *)&tmp_data, tmp_size);
110 y2_size = mtimes((double *)&cd_table_data, cd_table_size,
111 (double *)&b_tmp_data, (double *)&y2_data);
112 if (loop_ub - 1 >= 0) {
113 for (i = 0; i < i1; i++) {
114 cd_table_data = cd_table[(y1_idx_data + 5 * ((int)cd - 1)) - 1];
115 }
116 }
117 y1_size = mtimes((double *)&cd_table_data, cd_table_size,
118 (double *)&c_b_tmp_data, (double *)&y1_data);
119 if (loop_ub - 1 >= 0) {
120 for (i = 0; i < i1; i++) {
121 cd_table_data = cd_table[((int)y2_idx_data + 5 * (x1_idx_data - 1)) - 1];
122 }
123 }
124 x1_idx_data = mtimes((double *)&cd_table_data, cd_table_size,
125 (double *)&b_tmp_data, (double *)&x2_data);
126 if (loop_ub - 1 >= 0) {
127 for (i = 0; i < i1; i++) {
128 cd_table_data = cd_table[((int)y2_idx_data + 5 * ((int)cd - 1)) - 1];
129 }
130 }
131 y1_idx_data = mtimes((double *)&cd_table_data, cd_table_size,
132 (double *)&c_b_tmp_data, (double *)&x1_data);
133 if (y2_size == 1) {
134 i = y1_size;
135 } else {
136 i = y2_size;
137 }
138 if (i == 1) {
139 i1 = x1_idx_data;
140 } else {
141 i1 = i;
142 }
143 if ((y2_size == y1_size) && (i == x1_idx_data) && (i1 == y1_idx_data)) {
144 cd = 0.0;
145 loop_ub = tmp_size[1];
146 for (i = 0; i < loop_ub; i++) {
147 cd += tmp_data * (((y2_data * b_b_tmp_data + y1_data * b_b_tmp_data) +
148 x2_data * d_b_tmp_data) +
149 x1_data * d_b_tmp_data);
150 }
151 } else {
152 cd = binary_expand_op((double *)&tmp_data, tmp_size, (double *)&y2_data,
153 &y2_size, (double *)&b_b_tmp_data, (double *)&y1_data,
154 &y1_size, (double *)&x2_data, &x1_idx_data,
155 (double *)&d_b_tmp_data, (double *)&x1_data,
156 &y1_idx_data);
157 }
158 return cd;
159}
160
161/*
162 * File trailer for cdEvaluation.c
163 *
164 * [EOF]
165 */
double cdEvaluation(const double dep_states[6], const double mach_states[5], const double cd_table[30], double dep, double mach)
Estimates the coefficient of drag (Cd) via 2D bilinear interpolation.
Performs 2D bilinear interpolation to estimate the coefficient of drag (Cd).
double binary_expand_op(const double in1_data[], const int in1_size[2], const double in2_data[], const int *in2_size, const double in3_data[], const double in4_data[], const int *in4_size, const double in5_data[], const int *in5_size, const double in6_data[], const double in7_data[], const int *in7_size)
Performs a fused set of element-wise operations for 2D interpolation.
A MATLAB Coder helper for performing element-wise array operations.
int b_eml_find(const boolean_T x[5], int i_data[])
Finds the index of the last true element in a 5-element boolean array.
Definition find.c:21
int eml_find(const boolean_T x[6], int i_data[])
Finds the index of the last true element in a 6-element boolean array.
Definition find.c:51
Provides MATLAB Coder helper functions to find indices of true values.
const double mach_states[]
Definition main.c:261
static double cd_table[]
Definition main.c:263
void mrdiv_2(const double B_data[], int B_size, double Y_data[], int Y_size[2])
Performs element-wise division of a scalar by each element of a matrix.
Provides MATLAB Coder helper functions for right matrix division.
int mtimes(const double A_data[], const int A_size[2], const double B_data[], double C_data[])
Performs matrix multiplication: C = A * B.
Definition mtimes.c:23
A MATLAB Coder helper function for matrix multiplication.
Provides definitions and utility functions for non-finite floating-point values.