throttle speed before ejection
[aversive.git] / modules / devices / control_system / control_system_manager / control_system_manager.h
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
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: control_system_manager.h,v 1.7.4.5 2008-03-02 17:18:34 zer0 Exp $
19  *
20  */
21
22 /* Droids-corp, Eirbot, Microb Techology 2005
23  * Implementation for the control_system manager
24  */
25
26 /** \file control_system_manager.h
27  * \brief Interface for the control_system manager module.
28  *
29  * \todo Test the module on a real system.
30  *
31  * \test No test for the moment, only correct compilation.
32  *
33  * This module provide functions to control and regulate a system.
34  */
35     
36 #ifndef _CONTROL_SYSTEM_MANAGER_
37 #define _CONTROL_SYSTEM_MANAGER_
38
39 #include <aversive.h>
40
41 /** The data structure used by the control_system_manager module */
42 struct cs {
43         
44         int32_t (*consign_filter)(void *, int32_t);
45         void* consign_filter_params;
46
47         int32_t (*correct_filter)(void*, int32_t);
48         void* correct_filter_params;
49
50         int32_t (*feedback_filter)(void*, int32_t);
51         void* feedback_filter_params;
52
53         int32_t (*process_out)(void*);
54         void* process_out_params;
55
56         void (*process_in)(void*, int32_t);
57         void* process_in_params;
58
59         int32_t consign_value;
60         int32_t filtered_feedback_value;
61         int32_t filtered_consign_value;
62         int32_t error_value;
63         int32_t out_value;
64 };
65
66 /******* - Prototyping - *******/
67
68 /** Initiate the control_system structure by setting all fields to NULL */
69 void cs_init(struct cs* cs);
70
71 /** Set the cs consign_filter fields in the cs structure */
72 void cs_set_consign_filter(struct cs* cs,
73                                   int32_t (*consign_filter)(void*, int32_t),
74                                   void* consign_filter_params);
75
76 /** Set the cs correct_filter fields in the cs structure */
77 void  cs_set_correct_filter(struct cs* cs,
78                                    int32_t (*correct_filter)(void*, int32_t),
79                                    void* correct_filer_params);
80
81 /** Set the cs feedback_filter fields in the cs structure */
82 void  cs_set_feedback_filter(struct cs* cs,
83                                     int32_t (*feedback_filter)(void*, int32_t),
84                                     void* feedback_filer_params);
85
86 /** Set the cs process_in fields in the cs structure */
87 void cs_set_process_in(struct cs* cs,
88                               void (*process_in)(void*, int32_t),
89                               void* process_in_params);
90
91 /** Set the cs process_out fields in the cs structure */
92 void cs_set_process_out(struct cs* cs,
93                                int32_t (*process_out)(void*),
94                                void* process_out_params);
95
96
97 /** \brief This function do the main loop of the control system process.
98  *
99  * - Save the consign in the structure.
100  * - Apply the consign filter to the consign.
101  * - Read the process out
102  * - Apply the feedback filter to the process out
103  * - Substract filtered consign to filtered process out.
104  * - Save the result in error_value and apply the correct filter.
105  * - Save the filtered result and send it to process_in().
106  * - Return this result.
107  * 
108  */
109 int32_t cs_do_process(struct cs* cs, int32_t consign);
110
111 /** Apply cs_do_process() to the structure cs 
112  * \param cs should be a (struct cs*)
113  */
114 void cs_manage(void * cs);
115
116 /** Return the last output sent to process */
117 int32_t cs_get_out(struct cs* cs);
118
119 /** Return the last calculated error */
120 int32_t cs_get_error(struct cs* cs);
121
122 /** Return the current consign */
123 int32_t cs_get_consign(struct cs* cs);
124
125 /** Return the current consign, after filter */
126 int32_t cs_get_filtered_consign(struct cs* cs);
127
128 /** Return the last feedback value, after filter */
129 int32_t cs_get_filtered_feedback(struct cs* cs);
130
131 /** Change the consign without calculating control system */
132 void cs_set_consign(struct cs* cs, int32_t v);
133
134
135 #endif /* #ifndef _CONTROL_SYSTEM_MANAGER_ */