00001
00002
00003
00004
00005 #ifndef CAJUN_THROTTLE_H
00006 #define CAJUN_THROTTLE_H
00007
00008 #include "conf.H"
00009
00010 #include <cstdlib>
00011
00012 namespace cajun
00013 {
00014 class sog_data_t;
00015 class steering_data_t;
00016
00017 class base_throttle_t
00018 {
00019 public:
00020 base_throttle_t (const conf_t &conf)
00021 {
00022 init ();
00023 if (! read_config (conf))
00024 exit (-1);
00025 }
00026 virtual ~base_throttle_t () {}
00027
00028 virtual bool read_config (const conf_t &conf)
00029 {
00030 return conf.require ("debug_throttle",
00031 m_debug_throttle) &&
00032 conf.require ("min_steering_to_consider_as_turn",
00033 m_min_steering_to_consider_as_turn) &&
00034 conf.require ("max_straight_throttle",
00035 m_max_straight_throttle) &&
00036 conf.require ("max_turn_throttle",
00037 m_max_turn_throttle) &&
00038 conf.require ("speed_error_threshold",
00039 m_speed_error_threshold);
00040 }
00041
00042 virtual void init ()
00043 {
00044 m_throttle = 0;
00045 }
00046 virtual void throttle (double tstamp,
00047 steering_data_t &steering,
00048 sog_data_t const &sd,
00049 double desired_speed,
00050 double desired_speed_rate) = 0;
00051 protected:
00052 bool m_debug_throttle;
00053
00054 double m_min_steering_to_consider_as_turn;
00055 double m_max_straight_throttle;
00056 double m_max_turn_throttle;
00057 double m_speed_error_threshold;
00058 double m_throttle;
00059 };
00060
00061 class throttle_v1_t : public base_throttle_t
00062 {
00063 public:
00064 throttle_v1_t (const conf_t &conf);
00065 void init ();
00066 bool read_config (const conf_t &conf);
00067 void throttle (double tstamp_,
00068 steering_data_t &steering,
00069 sog_data_t const &sd,
00070 double desired_speed,
00071 double desired_speed_rate);
00072 double m_throttle_up_factor;
00073 protected:
00074 double m_throttle_down_factor;
00075 double m_last_speed;
00076 double m_last_speed_rate;
00077 double m_last_speed_tstamp;
00078 };
00079
00080
00081
00082 class throttle_v2_t : public base_throttle_t
00083 {
00084 public:
00085 throttle_v2_t (const conf_t &conf);
00086 virtual ~throttle_v2_t () {}
00087
00088 virtual bool read_config (const conf_t &conf);
00089
00090 virtual void init ()
00091 {
00092 m_throttle = 0;
00093 for (unsigned i = 0; i < 2; i++)
00094 {
00095 m_error[i] = 0;
00096 m_tstamp[i] = 0;
00097 }
00098 }
00099
00100 virtual void throttle (double tstamp,
00101 steering_data_t &steering,
00102 sog_data_t const &sd,
00103 double desired_speed,
00104 double desired_speed_rate);
00105
00106 protected:
00107 double m_min_steering_to_consider_as_turn;
00108 double m_max_straight_throttle;
00109 double m_max_turn_throttle;
00110 double m_speed_error_threshold;
00111
00112 double m_throttle;
00113 double m_error[2];
00114 double m_tstamp[2];
00115 double m_kp;
00116 double m_ki;
00117 double m_kd;
00118 };
00119
00120
00121
00122
00123
00124
00125 class throttle_v3_t : public base_throttle_t
00126 {
00127 public:
00128 throttle_v3_t (const conf_t &conf);
00129 virtual ~throttle_v3_t () {}
00130
00131 bool read_config (const conf_t &conf);
00132
00133 void init ()
00134 {
00135 m_prev_tstamp = 0;
00136 m_throttle = 0;
00137 }
00138
00139 void throttle (double tstamp, steering_data_t &steering,
00140 sog_data_t const &sd, double desired_speed,
00141 double desired_speed_rate);
00142
00143 protected:
00144 double m_min_steering_to_consider_as_turn;
00145 double m_max_straight_throttle;
00146 double m_max_turn_throttle;
00147 double m_speed_error_threshold;
00148
00149 double m_kp;
00150 double m_ki;
00151 double m_kd;
00152
00153 double m_throttle;
00154 double m_prev_tstamp;
00155 double m_prev_sog;
00156 double m_prev_acc_error;
00157 };
00158
00159 };
00160
00161
00162
00163
00164
00165 #endif