Firmware
gnss.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2014, 2015 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 
45 #pragma once
46 
47 #include <uORB/uORB.h>
48 #include <uORB/topics/vehicle_gps_position.h>
49 
50 #include <uavcan/uavcan.hpp>
51 #include <uavcan/equipment/gnss/Fix.hpp>
52 #include <uavcan/equipment/gnss/Fix2.hpp>
53 
54 #include "sensor_bridge.hpp"
55 
57 {
58  static constexpr unsigned ORB_TO_UAVCAN_FREQUENCY_HZ = 10;
59 
60 public:
61  static const char *const NAME;
62 
63  UavcanGnssBridge(uavcan::INode &node);
65 
66  const char *get_name() const override { return NAME; }
67 
68  int init() override;
69 
70  unsigned get_num_redundant_channels() const override;
71 
72  void print_status() const override;
73 
74 private:
78  void gnss_fix_sub_cb(const uavcan::ReceivedDataStructure<uavcan::equipment::gnss::Fix> &msg);
79  void gnss_fix2_sub_cb(const uavcan::ReceivedDataStructure<uavcan::equipment::gnss::Fix2> &msg);
80 
81  template <typename FixType>
82  void process_fixx(const uavcan::ReceivedDataStructure<FixType> &msg,
83  const float (&pos_cov)[9],
84  const float (&vel_cov)[9],
85  const bool valid_pos_cov,
86  const bool valid_vel_cov);
87 
88  void broadcast_from_orb(const uavcan::TimerEvent &);
89 
90  typedef uavcan::MethodBinder < UavcanGnssBridge *,
91  void (UavcanGnssBridge::*)(const uavcan::ReceivedDataStructure<uavcan::equipment::gnss::Fix> &) >
92  FixCbBinder;
93 
94  typedef uavcan::MethodBinder < UavcanGnssBridge *,
95  void (UavcanGnssBridge::*)(const uavcan::ReceivedDataStructure<uavcan::equipment::gnss::Fix2> &) >
96  Fix2CbBinder;
97 
98  typedef uavcan::MethodBinder<UavcanGnssBridge *,
99  void (UavcanGnssBridge::*)(const uavcan::TimerEvent &)>
100  TimerCbBinder;
101 
102  uavcan::INode &_node;
103  uavcan::Subscriber<uavcan::equipment::gnss::Fix, FixCbBinder> _sub_fix;
104  uavcan::Subscriber<uavcan::equipment::gnss::Fix2, Fix2CbBinder> _sub_fix2;
105  uavcan::Publisher<uavcan::equipment::gnss::Fix2> _pub_fix2;
106  uavcan::TimerEventForwarder<TimerCbBinder> _orb_to_uavcan_pub_timer;
107  int _receiver_node_id = -1;
108 
109  bool _old_fix_subscriber_active = true;
110 
111  orb_advert_t _report_pub;
112 
113  int _orb_sub_gnss = -1;
114 
115  bool _system_clock_set = false;
116 };
unsigned get_num_redundant_channels() const override
Returns number of active redundancy channels.
Definition: gnss.cpp:96
void print_status() const override
Prints current status in a human readable format to stdout.
Definition: gnss.cpp:101
A sensor bridge class must implement this interface.
Definition: sensor_bridge.hpp:49
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
API for the uORB lightweight object broker.
int init() override
Starts the bridge.
Definition: gnss.cpp:67
Definition: gnss.hpp:56
const char * get_name() const override
Returns ASCII name of the bridge.
Definition: gnss.hpp:66