PX4 Firmware
PX4 Autopilot Software http://px4.io
VehicleAngularVelocity.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #pragma once
35 
39 #include <px4_platform_common/px4_config.h>
40 #include <px4_platform_common/log.h>
41 #include <px4_platform_common/module_params.h>
42 #include <px4_platform_common/px4_work_queue/WorkItem.hpp>
43 #include <uORB/Publication.hpp>
44 #include <uORB/Subscription.hpp>
50 
54 
55 class VehicleAngularVelocity : public ModuleParams, public px4::WorkItem
56 {
57 public:
58 
60  virtual ~VehicleAngularVelocity();
61 
62  void Run() override;
63 
64  bool Start();
65  void Stop();
66 
67  void PrintStatus();
68 
69 private:
70 
71  void ParametersUpdate(bool force = false);
72  void SensorBiasUpdate(bool force = false);
73  bool SensorCorrectionsUpdate(bool force = false);
74 
75  static constexpr int MAX_SENSOR_COUNT = 3;
76 
77  DEFINE_PARAMETERS(
78  (ParamInt<px4::params::SENS_BOARD_ROT>) _param_sens_board_rot,
79 
80  (ParamFloat<px4::params::SENS_BOARD_X_OFF>) _param_sens_board_x_off,
81  (ParamFloat<px4::params::SENS_BOARD_Y_OFF>) _param_sens_board_y_off,
82  (ParamFloat<px4::params::SENS_BOARD_Z_OFF>) _param_sens_board_z_off
83  )
84 
85  uORB::Publication<vehicle_angular_velocity_s> _vehicle_angular_velocity_pub{ORB_ID(vehicle_angular_velocity)};
86 
87  uORB::Subscription _params_sub{ORB_ID(parameter_update)}; /**< parameter updates subscription */
88  uORB::Subscription _sensor_bias_sub{ORB_ID(sensor_bias)}; /**< sensor in-run bias correction subscription */
89  uORB::Subscription _sensor_correction_sub{ORB_ID(sensor_correction)}; /**< sensor thermal correction subscription */
90 
91  uORB::SubscriptionCallbackWorkItem _sensor_selection_sub{this, ORB_ID(sensor_selection)}; /**< selected primary sensor subscription */
92 
94  {this, ORB_ID(sensor_gyro), 0},
95  {this, ORB_ID(sensor_gyro), 1},
96  {this, ORB_ID(sensor_gyro), 2}
97  };
98 
99  uORB::SubscriptionCallbackWorkItem _sensor_control_sub[MAX_SENSOR_COUNT] { /**< sensor control data subscription */
100  {this, ORB_ID(sensor_gyro_control), 0},
101  {this, ORB_ID(sensor_gyro_control), 1},
102  {this, ORB_ID(sensor_gyro_control), 2}
103  };
104 
105  matrix::Dcmf _board_rotation; /**< rotation matrix for the orientation that the board is mounted */
106 
110 
112  uint8_t _selected_sensor{0};
115 
116 };
uORB::SubscriptionCallbackWorkItem _sensor_selection_sub
selected primary sensor subscription
void SensorBiasUpdate(bool force=false)
uORB::SubscriptionCallbackWorkItem _sensor_control_sub[MAX_SENSOR_COUNT]
sensor control data subscription
matrix::Dcmf _board_rotation
rotation matrix for the orientation that the board is mounted
Limiting / constrain helper functions.
void ParametersUpdate(bool force=false)
Vector rotation library.
Base publication wrapper class.
Definition: Publication.hpp:52
uORB::Subscription _sensor_bias_sub
sensor in-run bias correction subscription
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
static constexpr int MAX_SENSOR_COUNT
bool SensorCorrectionsUpdate(bool force=false)
DEFINE_PARAMETERS((ParamInt< px4::params::SENS_BOARD_ROT >) _param_sens_board_rot,(ParamFloat< px4::params::SENS_BOARD_X_OFF >) _param_sens_board_x_off,(ParamFloat< px4::params::SENS_BOARD_Y_OFF >) _param_sens_board_y_off,(ParamFloat< px4::params::SENS_BOARD_Z_OFF >) _param_sens_board_z_off) uORB uORB::Subscription _params_sub
parameter updates subscription
uORB::SubscriptionCallbackWorkItem _sensor_sub[MAX_SENSOR_COUNT]
sensor data subscription
uORB::Subscription _sensor_correction_sub
sensor thermal correction subscription