Difference between revisions of "Units"
Matejkarasek (talk | contribs) m (Added a correct link) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Paparazzi tries to use SI units everywhere. | Paparazzi tries to use SI units everywhere. | ||
All angles should be in radians and not in degrees! | All angles should be in radians and not in degrees! (But there are still exceptions [https://wiki.paparazziuav.org/wiki/Units#Defines_still_using_degrees]...) | ||
== Automatic unit conversion == | == Automatic unit conversion == | ||
For convenience Paparazzi handles some unit conversions automatically for you ( | For convenience Paparazzi handles some unit conversions automatically for you (since v3.9): | ||
In the [[Airframe_Configuration]] the <tt>unit</tt> and <tt>code_unit</tt> attributes are used for automatic conversion: | In the [[Airframe_Configuration]] the <tt>unit</tt> and <tt>code_unit</tt> attributes are used for automatic conversion: | ||
Line 22: | Line 22: | ||
<define name="BODY_TO_IMU_PSI" value="RadOfDeg(-45.)"/> | <define name="BODY_TO_IMU_PSI" value="RadOfDeg(-45.)"/> | ||
The units that you can use for <tt>unit</tt> and <tt>code_unit</tt> and their conversion are specified in [https://github.com/paparazzi/ | The units that you can use for <tt>unit</tt> and <tt>code_unit</tt> and their conversion are specified in PPRZlink [https://wiki.paparazziuav.org/wiki/Pprzlink] in units.xml [https://github.com/paparazzi/pprzlink/blob/master/message_definitions/common/units.xml] and hence can easily be extended. | ||
== Save settings == | == Save settings == | ||
Also "save settings" now gracefully handles values containing RadOfDeg(x) or DegOfRad(x) and converts it to the correct unit when reading from the airframe file. When saving the new value it will be correctly written without that macro. | Also "save settings" now gracefully handles values containing the deprecated <tt>RadOfDeg(x)</tt> or <tt>DegOfRad(x)</tt> macros and converts it to the correct unit when reading from the airframe file. When saving the new value it will be correctly written without that macro. | ||
When saving the settings the values are still always displayed in the | When saving the settings the values are still always displayed in the actual unit (e.g. rad). | ||
actual unit (e.g. rad). | |||
== | == Defines still using degrees == | ||
Regarding radians in the code: the defines | Regarding radians in the code: the defines | ||
Latest revision as of 02:21, 28 November 2017
Paparazzi tries to use SI units everywhere.
All angles should be in radians and not in degrees! (But there are still exceptions [1]...)
Automatic unit conversion
For convenience Paparazzi handles some unit conversions automatically for you (since v3.9):
In the Airframe_Configuration the unit and code_unit attributes are used for automatic conversion:
- if unit and code_unit are specified the value is converted to code_unit and then written to the generated/airframe.h file
- conversion is only done if the contents of the value attribute can be converted to float, otherwise string is simply copied like for any normal define
- special treatment for unit="deg" (and unit="deg/s"): if code_unit is not specified, code_unit="rad" (or code_unit="rad/s") is implicitly assumed!
- if you really want the define in degrees, explicitly specify code_unit="deg"
E.g. now you can write
<define name="BODY_TO_IMU_PHI" value="-4.0" unit="deg"/> <define name="BODY_TO_IMU_THETA" value="3.5" unit="deg"/> <define name="BODY_TO_IMU_PSI" value="-45." unit="deg"/>
instead of
<define name="BODY_TO_IMU_PHI" value="-0.0698" unit="rad"/> <define name="BODY_TO_IMU_THETA" value="RadOfDeg(3.5)" unit="rad"/> <define name="BODY_TO_IMU_PSI" value="RadOfDeg(-45.)"/>
The units that you can use for unit and code_unit and their conversion are specified in PPRZlink [2] in units.xml [3] and hence can easily be extended.
Save settings
Also "save settings" now gracefully handles values containing the deprecated RadOfDeg(x) or DegOfRad(x) macros and converts it to the correct unit when reading from the airframe file. When saving the new value it will be correctly written without that macro.
When saving the settings the values are still always displayed in the actual unit (e.g. rad).
Defines still using degrees
Regarding radians in the code: the defines
CAM_PAN_MAX CAM_PAN_MIN CAM_PAN_NEUTRAL CAM_PAN0 CAM_PAN_POSITION_FOR_FPV CAM_TILT_MAX CAM_TILT_MIN CAM_TILT_NEUTRAL CAM_TILT0 CAM_TILT_POSITION_FOR_FPV
are still in degrees and need to be defined in the airframe file either without any unit or with unit and code_unit both set to deg:
<define name="TILT_MAX" value="45" unit="deg" code_unit="deg"/>