servo_plugin.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2012, Johannes Meyer, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #ifndef SERVO_PLUGIN_H
30 #define SERVO_PLUGIN_H
31 
32 #include <gazebo/common/Plugin.hh>
33 #include <gazebo/common/Time.hh>
34 #if (GAZEBO_MAJOR_VERSION < 8)
35 #include <gazebo/math/Quaternion.hh>
36 #endif
37 
38 // ROS
39 #include <ros/ros.h>
41 #include <tf/transform_listener.h>
42 #include <geometry_msgs/QuaternionStamped.h>
43 #include <sensor_msgs/JointState.h>
44 
45 // Boost
46 #include <boost/thread.hpp>
47 #include <boost/bind.hpp>
48 
49 namespace gazebo
50 {
51 
52 class ServoPlugin : public ModelPlugin
53 {
54 
55 public:
56  ServoPlugin();
57  virtual ~ServoPlugin();
58 
59 protected:
60  virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf);
61  virtual void Init();
62  virtual void Reset();
63  virtual void Update();
64 
65 private:
66  void CalculateVelocities();
67  void publish_joint_states();
68 
69 private:
71  physics::WorldPtr world;
72 
73  // Simulation time of the last update
74  common::Time prevUpdateTime;
75 
77 
78  struct Servo {
79  std::string name;
80 #if (GAZEBO_MAJOR_VERSION >= 8)
81  ignition::math::Vector3d axis;
82 #else
83  math::Vector3 axis;
84 #endif
85  physics::JointPtr joint;
86  float velocity;
87  Servo() : velocity() {}
88  } servo[3];
89 
90  unsigned int countOfServos;
91  unsigned int orderOfAxes[3];
92  unsigned int rotationConv;
93  sensor_msgs::JointState joint_state;
94 
95  // parameters
96  std::string robotNamespace;
97  std::string topicName;
98  std::string jointStateName;
99  common::Time controlPeriod;
100 
105 
106  // ROS STUFF
111 
112  // Custom Callback Queue
114 // boost::thread* callback_queue_thread_;
115 // void QueueThread();
116 
117  // DiffDrive stuff
118  void cmdCallback(const geometry_msgs::QuaternionStamped::ConstPtr& cmd_msg);
119 
120  boost::mutex mutex;
121  geometry_msgs::QuaternionStamped::ConstPtr current_cmd;
122 #if (GAZEBO_MAJOR_VERSION >= 8)
123  ignition::math::Quaterniond rotation_;
124 #else
125  math::Quaternion rotation_;
126 #endif
127 
128  // Pointer to the update event connection
129  event::ConnectionPtr updateConnection;
130 };
131 
132 }
133 
134 #endif
std::string topicName
Definition: servo_plugin.h:97
common::Time prevUpdateTime
Definition: servo_plugin.h:74
unsigned int countOfServos
Definition: servo_plugin.h:90
event::ConnectionPtr updateConnection
Definition: servo_plugin.h:129
ros::Publisher jointStatePub_
Definition: servo_plugin.h:108
tf::TransformListener * transform_listener_
Definition: servo_plugin.h:110
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
math::Quaternion rotation_
Definition: servo_plugin.h:125
float proportionalControllerGain
Definition: servo_plugin.h:101
unsigned int orderOfAxes[3]
Definition: servo_plugin.h:91
ros::CallbackQueue queue_
Definition: servo_plugin.h:113
void cmdCallback(const geometry_msgs::QuaternionStamped::ConstPtr &cmd_msg)
ros::Subscriber sub_
Definition: servo_plugin.h:109
physics::WorldPtr world
The parent World.
Definition: servo_plugin.h:71
virtual void Reset()
unsigned int rotationConv
Definition: servo_plugin.h:92
common::Time controlPeriod
Definition: servo_plugin.h:99
std::string jointStateName
Definition: servo_plugin.h:98
geometry_msgs::QuaternionStamped::ConstPtr current_cmd
Definition: servo_plugin.h:121
std::string robotNamespace
Definition: servo_plugin.h:96
boost::mutex mutex
Definition: servo_plugin.h:120
physics::JointPtr joint
Definition: servo_plugin.h:85
float derivativeControllerGain
Definition: servo_plugin.h:102
ros::NodeHandle * rosnode_
Definition: servo_plugin.h:107
struct gazebo::ServoPlugin::Servo servo[3]
virtual void Update()
virtual void Init()
sensor_msgs::JointState joint_state
Definition: servo_plugin.h:93


hector_gazebo_plugins
Author(s): Stefan Kohlbrecher , Johannes Meyer
autogenerated on Fri Feb 5 2021 03:48:30