diff options
author | Bdale Garbee <bdale@gag.com> | 2014-01-22 20:55:41 -0700 |
---|---|---|
committer | Bdale Garbee <bdale@gag.com> | 2014-01-22 20:55:41 -0700 |
commit | 9884ca1449167a06bd2cebc7d28353eeac592493 (patch) | |
tree | 9fde328b3a5971c67954e669c1ba27042821fd8c /altoslib/AltosIMU.java | |
parent | 8e669694a60d34e2ea0f8f6b189e0bc3605d94d7 (diff) | |
parent | 0ef0c50536e5eb6ad3455b5828983307edbab828 (diff) |
Merge branch 'branch-1.3' into debian
Diffstat (limited to 'altoslib/AltosIMU.java')
-rw-r--r-- | altoslib/AltosIMU.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/altoslib/AltosIMU.java b/altoslib/AltosIMU.java index 6d88ccae..260f3587 100644 --- a/altoslib/AltosIMU.java +++ b/altoslib/AltosIMU.java @@ -15,18 +15,30 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_2; +package org.altusmetrum.altoslib_3; import java.util.concurrent.*; public class AltosIMU implements Cloneable { - public int accel_x; - public int accel_y; - public int accel_z; + public double accel_x; + public double accel_y; + public double accel_z; - public int gyro_x; - public int gyro_y; - public int gyro_z; + public double gyro_x; + public double gyro_y; + public double gyro_z; + + public static int counts_per_g = 2048; + + public static double convert_accel(int counts) { + return (double) counts / (double) counts_per_g * (-AltosConvert.GRAVITATIONAL_ACCELERATION); + } + + public static double counts_per_degsec = 16.4; + + public static double convert_gyro(int counts) { + return (double) counts / counts_per_degsec; + } public boolean parse_string(String line) { if (!line.startsWith("Accel:")) @@ -35,12 +47,12 @@ public class AltosIMU implements Cloneable { String[] items = line.split("\\s+"); if (items.length >= 8) { - accel_x = Integer.parseInt(items[1]); - accel_y = Integer.parseInt(items[2]); - accel_z = Integer.parseInt(items[3]); - gyro_x = Integer.parseInt(items[5]); - gyro_y = Integer.parseInt(items[6]); - gyro_z = Integer.parseInt(items[7]); + accel_x = convert_accel(Integer.parseInt(items[1])); + accel_y = convert_accel(Integer.parseInt(items[2])); + accel_z = convert_accel(Integer.parseInt(items[3])); + gyro_x = convert_gyro(Integer.parseInt(items[5])); + gyro_y = convert_gyro(Integer.parseInt(items[6])); + gyro_z = convert_gyro(Integer.parseInt(items[7])); } return true; } |