CessnaPlugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Open Source Robotics Foundation
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 
18 #ifndef _GAZEBO_CESSNA_PLUGIN_HH_
19 #define _GAZEBO_CESSNA_PLUGIN_HH_
20 
21 #include <array>
22 #include <mutex>
23 #include <string>
24 #include <sdf/sdf.hh>
25 #include <gazebo/common/PID.hh>
26 #include <gazebo/common/Plugin.hh>
28 #include <gazebo/msgs/msgs.hh>
31 
32 namespace gazebo
33 {
64  {
66  public: CessnaPlugin();
67 
69  public: ~CessnaPlugin();
70 
71  // Documentation Inherited.
72  public: virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
73 
81  private: bool FindJoint(const std::string &_sdfParam,
82  sdf::ElementPtr _sdf, physics::JointPtr &_joint);
83 
86  private: void Update(const common::UpdateInfo &_info);
87 
91  private: void OnControl(ConstCessnaPtr &_msg);
92 
95  private: void UpdatePIDs(double _dt);
96 
98  private: void PublishState();
99 
101  private: static const unsigned int kLeftAileron = 0;
102  private: static const unsigned int kLeftFlap = 1;
103  private: static const unsigned int kRightAileron = 2;
104  private: static const unsigned int kRightFlap = 3;
105  private: static const unsigned int kElevators = 4;
106  private: static const unsigned int kRudder = 5;
107  private: static const unsigned int kPropeller = 6;
108 
110  private: event::ConnectionPtr updateConnection;
111 
113  private: transport::NodePtr node;
114 
116  private: transport::SubscriberPtr controlSub;
117 
119  private: transport::PublisherPtr statePub;
120 
122  private: physics::ModelPtr model;
123 
125  private: std::array<physics::JointPtr, 7> joints;
126 
128  private: int32_t propellerMaxRpm = 2500;
129 
131  private: std::array<float, 7>cmds;
132 
134  private: common::PID propellerPID;
135 
137  private: std::array<common::PID, 6> controlSurfacesPID;
138 
140  private: gazebo::common::Time lastControllerUpdateTime;
141 
143  private: std::mutex mutex;
144  };
145 }
146 #endif
Allow moving the control surfaces of a Cessna C-172 plane.
Definition: CessnaPlugin.hh:63
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:147
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:84
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Forward declarations for transport.
Information for use in an update event.
Definition: UpdateInfo.hh:30
default namespace for gazebo
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:100
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
A plugin with access to physics::Model.
Definition: Plugin.hh:245
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:66
Generic PID controller class.
Definition: PID.hh:36
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:39