summaryrefslogtreecommitdiff
path: root/n/accel/calcul.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/accel/calcul.c')
-rw-r--r--n/accel/calcul.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/n/accel/calcul.c b/n/accel/calcul.c
new file mode 100644
index 0000000..f8e02bb
--- /dev/null
+++ b/n/accel/calcul.c
@@ -0,0 +1,68 @@
+/* calcul.c */
+/* Accelerometre {{{
+ *
+ * Copyright (C) 2004 Thomas Burg
+ *
+ * Robot APB Team/Efrei 2005.
+ * 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 "calcul.h"
+#include <inttypes.h>
+
+/* +AutoDec */
+/* -AutoDec */
+
+uint16_t T2_cal;
+uint16_t T1x_cal;
+uint16_t T1y_cal;
+uint32_t K;
+
+volatile enum T_etat etat;
+
+void
+calibration(void)
+{
+ uint8_t i = 0;
+ uint32_t T1x = 0;
+ uint32_t T1y = 0;
+ uint32_t T2 = 0;
+ while (i < 8 )
+ {
+ if( etat == calcul)
+ {
+ T1x += Tb;
+ T1y += Td - Tc;
+ T2 = (Td - (Td - Tc)/2) - Tb/2;
+ i++;
+ etat = strt_at_Ta;
+ }
+ }
+ T2_cal = T2 / 8;
+ T1x_cal = T1x / 8;
+ T1y_cal = T1y / 8;
+ K = ( 4 * ( T2_cal * BIT_SCALE_FACTOR) / T2_cal);
+}
+
+int16_t
+calculG ( uint16_t T1, uint16_t T2, uint16_t Zcal)
+{
+ uint32_t Zactual;
+ Zactual = Zcal * T2 / T2_cal;
+ return ( K * ( T1 - Zactual) / T2);
+}