Units

From PaparazziUAV
Jump to navigation Jump to search

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 conversions automatically for you (dev and 4.0_beta branches):

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 conf/units.xml and hence can easily be extended.

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.

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"/>