PX4 simulink serial problem

#1

Hello everyone I will make this one quick as I have been stuck for about a month in this problem which I really really appreciate any help in it.
my problem simply is that I want to send data from a running Simulink model to the Pixhawk and then send the data back from the Pixhawk to the Simulink model through serial but the problem is that there is a huge delay between the send and reception of the data.
what is confusing is that when I send sensor data from the pixhawk to the Simulink model through serial data is sent perfectly but when I try to do this loop the delay problem occuer

#2

We probably need some more details on how this all looks like to be able to help you.

What is the connection between the simulink computer and the Pixhawk? You’re saying serial? At what baudrate? How is it configured? Is this using a radio or a wire?

#3

For the connection I tried 3:
1 - I used USB between COM3 in the PC and ttyACM0 in the Pixhawk.
2 - I used USB to serial converter between COM7 in the PC and ttyS2 in the Pixhawk.
3 - I used the first to send data from the PC and the second to recive data from the Pixhawk.
all gave me the same result.

P.S I modify the rc.txt file for each test.

For the configuration:
baud: 115200
stop bits: 1
terminator and header: none
parity: even

a good example for my problem is the already implemented example in documentation of the Pixhawk Pilot Support Package [px4demo_HostSerial_TxRx] and [px4demo_Serial_TxRx] in this example the sensor data are just fine and I move the pixhawk I can se the change in the Accelerometer immediately but if you change constant that is being sent to the Pixhwak and sent back to the PC you will see this delay and if you try to send more data in this loop you will get wrong data.

Thanks for your replay.

#4

Ok, and what sort of rates are you trying to achieve? To me it sounds like the serial link might be overloaded.

#5

I thought so at the beginning as I was sending and receiving an amount of 116 bytes but then I decreased it to just 8 bytes (2 float32) and still I get the same delay and I tried different sampling time for the data to be sent and received still I get the problem but when I change the sample time I get different behaviors some times I send and receive the data correctly but with a delay and some other time I just receive 0 .

#6

At what rate? And do you know if there is some buffering happening somewhere?

#7

I am not really sure what do you mean by “at what rate” I send the data from the Simulink model at a frequency of 100 Hz if that what you mean.
And no I do not know if there is any buffering happening.

#8

Ok that’s what I meant. 100 Hz * 8 bytes is 800 B/s so that should be fine, 100 Hz * 116 bytes is 11600 B/s so that would max out at 115200.

I wonder if there is a buffer in the simulink output which only flushes once it’s full. Could you make sure it flushes after every packet?