Introducing the delay in the control loop in simulation

#1

Hello!

I’d like to simulate an additional delay in the attitude control loop. Like, for example, if the UAVCAN messages were much longer (or baudrate was much lower) and the ESCs received commands with ~1-2ms delay.
I’m not sure if I can do that by means of Gazebo/jmavsim only or should I modify the PX4 code?
If I should modify the firmware which module would it be?
Thank you in advance for any hint!

Best regards,
Olex

#2

So the estimation and control loops are usually triggered by incoming gyro samples. So, you only really slow down the whole system if the gyro input comes late.

If you want to add a delay to the outputs, you would have to add additional usleeps in the pwm_output_sim. However, this would probably only work with the current architecture, once lockstep support is merged, because at that point the simulator just waits for px4 to output the control signal.

If you want to simulate that delay, it might be an idea to just create a FIFO buffer of actuator outputs in jMAVSim/Gazebo, and therefore simulate the control signals taking some time to reach the actual actuators.

#3

Hi Julian,
Thanks for your answer!

Correct me if I’m wrong here, but I thought the control loop bandwidth will be compromised if the delay from the control law calculation to the actual output change is increased. Even though this delay still “fits” into the control loop period.

You mean in PWMSim::run() function? That seem to be the easiest solution, otherwise I might also try to [quote=“JulianOes, post:2, topic:8862”]
create a FIFO buffer of actuator outputs in jMAVSim/Gazebo
[/quote]

Thanks a lot for your suggestions!

Best,
Olex

#4

I think that’s correct. And adding a delay anywhere would probably work as long as lockstep is not added. Once we’re in lockstep, the world basically stands still the actuator control signal comes back, so we’re essentially down to 0 delay. Now that I think about it that’s actually not optimal either but that’s besides the point.

I think that could work (again without lockstep).