Hi Jun,
I understand that you want to modify your code so that it can use real-life data for velocity and acceleration. This can be done by loading the data from a file inside your function.
Please follow the below mentioned steps to use the real-life data into your code:
- Load the real-life data: Please load the real-life data into your MATLAB environment using the "load" function if the data is saved in a .mat file. This data could be in the form of arrays that correspond to the "t" array. Please follow the example MATLAB code below:
global mt lt It tt mp lp Ip tp g H T k d t omega i
global X_dot_data Y_dot_data Z_dot_data X_ddot_data Y_ddot_data Z_ddot_data time_data
- Interpolate the data and modify the "Two_Dof_Air" function: Since the ODE solver may use time points that are not exactly the same as the ones in the real-life data, the data should be interpolated using the "interp1" MATLAB function to find the values of velocity and acceleration at the exact time points needed by the solver. Please follow the example MATLAB code below:
function xs = Two_Dof_Air(t, x)
global mt lt It tt mp lp Ip tp g H T k d t omega i
global X_dot_data Y_dot_data Z_dot_data X_ddot_data Y_ddot_data Z_ddot_data time_data
X_dot = interp1(time_data, X_dot_data, t, 'linear', 'extrap');
Y_dot = interp1(time_data, Y_dot_data, t, 'linear', 'extrap');
Z_dot = interp1(time_data, Z_dot_data, t, 'linear', 'extrap');
X_ddot = interp1(time_data, X_ddot_data, t, 'linear', 'extrap');
Y_ddot = interp1(time_data, Y_ddot_data, t, 'linear', 'extrap');
Z_ddot = interp1(time_data, Z_ddot_data, t, 'linear', 'extrap');
x1 = x(1); x2 = x(2); x3 = x(3); x4 = x(4);
xs2 = (((-mt*g*lt*sin(x1))/(It*cos(x3))) ...
+(x4*sin(x3))*((2*x2/cos(x3))+(mt*lt/(It*(cos(x3).^2))*(X_dot*cos(x1)+Z_dot*sin(x1)))) ...
-((mt*lt*(X_ddot*cos(x1)+Z_ddot*sin(x1)))/(It*cos(x3))) ...
+(-tt*sign(x2))/(It*(cos(x3).^2)));
The above-mentioned steps will help to use real-life values for velocity and acceleration in your code.
Please follow the below mentioned MATLAB R2023b documentation links to get more information on "load" and "interp1" functions respectively:
I hope this helps to resolve your query.
Regards,
Abhimenyu