29 #ifndef HECTOR_QUADROTOR_CONTROLLER_HANDLES_H 30 #define HECTOR_QUADROTOR_CONTROLLER_HANDLES_H 32 #include <geometry_msgs/Pose.h> 33 #include <geometry_msgs/Twist.h> 34 #include <geometry_msgs/Wrench.h> 35 #include <sensor_msgs/Imu.h> 36 #include <hector_uav_msgs/MotorStatus.h> 37 #include <hector_uav_msgs/MotorCommand.h> 38 #include <hector_uav_msgs/AttitudeCommand.h> 39 #include <hector_uav_msgs/YawrateCommand.h> 40 #include <hector_uav_msgs/ThrustCommand.h> 46 using geometry_msgs::Pose;
47 using geometry_msgs::Point;
48 using geometry_msgs::Quaternion;
49 using geometry_msgs::Twist;
50 using geometry_msgs::Vector3;
51 using geometry_msgs::Wrench;
52 using sensor_msgs::Imu;
53 using hector_uav_msgs::MotorStatus;
54 using hector_uav_msgs::MotorCommand;
55 using hector_uav_msgs::AttitudeCommand;
56 using hector_uav_msgs::YawrateCommand;
57 using hector_uav_msgs::ThrustCommand;
59 template <
class Derived,
typename T>
77 Derived&
operator=(
const ValueType *source) {
value_ = source;
return static_cast<Derived &
>(*this); }
78 const ValueType *
get()
const {
return value_; }
91 using Base::operator=;
98 const ValueType&
pose()
const {
return *
get(); }
100 void getEulerRPY(
double &roll,
double &pitch,
double &yaw)
const;
101 double getYaw()
const;
102 Vector3 toBody(
const Vector3& nav)
const;
103 Vector3 fromBody(
const Vector3& nav)
const;
110 using Base::operator=;
117 const ValueType&
twist()
const {
return *
get(); }
124 using Base::operator=;
147 using Base::operator=;
153 const ValueType&
imu()
const {
return *
get(); }
160 using Base::operator=;
182 void *
get()
const {
return 0; }
189 template <
typename T> T*
ownData(T* data) { my_.reset(data);
return data; }
191 template <
typename Derived>
bool connectFrom(
const Derived& output) {
192 Derived *me =
dynamic_cast<Derived *
>(
this);
193 if (!me)
return false;
194 ROS_DEBUG(
"Connected output port '%s (%p)' to input port '%s (%p)'", output.getName().c_str(), &output, me->getName().c_str(), me);
198 template <
typename Derived>
bool connectTo(Derived& input)
const {
199 const Derived *me =
dynamic_cast<const Derived *
>(
this);
200 if (!me)
return false;
201 ROS_DEBUG(
"Connected output port '%s (%p)' to input port '%s (%p)'", me->getName().c_str(), me, input.getName().c_str(), &input);
213 bool wasNew()
const {
bool old = new_value_; new_value_ =
false;
return old; }
219 static typename Derived::ValueType *
get(
void *) {
return 0; }
223 template <
class Derived,
typename T,
class Parent = CommandHandle>
236 virtual void reset() { command_ = 0; Parent::reset(); }
238 using Parent::operator=;
239 Derived&
operator=(ValueType *source) { command_ = source;
return static_cast<Derived &
>(*this); }
244 const ValueType&
getCommand()
const { this->new_value_ =
false;
return *
get(); }
245 void setCommand(
const ValueType& command) { this->new_value_ =
true; *
get() = command; }
246 bool getCommand(ValueType& command)
const { command = *
get();
return this->wasNew(); }
250 command = getCommand();
261 using Base::operator=;
273 using Base::operator=;
281 using Base::getCommand;
288 using Base::setCommand;
291 this->new_value_ =
true;
299 getCommand(command.position.x, command.position.y);
303 void getError(
const PoseHandle &pose,
double &x,
double &y)
const;
309 static Point *
get(Pose *pose) {
return &(pose->position); }
316 using Base::operator=;
327 command.position.z = getCommand();
331 double getError(
const PoseHandle &pose)
const;
337 static double *
get(Pose *pose) {
return &(pose->position.z); }
344 using Base::operator=;
352 using Base::getCommand;
353 double getCommand()
const;
355 using Base::setCommand;
356 void setCommand(
double command);
359 bool update(Pose& command)
const;
361 double getError(
const PoseHandle &pose)
const;
370 static Quaternion *
get(Pose *pose) {
return &(pose->orientation); }
378 using Base::operator=;
390 using Base::operator=;
398 using Base::getCommand;
405 using Base::setCommand;
415 getCommand(command.linear.x, command.linear.y);
423 static Vector3 *
get(Twist *twist) {
return &(twist->linear); }
430 using Base::operator=;
441 command.linear.z = *
get();
449 static double *
get(Twist *twist) {
return &(twist->linear.z); }
456 using Base::operator=;
467 command.linear.z = *
get();
475 static double *
get(Twist *twist) {
return &(twist->angular.z); }
482 using Base::operator=;
493 using Base::operator=;
504 using Base::operator=;
515 using Base::operator=;
526 using Base::operator=;
536 #endif // HECTOR_QUADROTOR_CONTROLLER_HANDLES_H void setCommand(double x, double y)
virtual ~MotorCommandHandle()
AccelerationHandle(QuadrotorInterface *interface, const Vector3 *acceleration)
virtual const std::string & getName() const
virtual ~AccelerationHandle()
boost::shared_ptr< HeightCommandHandle > HeightCommandHandlePtr
virtual bool getCommand(double &x, double &y) const
const ValueType & operator*() const
virtual ~HorizontalPositionCommandHandle()
QuadrotorInterface * interface_
Handle_(QuadrotorInterface *interface, const std::string &name, const std::string &field=std::string())
HorizontalVelocityCommandHandle(QuadrotorInterface *interface, const std::string &name)
StateHandle(QuadrotorInterface *interface, const Pose *pose, const Twist *twist)
VerticalVelocityCommandHandle(QuadrotorInterface *interface, const std::string &name)
virtual ~CommandHandle_()
bool update(Twist &command) const
boost::shared_ptr< TwistHandle > TwistHandlePtr
PoseHandle(QuadrotorInterface *interface, const Pose *pose)
virtual ~AttitudeCommandHandle()
virtual ~HorizontalVelocityCommandHandle()
virtual ~TwistCommandHandle()
AngularVelocityCommandHandle(double *command)
HorizontalPositionCommandHandle(Point *command)
boost::shared_ptr< YawrateCommandHandle > YawrateCommandHandlePtr
const ValueType & imu() const
VerticalVelocityCommandHandle(double *command)
AngularVelocityCommandHandle(const TwistCommandHandle &other)
const ValueType & pose() const
WrenchCommandHandle(QuadrotorInterface *interface, const std::string &name)
HeightCommandHandle(const PoseCommandHandle &other)
boost::shared_ptr< ThrustCommandHandle > ThrustCommandHandlePtr
HeadingCommandHandle(Quaternion *command)
Handle_(QuadrotorInterface *interface, const ValueType *source, const std::string &name, const std::string &field=std::string())
const ValueType & twist() const
boost::shared_ptr< CommandHandle > CommandHandlePtr
CommandHandle(QuadrotorInterface *interface, const std::string &name, const std::string &field)
boost::shared_ptr< AngularVelocityCommandHandle > AngularVelocityCommandHandlePtr
HorizontalVelocityCommandHandle(const TwistCommandHandle &other)
bool update(Twist &command) const
HeadingCommandHandle(const PoseCommandHandle &other)
MotorCommandHandle(QuadrotorInterface *interface, const std::string &name)
VerticalVelocityCommandHandle()
HeightCommandHandle(QuadrotorInterface *interface, const std::string &name)
PoseHandle(QuadrotorInterface *interface)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
HorizontalPositionCommandHandle()
TwistHandle(QuadrotorInterface *interface)
static Derived::ValueType * get(void *)
virtual bool connected() const
CommandHandle_< Derived, T, Parent > Base
HeadingCommandHandle(QuadrotorInterface *interface, const std::string &name)
virtual const std::string & getName() const
virtual void setCommand(double x, double y)
HorizontalPositionCommandHandle(QuadrotorInterface *interface, const std::string &name)
boost::shared_ptr< ImuHandle > ImuHandlePtr
VerticalVelocityCommandHandle(const TwistCommandHandle &other)
void setCommand(const ValueType &command)
ROSLIB_DECL std::string command(const std::string &cmd)
const ValueType & getCommand() const
ImuHandle(QuadrotorInterface *interface, const Imu *imu)
virtual bool connected() const
bool update(ValueType &command) const
bool connectTo(Derived &input) const
Handle_(const std::string &name, const std::string &field=std::string())
Derived & operator=(ValueType *source)
HorizontalPositionCommandHandle(const PoseCommandHandle &other)
virtual const std::string & getField() const
TwistCommandHandle(Twist *command)
bool update(Pose &command) const
PoseCommandHandle(Pose *command)
HorizontalVelocityCommandHandle(Vector3 *command)
TwistHandle(QuadrotorInterface *interface, const Twist *twist)
HorizontalVelocityCommandHandle()
PoseCommandHandle(QuadrotorInterface *interface, const std::string &name, const std::string &field=std::string())
bool update(Pose &command) const
virtual ~HeightCommandHandle()
virtual ~HeadingCommandHandle()
bool getCommand(ValueType &command) const
bool connectFrom(const Derived &output)
virtual ~VerticalVelocityCommandHandle()
Derived & operator=(const ValueType *source)
CommandHandle_(QuadrotorInterface *interface, const std::string &name, const std::string &field=std::string())
boost::shared_ptr< HeadingCommandHandle > HeadingCommandHandlePtr
QuadrotorInterface * interface_
virtual ~AngularVelocityCommandHandle()
virtual ~YawrateCommandHandle()
boost::shared_ptr< HorizontalVelocityCommandHandle > HorizontalVelocityCommandHandlePtr
const ValueType & acceleration() const
MotorStatusHandle(QuadrotorInterface *interface, const MotorStatus *motor_status)
const ValueType & motorStatus() const
virtual bool connected() const
boost::shared_ptr< HorizontalPositionCommandHandle > HorizontalPositionCommandHandlePtr
virtual ~ThrustCommandHandle()
ThrustCommandHandle(QuadrotorInterface *interface, const std::string &name)
TwistCommandHandle(QuadrotorInterface *interface, const std::string &name, const std::string &field=std::string())
virtual const std::string & getField() const
AngularVelocityCommandHandle()
AngularVelocityCommandHandle(QuadrotorInterface *interface, const std::string &name)
boost::shared_ptr< AccelerationHandle > AccelerationHandlePtr
boost::shared_ptr< PoseCommandHandle > PoseCommandHandlePtr
boost::shared_ptr< void > my_
virtual ~MotorStatusHandle()
bool getCommand(double &x, double &y) const
boost::shared_ptr< MotorStatusHandle > MotorStatusHandlePtr
HeightCommandHandle(double *command)
boost::shared_ptr< PoseHandle > PoseHandlePtr
boost::shared_ptr< WrenchCommandHandle > WrenchCommandHandlePtr
virtual ~PoseCommandHandle()
ValueType & operator*() const
Handle_< Derived, T > Base
bool update(Twist &command) const
boost::shared_ptr< MotorCommandHandle > MotorCommandHandlePtr
AttitudeCommandHandle(QuadrotorInterface *interface, const std::string &name)
boost::shared_ptr< AttitudeCommandHandle > AttitudeCommandHandlePtr
YawrateCommandHandle(QuadrotorInterface *interface, const std::string &name)
boost::shared_ptr< VerticalVelocityCommandHandle > VerticalVelocityCommandHandlePtr
CommandHandle_(const Parent &other)
virtual ~WrenchCommandHandle()
boost::shared_ptr< TwistCommandHandle > TwistCommandHandlePtr