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_PLUGINS_CESSNAPLUGIN_HH_
19 #define GAZEBO_PLUGINS_CESSNAPLUGIN_HH_
20 
21 #include <array>
22 #include <mutex>
23 #include <string>
24 #include <sdf/sdf.hh>
25 #include <ignition/transport/Node.hh>
26 #include <gazebo/common/PID.hh>
27 #include <gazebo/common/Plugin.hh>
29 #include <gazebo/msgs/msgs.hh>
32 
33 namespace gazebo
34 {
65  {
67  public: CessnaPlugin();
68 
70  public: ~CessnaPlugin();
71 
72  // Documentation Inherited.
73  public: virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
74 
82  private: bool FindJoint(const std::string &_sdfParam,
83  sdf::ElementPtr _sdf, physics::JointPtr &_joint);
84 
87  private: void Update(const common::UpdateInfo &_info);
88 
92  private: void OnControl(ConstCessnaPtr &_msg);
93 
96  private: void UpdatePIDs(double _dt);
97 
99  private: void PublishState();
100 
102  private: static const unsigned int kLeftAileron = 0;
103  private: static const unsigned int kLeftFlap = 1;
104  private: static const unsigned int kRightAileron = 2;
105  private: static const unsigned int kRightFlap = 3;
106  private: static const unsigned int kElevators = 4;
107  private: static const unsigned int kRudder = 5;
108  private: static const unsigned int kPropeller = 6;
109 
111  private: event::ConnectionPtr updateConnection;
112 
114  private: transport::NodePtr node;
115 
117  private: transport::SubscriberPtr controlSub;
118 
120  private: transport::PublisherPtr statePub;
121 
123  private: physics::ModelPtr model;
124 
126  private: std::array<physics::JointPtr, 7> joints;
127 
129  private: int32_t propellerMaxRpm = 2500;
130 
132  private: std::array<float, 7> cmds;
133 
135  private: common::PID propellerPID;
136 
138  private: std::array<common::PID, 6> controlSurfacesPID;
139 
141  private: gazebo::common::Time lastControllerUpdateTime;
142 
144  private: std::mutex mutex;
145 
146  // Place ignition::transport objects at the end of this file to
147  // guarantee they are destructed first.
148 
150  private: ignition::transport::Node nodeIgn;
151 
153  private: ignition::transport::Node::Publisher statePubIgn;
154  };
155 }
156 #endif
Allow moving the control surfaces of a Cessna C-172 plane.
Definition: CessnaPlugin.hh:64
Forward declarations for transport.
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:117
Information for use in an update event.
Definition: UpdateInfo.hh:30
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
default namespace for gazebo
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:93
A plugin with access to physics::Model.
Definition: Plugin.hh:260
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:58
Generic PID controller class.
Definition: PID.hh:36
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44