2 * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
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.
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.
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
26 /* Initialize the two first fields to the max possible value and previous out to 0*/
28 void ramp_init(struct ramp_filter * r)
33 r->var_neg=0xFFFFFFFF;
34 r->var_pos=0xFFFFFFFF;
41 /*Set the field var_neg to neg and var_pos to pos */
43 void ramp_set_vars(struct ramp_filter * r, uint32_t neg, uint32_t pos)
55 /*Filter the in value using the ramp_filter r*/
56 int32_t ramp_do_filter(void * data, int32_t in)
59 struct ramp_filter * r = (struct ramp_filter *) data;
61 if (in>r->prev_out) /*test if the variation is positive or negative */
63 variation=in-r->prev_out; /* positive variation */
64 if (variation<r->var_pos) /* test if the variation is too high */
65 r->prev_out=in; /* variation ok return value will be in */
67 r->prev_out=r->prev_out+r->var_pos; /* variation too high so return value is filtered */
71 variation=r->prev_out-in; /* negative variation */
72 if (variation<r->var_neg) /* test if the variation is too high */
73 r->prev_out=in; /* variation ok return value will be in */
75 r->prev_out=r->prev_out-r->var_neg; /* variation too high so return value is filtered */