quadrotor_interface.h
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2013, 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 HECTOR_QUADROTOR_CONTROLLER_QUADROTOR_INTERFACE_H
30 #define HECTOR_QUADROTOR_CONTROLLER_QUADROTOR_INTERFACE_H
31 
33 
35 
36 #include <map>
37 #include <list>
38 
40 
41 using namespace hardware_interface;
42 
44 {
45 public:
47  virtual ~QuadrotorInterface();
48 
49  virtual PoseHandlePtr getPose() { return PoseHandlePtr(); }
50  virtual TwistHandlePtr getTwist() { return TwistHandlePtr(); }
52  virtual ImuHandlePtr getSensorImu() { return ImuHandlePtr(); }
54 
55  virtual bool getMassAndInertia(double &mass, double inertia[3]) { return false; }
56 
57  template <typename HandleType> boost::shared_ptr<HandleType> getHandle()
58  {
59  return boost::shared_ptr<HandleType>(new HandleType(this));
60  }
61 
62  template <typename HandleType> boost::shared_ptr<HandleType> addInput(const std::string& name)
63  {
64  boost::shared_ptr<HandleType> input = getInput<HandleType>(name);
65  if (input) return input;
66 
67  // create new input handle
68  input.reset(new HandleType(this, name));
69  inputs_[name] = input;
70 
71  // connect to output of same name
72  if (outputs_.count(name)) {
73  boost::shared_ptr<HandleType> output = boost::dynamic_pointer_cast<HandleType>(outputs_.at(name));
74  output->connectTo(*input);
75  }
76 
77  return input;
78  }
79 
80  template <typename HandleType> boost::shared_ptr<HandleType> addOutput(const std::string& name)
81  {
82  boost::shared_ptr<HandleType> output = getOutput<HandleType>(name);
83  if (output) return output;
84 
85  // create new output handle
86  output.reset(new HandleType(this, name));
87  outputs_[name] = output;
88  *output = output->ownData(new typename HandleType::ValueType());
89 
90  //claim resource
91  claim(name);
92 
93  // connect to output of same name
94  if (inputs_.count(name)) {
95  boost::shared_ptr<HandleType> input = boost::dynamic_pointer_cast<HandleType>(inputs_.at(name));
96  output->connectTo(*input);
97  }
98 
99  return output;
100  }
101 
102  template <typename HandleType> boost::shared_ptr<HandleType> getOutput(const std::string& name) const
103  {
104  if (!outputs_.count(name)) return boost::shared_ptr<HandleType>();
105  return boost::static_pointer_cast<HandleType>(outputs_.at(name));
106  }
107 
108  template <typename HandleType> boost::shared_ptr<HandleType> getInput(const std::string& name) const
109  {
110  if (!inputs_.count(name)) return boost::shared_ptr<HandleType>();
111  return boost::static_pointer_cast<HandleType>(inputs_.at(name));
112  }
113 
114  template <typename HandleType> typename HandleType::ValueType const* getCommand(const std::string& name) const
115  {
116  boost::shared_ptr<HandleType> output = getOutput<HandleType>(name);
117  if (!output || !output->connected()) return 0;
118  return &(output->command());
119  }
120 
121  virtual const Pose *getPoseCommand() const;
122  virtual const Twist *getTwistCommand() const;
123  virtual const Wrench *getWrenchCommand() const;
124  virtual const MotorCommand *getMotorCommand() const;
125 
126  bool enabled(const CommandHandle *handle) const;
127  bool start(const CommandHandle *handle);
128  void stop(const CommandHandle *handle);
129 
130  void disconnect(const CommandHandle *handle);
131 
132 private:
133 // typedef std::list< CommandHandlePtr > HandleList;
134 // std::map<const std::type_info *, HandleList> inputs_;
135 // std::map<const std::type_info *, HandleList> outputs_;
136  std::map<std::string, CommandHandlePtr> inputs_;
137  std::map<std::string, CommandHandlePtr> outputs_;
138  std::map<std::string, const CommandHandle *> enabled_;
139 };
140 
141 } // namespace hector_quadrotor_controller
142 
143 #endif // HECTOR_QUADROTOR_CONTROLLER_QUADROTOR_INTERFACE_H
virtual bool getMassAndInertia(double &mass, double inertia[3])
boost::shared_ptr< HandleType > addOutput(const std::string &name)
ROSCPP_DECL void start()
boost::shared_ptr< TwistHandle > TwistHandlePtr
Definition: handles.h:119
HandleType::ValueType const * getCommand(const std::string &name) const
std::map< std::string, CommandHandlePtr > outputs_
boost::shared_ptr< HandleType > addInput(const std::string &name)
std::map< std::string, const CommandHandle * > enabled_
virtual AccelerationHandlePtr getAcceleration()
boost::shared_ptr< ImuHandle > ImuHandlePtr
Definition: handles.h:155
boost::shared_ptr< HandleType > getHandle()
std::map< std::string, CommandHandlePtr > inputs_
boost::shared_ptr< HandleType > getInput(const std::string &name) const
boost::shared_ptr< HandleType > getOutput(const std::string &name) const
boost::shared_ptr< AccelerationHandle > AccelerationHandlePtr
Definition: handles.h:131
boost::shared_ptr< MotorStatusHandle > MotorStatusHandlePtr
Definition: handles.h:168
boost::shared_ptr< PoseHandle > PoseHandlePtr
Definition: handles.h:105


hector_quadrotor_controller
Author(s): Johannes Meyer
autogenerated on Sun Jul 10 2016 04:30:48