Problem with reading from / writing to multiple serial ports in Simulink

14 views (last 30 days)
Hi,
For my project I need to read from 3 sensors simultaneously and based on the input from the sensors I need to control the robotic end-effector. Individually all the sensors and end-effector are interfaced with simulink and I can read data accurately.
However, when I run simulink model with two or more sensors simultaneously, there is a problem of data loss and inconsistent data. Simply if we have two sensors in the model, simulink can read only one sensor data accurately and the data read/ written to other sensor isn't reliable.
I will appreciate your guidance. Thank you.

Answers (2)

shmulik e
shmulik e on 30 Oct 2018
Hello
How did you manage to read from multi Serial ports without significant delay ?

Walter Roberson
Walter Roberson on 30 Oct 2018
Reading from multiple devices simultaneously requires multiple independent bus controllers, together with a hardware trigger technique to synchronize the reading requests, such as using genlock or a hardware trigger line. Note that the fact that you read from the the devices simultaneously does not mean that the data will be available simultaneously.
One of the more common ways of handling this kind of situation is to use a National Instruments CompaqDaq chassis with multiple data acquisition boards, and program the daq for a common trigger signal, and use the data acquisition toolbox to read the combined set of readings (perhaps splitting the buffer into pieces to deliver the readings to different blocks.)
You also need to consider that although you might be able to get measurements from multiple sources, that does not mean that they are current readings. In cases where actual simultaneous readings are important (rather than polling in sequence), it is more common than not that you need to know how long ago the readings were taken. Many of the CompaqDaq chassis are able to timestamp readings.
I will be blunt that the CompaqDaq series are expensive and not nearly the highest performance you can get for the money, and that using them for high performance in MATLAB can take a fair bit more effort than one would expect. Using Simulink Real Time with a speedgoat system can improve performance. High speed low latency simultaneous data collection is not easy with a general program such as MATLAB which is not designed for real time work.
  4 Comments
shmulik e
shmulik e on 30 Oct 2018
On the Teensy side i use
Serial.Write()
to send that data from the sensors, this is the fastest way to send data through the Serial. And i understand that the micro-controller cant read the data from the sensors simultaneously, it reads it 1-by-1 and that the way it sends them.
I am not bothered with the minor delay between the data from each sensor (~few millisecond).
I didn't understand yo final conclusion, What can i do about the delay of 10 sec when all the ports are working together?
Is there a better program that i can use for this purpose ? I thought writing my own code in C++ but, then i wont use the Simulink blocks that are very helpful.
Walter Roberson
Walter Roberson on 31 Oct 2018
After all of the Serial.Write() for one set of sensor readings, use Serial.send_now();
At the moment I do not have any ideas as to why you might be getting a 10 second delay.
To debug, I would suggest that you have your Teensy send along a timestamp and also a cycle counter (increment once per set of readings), and that when you receive the data on the Simulink side, you also timestamp it. That should permit you to study the progression of delays and also to study whether you are getting dropped readings.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!