PX4 Firmware
PX4 Autopilot Software http://px4.io
SRF02 Class Reference
Inheritance diagram for SRF02:
Collaboration diagram for SRF02:

Public Member Functions

 SRF02 (uint8_t rotation=distance_sensor_s::ROTATION_DOWNWARD_FACING, int bus=SRF02_BUS_DEFAULT, int address=SRF02_BASEADDR)
 
virtual ~SRF02 ()
 
int init () override
 
int ioctl (device::file_t *filp, int cmd, unsigned long arg) override
 
void print_info ()
 Diagnostics - print some basic information about the driver. More...
 
ssize_t read (device::file_t *filp, char *buffer, size_t buflen) override
 

Protected Member Functions

int probe () override
 

Private Member Functions

int collect ()
 
int measure ()
 
int probe_address (uint8_t address)
 Test whether the device supported by the driver is present at a specific address. More...
 
void Run () override
 Perform a poll cycle; collect from the previous measurement and start a new one. More...
 
void start ()
 Initialise the automatic measurement state machine and start it. More...
 
void stop ()
 Stop the automatic measurement state machine. More...
 

Private Attributes

px4::Array< uint8_t, RANGE_FINDER_MAX_SENSORSaddr_ind
 
bool _sensor_ok {false}
 
bool _collect_phase {false}
 
int _class_instance {-1}
 
int _cycling_rate {0}
 
int _measure_interval {0}
 
int _orb_class_instance {-1}
 
uint8_t _cycle_counter {0}
 
uint8_t _index_counter {0}
 
uint8_t _rotation
 
float _max_distance {SRF02_MAX_DISTANCE}
 
float _min_distance {SRF02_MIN_DISTANCE}
 
perf_counter_t _comms_errors {perf_alloc(PC_COUNT, "srf02_com_err")}
 
perf_counter_t _sample_perf {perf_alloc(PC_ELAPSED, "srf02_read")}
 
orb_advert_t _distance_sensor_topic {nullptr}
 
ringbuffer::RingBuffer * _reports {nullptr}
 

Detailed Description

Definition at line 89 of file srf02.cpp.

Constructor & Destructor Documentation

◆ SRF02()

SRF02::SRF02 ( uint8_t  rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING,
int  bus = SRF02_BUS_DEFAULT,
int  address = SRF02_BASEADDR 
)

Definition at line 173 of file srf02.cpp.

Referenced by srf02::start_bus().

Here is the caller graph for this function:

◆ ~SRF02()

SRF02::~SRF02 ( )
virtual

Definition at line 180 of file srf02.cpp.

References _class_instance, _comms_errors, _reports, _sample_perf, perf_free(), RANGE_FINDER_BASE_DEVICE_PATH, and stop().

Here is the call graph for this function:

Member Function Documentation

◆ collect()

int SRF02::collect ( )
private

Definition at line 200 of file srf02.cpp.

References _comms_errors, _distance_sensor_topic, _max_distance, _min_distance, _reports, _rotation, _sample_perf, distance_sensor_s::current_distance, f(), hrt_absolute_time(), distance_sensor_s::id, distance_sensor_s::max_distance, distance_sensor_s::min_distance, ORB_ID, orb_publish(), distance_sensor_s::orientation, perf_begin(), perf_count(), perf_end(), distance_sensor_s::signal_quality, distance_sensor_s::timestamp, distance_sensor_s::type, and distance_sensor_s::variance.

Referenced by read(), and Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init()

int SRF02::init ( )
override

Definition at line 245 of file srf02.cpp.

References _class_instance, _cycling_rate, _distance_sensor_topic, _index_counter, _orb_class_instance, _reports, _sensor_ok, addr_ind, counter, ToneAlarmInterface::init(), measure(), OK, orb_advertise_multi(), ORB_ID, ORB_PRIO_LOW, px4::Array< T, N >::push_back(), RANGE_FINDER_BASE_DEVICE_PATH, RANGE_FINDER_MAX_SENSORS, px4::Array< T, N >::size(), SRF02_BASEADDR, SRF02_CONVERSION_INTERVAL, and SRF02_INTERVAL_BETWEEN_SUCCESIVE_FIRES.

Referenced by srf02::start_bus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ioctl()

int SRF02::ioctl ( device::file_t filp,
int  cmd,
unsigned long  arg 
)
override

Definition at line 318 of file srf02.cpp.

References _cycling_rate, _measure_interval, OK, SENSOR_POLLRATE_DEFAULT, SENSORIOCSPOLLRATE, and start().

Referenced by srf02::reset(), srf02::start_bus(), and srf02::test().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ measure()

int SRF02::measure ( )
private

Definition at line 379 of file srf02.cpp.

References _comms_errors, perf_count(), and SRF02_TAKE_RANGE_REG.

Referenced by init(), probe(), read(), and Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_info()

void SRF02::print_info ( )

Diagnostics - print some basic information about the driver.

Definition at line 398 of file srf02.cpp.

References _comms_errors, _measure_interval, _reports, _sample_perf, and perf_print_counter().

Referenced by srf02::status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ probe()

int SRF02::probe ( )
overrideprotected

Definition at line 407 of file srf02.cpp.

References measure().

Here is the call graph for this function:

◆ probe_address()

int SRF02::probe_address ( uint8_t  address)
private

Test whether the device supported by the driver is present at a specific address.

Parameters
addressThe I2C bus address to probe.
Returns
True if the device is present.

◆ read()

ssize_t SRF02::read ( device::file_t filp,
char *  buffer,
size_t  buflen 
)
override

Definition at line 413 of file srf02.cpp.

References _cycling_rate, _measure_interval, _reports, collect(), measure(), and OK.

Referenced by srf02::test().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Run()

void SRF02::Run ( )
overrideprivate

Perform a poll cycle; collect from the previous measurement and start a new one.

Definition at line 474 of file srf02.cpp.

References _collect_phase, _cycle_counter, _cycling_rate, _index_counter, _measure_interval, addr_ind, collect(), measure(), OK, px4::Array< T, N >::size(), and start().

Here is the call graph for this function:

◆ start()

void SRF02::start ( )
private

Initialise the automatic measurement state machine and start it.

Note
This function is called at open and error time. It might make sense to make it more aggressive about resetting the bus in case of errors.

Definition at line 525 of file srf02.cpp.

References _collect_phase, and _reports.

Referenced by ioctl(), and Run().

Here is the caller graph for this function:

◆ stop()

void SRF02::stop ( )
private

Stop the automatic measurement state machine.

Definition at line 536 of file srf02.cpp.

Referenced by ~SRF02().

Here is the caller graph for this function:

Member Data Documentation

◆ _class_instance

int SRF02::_class_instance {-1}
private

Definition at line 148 of file srf02.cpp.

Referenced by init(), and ~SRF02().

◆ _collect_phase

bool SRF02::_collect_phase {false}
private

Definition at line 146 of file srf02.cpp.

Referenced by Run(), and start().

◆ _comms_errors

perf_counter_t SRF02::_comms_errors {perf_alloc(PC_COUNT, "srf02_com_err")}
private

Definition at line 160 of file srf02.cpp.

Referenced by collect(), measure(), print_info(), and ~SRF02().

◆ _cycle_counter

uint8_t SRF02::_cycle_counter {0}
private

Definition at line 153 of file srf02.cpp.

Referenced by Run().

◆ _cycling_rate

int SRF02::_cycling_rate {0}
private

Definition at line 149 of file srf02.cpp.

Referenced by init(), ioctl(), read(), and Run().

◆ _distance_sensor_topic

orb_advert_t SRF02::_distance_sensor_topic {nullptr}
private

Definition at line 163 of file srf02.cpp.

Referenced by collect(), and init().

◆ _index_counter

uint8_t SRF02::_index_counter {0}
private

Definition at line 154 of file srf02.cpp.

Referenced by init(), and Run().

◆ _max_distance

float SRF02::_max_distance {SRF02_MAX_DISTANCE}
private

Definition at line 157 of file srf02.cpp.

Referenced by collect().

◆ _measure_interval

int SRF02::_measure_interval {0}
private

Definition at line 150 of file srf02.cpp.

Referenced by ioctl(), print_info(), read(), and Run().

◆ _min_distance

float SRF02::_min_distance {SRF02_MIN_DISTANCE}
private

Definition at line 158 of file srf02.cpp.

Referenced by collect().

◆ _orb_class_instance

int SRF02::_orb_class_instance {-1}
private

Definition at line 151 of file srf02.cpp.

Referenced by init().

◆ _reports

ringbuffer::RingBuffer* SRF02::_reports {nullptr}
private

Definition at line 165 of file srf02.cpp.

Referenced by collect(), init(), print_info(), read(), start(), and ~SRF02().

◆ _rotation

uint8_t SRF02::_rotation
private

Definition at line 155 of file srf02.cpp.

Referenced by collect().

◆ _sample_perf

perf_counter_t SRF02::_sample_perf {perf_alloc(PC_ELAPSED, "srf02_read")}
private

Definition at line 161 of file srf02.cpp.

Referenced by collect(), print_info(), and ~SRF02().

◆ _sensor_ok

bool SRF02::_sensor_ok {false}
private

Definition at line 145 of file srf02.cpp.

Referenced by init().

◆ addr_ind

px4::Array<uint8_t, RANGE_FINDER_MAX_SENSORS> SRF02::addr_ind
private

Definition at line 143 of file srf02.cpp.

Referenced by init(), and Run().


The documentation for this class was generated from the following file: