ground_vehicle_model.cpp
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2013, Johannes Meyer and contributors, Technische Universitat Darmstadt
00003 // All rights reserved.
00004 
00005 // Redistribution and use in source and binary forms, with or without
00006 // modification, are permitted provided that the following conditions are met:
00007 //     * Redistributions of source code must retain the above copyright
00008 //       notice, this list of conditions and the following disclaimer.
00009 //     * Redistributions in binary form must reproduce the above copyright
00010 //       notice, this list of conditions and the following disclaimer in the
00011 //       documentation and/or other materials provided with the distribution.
00012 //     * Neither the name of the Flight Systems and Automatic Control group,
00013 //       TU Darmstadt, nor the names of its contributors may be used to
00014 //       endorse or promote products derived from this software without
00015 //       specific prior written permission.
00016 
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //=================================================================================================
00028 
00029 #include <hector_pose_estimation/system/ground_vehicle_model.h>
00030 #include <hector_pose_estimation/pose_estimation.h>
00031 #include <hector_pose_estimation/filter/set_filter.h>
00032 
00033 #include <limits>
00034 
00035 namespace hector_pose_estimation {
00036 
00037 template class System_<GroundVehicleModel>;
00038 
00039 GroundVehicleModel::GroundVehicleModel()
00040 {
00041   gain_ = 1.0;
00042   base_height_ = 0.0;
00043   min_height_ = -std::numeric_limits<double>::quiet_NaN();
00044   max_height_ =  std::numeric_limits<double>::quiet_NaN();
00045 
00046   parameters().add("gain", gain_);
00047   parameters().add("base_height", base_height_);
00048   parameters().add("min_height", min_height_);
00049   parameters().add("max_height", max_height_);
00050 }
00051 
00052 GroundVehicleModel::~GroundVehicleModel()
00053 {
00054 }
00055 
00056 void GroundVehicleModel::getPrior(State &state)
00057 {
00058   GenericQuaternionSystemModel::getPrior(state);
00059   state.position().z() = base_height_;
00060 }
00061 
00062 void GroundVehicleModel::getDerivative(StateVector& x_dot, const State& state)
00063 {
00064   // forward to GenericQuaternionSystemModel
00065   GenericQuaternionSystemModel::getDerivative(x_dot, state);
00066 
00067   // State::ConstOrientationType q(state.getOrientation());
00068   State::ConstVelocityType v(state.getVelocity());
00069   // State::ConstPositionType p(state.getPosition());
00070 
00071   // Update the body z velocity towards 0
00072 #ifdef VELOCITY_IN_BODY_FRAME
00073   if (state.getVelocityIndex() >= 0) {
00074     x_dot(State::VELOCITY_Z) = -gain_ * v.z();
00075   }
00076 
00077 #else
00078   if (state.getVelocityIndex() >= 0) {
00079     // v_z_body = R.row(2).dot(v)
00080     x_dot(State::VELOCITY_Z) = -gain_ * R(2,2) * R.row(2).dot(v);
00081   }
00082 #endif // VELOCITY_IN_BODY_FRAME
00083 }
00084 
00085 void GroundVehicleModel::getStateJacobian(SystemMatrix& A, const State& state, bool init)
00086 {
00087   GenericQuaternionSystemModel::getStateJacobian(A, state, init);
00088 
00089   State::ConstOrientationType q(state.getOrientation());
00090   State::ConstVelocityType v(state.getVelocity());
00091 
00092 #ifdef VELOCITY_IN_BODY_FRAME
00093   if (state.getVelocityIndex() >= 0) {
00094     A(State::VELOCITY_Z,State::VELOCITY_Z) = -gain_;
00095   }
00096 
00097 #else
00098   if (state.getVelocityIndex() >= 0) {
00099     A.block<1,3>(State::VELOCITY_Z,State::VELOCITY_X) = -gain_ * R(2,2) * R.row(2);
00100 
00101     if (state.getOrientationIndex() >= 0) {
00102       dr3_dq_ <<  2*q.y(),  2*q.z(),  2*q.w(), 2*q.x(),
00103                  -2*q.x(), -2*q.w(),  2*q.z(), 2*q.y(),
00104                   2*q.w(), -2*q.x(), -2*q.y(), 2*q.z();
00105 
00106       A.block<1,4>(State::VELOCITY_Z,state.getOrientationIndex()) = -gain_ * ((dr3_dq_.row(2) * R.row(2).dot(v)) + R(2,2) * (v.transpose() * dr3_dq_));
00107     }
00108   }
00109 #endif // VELOCITY_IN_BODY_FRAME
00110 }
00111 
00112 SystemStatus GroundVehicleModel::getStatusFlags(const State& state)
00113 {
00114   SystemStatus flags = GenericQuaternionSystemModel::getStatusFlags(state);
00115   flags |= STATE_VELOCITY_Z;
00116   flags |= STATE_POSITION_Z;
00117   return flags;
00118 }
00119 
00120 bool GroundVehicleModel::limitState(State& state)
00121 {
00122   bool result = GenericQuaternionSystemModel::limitState(state);
00123   if (state.position().z() < min_height_) {
00124     state.position().z() = min_height_;
00125     result = false;
00126   }
00127   if (state.position().z() > max_height_) {
00128     state.position().z() = max_height_;
00129     result = false;
00130   }
00131   return result;
00132 }
00133 
00134 } // namespace hector_pose_estimation


hector_pose_estimation_core
Author(s): Johannes Meyer
autogenerated on Mon Oct 6 2014 00:24:16