Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef HECTOR_QUADROTOR_CONTROLLER_QUADROTOR_INTERFACE_H
00030 #define HECTOR_QUADROTOR_CONTROLLER_QUADROTOR_INTERFACE_H
00031
00032 #include <hardware_interface/internal/hardware_resource_manager.h>
00033
00034 #include <hector_quadrotor_controller/handles.h>
00035
00036 #include <map>
00037 #include <list>
00038
00039 namespace hector_quadrotor_controller {
00040
00041 using namespace hardware_interface;
00042
00043 class QuadrotorInterface : public HardwareInterface
00044 {
00045 public:
00046 QuadrotorInterface();
00047 virtual ~QuadrotorInterface();
00048
00049 virtual PoseHandlePtr getPose() { return PoseHandlePtr(); }
00050 virtual TwistHandlePtr getTwist() { return TwistHandlePtr(); }
00051 virtual AccelerationHandlePtr getAcceleration() { return AccelerationHandlePtr(); }
00052 virtual ImuHandlePtr getSensorImu() { return ImuHandlePtr(); }
00053 virtual MotorStatusHandlePtr getMotorStatus() { return MotorStatusHandlePtr(); }
00054
00055 virtual bool getMassAndInertia(double &mass, double inertia[3]) { return false; }
00056
00057 template <typename HandleType> boost::shared_ptr<HandleType> getHandle()
00058 {
00059 return boost::shared_ptr<HandleType>(new HandleType(this));
00060 }
00061
00062 template <typename HandleType> boost::shared_ptr<HandleType> addInput(const std::string& name)
00063 {
00064 boost::shared_ptr<HandleType> input = getInput<HandleType>(name);
00065 if (input) return input;
00066
00067
00068 input.reset(new HandleType(this, name));
00069 inputs_[name] = input;
00070
00071
00072 if (outputs_.count(name)) {
00073 boost::shared_ptr<HandleType> output = boost::dynamic_pointer_cast<HandleType>(outputs_.at(name));
00074 output->connectTo(*input);
00075 }
00076
00077 return input;
00078 }
00079
00080 template <typename HandleType> boost::shared_ptr<HandleType> addOutput(const std::string& name)
00081 {
00082 boost::shared_ptr<HandleType> output = getOutput<HandleType>(name);
00083 if (output) return output;
00084
00085
00086 output.reset(new HandleType(this, name));
00087 outputs_[name] = output;
00088 *output = output->ownData(new typename HandleType::ValueType());
00089
00090
00091 claim(name);
00092
00093
00094 if (inputs_.count(name)) {
00095 boost::shared_ptr<HandleType> input = boost::dynamic_pointer_cast<HandleType>(inputs_.at(name));
00096 output->connectTo(*input);
00097 }
00098
00099 return output;
00100 }
00101
00102 template <typename HandleType> boost::shared_ptr<HandleType> getOutput(const std::string& name) const
00103 {
00104 if (!outputs_.count(name)) return boost::shared_ptr<HandleType>();
00105 return boost::static_pointer_cast<HandleType>(outputs_.at(name));
00106 }
00107
00108 template <typename HandleType> boost::shared_ptr<HandleType> getInput(const std::string& name) const
00109 {
00110 if (!inputs_.count(name)) return boost::shared_ptr<HandleType>();
00111 return boost::static_pointer_cast<HandleType>(inputs_.at(name));
00112 }
00113
00114 template <typename HandleType> typename HandleType::ValueType const* getCommand(const std::string& name) const
00115 {
00116 boost::shared_ptr<HandleType> output = getOutput<HandleType>(name);
00117 if (!output || !output->connected()) return 0;
00118 return &(output->command());
00119 }
00120
00121 virtual const Pose *getPoseCommand() const;
00122 virtual const Twist *getTwistCommand() const;
00123 virtual const Wrench *getWrenchCommand() const;
00124 virtual const MotorCommand *getMotorCommand() const;
00125
00126 bool enabled(const CommandHandle *handle) const;
00127 bool start(const CommandHandle *handle);
00128 void stop(const CommandHandle *handle);
00129
00130 void disconnect(const CommandHandle *handle);
00131
00132 private:
00133
00134
00135
00136 std::map<std::string, CommandHandlePtr> inputs_;
00137 std::map<std::string, CommandHandlePtr> outputs_;
00138 std::map<std::string, const CommandHandle *> enabled_;
00139 };
00140
00141 }
00142
00143 #endif // HECTOR_QUADROTOR_CONTROLLER_QUADROTOR_INTERFACE_H