Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <hector_quadrotor_model/quadrotor_aerodynamics.h>
00030 #include <hector_quadrotor_model/helpers.h>
00031
00032 #include <ros/node_handle.h>
00033 #include <boost/array.hpp>
00034
00035 extern "C" {
00036 #include "quadrotorDrag/quadrotorDrag.h"
00037 #include "quadrotorDrag/quadrotorDrag_initialize.h"
00038 }
00039
00040 #include <boost/array.hpp>
00041
00042 namespace hector_quadrotor_model {
00043
00044
00045 struct QuadrotorAerodynamics::DragModel {
00046 DragParameters parameters_;
00047 boost::array<real_T,6> u;
00048 boost::array<real_T,6> y;
00049 };
00050
00051 QuadrotorAerodynamics::QuadrotorAerodynamics()
00052 {
00053
00054 quadrotorDrag_initialize();
00055 drag_model_ = new DragModel;
00056 }
00057
00058 QuadrotorAerodynamics::~QuadrotorAerodynamics()
00059 {
00060 delete drag_model_;
00061 }
00062
00063 inline void QuadrotorAerodynamics::f(const real_T uin[10], real_T dt, real_T y[14]) const
00064 {
00065 ::quadrotorDrag(uin, drag_model_->parameters_, dt, y);
00066 }
00067
00068 void QuadrotorAerodynamics::configure(const std::string &ns)
00069 {
00070 ros::NodeHandle param(ns);
00071
00072
00073 param.getParam("C_wxy", drag_model_->parameters_.C_wxy);
00074 param.getParam("C_wz", drag_model_->parameters_.C_wz);
00075 param.getParam("C_mxy", drag_model_->parameters_.C_mxy);
00076 param.getParam("C_mz", drag_model_->parameters_.C_mz);
00077
00078 #ifndef NDEBUG
00079 std::cout << "Loaded the following quadrotor drag model parameters from namespace " << param.getNamespace() << ":" << std::endl;
00080 std::cout << "C_wxy = " << drag_model_->parameters_.C_wxy << std::endl;
00081 std::cout << "C_wz = " << drag_model_->parameters_.C_wz << std::endl;
00082 std::cout << "C_mxy = " << drag_model_->parameters_.C_mxy << std::endl;
00083 std::cout << "C_mz = " << drag_model_->parameters_.C_mz << std::endl;
00084 #endif
00085
00086 reset();
00087 }
00088
00089 void QuadrotorAerodynamics::reset()
00090 {
00091 boost::mutex::scoped_lock lock(mutex_);
00092 drag_model_->u.assign(0.0);
00093 drag_model_->y.assign(0.0);
00094
00095 twist_ = geometry_msgs::Twist();
00096 wind_ = geometry_msgs::Vector3();
00097 wrench_ = geometry_msgs::Wrench();
00098 }
00099
00100 void QuadrotorAerodynamics::setTwist(const geometry_msgs::Twist& twist)
00101 {
00102 boost::mutex::scoped_lock lock(mutex_);
00103 twist_ = twist;
00104 }
00105
00106 void QuadrotorAerodynamics::setWind(const geometry_msgs::Vector3& wind)
00107 {
00108 boost::mutex::scoped_lock lock(mutex_);
00109 wind_ = wind;
00110 }
00111
00112 void QuadrotorAerodynamics::update(double dt)
00113 {
00114 if (dt <= 0.0) return;
00115 boost::mutex::scoped_lock lock(mutex_);
00116
00117
00118 drag_model_->u[0] = (twist_.linear.x - wind_.x);
00119 drag_model_->u[1] = -(twist_.linear.y - wind_.y);
00120 drag_model_->u[2] = -(twist_.linear.z - wind_.z);
00121 drag_model_->u[3] = twist_.angular.x;
00122 drag_model_->u[4] = -twist_.angular.y;
00123 drag_model_->u[5] = -twist_.angular.z;
00124
00125
00126
00127
00128
00129
00130 checknan(drag_model_->u, "drag model input");
00131
00132
00133 f(drag_model_->u.data(), dt, drag_model_->y.data());
00134
00135 checknan(drag_model_->y, "drag model output");
00136
00137
00138
00139
00140
00141
00142 wrench_.force.x = drag_model_->y[0];
00143 wrench_.force.y = -drag_model_->y[1];
00144 wrench_.force.z = -drag_model_->y[2];
00145 wrench_.torque.x = drag_model_->y[3];
00146 wrench_.torque.x = -drag_model_->y[4];
00147 wrench_.torque.x = -drag_model_->y[5];
00148 }
00149
00150 }