Pixhawk---超声波模块添加说明(I2C方式)

本文介绍了如何在Pixhawk飞行控制器上通过I2C方式添加超声波模块,以解决串口限制问题。Pixhawk固件已内置MB12xx超声波传感器驱动,详细连接说明和参考资料链接提供。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 说明

  在Pixhawk的固件中,已经实现了串口和i2c的底层驱动,并不需要自己去写驱动。通过串口的方式添加超声波的缺点是串口不够,不能添加多个超声波模块,此时需要用到i2c的方式去添加了。在Pixhawk固件中,i2c的方式去添加超声波模块传感器已经实现了一个mb12xx超声波产品的驱动,可以直接使用,模块位置为:../src/drivers/mb12xx。当然还可以通过PWM的方式去添加超声波模块(模块支持此功能);

2 模块连接说明

超声波mb12xx   

sonar
sonar-pixhawk

激光雷达(支持通过PWM方式)

PWM方式
I2C方式

3 相关资料

http://copter.ardupilot.com/wiki/common-optional-hardware/common-rangefinder-landingpag

const AP_Param::GroupInfo RangeFinder::var_info[] PROGMEM = { // @Param: _TYPE // @DisplayName: Rangefinder type // @Description: What type of rangefinder device that is connected // @Values: 0:None,1:Analog,2:APM2-MaxbotixI2C,3:APM2-PulsedLightI2C,4:PX4-I2C,5:PX4-PWM,6:BBB-PRU AP_GROUPINFO("_TYPE", 0, RangeFinder, _type[0], 0), // @Param: _PIN // @DisplayName: Rangefinder pin // @Description: Analog pin that rangefinder is connected to. Set this to 0..9 for the APM2 analog pins. Set to 64 on an APM1 for the dedicated 'airspeed' port on the end of the board. Set to 11 on PX4 for the analog 'airspeed' port. Set to 15 on the Pixhawk for the analog 'airspeed' port. // @Values: -1:Not Used, 0:APM2-A0, 1:APM2-A1, 2:APM2-A2, 3:APM2-A3, 4:APM2-A4, 5:APM2-A5, 6:APM2-A6, 7:APM2-A7, 8:APM2-A8, 9:APM2-A9, 11:PX4-airspeed port, 15:Pixhawk-airspeed port, 64:APM1-airspeed port AP_GROUPINFO("_PIN", 1, RangeFinder, _pin[0], -1), // @Param: _SCALING // @DisplayName: Rangefinder scaling // @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. // @Units: meters/Volt // @Increment: 0.001 AP_GROUPINFO("_SCALING", 2, RangeFinder, _scaling[0], 3.0f), // @Param: _OFFSET // @DisplayName: rangefinder offset // @Description: Offset in volts for zero distance for analog rangefinders. Offset added to distance in centimeters for PWM and I2C Lidars // @Units: Volts // @Increment: 0.001 AP_GROUPINFO("_OFFSET", 3, RangeFinder, _offset[0], 0.0f), // @Param: _FUNCTION // @DisplayName: Rangefinder function // @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. // @Values: 0:Linear,1:Inverted,2:Hyperbolic AP_GROUPINFO("_FUNCTION", 4, RangeFinder, _function[0], 0), // @Param: _MIN_CM // @DisplayName: Rangefinder minimum distance // @Description: Minimum distance in centimeters that rangefinder can reliably read // @Units: centimeters // @Increment: 1 AP_GROUPINFO("_MIN_CM", 5, RangeFinder, _min_distance_cm[0], 20), // @Param: _MAX_CM // @DisplayName: Rangefinder maximum distance // @Description: Maximum distance in centimeters that rangefinder can reliably read // @Units: centimeters // @Increment: 1 AP_GROUPINFO("_MAX_CM", 6, RangeFinder, _max_distance_cm[0], 700), // @Param: _STOP_PIN // @DisplayName: Rangefinder stop pin // @Description: Digital pin that enables/disables rangefinder measurement for an analog 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 can be used to ensure that multiple sonar rangefinders don't interfere with each other. // @Values: -1:Not Used,50:Pixhawk AUXOUT1,51:Pixhawk AUXOUT2,52:Pixhawk AUXOUT3,53:Pixhawk AUXOUT4,54:Pixhawk AUXOUT5,55:Pixhawk AUXOUT6,111:PX4 FMU Relay1,112:PX4 FMU Relay2,113:PX4IO Relay1,114:PX4IO Relay2,115:PX4IO ACC1,116:PX4IO ACC2 AP_GROUPINFO("_STOP_PIN", 7, RangeFinder, _stop_pin[0], -1), // @Param: _SETTLE // @DisplayName: Rangefinder settle time // @Description: The time in milliseconds that the rangefinder reading takes to settle. This is only used when a STOP_PIN is specified. It determines how long we have to wait for the rangefinder to give a reading after we set the STOP_PIN high. For a sonar rangefinder with a range of around 7m this would need to be around 50 milliseconds to allow for the sonar pulse to travel to the target and back again. // @Units: milliseconds // @Increment: 1 AP_GROUPINFO("_SETTLE", 8, RangeFinder, _settle_time_ms[0], 0), // @Param: _RMETRIC // @DisplayName: Ratiometric // @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. // @Values: 0:No,1:Yes AP_GROUPINFO("_RMETRIC", 9, RangeFinder, _ratiometric[0], 1), // @Param: RNGFND_PWRRNG // @DisplayName: Powersave range // @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 // @Units: meters // @Range: 0 32767 AP_GROUPINFO("_PWRRNG", 10, RangeFinder, _powersave_range, 0), // @Param: _GNDCLEAR // @DisplayName: Distance (in cm) from the range finder to the ground // @Description: This parameter sets the expected range measurement(in cm) that the range finder should return when the vehicle is on the ground. // @Units: centimeters // @Range: 0 127 // @Increment: 1 // @User: Advanced AP_GROUPINFO("_GNDCLEAR", 11, RangeFinder, _ground_clearance_cm[0], RANGEFINDER_GROUND_CLEARANCE_CM_DEFAULT), // 10..12 left for future expansion #if RANGEFINDER_MAX_INSTANCES > 1 // @Param: 2_TYPE // @DisplayName: Second Rangefinder type // @Description: What type of rangefinder device that is connected // @Values: 0:None,1:Analog,2:APM2-MaxbotixI2C,3:APM2-PulsedLightI2C,4:PX4-I2C,5:PX4-PWM,6:BBB-PRU AP_GROUPINFO("2_TYPE", 12, RangeFinder, _type[1], 0), // @Param: 2_PIN // @DisplayName: Rangefinder pin // @Description: Analog pin that rangefinder is connected to. Set this to 0..9 for the APM2 analog pins. Set to 64 on an APM1 for the dedicated 'airspeed' port on the end of the board. Set to 11 on PX4 for the analog 'airspeed' port. Set to 15 on the Pixhawk for the analog 'airspeed' port. // @Values: -1:Not Used, 0:APM2-A0, 1:APM2-A1, 2:APM2-A2, 3:APM2-A3, 4:APM2-A4, 5:APM2-A5, 6:APM2-A6, 7:APM2-A7, 8:APM2-A8, 9:APM2-A9, 11:PX4-airspeed port, 15:Pixhawk-airspeed port, 64:APM1-airspeed port AP_GROUPINFO("2_PIN", 13, RangeFinder, _pin[1], -1), // @Param: 2_SCALING // @DisplayName: Rangefinder scaling // @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. // @Units: meters/Volt // @Increment: 0.001 AP_GROUPINFO("2_SCALING", 14, RangeFinder, _scaling[1], 3.0f), // @Param: 2_OFFSET // @DisplayName: rangefinder offset // @Description: Offset in volts for zero distance // @Units: Volts // @Increment: 0.001 AP_GROUPINFO("2_OFFSET", 15, RangeFinder, _offset[1], 0.0f), // @Param: 2_FUNCTION // @DisplayName: Rangefinder function // @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. // @Values: 0:Linear,1:Inverted,2:Hyperbolic AP_GROUPINFO("2_FUNCTION", 16, RangeFinder, _function[1], 0), // @Param: 2_MIN_CM // @DisplayName: Rangefinder minimum distance // @Description: Minimum distance in centimeters that rangefinder can reliably read // @Units: centimeters // @Increment: 1 AP_GROUPINFO("2_MIN_CM", 17, RangeFinder, _min_distance_cm[1], 20), // @Param: 2_MAX_CM // @DisplayName: Rangefinder maximum distance // @Description: Maximum distance in centimeters that rangefinder can reliably read // @Units: centimeters // @Increment: 1 AP_GROUPINFO("2_MAX_CM", 18, RangeFinder, _max_distance_cm[1], 700), // @Param: 2_STOP_PIN // @DisplayName: Rangefinder stop pin // @Description: Digital pin that enables/disables rangefinder measurement for an analog 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 can be used to ensure that multiple sonar rangefinders don't interfere with each other. // @Values: -1:Not Used,50:Pixhawk AUXOUT1,51:Pixhawk AUXOUT2,52:Pixhawk AUXOUT3,53:Pixhawk AUXOUT4,54:Pixhawk AUXOUT5,55:Pixhawk AUXOUT6,111:PX4 FMU Relay1,112:PX4 FMU Relay2,113:PX4IO Relay1,114:PX4IO Relay2,115:PX4IO ACC1,116:PX4IO ACC2 AP_GROUPINFO("2_STOP_PIN", 19, RangeFinder, _stop_pin[1], -1), // @Param: 2_SETTLE // @DisplayName: Sonar settle time // @Description: The time in milliseconds that the rangefinder reading takes to settle. This is only used when a STOP_PIN is specified. It determines how long we have to wait for the rangefinder to give a reading after we set the STOP_PIN high. For a sonar rangefinder with a range of around 7m this would need to be around 50 milliseconds to allow for the sonar pulse to travel to the target and back again. // @Units: milliseconds // @Increment: 1 AP_GROUPINFO("2_SETTLE", 20, RangeFinder, _settle_time_ms[1], 0), // @Param: 2_RMETRIC // @DisplayName: Ratiometric // @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. // @Values: 0:No,1:Yes AP_GROUPINFO("2_RMETRIC", 21, RangeFinder, _ratiometric[1], 1), // @Param: 2_GNDCLEAR // @DisplayName: Distance (in cm) from the second range finder to the ground // @Description: This parameter sets the expected range measurement(in cm) that the second range finder should return when the vehicle is on the ground. // @Units: centimeters // @Range: 0 127 // @Increment: 1 // @User: Advanced AP_GROUPINFO("2_GNDCLEAR", 22, RangeFinder, _ground_clearance_cm[1], RANGEFINDER_GROUND_CLEARANCE_CM_DEFAULT), #endif AP_GROUPEND }; 这些代码说了什么
最新发布
07-17
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值