diff options
author | Keith Packard <keithp@keithp.com> | 2013-12-20 19:37:08 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2013-12-20 19:37:08 -0800 |
commit | 91bcfae2e64ecb2e7de1292b264910382b635aea (patch) | |
tree | ec54fbfec63ffa3f5744b4530c8d23f2d9724048 /altoslib/AltosMag.java | |
parent | 2ad31bad20b20615e9d8b29088e2488fddc81ac9 (diff) |
altoslib: Convert IMU and Mag sensor values to useful units
Convert from raw sensor values to metric units
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosMag.java')
-rw-r--r-- | altoslib/AltosMag.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index 89e72bd6..5136bfd2 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -20,9 +20,15 @@ package org.altusmetrum.altoslib_2; import java.util.concurrent.*; public class AltosMag implements Cloneable { - public int x; - public int y; - public int z; + public double x; + public double y; + public double z; + + public static double counts_per_gauss = 1090; + + public static double convert_gauss(int counts) { + return (double) counts / counts_per_gauss; + } public boolean parse_string(String line) { // if (line.startsWith("Syntax error")) { @@ -36,9 +42,9 @@ public class AltosMag implements Cloneable { String[] items = line.split("\\s+"); if (items.length >= 6) { - x = Integer.parseInt(items[1]); - y = Integer.parseInt(items[3]); - z = Integer.parseInt(items[5]); + x = convert_gauss(Integer.parseInt(items[1])); + y = convert_gauss(Integer.parseInt(items[3])); + z = convert_gauss(Integer.parseInt(items[5])); } return true; } |