Receiving messages from the CAN via CANcase using Vehicle Network Toolbox(R2010b) and working with it in realtime.
4 ビュー (過去 30 日間)
Karthik Suresh 2011 年 7 月 8 日
コメント済み: Jorge Garza 2016 年 9 月 7 日
I would want to receive a few CAN messages in real time using VNT and give it as an input to my algorithm running in MATLAB. But the CAN communication takes longer time than real time. I am currently using a timer that calls the timer function callback every 100ms. I need to receive CAN messages from two CAN channels and process the data within this 100ms. I am sure that the process is not slower due to the algorithm which processes the CAN messages itself. I am also attaching the piece of codes which i used for CAN interface. Please tell me where i went wrong?
% Accesing the database file
db1 = canDatabase('PT_CAN.dbc');
db2 = canDatabase('LWS_CAN.dbc');
% Initializing the Recieving Channels
% Assigning DBC to CAN channel
rxcanch1.Database = db1;
rxcanch2.Database = db2;
% Filter out messages needed from the channel
filterAcceptRange(rxcanch1, 206, 206)
filterAcceptRange(rxcanch1, 304, 304)
filterAcceptRange(rxcanch1, 760, 764)
filterAcceptRange(rxcanch2, 194, 194);
% Make receiving channel available
% Timer to receive CAN messages
timer_can = timer('StartDelay',.1,'ExecutionMode','fixedRate','Period',0.1,'BusyMode','queue','TasksToExecute',600);
And the Timer function callback is as follows.
message1 = receive(rxcanch1,Inf);% PT_CAN
message2 = receive(rxcanch2,Inf);% LWS_CAN
The CAN communication consumes the most part of the running time of the algorithm. Since I am new to VNT I could'nt find the solution myself.
Jorge Garza 2016 年 9 月 7 日
Hi, just wanted to update my question. I can read CAN values not real time but using a while loop, the loop uses a pause with the message transmision rate. The value reading works fine, now there is still to see if while values are being read the algorithm processing doesnt ruin the script performance and CAN messages/sensor info get loss.
回答 (3 件)
Gerd 2011 年 7 月 8 日
realtime behaviour with the VNT is not easy to accomplish. Looking at your code you might be able to use the 'MessageReceive Callback' from your CAN channels. Everytime a filtered CAN message is available this callback function is executed.
But my experience is that this functionality don't work in realtime also. The Mathworks support had only a workaround.
You have to increase the sample time for the CAN message update function and have a second timer for your algorithm. I think the CANTool which Mathworks is providing works the same.
Please contact the Mathworks support, hopefully they can make the performance in a future Release better.
Shankar Subramanian 2011 年 7 月 22 日
A few thoughts on this:
- How many messages are you getting from the network every 100ms? This is more to know network load/traffic.
- Receiving messages in CAN channel is Asynchronous process. Have you checked to see the timestamps on the received messages? You can use canTool to see if it is able to keep up with your network bursts.
- As suggested, using MessageReceivedFcn and MessageReceivedFcnCount might be better.
- When you use the extractAll method, use the second output remainder for subsequent extractAll calls. You can see the doc here for the signature of the function.
Again, at this point, since I do not know much about your network, it is tough to comment on the timing/speed aspect. Above information might be a good point to start the investigation.
Jaremy 2011 年 7 月 25 日
A few additional thoughts are:
1. If you only need the latest information received to feed your algorithm every 100 ms, then try using ExtractRecent instead of ExtractAll.
2. As Shankar mentioned, the Extract functions also return a remainder argument. You can use that in each subsequent Extract call for faster processing. It will avoid reparsing the same messages again and again.
3. You can try putting tic/toc calls in your timer function. This would help to understand how long that processing is taking. Put the tic at the top and the toc at the end. You will see a screen print of the time expired during the function.
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!