Vehicle Network Toolbox Value Table Use

3 vues (au cours des 30 derniers jours)
Min
Min le 30 Jan 2024
Modifié(e) : Min le 6 Fév 2024
Hi, I have been decoding this CAN message using DBC file which contains meanings of each message; for example, 1 is on and 0 is off.
This information is under canDB (DBC file information) -> Message info -> signal info -> Value Table.
canDB = canDatabse (example_dbcfile)
There is a function to create a canMessageTimetable as in a timetable with only values (1 and 0) but don't see any functions or ways to create a timetable to saw (on or off) using the value table.
Is there a way to create a timetable using this value table automatically for each CAN message?

Réponse acceptée

Harimurali
Harimurali le 6 Fév 2024
Modifié(e) : Harimurali le 6 Fév 2024
Hi Min,
A timetable that shows "on" or "off" instead of 1 or 0 can be created using the value table defined in the DBC file by writing a MATLAB script. The script decodes the raw data based on the value table and then creates a new timetable with the decoded values. Here is an example MATLAB script to do the same:
% Load the DBC file
candb = canDatabase("example_dbcfile.dbc");
% Assume canMsgs is a variable containing your raw CAN messages
% Create a canMessageTimetable from the raw CAN messages
canTimetable = canMessageTimetable(canMsgs, candb);
% Initialize a cell array to hold the decoded messages
decodedMessages = cell(size(canTimetable, 1), 2);
decodedMessages(:, 1) = {candb.MessageInfo.Name};
for i = 1:numel(candb.Messages)
message = candb.MessageInfo(i);
signals = canTimetable.Signals{i};
% structure to store the decoded values for each signal for a given message
sigVal = struct();
for j = 1:numel(message.Signals)
signal = message.SignalInfo(j);
rawValues = num2cell(signals.(signal.Name));
if numel(rawValues) ~= 0
decodedValues = cell(numel(rawValues), 1);
else
decodedValues = cell(numel(rawValues) + 1, 1);
end
% Check if the signal has a value table
if ~isempty(signal.ValueTable)
for k = 1:length(rawValues)
% Decode based on value table
decodedValues{k} = signal.ValueTable(rawValues(k));
end
else
% If no value table, just copy the raw values
decodedValues = rawValues;
end
% Store the decoded values in the structue
sigVal.(signal.Name) = decodedValues;
end
decodedMessages{i, 2} = sigVal;
end
% Create a new timetable with the decoded values
decodedTimetable = array2timetable(decodedMessages, 'RowTimes', canTimetable.Time);
% Add variable names to the timetable
decodedTimetable.Properties.VariableNames = [, "MessageName", "SignalInfo"];
Refer the following documentation for more information on CAN "canMessageTimeTable" and it's format: https://www.mathworks.com/help/releases/R2023a/vnt/ug/canmessagetimetable.html
  1 commentaire
Min
Min le 6 Fév 2024
Modifié(e) : Min le 6 Fév 2024
Hi Harimurali, thanks for the info! I am sorry but I forgot to take this question down since I was able to complete/solve the issue by creating a timetable based on number of messages, variable type, and automate based on variable names; then create double for loop ro run using 'valueTableText'.
Thanks for your time though! :) I will accept this as an answer and also share my code here for anyone to use.
numMsg = height(app.data); %Can be stand alone/used in all signal since the time height are the same?
data_numberofmessage = width(app.data);
data_numberofstrings = repmat({'string'}, 1, data_numberofmessage);
data_columnNames = app.data.Properties.VariableNames;
app.data_Status = timetable('Size',[numMsg data_numberofmessage],'VariableTypes',data_numberofstrings,'RowTimes',app.data.Time,'VariableNames', data_columnNames);
for ii = 2:numel(data_columnNames)
for iii = 1:numMsg
app.data_Status.(data_columnNames{ii})(iii) = valueTableText(canDB,"data", data_columnNames{ii},app.data.(data_columnNames{ii})(iii));
end
end

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by