remove ~files
[aversive.git] / modules / devices / robot / blocking_detection_manager / blocking_detection_manager.h
1 /*  
2  *  Copyright Droids Corporation (2007)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: blocking_detection_manager.h,v 1.1.2.6 2008-05-09 08:25:10 zer0 Exp $
19  *
20  *  Olivier MATZ <zer0@droids-corp.org>
21  */
22
23 /* blocking detection manager */
24
25 #ifndef BLOCKING_DETECTION_MANAGER_H_
26 #define BLOCKING_DETECTION_MANAGER_H_
27
28 /* display debug every 128 calls of manage if defined */
29 #define BD_DEBUG 128
30
31 #include <control_system_manager.h>
32
33 /* detect blocking based on motor current. 
34  * triggers the blocking if:
35  *   - the current in the motor is a above a threshold 
36  *     during n tests
37  *   - the speed is below the threshold (if specified)
38  *
39  * We suppose that i = k1.V - k2.w
40  * (V is the voltage applied on the motor, and w the current speed 
41  * of the motor)
42  */
43
44 struct blocking_detection {
45         struct cs *cs;
46
47         uint32_t i_thres;
48         int32_t k1;
49         int32_t k2;
50         uint16_t cpt_thres;
51         uint16_t cpt;
52         uint16_t speed_thres;
53 #ifdef BD_DEBUG
54         uint16_t debug_cpt;
55 #endif
56
57         int32_t prev_pos;
58         int32_t speed;
59 };
60
61 /** init module, give the cs as parameter */
62 void bd_init(struct blocking_detection * bd);
63
64 /** thresholds for current-based blocking detection. If cpt_thres 
65  *  is 0, disable it. */
66 void bd_set_current_thresholds(struct blocking_detection * bd, 
67                                int32_t k1, int32_t k2, 
68                                uint32_t i_thres, uint16_t cpt_thres);
69
70 /** speed threshold: if speed is above it, disable
71  *  blocking_detection. */
72 void bd_set_speed_threshold(struct blocking_detection * bd, 
73                             uint16_t speed);
74
75 /** reset the blocking */
76 void bd_reset(struct blocking_detection * bd);
77
78 /** function to be called periodicallyn, when we use cs structure */
79 void bd_manage_from_cs(struct blocking_detection * bd, struct cs *cs);
80
81 /** function to be called periodically, when we use values directly */
82 void bd_manage_from_pos_cmd(struct blocking_detection * bd, 
83                             int32_t pos, int32_t cmd);
84
85 /** function to be called periodically, when we use values directly */
86 void bd_manage_from_speed_cmd(struct blocking_detection * bd, 
87                               int32_t speed, int32_t cmd);
88
89 /** get value of blocking detection */
90 uint8_t bd_get(struct blocking_detection * bd);
91
92 #endif