34 #include <geometry_msgs/PoseStamped.h> 35 #include <geometry_msgs/TwistStamped.h> 62 node_handle_ = root_nh;
87 pose_command_ = *command;
88 if (!(pose_input_->connected())) *pose_input_ = &(pose_command_.pose);
91 ros::Time start_time = command->header.stamp;
93 if (!isRunning()) this->startRequest(start_time);
98 twist_command_ = *command;
99 if (!(twist_input_->connected())) *twist_input_ = &(twist_command_.twist);
100 twist_input_->start();
102 ros::Time start_time = command->header.stamp;
104 if (!isRunning()) this->startRequest(start_time);
110 twist_output_->start();
115 twist_output_->stop();
126 if (pose_input_->enabled()) {
128 double error_n, error_w;
130 output.linear.x = pid_.x.update(error_n, twist_->twist().linear.x, period);
131 output.linear.y = pid_.y.update(error_w, twist_->twist().linear.y, period);
141 if (twist_input_->enabled())
143 output.linear.x += twist_input_->getCommand().linear.x;
144 output.linear.y += twist_input_->getCommand().linear.y;
145 output.linear.z += twist_input_->getCommand().linear.z;
146 output.angular.x += twist_input_->getCommand().angular.x;
147 output.angular.y += twist_input_->getCommand().angular.y;
148 output.angular.z += twist_input_->getCommand().angular.z;
152 if (twist_limit_->enabled())
154 double linear_xy = sqrt(output.linear.x*output.linear.x + output.linear.y*output.linear.y);
155 double limit_linear_xy = std::max(twist_limit_->get()->linear.x, twist_limit_->get()->linear.y);
156 if (limit_linear_xy > 0.0 && linear_xy > limit_linear_xy) {
157 output.linear.x *= limit_linear_xy / linear_xy;
158 output.linear.y *= limit_linear_xy / linear_xy;
160 if (twist_limit_->get()->linear.z > 0.0 && fabs(output.linear.z) > twist_limit_->get()->linear.z) {
161 output.linear.z *= twist_limit_->get()->linear.z / fabs(output.linear.z);
163 double angular_xy = sqrt(output.angular.x*output.angular.x + output.angular.y*output.angular.y);
164 double limit_angular_xy = std::max(twist_limit_->get()->angular.x, twist_limit_->get()->angular.y);
165 if (limit_angular_xy > 0.0 && angular_xy > limit_angular_xy) {
166 output.angular.x *= limit_angular_xy / angular_xy;
167 output.angular.y *= limit_angular_xy / angular_xy;
169 if (twist_limit_->get()->angular.z > 0.0 && fabs(output.angular.z) > twist_limit_->get()->angular.z) {
170 output.angular.z *= twist_limit_->get()->angular.z / fabs(output.angular.z);
175 twist_output_->setCommand(output);
TwistCommandHandlePtr twist_output_
TwistCommandHandlePtr twist_input_
ros::NodeHandle node_handle_
boost::shared_ptr< HandleType > addOutput(const std::string &name)
bool init(QuadrotorInterface *interface, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
boost::shared_ptr< HandleType > addInput(const std::string &name)
geometry_msgs::PoseStamped pose_command_
geometry_msgs::TwistStamped twist_command_
void poseCommandCallback(const geometry_msgs::PoseStampedConstPtr &command)
PoseCommandHandlePtr pose_input_
void starting(const ros::Time &time)
ros::Subscriber twist_subscriber_
void stopping(const ros::Time &time)
void update(const ros::Time &time, const ros::Duration &period)
void twistCommandCallback(const geometry_msgs::TwistStampedConstPtr &command)
double getError(const PoseHandle &pose) const
double getError(const PoseHandle &pose) const
virtual PoseHandlePtr getPose()
ros::Subscriber pose_subscriber_
void getError(const PoseHandle &pose, double &x, double &y) const
TwistCommandHandlePtr twist_limit_
virtual TwistHandlePtr getTwist()