PX4的PX4flow光流驱动文件分析,PX4里面一个驱动就有一个类

2023-05-16

PX4的PX4flow光流驱动文件分析

主要还是想找到他们发布的是哪种uORB,这样自己写光流驱动的时候直接用这个,这样也免得改动其他文件。

看头文件可以看出他们用了哪两种msg,和ROS话题一样,msg文件编译后会生成对应相同名称头文件,在cpp里面需要include,和ROS一样,《一本书看懂多旋翼无人机》里面也有讲,在讲msg的时候,比如P145面。

https://gitee.com/amovlab/prometheus_px4/blob/Prometheus_PX4_1.11.1/src/drivers/optical_flow/px4flow/px4flow.cpp

继而在msg文件夹找到对应msg文件

https://gitee.com/amovlab/prometheus_px4/blob/Prometheus_PX4_1.11.1/msg/optical_flow.msg

# Optical flow in XYZ body frame in SI units.
# http://en.wikipedia.org/wiki/International_System_of_Units

uint64 timestamp		# time since system start (microseconds)

uint8 sensor_id			# id of the sensor emitting the flow value
float32 pixel_flow_x_integral	# accumulated optical flow in radians where a positive value is produced by a RH rotation about the X body axis
float32 pixel_flow_y_integral	# accumulated optical flow in radians where a positive value is produced by a RH rotation about the Y body axis
float32 gyro_x_rate_integral	# accumulated gyro value in radians where a positive value is produced by a RH rotation about the X body axis. Set to NaN if flow sensor does not have 3-axis gyro data.
float32 gyro_y_rate_integral	# accumulated gyro value in radians where a positive value is produced by a RH rotation about the Y body axis. Set to NaN if flow sensor does not have 3-axis gyro data.
float32 gyro_z_rate_integral	# accumulated gyro value in radians where a positive value is produced by a RH rotation about the Z body axis. Set to NaN if flow sensor does not have 3-axis gyro data.
float32 ground_distance_m	# Altitude / distance to ground in meters
uint32 integration_timespan	# accumulation timespan in microseconds
uint32 time_since_last_sonar_update	# time since last sonar update in microseconds
uint16 frame_count_since_last_readout	# number of accumulated frames in timespan
int16 gyro_temperature	# Temperature * 100 in centi-degrees Celsius
uint8 quality	# Average of quality of accumulated frames, 0: bad quality, 255: maximum quality

float32 max_flow_rate # Magnitude of maximum angular which the optical flow sensor can measure reliably
float32 min_ground_distance # Minimum distance from ground at which the optical flow sensor operates reliably
float32 max_ground_distance # Maximum distance from ground at which the optical flow sensor operates reliably

https://gitee.com/amovlab/prometheus_px4/blob/Prometheus_PX4_1.11.1/msg/distance_sensor.msg

# DISTANCE_SENSOR message data

uint64 timestamp		# time since system start (microseconds)

float32 min_distance		# Minimum distance the sensor can measure (in m)
float32 max_distance		# Maximum distance the sensor can measure (in m)
float32 current_distance	# Current distance reading (in m)
float32 variance		# Measurement variance (in m^2), 0 for unknown / invalid readings
int8 signal_quality		# Signal quality in percent (0...100%), where 0 = invalid signal, 100 = perfect signal, and -1 = unknown signal quality.

uint8 type			# Type from MAV_DISTANCE_SENSOR enum
uint8 MAV_DISTANCE_SENSOR_LASER = 0
uint8 MAV_DISTANCE_SENSOR_ULTRASOUND = 1
uint8 MAV_DISTANCE_SENSOR_INFRARED = 2
uint8 MAV_DISTANCE_SENSOR_RADAR = 3

uint8 id			# Onboard ID of the sensor

float32 h_fov # Sensor horizontal field of view (rad)
float32 v_fov # Sensor vertical field of view (rad)
float32[4] q # Quaterion sensor orientation with respect to the vehicle body frame to specify the orientation ROTATION_CUSTOM

uint8 orientation		# Direction the sensor faces from MAV_SENSOR_ORIENTATION enum

uint8 ROTATION_YAW_0		= 0 # MAV_SENSOR_ROTATION_NONE
uint8 ROTATION_YAW_45		= 1 # MAV_SENSOR_ROTATION_YAW_45
uint8 ROTATION_YAW_90		= 2 # MAV_SENSOR_ROTATION_YAW_90
uint8 ROTATION_YAW_135		= 3 # MAV_SENSOR_ROTATION_YAW_135
uint8 ROTATION_YAW_180		= 4 # MAV_SENSOR_ROTATION_YAW_180
uint8 ROTATION_YAW_225		= 5 # MAV_SENSOR_ROTATION_YAW_225
uint8 ROTATION_YAW_270		= 6 # MAV_SENSOR_ROTATION_YAW_270
uint8 ROTATION_YAW_315		= 7 # MAV_SENSOR_ROTATION_YAW_315

uint8 ROTATION_FORWARD_FACING	= 0 # MAV_SENSOR_ROTATION_NONE
uint8 ROTATION_RIGHT_FACING	= 2 # MAV_SENSOR_ROTATION_YAW_90
uint8 ROTATION_BACKWARD_FACING	= 4 # MAV_SENSOR_ROTATION_YAW_180
uint8 ROTATION_LEFT_FACING	= 6 # MAV_SENSOR_ROTATION_YAW_270

uint8 ROTATION_UPWARD_FACING   = 24 # MAV_SENSOR_ROTATION_PITCH_90
uint8 ROTATION_DOWNWARD_FACING = 25 # MAV_SENSOR_ROTATION_PITCH_270

uint8 ROTATION_CUSTOM          = 100 # MAV_SENSOR_ROTATION_CUSTOM

------------------------------------------------------------------------------------------------------------------------------

应该是有两个uORB发布的,一个是距离,应该就是高度,一个是光流。光流模块本身就是要结合测高传感器来。

PX4flow上面是有超声波的。

https://gitee.com/amovlab/prometheus_px4/blob/Prometheus_PX4_1.11.1/src/drivers/optical_flow/px4flow/px4flow.cpp

 https://gitee.com/amovlab/prometheus_px4/blob/Prometheus_PX4_1.11.1/src/drivers/optical_flow/px4flow/px4flow.cpp

我怀疑啊上面pubulish函数里面就是调用的orb_publish函数,这才是真正uORB的发布函数。

------------------------------------------------------------------------------------------------------------------------------

在对应的cmakelists里面应该可以看到这个模块的名称,那么就可以在终端通过模块名称 status查看这个模块的数据。

https://gitee.com/amovlab/prometheus_px4/tree/Prometheus_PX4_1.11.1/src/drivers/optical_flow/px4flow

https://gitee.com/amovlab/prometheus_px4/blob/Prometheus_PX4_1.11.1/src/drivers/optical_flow/px4flow/CMakeLists.txt

当然GPS模块的名称就叫gps 不叫drivers___gps,看来是看main那个后面的名称?

看了《一本书看懂多旋翼无人机》P258上面写的注释清楚了,模块名称应该是横杠后面的部分。PX4FLOW的驱动模块名称就叫px4flow  GPS的模型名称就叫gps

-----------------------------------------------------------------------------------------------------------------------------------

px4flow.cpp里面百分之九十都是写PX4FLOW 这个类,先定义了这个类,类里面具体函数的实现放在类外面写的,也是放在这个cpp里面,所以这么看这个cpp文件就比较清晰了!!!也可以顺带学学C++面向对象 类的写法用法。他们这每个驱动似乎都是一个类,你看看你您不能写出自己的类,哪怕是继承这个PX4FLOW这个类也可以啊,自己写一个。

最后是单独写了个px4flow_main函数,可能是类似于main函数,在这里面对类创建实例化对象来用?

PX4的驱动的类的方法里面经常会看到方法前面加个virtual   虚函数,这也是C++里面的常用用法,不清楚说明你需要去补一补C++基础

拍自《一本书看懂多旋翼无人机》P262

拍自《一本书看懂多旋翼无人机》P281

真正明白虚函数的意义之后,就自然明白下面所说的 洗后函数一般声明成虚函数

拍自《C++程序设计教程》第3版 竞技版 P413

这里甚至建议,尽量将成员函数设计成虚函数,java里面所有的成员函数都是虚函数。这么看PX4的驱动类里面那么多虚函数也是很合理的。

 拍自《C++程序设计教程》第3版 竞技版 P407

下面拍自 《C++primer plus》P403 这里有讲virtual 

《C++ primer》P552 里面也有专门一小节讲虚析构函数

似乎虚函数是为了实现多态

https://blog.csdn.net/sinat_16643223/article/details/119423437

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

我发现PX4的正点原子光流模块的驱动和PX4flow光流模块的驱动发布的uORB都是一个,这么我觉得优象光流也应该是可以用这个的。,这个不是单为PX4flow设计的。

optical_flow.msg

https://gitee.com/maxibooksiyi/prometheus_px4/blob/Prometheus_PX4_1.11.1/src/drivers/optical_flow/pmw3901/PMW3901.hpp

PX4官方手册里给了非常详细的使用方法,设置方法。

这样我连PX4怎么设置也知道了。我可以直接用优象光流替代这个光流,因为我看这个光流模块也没有带有什么测高传感器,那么高度这一块可以暂时不用管对不对。很多其他地方就不用管不用考虑,只需要和它发一样的uORB就可以了应该。

http://docs.px4.io/master/zh/sensor/pmw3901.html

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 C++11 中的 override 关键字,可以显式的在派生类中声明,哪些成员函数需要被重写,如果没被重写,则编译器会报错。

https://www.cnblogs.com/xinxue/p/5471708.html

 那么再看驱动代码时经常出现的override就好理解了。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PX4的PX4flow光流驱动文件分析,PX4里面一个驱动就有一个类 的相关文章

随机推荐