Difference between revisions of "Units"

From PaparazziUAV
Jump to navigation Jump to search
(Created page with "Paparazzi tries to use SI units everywhere. All angles should be in radians and not in degrees! == Automatic unit conversion == For convenience Paparazzi handles some unit conv…")
 
m (Added a correct link)
 
(5 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 (dev and 4.0_beta branches):
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:


* if <tt>unit</tt> and <tt>code_unit</tt> are specified the value is converted to <tt>code_unit</tt> and then written to the <tt>generated/airframe.h</tt> file
* if <tt>unit</tt> '''and''' <tt>code_unit</tt> are specified the value is converted to <tt>code_unit</tt> and then written to the <tt>generated/airframe.h</tt> 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
* 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 <tt>unit="deg"</tt>: if <tt>code_unit</tt> is not specified, <tt>code_unit="rad"</tt> is implicitly assumed!
* '''special treatment for <tt>unit="deg"</tt>''' (and <tt>unit="deg/s"</tt>): if <tt>code_unit</tt> is not specified, <tt>code_unit="rad"</tt> (or <tt>code_unit="rad/s"</tt>) is implicitly assumed!
** if you really want the define in degrees, explicitly specify <tt>code_unit="deg"</tt>
** if you really want the define in degrees, explicitly specify <tt>code_unit="deg"</tt>


E.g. now you can write
E.g. now you can write
<section name="INS" prefix="INS_">
  <define name="BODY_TO_IMU_PHI"   value="-4.0" unit="deg"/>
   <define name="ROLL_NEUTRAL_DEFAULT" value="-4.0" unit="deg"/>
   <define name="BODY_TO_IMU_THETA" value="3.5" unit="deg"/>
   <define name="PITCH_NEUTRAL_DEFAULT" value="3.5" unit="deg"/>
   <define name="BODY_TO_IMU_PSI"   value="-45." unit="deg"/>
</section>
instead of
instead of
<section name="INS" prefix="INS_">
   <define name="BODY_TO_IMU_PHI"   value="-0.0698" unit="rad"/>
   <define name="ROLL_NEUTRAL_DEFAULT" value="-0.0698" unit="rad"/>
   <define name="BODY_TO_IMU_THETA" value="RadOfDeg(3.5)" unit="rad"/>
   <define name="PITCH_NEUTRAL_DEFAULT" value="RadOfDeg(3.5)" unit="rad"/>
  <define name="BODY_TO_IMU_PSI"  value="RadOfDeg(-45.)"/>
</section>


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/paparazzi/blob/dev/conf/units.xml conf/units.xml] and hence can easily be extended.
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 ==
== 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"/>