window_lib.h

Go to the documentation of this file.
00001 
00013 
00014 /*!*************** HOW TO DETERMINE DEFAULT GAIN CONSTANT *********************/
00027 /******************************************************************************/
00048 /******************************************************************************/
00049 #ifndef _WINDOW_LIB_H
00050 #define _WINDOW_LIB_H
00051 
00052 
00053 /*_____ I N C L U D E S ______________________________________________________*/
00054 
00055 #include "config.h"
00056 
00057 
00058   
00059 /*_____ D E F I N I T I O N S ________________________________________________*/
00063 
00065 #define PINCH_THRES 80       
00066 
00067 
00070 #define GAIN        27  
00078 
00079 
00080 #define PINCH       (unsigned char)(GAIN * PINCH_THRES >> 5)  
00081 
00083 
00087 
00090 #define WINDOW_HEIGHT_MM  450              
00091 
00094 #define TOP_MM            2.0222
00095 
00097 #define H_DETECT_MIN_MM   210               
00098 
00100 #define H_DETECT_MIN      (U16)(H_DETECT_MIN_MM*TOP_MM)  
00101 
00103 #define H_MAX_MM          20  
00104 
00106 #define H_MAX             (U16)(H_MAX_MM*TOP_MM)    
00107 
00109 #define DOWN              (U16)(WINDOW_HEIGHT_MM*TOP_MM)   // limite butee basse
00111 
00113 #define PT_NUM_MAX        8
00114 
00116 #define PT_NUM_ADR        15    
00117 
00118 
00119 /*_____ S T A T E _ M A C H I N E _ D E F I N I T I O N S ____________________*/
00123 #define STOP_STATE      0 
00124 
00125 #define START_UP_STATE  1 
00126 
00127 #define GO_UP_STATE     2 
00128 
00129 #define OBSTRUCT_STATE  3 
00130 
00131 
00132 #define PINCH_STATE     4
00134 #define REVERSE_STATE   5
00136 #define STOPING_STATE   6
00138 #define GO_DOWN_STATE   7
00140 
00141 //HARD BLOCKING POINTS STATE MACHINE DEFINITIONS
00142 #define NORMAL_STATE    1
00143 #define BLOCKING_STATE  2
00144 //#define PINCH_STATE     4
00145 #define SORT_STATE      5
00146 
00147 // 
00151 #define INIT_START_INIT       0
00152 #define INIT_DETECT_BOTTOM    1
00153 #define INIT_START_TOP_DETECT 2
00154 #define INIT_DETECT_TOP       3
00155 #define INIT_COMPUTE_PARAMS   4
00156 #define INIT_BACKLASH_START   5
00157 #define INIT_BACKLASH_DOWN    6
00158 #define INIT_BACKLASH_ACQUIRE 7
00159 #define INIT_END_INIT         8
00161 
00165 #define INIT_EEP_DONE         0x00
00166 #define INIT_POSITION_REQUEST 0x01
00167 #define INIT_RE_INIT          0x80
00169 
00174 #define ANTI_PINCH_ENABLED  0 
00175 #define ANTI_PINCH_DISABLED 1 
00176 
00177 #define CMDE_NO_CMDE        0 
00178 #define CMDE_NEW_CMDE       1 
00179 #define CMDE_PERFORMED      2 
00180 
00181 
00182 #define UPWARD              1 
00183 #define DOWNWARD            0 
00184 
00185 /*_____ T Y P E D E F - D E C L A R A T I O N ________________________________*/
00186 
00190 
00192 typedef struct
00193 {
00194     U16 position;         
00195     U8  last_direction;   
00196     U8  pinch_threshold;  
00197     U8  gain;             
00198     U16 window_height_mm; 
00199     U8  h_max_mm;         
00200     U16 h_detect_min_mm;  
00201     U16 down;             
00202     U16 backlash;         
00203 }st_eep_WindowParam;
00204 
00206 typedef union 
00207 {
00208   U8 U8_ptr[sizeof(st_eep_WindowParam)]; 
00209   st_eep_WindowParam param;              
00210 } un_eep_WindowParam;
00212 
00213 
00215 typedef struct
00216   {
00217     U16 origin;
00218     U16 end;
00219     U8 occ;
00220   } st_b_point;
00221 
00222 typedef struct
00223 {
00224   U8 pt_num;
00225   st_b_point point[PT_NUM_MAX];
00226 } st_b_point_tab;
00227 
00228 /*_____ G L O B A L S ________________________________________________________*/
00229 
00230 extern un_eep_WindowParam eep; // eeprom parameters @ingroup Eeprom_storage
00231 
00232 // Window position buffer
00233 // Range [0 to down]
00234 // 0 is origin at top of the window
00235 // down is the max registrable hall sensor edges
00236 extern U16 position; 
00237 
00238 // Computed current reference ( I(A) <-> ADC * ADC gain )
00239 // Range : [0 to (current measured values) * (ADC gain)]
00240 // It's the reference to be compared with current*gain (ADC values) to detect
00241 // a pinch
00242 extern U16 ref;
00243 
00244 // Current Image: Has to be filtered (meaned) for the algorithm to work well.
00245 // Range [0 to (current * ADC gain)]
00246 // To be compared with reference current value (ref)
00247 extern U16 current;
00248 
00249 // Window operating direction (according to command).
00250 // Range : [DOWNWARD, UPWARD]
00251 extern U8 direction;
00252 
00253 // Window bottom max position
00254 extern U16 down;
00255 
00256 // number of hall sensor edges per millimeters (left shifted by 8 to allow
00257 // a good precision, see @ref Window_areas).
00258 extern U16 top_mm;
00259 
00260 // Distance from top of window to inactivate anti-pinch in hall sensor edges
00261 // computed using h_max_mm and down variables
00262 extern U8 h_max;
00263 
00264 /*_____ P R O T O T Y P E S - D E C L A R A T I O N __________________________*/
00265 
00266 U8 Read_Eep_WindowParameters(void);
00267 
00268   //  Allows to automatically operate window down, then up to detect
00269   //  Bottom and top ends.
00270 U8 init_window_size_position(void);
00271 
00272   // Returns window control machine state
00273 signed char get_window_state (void);
00274 
00275   //returns value under which anti-pinch protection should be activated
00276 U16 get_h_detect_min(void);
00277 
00278   // returns value under which anti-pinch protection should be disabled
00279   // (typically into rubber joints)
00280 U8 get_h_max(void);
00281 
00282   // Force window control machine state, returns window state
00283 signed char force_window_state (signed char temp);
00284 
00285   // Reads EEprom to load parameters, Returns Initialisation status
00286 //void init_window_parameters(signed char*);
00287 void save_window_parameters(void);
00288 U8 window_ctrl( signed char*, signed char*,U8);
00289 
00290 U8 update_point (void);
00291 void clean_point(void);
00292 U8 get_table_indice (U16);
00293 U8 blocking_point(signed char);
00294 U8 get_block_point(U16);
00295 void erase_block_point(void);
00296 void block_point_set_origin(U16 origin);
00297 void init_window_peripherals(void);
00298 
00299 #endif  //_WINDOW_LIB_H
00300 

Generated on Mon May 28 20:26:50 2007 for WINDOWLIFTLIBRARY by  doxygen 1.4.7