gazebo_fw_dynamics_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Pavel Vechersky, ASL, ETH Zurich, Switzerland
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ROTORS_GAZEBO_PLUGINS_FW_DYNAMICS_PLUGIN_H
18 #define ROTORS_GAZEBO_PLUGINS_FW_DYNAMICS_PLUGIN_H
19 
20 #include <gazebo/common/Plugin.hh>
21 #include <gazebo/common/common.hh>
22 #include <gazebo/gazebo.hh>
23 #include <gazebo/physics/physics.hh>
25 
26 #include "Actuators.pb.h"
27 #include "RollPitchYawrateThrust.pb.h"
28 #include "WindSpeed.pb.h"
29 
32 
33 namespace gazebo {
34 
41 
42 // Default values.
43 static constexpr bool kDefaultIsInputJoystick = false;
44 
45 // Constants.
46 static constexpr double kAirDensity = 1.18;
47 static constexpr double kGravity = 9.81;
48 static constexpr double kMinAirSpeedThresh = 0.1;
49 
50 class GazeboFwDynamicsPlugin : public ModelPlugin {
51  public:
54 
56  virtual ~GazeboFwDynamicsPlugin();
57 
58  protected:
61  void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
62 
64  void OnUpdate(const common::UpdateInfo&);
65 
69 
72  double NormalizedInputToAngle(const ControlSurface& surface, double input);
73 
74  private:
78 
83 
90  void CreatePubsAndSubs();
91 
93  std::string namespace_;
95  std::string actuators_sub_topic_;
99  std::string wind_speed_sub_topic_;
100 
102  transport::NodePtr node_handle_;
103 
105  gazebo::transport::SubscriberPtr actuators_sub_;
107  gazebo::transport::SubscriberPtr roll_pitch_yawrate_thrust_sub_;
109  gazebo::transport::SubscriberPtr wind_speed_sub_;
110 
112  physics::WorldPtr world_;
114  physics::ModelPtr model_;
116  physics::LinkPtr link_;
118  event::ConnectionPtr updateConnection_;
119 
121  ignition::math::Vector3d W_wind_speed_W_B_;
122 
125 
128 
136  double delta_flap_;
140  double throttle_;
141 
146  void ActuatorsCallback(GzActuatorsMsgPtr& actuators_msg);
147 
153  roll_pitch_yawrate_thrust_msg);
154 
158  void WindSpeedCallback(GzWindSpeedMsgPtr& wind_speed_msg);
159 };
160 
161 } // namespace gazebo
162 
163 #endif // ROTORS_GAZEBO_PLUGINS_FW_DYNAMICS_PLUGIN_H
void CreatePubsAndSubs()
Creates all required publishers and subscribers, incl. routing of messages to/from ROS if required...
const boost::shared_ptr< const gz_mav_msgs::WindSpeed > GzWindSpeedMsgPtr
physics::LinkPtr link_
Pointer to the link.
const boost::shared_ptr< const gz_mav_msgs::RollPitchYawrateThrust > GzRollPitchYawrateThrustMsgPtr
std::string actuators_sub_topic_
Topic name for actuator commands.
transport::NodePtr node_handle_
Handle for the Gazebo node.
static constexpr bool kDefaultIsInputJoystick
static constexpr double kAirDensity
void ActuatorsCallback(GzActuatorsMsgPtr &actuators_msg)
Processes the actuator commands.
double NormalizedInputToAngle(const ControlSurface &surface, double input)
Convert control surface input that is normalized in range [-1, 1] to a physical deflection angle valu...
double throttle_
Throttle input, in range from 0 to 1.
const boost::shared_ptr< const gz_sensor_msgs::Actuators > GzActuatorsMsgPtr
event::ConnectionPtr updateConnection_
Pointer to the update event connection.
void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Called when the plugin is first created, and after the world has been loaded. This function should no...
gazebo::transport::SubscriberPtr wind_speed_sub_
Subscriber ror receiving wind speed readings.
double delta_aileron_left_
Left aileron deflection [rad].
ignition::math::Vector3d W_wind_speed_W_B_
Most current wind speed reading [m/s].
void OnUpdate(const common::UpdateInfo &)
This gets called by the world update start event.
std::string roll_pitch_yawrate_thrust_sub_topic_
Topic name for roll_pitch_yawrate_thrust commands.
FWVehicleParameters vehicle_params_
The physical properties of the aircraft.
std::string namespace_
Transport namespace.
physics::ModelPtr model_
Pointer to the model.
void UpdateForcesAndMoments()
Calculates the forces and moments to be applied to the fixed-wing body.
gazebo::transport::SubscriberPtr actuators_sub_
Subscriber for receiving actuator commands.
double delta_rudder_
Rudder deflection [rad].
double delta_flap_
Flap deflection [rad].
void WindSpeedCallback(GzWindSpeedMsgPtr &wind_speed_msg)
Processes the wind speed readings.
void RollPitchYawrateThrustCallback(GzRollPitchYawrateThrustMsgPtr &roll_pitch_yawrate_thrust_msg)
Process the roll_pitch_yawrate_thrust commands.
bool is_input_joystick_
Are the input commands coming from a joystick (as opposed to a remote control via HIL interface...
physics::WorldPtr world_
Pointer to the world.
FWAerodynamicParameters aero_params_
The aerodynamic properties of the aircraft.
std::string wind_speed_sub_topic_
Topic name for wind speed readings.
gazebo::transport::SubscriberPtr roll_pitch_yawrate_thrust_sub_
Subscriber for receiving roll_pitch_yawrate_thrust commands.
static constexpr double kGravity
static constexpr double kMinAirSpeedThresh
double delta_elevator_
Elevator deflection [rad].
bool pubs_and_subs_created_
Flag that is set to true once CreatePubsAndSubs() is called, used to prevent CreatePubsAndSubs() from...
double delta_aileron_right_
Right aileron deflection [rad].


rotors_gazebo_plugins
Author(s): Fadri Furrer, Michael Burri, Mina Kamel, Janosch Nikolic, Markus Achtelik
autogenerated on Mon Feb 28 2022 23:39:03