X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Ftests%2Fhostsim%2Frobotsim.c;fp=projects%2Fmicrob2010%2Ftests%2Fhostsim%2Frobotsim.c;h=6f4dbbfa405615c789439614e20a73b9d31e5a36;hp=0000000000000000000000000000000000000000;hb=1f8274e9bca0d2433f101f267b86bc70dc2ae8c4;hpb=09fd7b53a60d7201b6d019d88d3fee3d43a14c3f diff --git a/projects/microb2010/tests/hostsim/robotsim.c b/projects/microb2010/tests/hostsim/robotsim.c new file mode 100644 index 0000000..6f4dbbf --- /dev/null +++ b/projects/microb2010/tests/hostsim/robotsim.c @@ -0,0 +1,81 @@ +/* + * Copyright Droids Corporation, Microb Technology, Eirbot (2005) + * + * 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 + * + * Revision : $Id: main.c,v 1.9.4.5 2007-06-01 09:37:22 zer0 Exp $ + * + */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "main.h" + +static int32_t l_pwm, r_pwm; +static int32_t l_enc, r_enc; + +/* */ +#define FILTER 98 +#define FILTER2 (100-FILTER) + +/* must be called periodically */ +void robotsim_update(void) +{ + static int32_t l_speed, r_speed; + + /* XXX should lock */ + l_speed = ((l_speed * FILTER) / 100) + ((l_pwm * 1000 * FILTER2)/1000); + l_enc += (l_speed / 1000); + r_speed = ((r_speed * FILTER) / 100) + ((r_pwm * 1000 * FILTER2)/1000); + r_enc += (r_speed / 1000); +} + +void robotsim_pwm(void *arg, int32_t val) +{ + // printf("%p, %d\n", arg, val); + if (arg == LEFT_PWM) + l_pwm = val; + else if (arg == RIGHT_PWM) + r_pwm = val; +} + +int32_t robotsim_encoder_get(void *arg) +{ + if (arg == LEFT_ENCODER) + return l_enc; + else if (arg == RIGHT_ENCODER) + return r_enc; + return 0; +}