Sonar ADC driver.
Reads an anlog sonar sensor and outputs sonar distance in [m]
Example for airframe file
Add to your firmware section: This example contains all possible configuration options, not all of them are mandatory!
<module name="sonar_adc">
b'<define name="SONAR_OFFSET" value="0" />\n '
b'<define name="SONAR_SCALE" value="0.0166" />\n '
b'<define name="USE_SONAR" value="" />\n '
b'<configure name="ADC_SONAR" value="ADC_X" />\n '
</module>
Module configuration options
Configure Options
- name:
ADC_SONAR
value: ADC_X
Description: select ADC to use with the sonar
Define Options
- name:
SONAR_OFFSET
value: 0
Description: sensor offset in [adc] - default is 0
- name:
SONAR_SCALE
value: 0.0166
Description: sensor scale factor [m/adc] - default is 0.0166
- name:
USE_SONAR
value:
Description: activate use of sonar in INS extended filter (only rotorcraft)
Module functions
Init Functions
These initialization functions are called once on startup.
Periodic Functions
These functions are called periodically at the specified frequency from the module periodic loop.
- sonar_adc_read()
- Frequency in Hz: 20
- Autorun: LOCK
Periodic function automatically starts after init and can't be stopped.
Files
Header Files
The following headers are automatically included in modules.h
Source Files
Raw sonar_adc.xml file:
<!DOCTYPE module SYSTEM "module.dtd">
<module name="sonar_adc" dir="sonar" task="sensors">
<doc>
<description>
Sonar ADC driver.
Reads an anlog sonar sensor and outputs sonar distance in [m]
</description>
<configure name="ADC_SONAR" value="ADC_X" description="select ADC to use with the sonar"/>
<define name="SONAR_OFFSET" value="0" description="sensor offset in [adc] - default is 0"/>
<define name="SONAR_SCALE" value="0.0166" description="sensor scale factor [m/adc] - default is 0.0166"/>
<define name="USE_SONAR" value="" description="activate use of sonar in INS extended filter (only rotorcraft)"/>
</doc>
<dep>
<depends>adc</depends>
<provides>sonar</provides>
</dep>
<header>
<file name="sonar_adc.h"/>
</header>
<init fun="sonar_adc_init()"/>
<periodic fun="sonar_adc_read()" freq="20"/>
<makefile target="ap|sim">
<file name="sonar_adc.c"/>
</makefile>
<makefile target="ap">
<define name="ADC_CHANNEL_SONAR" value="$(ADC_SONAR)"/>
<define name="USE_$(ADC_SONAR)"/>
</makefile>
</module>