pid.h
Go to the documentation of this file.
1 /***************************************************************************/
36 #ifndef PID_H
37 #define PID_H
38 
39 #include "ros/ros.h"
40 #include <dynamic_reconfigure/server.h>
41 #include <iostream>
42 #include <pid/PidConfig.h>
43 #include <ros/time.h>
44 #include <std_msgs/Bool.h>
45 #include <std_msgs/Float64.h>
46 #include <std_msgs/Float64MultiArray.h>
47 #include <stdio.h>
48 #include <string>
49 
50 namespace pid_ns
51 {
52 class PidObject
53 {
54 public:
55  PidObject();
56 
57  // Primary output variable
58  double control_effort_ = 0; // output of pid controller
59 
60 private:
61  void doCalcs();
62  void getParams(double in, double& value, double& scale);
63  void pidEnableCallback(const std_msgs::Bool& pid_enable_msg);
64  void plantStateCallback(const std_msgs::Float64& state_msg);
65  void printParameters();
66  void reconfigureCallback(pid::PidConfig& config, uint32_t level);
67  void setpointCallback(const std_msgs::Float64& setpoint_msg);
68  bool validateParameters();
69 
70  // Primary PID controller input variables
71  double plant_state_; // current output of plant
72  bool pid_enabled_ = true; // PID is enabled to run
73  bool new_state_or_setpt_ = false; // Indicate that fresh calculations need to be run
74  double setpoint_ = 0; // desired output of plant
75 
78  bool first_reconfig_ = true;
79 
80  double error_integral_ = 0;
81  double proportional_ = 0; // proportional term of output
82  double integral_ = 0; // integral term of output
83  double derivative_ = 0; // derivative term of output
84 
85  // PID gains
86  double Kp_ = 0, Ki_ = 0, Kd_ = 0;
87 
88  // Parameters for error calc. with disconinuous input
89  bool angle_error_ = false;
90  double angle_wrap_ = 2.0 * 3.14159;
91 
92  // Cutoff frequency for the derivative calculation in Hz.
93  // Negative -> Has not been set by the user yet, so use a default.
94  double cutoff_frequency_ = -1;
95 
96  // Used in filter calculations. Default 1.0 corresponds to a cutoff frequency
97  // at
98  // 1/4 of the sample rate.
99  double c_ = 1.;
100 
101  // Used to check for tan(0)==>NaN in the filter calculation
102  double tan_filt_ = 1.;
103 
104  // Upper and lower saturation limits
105  double upper_limit_ = 1000, lower_limit_ = -1000;
106 
107  // Anti-windup term. Limits the absolute value of the integral term.
108  double windup_limit_ = 1000;
109 
110  // Initialize filter data with zeros
112 
113  // Topic and node names and message objects
116 
118  std::string pid_debug_pub_name_;
119  std_msgs::Float64 control_msg_, state_msg_;
120 
121  // Diagnostic objects
122  double min_loop_frequency_ = 1, max_loop_frequency_ = 1000;
123  int measurements_received_ = 0;
124 };
125 } // end pid namespace
126 
127 #endif
ros::Duration delta_t_
Definition: controller.h:64
std::string topic_from_controller_
Definition: controller.h:102
std::vector< double > filtered_error_deriv_
Definition: controller.h:98
ros::Publisher control_effort_pub_
Definition: controller.h:101
std::string pid_debug_pub_name_
Definition: pid.h:118
double max_loop_frequency_
Definition: controller.h:107
std::vector< double > error_deriv_
Definition: controller.h:98
double plant_state_
Definition: controller.h:57
double windup_limit_
Definition: controller.h:95
double min_loop_frequency_
Definition: controller.h:107
std::string topic_from_plant_
Definition: controller.h:102
std::string pid_enable_topic_
Definition: controller.h:102
std::string setpoint_topic_
Definition: controller.h:102
bool new_state_or_setpt_
Definition: controller.h:61
double upper_limit_
Definition: controller.h:92
double error_integral_
Definition: controller.h:67
bool validateParameters()
Definition: pid.cpp:126
std_msgs::Float64 state_msg_
Definition: controller.h:104
double derivative_
Definition: controller.h:70
ros::Time prev_time_
Definition: controller.h:63
void reconfigureCallback(pid::PidConfig &config, uint32_t level)
Definition: pid.cpp:157
double cutoff_frequency_
Definition: controller.h:81
double angle_wrap_
Definition: controller.h:77
ros::Publisher pid_debug_pub_
Definition: pid.h:115
double lower_limit_
Definition: controller.h:92
int measurements_received_
Definition: controller.h:108
double control_effort_
Definition: controller.h:58
void doCalcs()
Definition: pid.cpp:174
std::vector< double > filtered_error_
Definition: controller.h:98
void pidEnableCallback(const std_msgs::Bool &pid_enable_msg)
Definition: pid.cpp:96
void setpointCallback(const std_msgs::Float64 &setpoint_msg)
Definition: pid.cpp:82
std_msgs::Float64 control_msg_
Definition: controller.h:104
void printParameters()
Definition: pid.cpp:138
void getParams(double in, double &value, double &scale)
Definition: pid.cpp:101
double proportional_
Definition: controller.h:68
void plantStateCallback(const std_msgs::Float64 &state_msg)
Definition: pid.cpp:89
std::vector< double > error_
Definition: controller.h:98


pid
Author(s): Andy Zelenak , Paul Bouchier
autogenerated on Mon Apr 15 2019 02:41:32