Deadalus
|
00001 /* ----------------------------------------------------------------------------- 00002 * 00003 * 00004 * ____ _____ _ 00005 * / ___| __ _ _ __ _ __|__ / __| | ___ 00006 * \___ \ / _` | '_ \| '_ \ / / / _` |/ _ \ 00007 * ___) | (_| | |_) | |_) / /_ | (_| | __/ 00008 * |____/ \__,_| .__/| .__/____(_)__,_|\___| 00009 * |_| |_| 00010 * 00011 * 00012 * 00013 * Author: Andreas Gschossmann 00014 * Email: andreas.gschossmann@hs-regensburg.de 00015 * 00016 * gazebo_model_plugin.cc - gazebo-plugin to get access to gazebo-API 00017 * 00018 * ----------------------------------------------------------------------------*/ 00019 00020 #ifndef _GAZEBO_MODEL_PLUGIN_HH_ 00021 #define _GAZEBO_MODEL_PLUGIN_HH_ 00022 00023 #include <iostream> 00024 #include <math.h> 00025 #include <boost/shared_ptr.hpp> 00026 00027 00028 #include <boost/bind.hpp> 00029 #include <gazebo/gazebo.hh> 00030 #include <gazebo/physics/physics.hh> 00031 #include <gazebo/common/common.hh> 00032 #include <stdio.h> 00033 00034 #include <gazebo/transport/transport.hh> 00035 #include <gazebo/msgs/msgs.hh> 00036 00037 #include <boost/shared_ptr.hpp> 00038 #include <sdf/sdf.hh> 00039 #include <boost/gil/gil_all.hpp> 00040 #include <boost/gil/extension/io/png_dynamic_io.hpp> 00041 00042 //#include "gazebo/math/Vector3.hh" 00043 //#include "gazebo/physics/physics.hh" 00044 //#include "imu.pb.h" 00045 00046 #include "../quadrotor_dynamics/quadrotor_dynamics.hh" 00047 #include "../dependencies/resources.hh" 00048 00049 #include "../sil/sil.hh" 00050 00051 namespace gazebo 00052 { 00053 00055 00056 class GazeboModelPlugin : public ModelPlugin 00057 { 00058 //private 00059 transport::NodePtr node; 00060 transport::SubscriberPtr imuSubscriber; 00061 00063 public: GazeboModelPlugin(); //: ModelPlugin();//, _myQuadRotorDynamics(), _rotor_speed() 00065 //public: virtual ~GazeboModelPlugin(); 00066 00067 public: 00072 QuadRotorDynamics _myQuadRotorDynamics; 00073 AngularVel _rotor_speed; 00074 Mechanics _mechanics; 00075 00076 00077 private: 00078 SIL _sil; 00079 Sensors _sensor_vals; 00080 00081 00082 private: 00083 enum MotorNumber {m1, m2, m3, m4, front, rear, right, left, all}; 00084 00085 public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/); 00086 00088 public: void callback_imu(ConstIMUPtr &msg); 00089 00091 public: void OnUpdate(const common::UpdateInfo & /*_info*/); 00092 00094 private: physics::ModelPtr model; 00095 // Pointer to the motor links 00096 private: 00097 physics::LinkPtr motor_1, motor_front; 00098 physics::LinkPtr motor_2, motor_right; 00099 physics::LinkPtr motor_3, motor_rear; 00100 physics::LinkPtr motor_4, motor_left; 00101 00102 // Pointer to the center Link 00103 private: 00104 physics::LinkPtr frame_center; 00105 00106 // Pointer to the motor rod links 00107 private: 00108 physics::LinkPtr motor_prop_1, motor_prop_front; 00109 physics::LinkPtr motor_prop_2, motor_prop_right; 00110 physics::LinkPtr motor_prop_3, motor_prop_rear; 00111 physics::LinkPtr motor_prop_4, motor_prop_left; 00112 00113 // Pointer to the update event connection 00114 private: event::ConnectionPtr updateConnection; 00115 00116 // Gazebo Time 00117 private: 00118 common::Time _current_time; 00119 common::Time _last_time; 00120 common::Time _dt; 00121 00122 private: 00123 const gazebo::math::Vector3 _earth_mag_vec3; 00124 00125 private: void get_magnetic_field(); 00126 // Set motor-values: forces, angular velocities, moments (own approach) 00127 //public: bool SetPhysics(const MotorNumber myMotorNmb, double value, bool update = false); 00128 //public: bool SetThrust(const MotorNumber myMotorNmb, double value); 00129 00130 }; 00131 } 00132 00133 #endif