summaryrefslogtreecommitdiff
path: root/n/asserv/src/asserv/motor_model.host.c
blob: 1d0855b4fb782437e31c48cff32265012f720402 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* motor_model.c - DC motor model. */
/* asserv - Position & speed motor control on AVR. {{{
 *
 * Copyright (C) 2006 Nicolas Schodet
 *
 * Robot APB Team/Efrei 2006.
 *        Web: http://assos.efrei.fr/robot/
 *      Email: robot AT efrei DOT fr
 *
 * 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.
 *
 * }}} */
#include "common.h"
#include "motor_model.host.h"

/**
 * Switching to french for all thoses non english speaking people.
 *
 * Ce fichier permet de mod�liser un moteur � courant continue. Il y a deux
 * parties, la mod�lisation �lectrique et la mod�lisation m�canique.
 *
 * On peut trouver de l'aide sur :
 *  - le site de maxon : http://www.maxonmotor.com/
 *  - ici : http://www.mathworks.com/access/helpdesk/help/toolbox/control/getstart/buildmo4.html
 *  - l� : http://iai.eivd.ch/users/mee/Regulation_automatique_anal.htm
 *
 * Voici ce qui en r�sulte, des belles �quations diff�rentielles :
 * u(t) = R i(t) + L di(t)/dt + Ke o(t)
 * J do(t)/dt = Kt i(t) - Rf o(t)
 * dth(t)/dt = o(t)
 *
 * Les variables sont d�crites dans la structure motor_t.
 *
 * � cela, il faut ajouter un coef pour le r�ducteur, je vous laisse �a en
 * exercice.
 *
 * On va r�soudre ces belles �quadiff num�riquement par la m�thode d'Euler (il
 * est partout celui l�). Si vous voulez plus de d�tail, mailez moi. On arrive
 * � :
 *
 * i(t+h) = i(t) + h (1/L u(t) - R/L i(t) - 1/(Ke L) o(t))
 * o(t+h) = o(t) + h (i_G^2 ro_G)/J (Kt i(t) - Rf o(t))
 * th(t+h) = th(t) + h o(t)
 *
 * C'est consternant de simplicit� non ?
 */

/** Make a simulation step. */
void motor_model_step (struct motor_t *m)
{
    double i_, o_, th_; /* New computed values. */
    double h; /* Infinitesimal step...  Well, not so infinite. */
    int d;
    d = m->d;
    h = m->h / d;
    /* Make several small steps to increase precision. */
    for (; d; d--)
      {
	/* Ah, the mistical power of computation. */
	i_ = m->i
	    + h * (1.0 / m->L * m->u
		   - m->R / m->L * m->i
		   - 1.0 / m->Ke / m->L * m->o);
	o_ = m->o
	    + h * m->i_G * m->i_G * m->ro_G / m->J
	    * (m->Kt * m->i - m->Rf * m->o);
	th_ = m->th + h * m->o;
	/* Ok, now store this step. */
	m->i = i_;
	m->o = o_;
	m->th = th_;
      }
    /* Damn!  It's finished yet! */
    m->t += m->h;
}