LCOV - code coverage report
Current view: top level - AP_RangeFinder - AP_RangeFinder_Params.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 8 8 100.0 %
Date: 2026-09-09 11:02:08 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "AP_RangeFinder_config.h"
       2             : 
       3             : #if AP_RANGEFINDER_ENABLED
       4             : 
       5             : #include "AP_RangeFinder_Params.h"
       6             : #include "AP_RangeFinder.h"
       7             : 
       8             : #ifndef AP_RANGEFINDER_DEFAULT_ORIENTATION
       9             : #define AP_RANGEFINDER_DEFAULT_ORIENTATION ROTATION_PITCH_270
      10             : #endif
      11             : 
      12             : // table of user settable parameters
      13             : const AP_Param::GroupInfo AP_RangeFinder_Params::var_info[] = {
      14             :     // @Param: TYPE
      15             :     // @DisplayName: Rangefinder type
      16             :     // @Description: Type of connected rangefinder
      17             :     // @SortValues: AlphabeticalZeroAtTop
      18             :     // @RebootRequired: True
      19             :     // @Values: 0:None
      20             :     // @Values: 1:Analog
      21             :     // @Values: 2:MaxbotixI2C
      22             :     // @Values: 3:LidarLite-I2C
      23             :     // @Values: 5:PWM
      24             :     // @Values: 6:BBB-PRU
      25             :     // @Values: 7:LightWareI2C
      26             :     // @Values: 8:LightWareSerial
      27             :     // @Values: 9:Bebop
      28             :     // @Values: 10:MAVLink
      29             :     // @Values: 11:USD1_Serial
      30             :     // @Values: 12:LeddarOne
      31             :     // @Values: 13:MaxbotixSerial
      32             :     // @Values: 14:TeraRangerI2C
      33             :     // @Values: 15:LidarLiteV3-I2C
      34             :     // @Values: 16:VL53L0X or VL53L1X
      35             :     // @Values: 17:NMEA
      36             :     // @Values: 18:WASP-LRF
      37             :     // @Values: 19:BenewakeTF02
      38             :     // @Values: 20:BenewakeTFmini-Serial
      39             :     // @Values: 21:LidarLightV3HP
      40             :     // @Values: 22:PWM
      41             :     // @Values: 23:BlueRoboticsPing
      42             :     // @Values: 24:DroneCAN
      43             :     // @Values: 25:BenewakeTFmini-I2C
      44             :     // @Values: 26:LanbaoPSK-CM8JL65-CC5
      45             :     // @Values: 27:BenewakeTF03
      46             :     // @Values: 28:VL53L1X-ShortRange
      47             :     // @Values: 29:LeddarVu8-Serial
      48             :     // @Values: 30:HC-SR04
      49             :     // @Values: 31:GYUS42v2
      50             :     // @Values: 32:MSP
      51             :     // @Values: 33:USD1_CAN
      52             :     // @Values: 34:Benewake_CAN
      53             :     // @Values: 35:TeraRangerSerial
      54             :     // @Values: 36:Lua_Scripting
      55             :     // @Values: 37:NoopLoop_TOFSense
      56             :     // @Values: 38:NoopLoop_TOFSense_CAN
      57             :     // @Values: 39:NRA24_CAN
      58             :     // @Values: 40:NoopLoop_TOFSenseF_I2C
      59             :     // @Values: 41:JRE_Serial
      60             :     // @Values: 42:Ainstein_LR_D1
      61             :     // @Values: 43:RDS02UF
      62             :     // @Values: 44:HexsoonRadar
      63             :     // @Values: 45:LightWare-GRF
      64             :     // @Values: 46:BenewakeTFS20L
      65             :     // @Values: 47:DTS6012M-Serial
      66             :     // @Values: 48:LightWare-GRF-I2C
      67             :     // @Values: 100:SITL
      68             :     // @User: Standard
      69             :     AP_GROUPINFO_FLAGS("TYPE", 1, AP_RangeFinder_Params, type, 0, AP_PARAM_FLAG_ENABLE),
      70             : 
      71             :     // @Param: PIN
      72             :     // @DisplayName: Rangefinder pin
      73             :     // @Description: Analog or PWM input pin that rangefinder is connected to. Analog RSSI or Airspeed ports can be used for Analog inputs (some autopilots provide others also), Non-IOMCU Servo/MotorOutputs can be used for PWM input when configured as "GPIOs". Values for some autopilots are given as examples. Search wiki for "Analog pins" for analog pin or "GPIOs", if PWM input type, to determine pin number.
      74             :     // @Values: -1:Not Used,11:Pixracer,13:Pixhawk ADC4,14:Pixhawk ADC3,15:Pixhawk ADC6/Pixhawk2 ADC,50:AUX1,51:AUX2,52:AUX3,53:AUX4,54:AUX5,55:AUX6,103:Pixhawk SBUS
      75             :     // @Range: -1 127
      76             :     // @User: Standard
      77             :     AP_GROUPINFO("PIN",     2, AP_RangeFinder_Params, pin, -1),
      78             : 
      79             :     // @Param: SCALING
      80             :     // @DisplayName: Rangefinder scaling
      81             :     // @Description: Scaling factor between rangefinder reading and distance. For the linear and inverted functions this is in meters per volt. For the hyperbolic function the units are meterVolts. For Maxbotix serial sonar this is unit conversion to meters.
      82             :     // @Units: m/V
      83             :     // @Increment: 0.001
      84             :     // @User: Standard
      85             :     AP_GROUPINFO("SCALING", 3, AP_RangeFinder_Params, scaling, 3.0f),
      86             : 
      87             :     // @Param: OFFSET
      88             :     // @DisplayName: rangefinder offset
      89             :     // @Description: Offset in volts for zero distance for analog rangefinders. Offset added to distance in centimeters for PWM lidars
      90             :     // @Units: V
      91             :     // @Increment: 0.001
      92             :     // @User: Standard
      93             :     AP_GROUPINFO("OFFSET",  4, AP_RangeFinder_Params, offset, 0.0f),
      94             : 
      95             :     // @Param: FUNCTION
      96             :     // @DisplayName: Rangefinder function
      97             :     // @Description: Control over what function is used to calculate distance. For a linear function, the distance is (voltage-offset)*scaling. For a inverted function the distance is (offset-voltage)*scaling. For a hyperbolic function the distance is scaling/(voltage-offset). The functions return the distance in meters.
      98             :     // @Values: 0:Linear,1:Inverted,2:Hyperbolic
      99             :     // @User: Standard
     100             :     AP_GROUPINFO("FUNCTION", 5, AP_RangeFinder_Params, function, 0),
     101             : 
     102             :     // @Param: MIN
     103             :     // @DisplayName: Rangefinder minimum distance
     104             :     // @Description: Minimum distance in metres that rangefinder can reliably read
     105             :     // @Units: m
     106             :     // @Increment: 0.01
     107             :     // @User: Standard
     108             :     AP_GROUPINFO("MIN",  6, AP_RangeFinder_Params, min_distance, 0.20),
     109             : 
     110             :     // @Param: MAX
     111             :     // @DisplayName: Rangefinder maximum distance
     112             :     // @Description: Maximum distance in metres that rangefinder can reliably read
     113             :     // @Units: m
     114             :     // @Increment: 0.01
     115             :     // @User: Standard
     116             :     AP_GROUPINFO("MAX",  7, AP_RangeFinder_Params, max_distance, 7.00),
     117             : 
     118             :     // @Param: STOP_PIN
     119             :     // @DisplayName: Rangefinder stop pin
     120             :     // @Description: Digital pin that enables/disables rangefinder measurement for the pwm rangefinder. A value of -1 means no pin. If this is set, then the pin is set to 1 to enable the rangefinder and set to 0 to disable it. This is used to enable powersaving when out of range. Some common values are given, but see the Wiki's "GPIOs" page for how to determine the pin number for a given autopilot.
     121             :     // @Values: -1:Not Used,50:AUX1,51:AUX2,52:AUX3,53:AUX4,54:AUX5,55:AUX6,111:PX4 FMU Relay1,112:PX4 FMU Relay2,113:PX4IO Relay1,114:PX4IO Relay2,115:PX4IO ACC1,116:PX4IO ACC2
     122             :     // @Range: -1 127
     123             :     // @User: Standard
     124             :     AP_GROUPINFO("STOP_PIN", 8, AP_RangeFinder_Params, stop_pin, -1),
     125             : 
     126             :     // 9 was SETTLE
     127             : 
     128             :     // @Param: RMETRIC
     129             :     // @DisplayName: Ratiometric
     130             :     // @Description: This parameter sets whether an analog rangefinder is ratiometric. Most analog rangefinders are ratiometric, meaning that their output voltage is influenced by the supply voltage. Some analog rangefinders (such as the SF/02) have their own internal voltage regulators so they are not ratiometric.
     131             :     // @Values: 0:No,1:Yes
     132             :     // @User: Standard
     133             :     AP_GROUPINFO("RMETRIC", 10, AP_RangeFinder_Params, ratiometric, 1),
     134             : 
     135             :     // @Param: PWRRNG
     136             :     // @DisplayName: Powersave range
     137             :     // @Description: This parameter sets the estimated terrain distance in meters above which the sensor will be put into a power saving mode (if available). A value of zero means power saving is not enabled
     138             :     // @Units: m
     139             :     // @Range: 0 32767
     140             :     // @User: Standard
     141             :     AP_GROUPINFO("PWRRNG", 11, AP_RangeFinder_Params, powersave_range, 0),
     142             : 
     143             :     // @Param: GNDCLR
     144             :     // @DisplayName: Distance from the range finder to the ground
     145             :     // @Description: This parameter sets the expected range measurement that the range finder should return when the vehicle is on the ground.
     146             :     // @Units: m
     147             :     // @Range: 0.05 1.5
     148             :     // @Increment: 0.01
     149             :     // @User: Standard
     150             :     AP_GROUPINFO("GNDCLR", 12, AP_RangeFinder_Params, ground_clearance, RANGEFINDER_GROUND_CLEARANCE_DEFAULT),
     151             : 
     152             :     // @Param: ADDR
     153             :     // @DisplayName: Bus address of sensor
     154             :     // @Description: This sets the bus address of the sensor, where applicable. Used for the I2C and DroneCAN sensors to allow for multiple sensors on different addresses. For MAVLink rangefinders, this sets the DISTANCE_SENSOR message id to accept. A value of zero accepts any id.
     155             :     // @Range: 0 127
     156             :     // @Increment: 1
     157             :     // @User: Standard
     158             :     AP_GROUPINFO("ADDR", 23, AP_RangeFinder_Params, address, 0),
     159             : 
     160             :     // @Param: POS_X
     161             :     // @DisplayName:  X position offset
     162             :     // @Description: X position of the rangefinder in body frame. Positive X is forward of the origin. Use the zero range datum point if supplied.
     163             :     // @Units: m
     164             :     // @Range: -5 5
     165             :     // @Increment: 0.01
     166             :     // @User: Advanced
     167             : 
     168             :     // @Param: POS_Y
     169             :     // @DisplayName: Y position offset
     170             :     // @Description: Y position of the rangefinder in body frame. Positive Y is to the right of the origin. Use the zero range datum point if supplied.
     171             :     // @Units: m
     172             :     // @Range: -5 5
     173             :     // @Increment: 0.01
     174             :     // @User: Advanced
     175             : 
     176             :     // @Param: POS_Z
     177             :     // @DisplayName: Z position offset
     178             :     // @Description: Z position of the rangefinder in body frame. Positive Z is down from the origin. Use the zero range datum point if supplied.
     179             :     // @Units: m
     180             :     // @Range: -5 5
     181             :     // @Increment: 0.01
     182             :     // @User: Advanced
     183             :     AP_GROUPINFO("POS", 49, AP_RangeFinder_Params, pos_offset, 0.0f),
     184             : 
     185             :     // @Param: ORIENT
     186             :     // @DisplayName: Rangefinder orientation
     187             :     // @Description: Orientation of rangefinder
     188             :     // @Values: 0:Forward, 1:Forward-Right, 2:Right, 3:Back-Right, 4:Back, 5:Back-Left, 6:Left, 7:Forward-Left, 24:Up, 25:Down
     189             :     // @User: Advanced
     190             :     AP_GROUPINFO("ORIENT", 53, AP_RangeFinder_Params, orientation, AP_RANGEFINDER_DEFAULT_ORIENTATION),
     191             : 
     192             :     AP_GROUPEND
     193             : };
     194             : 
     195             : 
     196             : // PARAMETER_CONVERSION - Added: Dec-2024 for ArduPilot-4.7
     197       20570 : void AP_RangeFinder_Params::convert_min_max_params(void)
     198             : {
     199             :     // ./Tools/autotest/test_param_upgrade.py --vehicle=arducopter --param "RNGFND1_MAX_CM=300->RNGFND1_MAX=3.00" --param "RNGFND2_MIN_CM=678->RNGFND2_MIN=6.78" --param "RNGFNDA_MIN_CM=1->RNGFNDA_MIN=0.01" --param "RNGFND5_GNDCLEAR=103->RNGFND5_GNDCLR=1.03"
     200       20570 :     max_distance.convert_parameter_width(AP_PARAM_INT16, 0.01);
     201       20570 :     min_distance.convert_parameter_width(AP_PARAM_INT16, 0.01);
     202       20570 :     ground_clearance.convert_parameter_width(AP_PARAM_INT8, 0.01);
     203       20570 : }
     204             : 
     205       20980 : AP_RangeFinder_Params::AP_RangeFinder_Params(void) {
     206       20980 :     AP_Param::setup_object_defaults(this, var_info);
     207       20980 : }
     208             : 
     209             : #endif  // AP_RANGEFINDER_ENABLED

Generated by: LCOV version 1.14