29 #ifndef HECTOR_QUADROTOR_INTERFACE_LIMITERS_H 30 #define HECTOR_QUADROTOR_INTERFACE_LIMITERS_H 34 #include <geometry_msgs/Wrench.h> 35 #include <geometry_msgs/Vector3.h> 36 #include <geometry_msgs/Twist.h> 37 #include <geometry_msgs/Point.h> 38 #include <hector_uav_msgs/AttitudeCommand.h> 39 #include <hector_uav_msgs/ThrustCommand.h> 40 #include <hector_uav_msgs/YawrateCommand.h> 53 : min_(-
std::numeric_limits<T>::infinity())
54 , max_(
std::numeric_limits<T>::infinity())
59 std::string prefix = !field.empty() ? field +
"/" :
"";
61 nh.
param<T>(prefix +
"max", max_, std::numeric_limits<T>::infinity());
62 nh.
param<T>(prefix +
"min", min_, -max_);
63 ROS_INFO_STREAM(
"Limits " << nh.
getNamespace() +
"/" + field <<
" initialized " << field <<
" with min " << min_ <<
" and max " << max_);
69 return std::max(min_, std::min(max_, value));
86 x.init(field_nh,
"x");
87 y.init(field_nh,
"y");
88 z.init(field_nh,
"z");
94 output.x = x.limit(input.x);
95 output.y = y.limit(input.y);
96 output.z = z.limit(input.z);
114 x.init(field_nh,
"x");
115 y.init(field_nh,
"y");
116 z.init(field_nh,
"z");
117 field_nh.
param(
"max", absolute_maximum, std::numeric_limits<double>::infinity());
118 field_nh.
param(
"max_xy", absolute_maximum_xy, std::numeric_limits<double>::infinity());
124 output.x = x.limit(input.x);
125 output.y = y.limit(input.y);
126 output.z = z.limit(input.z);
128 double absolute_value_xy =
sqrt(output.x * output.x + output.y * output.y);
129 if (absolute_value_xy > absolute_maximum_xy) {
130 output.x *= absolute_maximum_xy / absolute_value_xy;
131 output.y *= absolute_maximum_xy / absolute_value_xy;
132 output.z *= absolute_maximum_xy / absolute_value_xy;
135 double absolute_value =
sqrt(output.x * output.x + output.y * output.y + output.z * output.z);
136 if (absolute_value > absolute_maximum) {
137 output.x *= absolute_maximum / absolute_value;
138 output.y *= absolute_maximum / absolute_value;
139 output.z *= absolute_maximum / absolute_value;
161 linear.init(field_nh,
"linear");
162 angular.init(field_nh,
"angular");
168 output.linear = linear.limit(input.linear);
169 output.angular = angular.limit(input.angular);
187 force.init(field_nh,
"force");
188 torque.init(field_nh,
"torque");
194 output.force = force.limit(input.force);
195 output.torque = torque.limit(input.torque);
213 roll.init(field_nh,
"roll");
214 pitch.init(field_nh,
"pitch");
215 field_nh.
param(
"max_roll_pitch", absolute_max, std::numeric_limits<double>::infinity());
218 AttitudeCommand
limit(
const AttitudeCommand &input)
220 AttitudeCommand output;
221 output.header = input.header;
222 output.roll = roll.limit(input.roll);
223 output.pitch = pitch.limit(input.pitch);
225 double absolute_value =
sqrt(output.roll * output.roll + output.pitch * output.pitch);
226 if (absolute_value > absolute_max) {
227 output.roll *= absolute_max / absolute_value;
228 output.pitch *= absolute_max / absolute_value;
249 turnrate.init(nh, field);
252 YawrateCommand
limit(
const YawrateCommand &input)
254 YawrateCommand output;
255 output.header = input.header;
256 output.turnrate = turnrate.limit(input.turnrate);
273 thrust.init(nh, field);
276 ThrustCommand
limit(
const ThrustCommand &input)
278 ThrustCommand output;
279 output.header = input.header;
280 output.thrust = thrust.limit(input.thrust);
294 #endif // HECTOR_QUADROTOR_INTERFACE_LIMITERS_H void init(const ros::NodeHandle &nh, const std::string &field=std::string())
Twist operator()(const Twist &input)
T operator()(const T &value)
ThrustCommand operator()(const ThrustCommand &input)
YawrateCommand operator()(const YawrateCommand &input)
double absolute_maximum_xy
void init(const ros::NodeHandle &nh, const std::string &field=std::string())
AttitudeCommand operator()(const AttitudeCommand &input)
Wrench limit(const Wrench &input)
YawrateCommand limit(const YawrateCommand &input)
void init(const ros::NodeHandle &nh, const std::string &field=std::string())
Point operator()(const Point &input)
void init(const ros::NodeHandle &nh, const std::string &field=std::string())
void init(const ros::NodeHandle &nh, const std::string &field=std::string())
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
const std::string & getNamespace() const
void init(const ros::NodeHandle &nh, const std::string &field=std::string())
Point limit(const Point &input)
Twist limit(const Twist &input)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
FieldLimiter< double > thrust
void init(const ros::NodeHandle &nh, const std::string &field=std::string())
FieldLimiter< double > turnrate
AttitudeCommand limit(const AttitudeCommand &input)
#define ROS_INFO_STREAM(args)
Vector3 limit(const Vector3 &input)
Wrench operator()(const Wrench &input)
bool hasParam(const std::string &key) const
Vector3 operator()(const Vector3 &input)
ThrustCommand limit(const ThrustCommand &input)
FieldLimiter< double > roll
void init(const ros::NodeHandle &nh, const std::string &field=std::string())