Expression 'IMU_Bus' for type of data 'imu_data_struct' did not evaluate to a valid type.
Caused by:
Invalid setting in 'MATLAB Function' for parameter 'Datatype'
Error evaluating MATLAB Function parameter data 'Datatype' in its parent workspace.
Unrecognized function or variable 'IMU_Bus'.
Variable 'IMU_Bus' does not exist.
Suggested Actions:
Load a file into base workspace. - Fix
Create a new variable. - Fix
I am not able to understand this error as I have below file when i load it then it works but when i run simulation then shows same error.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: read_imu_data.m
% Description:
% Reads custom IMU file and returns a structured array containing raw
% IMU increments, message counters, sample times, etc.
%
% Guidelines:
% - snake_case for function and variables
% - no global usage
% - columns are identified and documented
%
% Author: <Your Name>
% Date: <Date>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function imu_data_struct = read_imu_data(file_name)
% READ_IMU_DATA Reads the specified IMU file and parses data columns.
%
% INPUT:
% file_name [string] - path to the IMU data file (no spaces).
%
% OUTPUT:
% imu_data_struct - a structure with fields:
% .msg_counter : message counter [0..255]
% .sample_time_s : sample time in seconds [resets at each PPS]
% .gyro_x_inc : gyro X increments
% .gyro_y_inc : gyro Y increments
% .gyro_z_inc : gyro Z increments
% .acc_x_inc : accelerometer X increments
% .acc_y_inc : accelerometer Y increments
% .acc_z_inc : accelerometer Z increments
% .temperature : sensor temperature (unit depends on sensor)
% .status_code : status code (unitless)
%
% Example usage:
% imu_data = read_imu_data('IMU_19.dat');
fid = fopen(file_name, 'r');
if fid == -1
error('read_imu_data:CannotOpenFile', ...
'Could not open IMU file: %s', file_name);
end
data_array = textscan(fid, '%f %f %f %f %f %f %f %f %f %f', ...
'Delimiter',' ', 'MultipleDelimsAsOne', true);
fclose(fid);
data_matrix = cell2mat(data_array);
% Parse columns into a structured form
imu_data_struct.msg_counter = data_matrix(:,1);
imu_data_struct.sample_time_s = data_matrix(:,2);
imu_data_struct.gyro_x_inc = data_matrix(:,3);
imu_data_struct.gyro_y_inc = data_matrix(:,4);
imu_data_struct.gyro_z_inc = data_matrix(:,5);
imu_data_struct.acc_x_inc = data_matrix(:,6);
imu_data_struct.acc_y_inc = data_matrix(:,7);
imu_data_struct.acc_z_inc = data_matrix(:,8);
imu_data_struct.temperature = data_matrix(:,9);
imu_data_struct.status_code = data_matrix(:,10);
end

댓글 수: 2

Shivam Gothi
Shivam Gothi 2024년 12월 26일
Hello @Vims,
I am not able to reproduce the issue from my end.
The simulink model contains the scripts "load_IMU_data" and "load_IMU_data_simple". Can you please share those files if possible ? Also, I investigated that the model reads the sensor data from a text file. Can you also provide a sample file ?
It will be helpful in reproducing the issue and suggesting proper solutions.
Vims
Vims 2024년 12월 27일

댓글을 달려면 로그인하십시오.

답변 (1개)

Shivam Gothi
Shivam Gothi 2024년 12월 26일

1 개 추천

Hello @Vims,
I understand that you are trying to run the attached simulink model, but facing some error. Basically, you want to use the structure named "imu_data_struct" defined in the base workspace, in your simulink model.
You can achieve this using the below suggested work-around.
You need not to have an additional "input" port in your MATLAB function block to get the structure "imu_data_struct" as an input data.
Instead of it, you can define "imu_data_struct", appearing in all of the MATLAB function blocks as "parameter data" in the symbols pane. This will not create an input port, but will directly fetch the value of "imu_data_struct" from the base workspace (if it is defined there). Follow the below steps to define "imu_data_struct" as "parameter data":
  • Double click on the MATLAB function block. This will open the editor.
  • Navigate to the "Modelling" tab in the tool-strip and click the "Symbols Pane" icon. This will open the symbols pane on the right hand side of the window as shown in the below figure.
  • Click the symbol appearing besides the "imu_data_struct" in the symbols pane and change the "type" to "parameter data" as shown in below figure.
  • Now, your MATLAB function block will not have any "input port" as seen below:
This will also resolve the error attached by you in the screen-shot.
NOTE: YOU FIRST NEED TO DEFINE "imu_data_struct" IN THE BASE WORKSPACE AND ALSO ASSIGN PROPER VALUES TO ITS ELEMENTS.
You can achieve this by typing the below lines of code in the "PreLoadFcn" callback appearing in the "Model properties" under the "Modelling" tab.
%The below lines of code will read the IMU data file and stores the values
%in appropriate fields of structure.
file_name="IMU_sample_data.txt";
T=readtable("IMU_sample_data.txt");
data_array=table2array(T);
data_matrix = data_array;
% Parse columns into a structured form
imu_data_struct.msg_counter = data_matrix(:,1);
imu_data_struct.sample_time_s = data_matrix(:,2);
imu_data_struct.gyro_x_inc = data_matrix(:,3);
imu_data_struct.gyro_y_inc = data_matrix(:,4);
imu_data_struct.gyro_z_inc = data_matrix(:,5);
imu_data_struct.acc_x_inc = data_matrix(:,6);
imu_data_struct.acc_y_inc = data_matrix(:,7);
imu_data_struct.acc_z_inc = data_matrix(:,8);
imu_data_struct.temperature = data_matrix(:,9);
imu_data_struct.status_code = data_matrix(:,10);
This will create the structure "imu_data_struct" in the base workspace whenever you open the simulink model.
I hope you find this useful !

댓글 수: 3

Vims
Vims 2024년 12월 27일
편집: Vims 2024년 12월 27일
Thank you very much Shivam.
I can explain my issue here.
1- I have two file as data file name is
IMU_19.dat and GNSS_19.dat
2- I want to process the data using simulink block espicially user define block.
Now I have develop the block and put the function in the user define block which load the data from same folder location and read the data with specify variable.
3- Now there are multiple options to do it but there is always issue like bus in the code and below code are mention.
Now can you please guide me ?
If possible then give me one simple example how anyone can load the data using user define block by developing function?
I have created script for matlab which is properly working are as below
clc;
clear all;
close all;
format long g;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1) GNSS DATA PROCESSING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -------------------- File Reading --------------------
gnssFileName = 'GNSS_19.dat'; % Example GNSS data file (modify as needed)
try
% We assume 'GNSS_19.dat' has columns like:
% GPS_Week, Week_Time, RX_Pos_X, RX_Pos_Y, RX_Pos_Z, RX_Vel_X, RX_Vel_Y, RX_Vel_Z
GNSS_data = readtable(gnssFileName, 'Delimiter', ',', 'ReadVariableNames', true);
catch ME
error('Error reading GNSS file: %s', ME.message);
end
% -------------------- Basic Extraction -----------------
GNSS.GPS_Week = GNSS_data.GPS_Week;
GNSS.Week_Time = GNSS_data.Week_Time; % GNSS time reference
GNSS.RX_Pos_X = GNSS_data.RX_Pos_X;
GNSS.RX_Pos_Y = GNSS_data.RX_Pos_Y;
GNSS.RX_Pos_Z = GNSS_data.RX_Pos_Z;
GNSS.RX_Vel_X = GNSS_data.RX_Vel_X;
GNSS.RX_Vel_Y = GNSS_data.RX_Vel_Y;
GNSS.RX_Vel_Z = GNSS_data.RX_Vel_Z;
% -------------------- Compute Derived Quantities -------
% Velocity magnitude
GNSS.Vel_Magnitude = sqrt(GNSS.RX_Vel_X.^2 + GNSS.RX_Vel_Y.^2 + GNSS.RX_Vel_Z.^2);
% Heading in degrees (atan2d returns degrees)
GNSS.Heading_deg = atan2d(GNSS.RX_Vel_Y, GNSS.RX_Vel_X);
disp('GNSS data structure created successfully.');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2) IMU DATA PROCESSING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -------------------- File Reading --------------------
imuFileName = 'IMU_19.dat'; % Example IMU data file (modify as needed)
fid = fopen(imuFileName, 'r');
if fid == -1
error('Cannot open the file "%s".', imuFileName);
end
try
% We assume 'IMU_19.dat' has 10 columns with 10,000 rows:
% Time, <unused>, AccX, AccY, AccZ, GyroX, GyroY, GyroZ, <unused>, <unused>
rawData = textscan(fid, '%f %f %f %f %f %f %f %f %f %f', ...
'Delimiter', {' ', '\t'}, 'MultipleDelimsAsOne', true);
fclose(fid);
catch ME
fclose(fid);
error('Error reading IMU file: %s', ME.message);
end
IMU_data = cell2mat(rawData);
[numRows, numCols] = size(IMU_data);
if (numRows ~= 10000 || numCols ~= 10)
error('Unexpected IMU data dimensions: %d rows x %d cols (expected 10000 x 10)', ...
numRows, numCols);
end
% -------------------- Basic Extraction -----------------
IMU.Time = IMU_data(:, 1); % 1) Time
IMU.Acc_X = IMU_data(:, 3); % 3) Acc X
IMU.Acc_Y = IMU_data(:, 4); % 4) Acc Y
IMU.Acc_Z = IMU_data(:, 5); % 5) Acc Z
IMU.Gyro_X = IMU_data(:, 6); % 6) Gyro X
IMU.Gyro_Y = IMU_data(:, 7); % 7) Gyro Y
IMU.Gyro_Z = IMU_data(:, 8); % 8) Gyro Z
disp('IMU data structure created successfully.');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3) OPTIONAL PSEUDORANGE/TDCP DATA HANDLING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% If you have another file containing pseudorange & TDCP data, read them here:
%
% pseudoFileName = 'pseudorange_data.dat';
% tdcpFileName = 'tdcp_data.dat';
% [Pseudo, TDCP] = read_pseudorange_tdcp(pseudoFileName, tdcpFileName);
%
% For now, we assume you have placeholders or do not need them in the final code.
% Make sure any arrays from these sources get interpolated to match IMU.Time if needed.
Similarly I have to do for simulink
Vims
Vims 2024년 12월 27일
https://github.com/VimsRocz/Project here is the repository
Vims
Vims 2024년 12월 28일
I have resolve the issue with data loading which is Task_1 folder of github
read the read_me_file and proceed it. Thanks
Close this issue

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Motion Planning에 대해 자세히 알아보기

질문:

2024년 12월 25일

댓글:

2024년 12월 28일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by