controller.h
Go to the documentation of this file.
00001 /***************************************************************************/
00036 #ifndef CONTROLLER_H
00037 #define CONTROLLER_H
00038 
00039 #include <dynamic_reconfigure/server.h>
00040 #include <iostream>
00041 #include "math.h"
00042 #include <pid/PidConfig.h>
00043 #include "ros/ros.h"
00044 #include <ros/time.h>
00045 #include <std_msgs/Float64.h>
00046 #include <std_msgs/Bool.h>
00047 #include <stdio.h>
00048 #include <string>
00049 
00050 namespace pid
00051 {
00052   // Primary PID controller input & output variables
00053   double plant_state;                 // current output of plant
00054   double control_effort;              // output of pid controller
00055   double setpoint = 0;                // desired output of plant
00056   bool pid_enabled = true;            // PID is enabled to run
00057 
00058   ros::Time prev_time;
00059   ros::Duration delta_t;
00060   bool first_reconfig = true;
00061 
00062   double error_integral = 0;
00063   double proportional = 0;         // proportional term of output
00064   double integral = 0;             // integral term of output
00065   double derivative = 0;           // derivative term of output
00066 
00067   // PID gains
00068   double Kp = 0, Ki = 0, Kd = 0;
00069 
00070   // Parameters for error calc. with disconinuous input
00071   bool angle_error = false;
00072   double angle_wrap = 2.0*3.14159;
00073 
00074   // Cutoff frequency for the derivative calculation in Hz.
00075   // Negative -> Has not been set by the user yet, so use a default.
00076   double cutoff_frequency = -1; 
00077 
00078   // Used in filter calculations. Default 1.0 corresponds to a cutoff frequency at
00079   // 1/4 of the sample rate.
00080   double c=1.;
00081 
00082   // Used to check for tan(0)==>NaN in the filter calculation
00083   double tan_filt = 1.;
00084 
00085   // Upper and lower saturation limits
00086   double upper_limit =  1000, lower_limit = -1000;
00087 
00088   // Anti-windup term. Limits the absolute value of the integral term.
00089   double windup_limit = 1000;
00090 
00091   // Initialize filter data with zeros
00092   std::vector<double> error(3, 0), filtered_error(3, 0), error_deriv(3, 0), filtered_error_deriv(3, 0);
00093 
00094   // Topic and node names and message objects
00095   ros::Publisher control_effort_pub;
00096 
00097   std::string topic_from_controller, topic_from_plant, setpoint_topic, pid_enable_topic, node_name = "pid_node";
00098 
00099   std_msgs::Float64 control_msg, state_msg;
00100 
00101   // Diagnostic objects
00102   double min_loop_frequency = 1, max_loop_frequency = 1000;
00103   int measurements_received = 0;
00104 
00105 } // end pid namespace
00106 
00107 #endif


pid
Author(s): Andy Zelenak , Paul Bouchier
autogenerated on Tue May 2 2017 02:49:51