Open Zolkin1 opened 3 months ago
Spinning up another thread from withing the ROS node and running the same code is much better. See the below timings. This would further confirm that the ROS executor is using my thread for other tasks. So there are a few options here:
[ll_controller-2] =============================================================================================================================================== MPC Statistics ===============================================================================================================================================
[ll_controller-2] Solve # Solve Status Time (ms) Constr. Time (ms) Cost Time (ms) LS Time (ms) d-norm (post LS) Alpha LS Termination Constr. Vio. (Scaled) Cost (post LS) QP Cost (pre LS)
[ll_controller-2] 0 Max Iterations 10.432 2.721 0.396 0.745 17.739 1 Constraint Vio. 0.0222591 0.0224777 0.0224777
[ll_controller-2] 1 Max Iterations 9.287 2.065 0.381 1.425 1.51542 0.25 Constraint Vio. 0.0117601 0.0221844 -0.00150576
[ll_controller-2] 2 Max Iterations 10.494 2.103 0.379 2.568 2.13415 0.03125 Constraint Vio. 0.0113445 0.0215505 -0.0106802
[ll_controller-2] 3 Max Iterations 10.389 1.935 0.368 2.802 1.03811 0.015625 Constraint Vio. 0.011507 0.0212508 -0.0100351
[ll_controller-2] 4 Max Iterations 10.851 2.024 0.368 3.152 0.512731 0.0078125 Constraint Vio. 0.0115939 0.021105 -0.00973054
[ll_controller-2] 5 Max Iterations 10.67 1.906 0.366 3.154 0.509624 0.0078125 Constraint Vio. 0.0116391 0.0209614 -0.00958232
[ll_controller-2] 6 Max Iterations 11.105 2.003 0.356 3.519 0.253128 0.00390625 Constraint Vio. 0.0116845 0.0208907 -0.00943604
[ll_controller-2] 7 Max Iterations 11.362 1.883 0.364 3.841 0.126183 0.00195312 Constraint Vio. 0.0117075 0.0208555 -0.00936404
[ll_controller-2] 8 Max Iterations 11.509 2.008 0.368 3.852 0 0 Alpha small 0.0117191 0.0208555 -0.00932828
[ll_controller-2] 9 Max Iterations 11.346 1.872 0.36 3.854 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 10 Max Iterations 11.438 2.001 0.367 3.836 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 11 Max Iterations 11.295 1.871 0.356 3.844 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 12 Max Iterations 19.381 3.208 0.741 6.488 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 13 Max Iterations 11.976 2.416 0.38 3.856 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 14 Max Iterations 11.538 2.043 0.375 3.841 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 15 Max Iterations 11.368 1.895 0.367 3.839 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 16 Max Iterations 11.4 1.986 0.359 3.835 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 17 Max Iterations 11.344 1.875 0.367 3.835 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 18 Max Iterations 11.46 1.987 0.359 3.846 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 19 Max Iterations 11.383 1.874 0.362 3.842 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 20 Max Iterations 11.42 1.982 0.354 3.844 0 0 Alpha small 0.0117191 0.0208555 -0.00932836
[ll_controller-2] 21 Max Iterations 10.12 3.457 0.39 0.732 109.426 1 Constraint Vio. 0.0738822 0.45633 -0.00193624
[ll_controller-2] 22 Max Iterations 9.046 2.119 0.382 0.761 6.67122 1 Cost & Constr. 0.00863229 0.454741 -0.000660267
[ll_controller-2] 23 Max Iterations 8.571 1.894 0.372 0.731 57.8571 1 Constraint Vio. 0.0412314 1.21669 0.00451252
[ll_controller-2] 24 Max Iterations 9.267 2.187 0.373 1.176 28.0069 1 Constraint Vio. 0.0312112 0.0640833 0.0112125
[ll_controller-2] 25 Max Iterations 11.869 3.125 0.745 0.735 76.7305 1 Constraint Vio. 0.0463719 0.0287299 -0.0157606
[ll_controller-2] 26 Max Iterations 8.657 2.022 0.396 0.725 36.0398 1 Constraint Vio. 0.0169596 0.0553494 -0.000423959
[ll_controller-2] 27 Max Iterations 11.332 3.137 0.636 0.726 17.971 1 Cost & Constr. 0.00726488 0.0735171 0.000409318
[ll_controller-2] 28 Max Iterations 13.437 3.153 0.736 0.736 24.021 1 Cost & Constr. 0.00770841 0.146878 0.000686594
[ll_controller-2] 29 Max Iterations 9.289 2.121 0.497 0.859 12.632 1 Cost & Constr. 0.0065797 0.160314 0.000761276
[ll_controller-2] 30 Max Iterations 9.623 1.91 0.373 1.219 13.1454 1 Cost & Constr. 0.00585627 0.131017 0.000547705
[ll_controller-2] 31 Max Iterations 13.696 3.194 0.752 0.729 11.569 1 Cost & Constr. 0.00599776 0.0948979 0.00028071
[ll_controller-2] 32 Max Iterations 8.616 1.939 0.396 0.728 15.7652 1 Cost & Constr. 0.00778837 0.0491175 0.000731325
[ll_controller-2] 33 Max Iterations 8.527 1.912 0.382 0.721 22.7657 1 Constraint Vio. 0.0155961 0.0313829 -0.00128082
[ll_controller-2] 34 Max Iterations 8.978 2.042 0.382 0.738 58.0606 1 Constraint Vio. 0.128504 0.0370216 -0.00094114
[ll_controller-2] 35 Max Iterations 8.633 1.929 0.381 0.726 17.7913 1 Constraint Vio. 0.0507902 0.0483244 0.000918355
[ll_controller-2] 36 Max Iterations 8.869 1.899 0.398 0.895 13.6334 1 Constraint Vio. 0.0284923 0.057063 0.000921084
[ll_controller-2] 37 Max Iterations 8.509 1.902 0.383 0.733 18.9256 1 Constraint Vio. 0.0230733 0.0465285 0.000533227
[ll_controller-2] 38 Max Iterations 8.558 1.898 0.388 0.751 22.5115 1 Constraint Vio. 0.0597208 0.0443469 -0.00135158
[ll_controller-2] 39 Max Iterations 8.879 1.964 0.404 0.756 35.068 1 Constraint Vio. 0.120052 0.0550595 0.000192447
[ll_controller-2] 40 Max Iterations 8.752 1.921 0.384 0.74 14.371 1 Constraint Vio. 0.0529454 0.0868951 0.00150442
I have encountered a weird issue where running my code in Obelisk (i.e. with my whole robot stack running) causes the code to be much less consistent timing-wise. To clarify, I am NOT suggesting that the ROS2 timer is bad, but that when I am within a callback executing computationally intensive code (that has a nominal run time of about 10ms), the runtime has high variance.
The callback is within a separate callback group and thus should be executing parallel to all the other callbacks in the node. I have confirmed this by plotting some other outputs and verifying that the other callbacks happen in parallel.
So there are a few options:
malloc
orfree
)To help eliminate some of these options, I booted up my robot stack (simulator, estimator, controller) and stopped the MPC computation (which is the computation in question). Then I ran my MPC separately (i.e. with no ROS or obelisk) and the timings were still consistent.
This would seem to imply that options 2-4 are non-issues, as those would be present no matter where I was running my MPC. So for now I am investigating the first option.
There appear to be a few options like:
Both of these options are kinda painful, and using a real time kernel come with other overhead, like dealing with memory allocation correctly.
I will update this thread with findings as I get them.
For maximum information, here are my timings. On my local machine, without ROS/Obelisk:
Running the came code in the obelisk stack: