summaryrefslogtreecommitdiff
path: root/digital/avr/modules/motor/pos_control/pos_control.h
blob: 1378f3ad165f7515d26c2e82ffbc22cafbdea9f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef pos_control_h
#define pos_control_h
/* pos_control.h */
/* motor - Motor control module. {{{
 *
 * Copyright (C) 2011 Nicolas Schodet
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}} */

/** Position control state. */
struct pos_control_t
{
    /** Current position. */
    uint32_t cur;
    /** Consign position. */
    uint32_t cons;
    /** PID coefficients (f8.8, maximum depends on saturation values). */
    uint16_t kp, ki, kd;
    /** Error saturation. */
    int32_t e_sat;
    /** Integral saturation. */
    int32_t i_sat;
    /** Differential saturation. */
    int32_t d_sat;
    /** Current integral value. */
    int32_t i;
    /** Last error value. */
    int32_t last_error;
};
typedef struct pos_control_t pos_control_t;

/** Initialise position control. */
void
pos_control_init (pos_control_t *pos_control);

/** Control position of system, take current speed as input, return the new
 * command. */
int16_t
pos_control_update (pos_control_t *pos_control, int16_t cur_speed,
		    uint8_t enabled);

#endif /* pos_control_h */