This example shows you how to log and replay CAN FD messages using MathWorks Virtual CAN FD channels in Simulink®. You can update this model to connect to supported hardware on your system.
Load the saved CAN FD message from sourceFDMsgs.mat
file from the examples folder. The file contains CAN FD messages representing a 90 second drive cycle around a test track.
Convert these messages to a format compatible with the CAN FD Replay block and save it to a separate file.
Name Size Bytes Class Attributes canFDMsgTimetable 100000x12 45411726 timetable canFDMsgs 1x1 8401848 struct
This model contains:
A CAN FD Replay block that transmits to MathWorks Virtual Channel 1
.
A CAN FD Receive block that receives the messages on a CAN FD network, through MathWorks Virtual Channel 2
.
The CAN FD Receive block is configured to block all extended IDs and allow only the WheelSpeed
message with the standard ID 1200
to pass.
The Wheel Speeds subsystem unpacks the wheel speed information from the received CAN FD messages and plots them to a scope. The subsystem also logs the messages to a file.
The plot shows the wheel speed for all wheels for the duration of the test drive.
The CAN FD Log block creates a unique file each time you run the model. Use dir
in the MATLAB Command Window to find the latest log file.
WheelSpeeds_2018-Apr-30_132033.mat Name Size Bytes Class Attributes canFDMsgTimetable 100000x12 45411726 timetable canFDMsgs 1x1 8401848 struct outFDMsgs 1x1 841848 struct
Use canFDMessageTimetable
to convert messages logged during the simulation to a timetable that you can use in the command window.
To access message signals directly, use the appropriate database file in the conversion along with canSignalTimetable
.
ans = 15x12 timetable Time ID Extended Name ProtocolMode Data Length DLC Signals Error Remote BRS ESI __________ ____ ________ _______________ ____________ ___________ ______ ___ ____________ _____ ______ _____ _____ 75.393 sec 576 false {0x0 char } {'CAN FD'} {1x4 uint8} 4 4 {0x0 struct} false false true false 75.397 sec 1200 false {'WheelSpeeds'} {'CAN FD'} {1x8 uint8} 8 8 {1x1 struct} false false true false 75.398 sec 128 false {0x0 char } {'CAN FD'} {1x7 uint8} 7 7 {0x0 struct} false false true false 75.398 sec 133 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.398 sec 144 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.398 sec 528 false {0x0 char } {'CAN FD'} {1x7 uint8} 7 7 {0x0 struct} false false true false 75.399 sec 529 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.399 sec 1201 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.399 sec 512 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.399 sec 513 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.399 sec 533 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.4 sec 1312 false {0x0 char } {'CAN FD'} {1x5 uint8} 5 5 {0x0 struct} false false true false 75.405 sec 1200 false {'WheelSpeeds'} {'CAN FD'} {1x8 uint8} 8 8 {1x1 struct} false false true false 75.406 sec 1201 false {0x0 char } {'CAN FD'} {1x8 uint8} 8 8 {0x0 struct} false false true false 75.408 sec 1296 false {0x0 char } {'CAN FD'} {1x3 uint8} 3 3 {0x0 struct} false false true false ans = 15x4 timetable Time RR_WSpeed RF_WSpeed LR_WSpeed LF_WSpeed __________ _________ _________ _________ _________ 75.397 sec 41.19 40.04 41.19 39.95 75.405 sec 41.2 40.04 41.21 39.97 75.414 sec 41.22 40.05 41.26 40.03 75.424 sec 41.25 40.13 41.3 40.05 75.433 sec 41.19 40.14 41.28 40.08 75.441 sec 41.17 40.18 41.31 40.14 75.45 sec 41.31 40.27 41.31 40.17 75.458 sec 41.37 40.25 41.31 40.19 75.466 sec 41.39 40.22 41.3 40.19 75.475 sec 41.39 40.25 41.3 40.2 75.483 sec 41.37 40.26 41.33 40.21 75.492 sec 41.44 40.35 41.33 40.19 75.501 sec 41.51 40.44 41.36 40.22 75.509 sec 41.58 40.47 41.44 40.29 75.517 sec 41.63 40.45 41.44 40.31
MathWorks CAN FD Virtual channels were used for this example. You can however connect your models to other supported hardware.