# Best way to test a new control law

**URL:** <https://discuss.px4.io/t/best-way-to-test-a-new-control-law/25461>\
**Category:** PX4 Autopilot\
**Created:** [December 15, 2021, 3:15pm UTC](https://discuss.px4.io/t/best-way-to-test-a-new-control-law/25461 "2021-12-15T15:15:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evandro](https://discuss.px4.io/user_avatar/discuss.px4.io/evandro/32/5053_2.png) [@Evandro](https://discuss.px4.io/u/Evandro)\
**Post date:** [December 15, 2021, 3:15pm UTC](https://discuss.px4.io/t/best-way-to-test-a-new-control-law/25461/1 "2021-12-15T15:15:17Z")

</div>

Sorry if this has been answered before, but I could only find a topic about it without answers, so here’s my question:

I want to test a new control law to have tests for a paper. How is the best way to do this?

If I understand correctly, the modules mc\_att\_control and mc\_pos\_control are the modules that calculate the needed control outputs, while comparing the position/orientation of the drone with the desired setpoint and checking if any parameter has been changed.

Then, some module mixes both outputs and publish the final control vector to actuator\_controls\_0.

What is the best way to do the same thing for my new control law? Is it just easier to modify these modules and completely replace the original control law?

If I do this, what part of the code should I modify and what part of the code I should absolutely not touch?

Thanks!

---

<div class="post-metadata">

**Author:** ![romar](https://discuss.px4.io/user_avatar/discuss.px4.io/romar/32/9730_2.png) [@romar](https://discuss.px4.io/u/romar)\
**Post date:** [December 17, 2021, 12:26am UTC](https://discuss.px4.io/t/best-way-to-test-a-new-control-law/25461/2 "2021-12-17T00:26:46Z")

</div>

Hi, I’m quite a beginner in the PX4 space but had to do something similar and might be able to help you.  
For controlling the drones attitude you should look into the mc\_rate\_control module.  
There you can find the implementation of the PID controller that drives the current angular rates to the desired angular rates. Just replacing that piece of code (that calls the PID controller) with your attitude controller should work and then save to att\_control.  
Note that the mc\_att\_control only gives the desired angular rates through a quaternion error law, so the controller is not _really_ there, you can check this in the doc.  
I haven’t touched the position controller so can’t help you with that.
