GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2011,2013 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef GR_BLOCKS_CONTROL_LOOP 00024 #define GR_BLOCKS_CONTROL_LOOP 00025 00026 #include <blocks/api.h> 00027 00028 namespace gr { 00029 namespace blocks { 00030 00031 class BLOCKS_API control_loop 00032 { 00033 protected: 00034 float d_phase, d_freq; 00035 float d_max_freq, d_min_freq; 00036 float d_damping, d_loop_bw; 00037 float d_alpha, d_beta; 00038 00039 public: 00040 control_loop(float loop_bw, float max_freq, float min_freq); 00041 virtual ~control_loop(); 00042 00043 /*! \brief update the system gains from the loop bandwidth and damping factor 00044 * 00045 * This function updates the system gains based on the loop 00046 * bandwidth and damping factor of the system. These two 00047 * factors can be set separately through their own set 00048 * functions. 00049 */ 00050 void update_gains(); 00051 00052 /*! \brief Advance the control loop based on the current gain 00053 * settings and the inputted error signal. 00054 */ 00055 void advance_loop(float error); 00056 00057 /*! \brief Keep the phase between -2pi and 2pi 00058 * 00059 * This function keeps the phase between -2pi and 2pi. If the 00060 * phase is greater than 2pi by d, it wraps around to be -2pi+d; 00061 * similarly if it is less than -2pi by d, it wraps around to 00062 * 2pi-d. 00063 * 00064 * This function should be called after advance_loop to keep the 00065 * phase in a good operating region. It is set as a separate 00066 * method in case another way is desired as this is fairly 00067 * heavy-handed. 00068 */ 00069 void phase_wrap(); 00070 00071 /*! \brief Keep the frequency between d_min_freq and d_max_freq 00072 * 00073 * This function keeps the frequency between d_min_freq and 00074 * d_max_freq. If the frequency is greater than d_max_freq, it 00075 * is set to d_max_freq. If the frequency is less than 00076 * d_min_freq, it is set to d_min_freq. 00077 * 00078 * This function should be called after advance_loop to keep the 00079 * frequency in the specified region. It is set as a separate 00080 * method in case another way is desired as this is fairly 00081 * heavy-handed. 00082 */ 00083 void frequency_limit(); 00084 00085 /******************************************************************* 00086 * SET FUNCTIONS 00087 *******************************************************************/ 00088 00089 /*! 00090 * \brief Set the loop bandwidth 00091 * 00092 * Set the loop filter's bandwidth to \p bw. This should be 00093 * between 2*pi/200 and 2*pi/100 (in rads/samp). It must also be 00094 * a positive number. 00095 * 00096 * When a new damping factor is set, the gains, alpha and beta, 00097 * of the loop are recalculated by a call to update_gains(). 00098 * 00099 * \param bw (float) new bandwidth 00100 */ 00101 void set_loop_bandwidth(float bw); 00102 00103 /*! 00104 * \brief Set the loop damping factor 00105 * 00106 * Set the loop filter's damping factor to \p df. The damping 00107 * factor should be sqrt(2)/2.0 for critically damped systems. 00108 * Set it to anything else only if you know what you are 00109 * doing. It must be a number between 0 and 1. 00110 * 00111 * When a new damping factor is set, the gains, alpha and beta, 00112 * of the loop are recalculated by a call to update_gains(). 00113 * 00114 * \param df (float) new damping factor 00115 */ 00116 void set_damping_factor(float df); 00117 00118 /*! 00119 * \brief Set the loop gain alpha 00120 * 00121 * Set's the loop filter's alpha gain parameter. 00122 * 00123 * This value should really only be set by adjusting the loop 00124 * bandwidth and damping factor. 00125 * 00126 * \param alpha (float) new alpha gain 00127 * 00128 */ 00129 void set_alpha(float alpha); 00130 00131 /*! 00132 * \brief Set the loop gain beta 00133 * 00134 * Set's the loop filter's beta gain parameter. 00135 * 00136 * This value should really only be set by adjusting the loop 00137 * bandwidth and damping factor. 00138 * 00139 * \param beta (float) new beta gain 00140 */ 00141 void set_beta(float beta); 00142 00143 /*! 00144 * \brief Set the control loop's frequency. 00145 * 00146 * Set's the control loop's frequency. While this is normally 00147 * updated by the inner loop of the algorithm, it could be 00148 * useful to manually initialize, set, or reset this under 00149 * certain circumstances. 00150 * 00151 * \param freq (float) new frequency 00152 */ 00153 void set_frequency(float freq); 00154 00155 /*! 00156 * \brief Set the control loop's phase. 00157 * 00158 * Set's the control loop's phase. While this is normally 00159 * updated by the inner loop of the algorithm, it could be 00160 * useful to manually initialize, set, or reset this under 00161 * certain circumstances. 00162 * 00163 * \param phase (float) new phase 00164 */ 00165 void set_phase(float phase); 00166 00167 /*! 00168 * \brief Set the control loop's maximum frequency. 00169 * 00170 * Set the maximum frequency the control loop can track. 00171 * 00172 * \param freq (float) new max frequency 00173 */ 00174 void set_max_freq(float freq); 00175 00176 /*! 00177 * \brief Set the control loop's minimum frequency. 00178 * 00179 * Set the minimum frequency the control loop can track. 00180 * 00181 * \param freq (float) new min frequency 00182 */ 00183 void set_min_freq(float freq); 00184 00185 /******************************************************************* 00186 * GET FUNCTIONS 00187 *******************************************************************/ 00188 00189 /*! 00190 * \brief Returns the loop bandwidth 00191 */ 00192 float get_loop_bandwidth() const; 00193 00194 /*! 00195 * \brief Returns the loop damping factor 00196 */ 00197 float get_damping_factor() const; 00198 00199 /*! 00200 * \brief Returns the loop gain alpha 00201 */ 00202 float get_alpha() const; 00203 00204 /*! 00205 * \brief Returns the loop gain beta 00206 */ 00207 float get_beta() const; 00208 00209 /*! 00210 * \brief Get the control loop's frequency estimate 00211 */ 00212 float get_frequency() const; 00213 00214 /*! 00215 * \brief Get the control loop's phase estimate 00216 */ 00217 float get_phase() const; 00218 00219 /*! 00220 * \brief Get the control loop's maximum frequency. 00221 */ 00222 float get_max_freq() const; 00223 00224 /*! 00225 * \brief Get the control loop's minimum frequency. 00226 */ 00227 float get_min_freq() const; 00228 }; 00229 00230 } /* namespace blocks */ 00231 } /* namespace gr */ 00232 00233 #endif /* GR_BLOCKS_CONTROL_LOOP */