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

Public Member Functions

 MB12XX (const int bus=MB12XX_BUS_DEFAULT)
 
virtual ~MB12XX ()
 
virtual int init () override
 
void print_info ()
 Diagnostics - print some basic information about the driver. More...
 
int set_address (const uint8_t address=MB12XX_BASE_ADDR)
 Sets a new device address. More...
 
void start ()
 Initialise the automatic measurement state machine and start it. More...
 
void stop ()
 Stop the automatic measurement state machine. More...
 

Private Member Functions

int collect ()
 Collects the most recent sensor measurement data from the i2c bus. More...
 
int get_sensor_rotation (const size_t index)
 Gets the current sensor rotation value. More...
 
int measure ()
 Sends an i2c measure command to start the next sonar ping. More...
 
void Run () override
 Perform a poll cycle; collect from the previous measurement and start a new one. More...
 
 DEFINE_PARAMETERS ((ParamInt< px4::params::SENS_EN_MB12XX >) _p_sensor_enabled,(ParamInt< px4::params::SENS_MB12_0_ROT >) _p_sensor0_rot,(ParamInt< px4::params::SENS_MB12_1_ROT >) _p_sensor1_rot,(ParamInt< px4::params::SENS_MB12_2_ROT >) _p_sensor2_rot,(ParamInt< px4::params::SENS_MB12_3_ROT >) _p_sensor3_rot,(ParamInt< px4::params::SENS_MB12_4_ROT >) _p_sensor4_rot,(ParamInt< px4::params::SENS_MB12_5_ROT >) _p_sensor5_rot,(ParamInt< px4::params::SENS_MB12_6_ROT >) _p_sensor6_rot,(ParamInt< px4::params::SENS_MB12_7_ROT >) _p_sensor7_rot,(ParamInt< px4::params::SENS_MB12_8_ROT >) _p_sensor8_rot,(ParamInt< px4::params::SENS_MB12_9_ROT >) _p_sensor9_rot,(ParamInt< px4::params::SENS_MB12_10_ROT >) _p_sensor10_rot,(ParamInt< px4::params::SENS_MB12_11_ROT >) _p_sensor11_rot)
 

Private Attributes

px4::Array< uint8_t, RANGE_FINDER_MAX_SENSORS_sensor_addresses {}
 
px4::Array< uint8_t, RANGE_FINDER_MAX_SENSORS_sensor_rotations {}
 
int _measure_interval {MB12XX_MEASURE_INTERVAL}
 
int _orb_class_instance {-1}
 
size_t _sensor_index {0}
 
size_t _sensor_count {0}
 
orb_advert_t _distance_sensor_topic {nullptr}
 
perf_counter_t _comms_error {perf_alloc(PC_ELAPSED, "mb12xx_comms_error")}
 
perf_counter_t _sample_perf {perf_alloc(PC_COUNT, "mb12xx_sample_perf")}
 

Detailed Description

Definition at line 91 of file mb12xx.cpp.

Constructor & Destructor Documentation

◆ MB12XX()

MB12XX::MB12XX ( const int  bus = MB12XX_BUS_DEFAULT)

Definition at line 181 of file mb12xx.cpp.

Referenced by mb12xx::start_bus().

Here is the caller graph for this function:

◆ ~MB12XX()

MB12XX::~MB12XX ( )
virtual

Definition at line 188 of file mb12xx.cpp.

References _comms_error, _distance_sensor_topic, _sample_perf, orb_unadvertise(), perf_free(), and stop().

Here is the call graph for this function:

Member Function Documentation

◆ collect()

int MB12XX::collect ( )
private

Collects the most recent sensor measurement data from the i2c bus.

Definition at line 204 of file mb12xx.cpp.

References _comms_error, _distance_sensor_topic, _sample_perf, _sensor_addresses, _sensor_count, _sensor_index, _sensor_rotations, distance_sensor_s::current_distance, f(), hrt_absolute_time(), distance_sensor_s::id, distance_sensor_s::max_distance, MB12XX_MAX_DISTANCE, MB12XX_MIN_DISTANCE, measure(), distance_sensor_s::min_distance, ORB_ID, ORB_PRIO_DEFAULT, orb_publish_auto(), 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 Run().

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

◆ DEFINE_PARAMETERS()

MB12XX::DEFINE_PARAMETERS ( (ParamInt< px4::params::SENS_EN_MB12XX >)  _p_sensor_enabled,
(ParamInt< px4::params::SENS_MB12_0_ROT >)  _p_sensor0_rot,
(ParamInt< px4::params::SENS_MB12_1_ROT >)  _p_sensor1_rot,
(ParamInt< px4::params::SENS_MB12_2_ROT >)  _p_sensor2_rot,
(ParamInt< px4::params::SENS_MB12_3_ROT >)  _p_sensor3_rot,
(ParamInt< px4::params::SENS_MB12_4_ROT >)  _p_sensor4_rot,
(ParamInt< px4::params::SENS_MB12_5_ROT >)  _p_sensor5_rot,
(ParamInt< px4::params::SENS_MB12_6_ROT >)  _p_sensor6_rot,
(ParamInt< px4::params::SENS_MB12_7_ROT >)  _p_sensor7_rot,
(ParamInt< px4::params::SENS_MB12_8_ROT >)  _p_sensor8_rot,
(ParamInt< px4::params::SENS_MB12_9_ROT >)  _p_sensor9_rot,
(ParamInt< px4::params::SENS_MB12_10_ROT >)  _p_sensor10_rot,
(ParamInt< px4::params::SENS_MB12_11_ROT >)  _p_sensor11_rot 
)
private

◆ get_sensor_rotation()

int MB12XX::get_sensor_rotation ( const size_t  index)
private

Gets the current sensor rotation value.

Definition at line 256 of file mb12xx.cpp.

Referenced by init().

Here is the caller graph for this function:

◆ init()

int MB12XX::init ( )
overridevirtual

Definition at line 288 of file mb12xx.cpp.

References _measure_interval, _sensor_addresses, _sensor_count, _sensor_rotations, get_sensor_rotation(), ToneAlarmInterface::init(), MB12XX_BASE_ADDR, MB12XX_INTERVAL_BETWEEN_SUCCESIVE_FIRES, MB12XX_MIN_ADDR, measure(), OK, and RANGE_FINDER_MAX_SENSORS.

Referenced by mb12xx::start_bus().

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

◆ measure()

int MB12XX::measure ( )
private

Sends an i2c measure command to start the next sonar ping.

Definition at line 337 of file mb12xx.cpp.

References MB12XX_TAKE_RANGE_REG.

Referenced by collect(), and init().

Here is the caller graph for this function:

◆ print_info()

void MB12XX::print_info ( )

Diagnostics - print some basic information about the driver.

Definition at line 347 of file mb12xx.cpp.

References _comms_error, _measure_interval, _sample_perf, _sensor_addresses, _sensor_count, and perf_print_counter().

Referenced by mb12xx::status().

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

◆ Run()

void MB12XX::Run ( )
overrideprivate

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

Definition at line 359 of file mb12xx.cpp.

References collect().

Here is the call graph for this function:

◆ set_address()

int MB12XX::set_address ( const uint8_t  address = MB12XX_BASE_ADDR)

Sets a new device address.

Parameters
addressThe new sensor address to be set: 200-224 even addresses only.
Returns
Returns PX4_OK iff successful, PX4_ERROR otherwise.

Definition at line 368 of file mb12xx.cpp.

References _sensor_count, MB12XX_SET_ADDRESS_1, and MB12XX_SET_ADDRESS_2.

Referenced by mb12xx::set_address().

Here is the caller graph for this function:

◆ start()

void MB12XX::start ( )

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 399 of file mb12xx.cpp.

References _measure_interval.

Referenced by mb12xx::reset(), and mb12xx::start_bus().

Here is the caller graph for this function:

◆ stop()

void MB12XX::stop ( )

Stop the automatic measurement state machine.

Definition at line 409 of file mb12xx.cpp.

Referenced by mb12xx::reset(), and ~MB12XX().

Here is the caller graph for this function:

Member Data Documentation

◆ _comms_error

perf_counter_t MB12XX::_comms_error {perf_alloc(PC_ELAPSED, "mb12xx_comms_error")}
private

Definition at line 161 of file mb12xx.cpp.

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

◆ _distance_sensor_topic

orb_advert_t MB12XX::_distance_sensor_topic {nullptr}
private

Definition at line 159 of file mb12xx.cpp.

Referenced by collect(), and ~MB12XX().

◆ _measure_interval

int MB12XX::_measure_interval {MB12XX_MEASURE_INTERVAL}
private

Definition at line 152 of file mb12xx.cpp.

Referenced by init(), print_info(), and start().

◆ _orb_class_instance

int MB12XX::_orb_class_instance {-1}
private

Definition at line 153 of file mb12xx.cpp.

◆ _sample_perf

perf_counter_t MB12XX::_sample_perf {perf_alloc(PC_COUNT, "mb12xx_sample_perf")}
private

Definition at line 162 of file mb12xx.cpp.

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

◆ _sensor_addresses

px4::Array<uint8_t, RANGE_FINDER_MAX_SENSORS> MB12XX::_sensor_addresses {}
private

Definition at line 149 of file mb12xx.cpp.

Referenced by collect(), init(), and print_info().

◆ _sensor_count

size_t MB12XX::_sensor_count {0}
private

Definition at line 157 of file mb12xx.cpp.

Referenced by collect(), init(), print_info(), and set_address().

◆ _sensor_index

size_t MB12XX::_sensor_index {0}
private

Definition at line 155 of file mb12xx.cpp.

Referenced by collect().

◆ _sensor_rotations

px4::Array<uint8_t, RANGE_FINDER_MAX_SENSORS> MB12XX::_sensor_rotations {}
private

Definition at line 150 of file mb12xx.cpp.

Referenced by collect(), and init().


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