gps.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2011, Johannes Meyer, TU Darmstadt
3 // 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 are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
32 
33 namespace hector_pose_estimation {
34 
35 template class Measurement_<GPSModel>;
36 
38 {
39  position_stddev_ = 10.0;
40  velocity_stddev_ = 1.0;
41  parameters().add("position_stddev", position_stddev_);
42  parameters().add("velocity_stddev", velocity_stddev_);
43 }
44 
46 
47 void GPSModel::getMeasurementNoise(NoiseVariance& R, const State&, bool init)
48 {
49  if (init) {
50  R(0,0) = R(1,1) = pow(position_stddev_, 2);
51  R(2,2) = R(3,3) = pow(velocity_stddev_, 2);
52  }
53 }
54 
55 bool GPSModel::prepareUpdate(State &state, const MeasurementUpdate &update)
56 {
57  state.getRotationMatrix(R);
58  return true;
59 }
60 
61 void GPSModel::getExpectedValue(MeasurementVector& y_pred, const State& state)
62 {
63  y_pred(0) = state.getPosition().x();
64  y_pred(1) = state.getPosition().y();
65  y_pred(2) = state.getVelocity().x();
66  y_pred(3) = state.getVelocity().y();
67 }
68 
69 void GPSModel::getStateJacobian(MeasurementMatrix& C, const State& state, bool init)
70 {
71  if (!init) return; // C is time-constant
72 
73  if (state.position()) {
74  state.position()->cols(C)(0,X) = 1.0;
75  state.position()->cols(C)(1,Y) = 1.0;
76  }
77 
78  if (state.velocity()) {
79  state.velocity()->cols(C)(2,X) = 1.0;
80  state.velocity()->cols(C)(3,Y) = 1.0;
81  }
82 }
83 
84 GPS::GPS(const std::string &name)
85  : Measurement_<GPSModel>(name)
86  , auto_reference_(true)
87  , y_(4)
88 {
89  parameters().add("auto_reference", auto_reference_);
90 }
91 
93 {}
94 
95 void GPS::onReset() {
96  reference_.reset();
97 }
98 
99 GPSModel::MeasurementVector const& GPS::getVector(const GPSUpdate &update, const State&) {
100  if (!reference_) {
101  y_.setConstant(0.0/0.0);
102  return y_;
103  }
104 
105  reference_->fromWGS84(update.latitude, update.longitude, y_(0), y_(1));
106  reference_->fromNorthEast(update.velocity_north, update.velocity_east, y_(2), y_(3));
107 
108  return y_;
109 }
110 
111 bool GPS::prepareUpdate(State &state, const Update &update) {
112  // reset reference position if GPS has not been updated for a while
113  if (timedout()) reference_.reset();
114 
115  // find new reference position
118  if (!auto_reference_ && !reference_->hasPosition()) {
119  ROS_ERROR("Cannot use GPS measurements if no reference latitude/longitude is set and %s/auto_reference parameter is false.", name_.c_str());
120  return false;
121  }
122  if (auto_reference_) reference_->setCurrentPosition(state, update.latitude, update.longitude);
123  }
124 
125  return true;
126 }
127 
128 } // namespace hector_pose_estimation
virtual bool update(const MeasurementUpdate &update)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW GPS(const std::string &name="gps")
Definition: gps.cpp:84
static const GlobalReferencePtr & Instance()
virtual void getExpectedValue(MeasurementVector &y_pred, const State &state)
Definition: gps.cpp:61
virtual bool prepareUpdate(State &state, const GPSUpdate &update)
Definition: gps.cpp:111
virtual ParameterList & parameters()
Definition: measurement.h:63
virtual ConstVelocityType getVelocity() const
Definition: state.cpp:119
virtual const boost::shared_ptr< PositionStateType > & position() const
Definition: state.h:114
virtual void getStateJacobian(MeasurementMatrix &C, const State &state, bool init)
Definition: gps.cpp:69
ParameterList & add(const std::string &key, T &value, const T &default_value)
Definition: parameters.h:148
ParameterList & parameters()
Definition: model.h:47
virtual bool prepareUpdate(State &state, const MeasurementUpdate &update)
Definition: gps.cpp:55
virtual const boost::shared_ptr< VelocityStateType > & velocity() const
Definition: state.h:115
State::RotationMatrix R
Definition: gps.h:53
void getRotationMatrix(RotationMatrix &R) const
Definition: state.cpp:122
GlobalReferencePtr reference_
Definition: gps.h:84
virtual void onReset()
Definition: gps.cpp:95
virtual bool init(PoseEstimation &estimator, Measurement &measurement, State &state)
virtual void getMeasurementNoise(NoiseVariance &R, const State &, bool init)
Definition: gps.cpp:47
GPSModel::MeasurementVector y_
Definition: gps.h:85
#define ROS_ERROR(...)
virtual ConstPositionType getPosition() const
Definition: state.cpp:118
virtual GPSModel::MeasurementVector const & getVector(const GPSUpdate &update, const State &)
Definition: gps.cpp:99


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Thu Feb 18 2021 03:29:30