00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 using System.Threading;
00006
00007 namespace NavigationController {
00008 public class NavigationData {
00009
00010 public const double AD_MULTIPLIER = 3.3 / 65472;
00011 public const double RESISTOR_DIVIDER = 1.2 / (1.2 + 12.0);
00012
00013 public const double ACCELEROMETER_NULL = 1.66;
00014 public const double V_PER_G = 0.333;
00015 public const double X_OFFSET = 0.08;
00016 public const double Y_OFFSET = -0.06;
00017 public const double Z_OFFSET = 0.01;
00018 public readonly double COUNTS_PER_METER = 1000.0;
00019
00020
00021
00022
00023 public NavigationData(double countsPerMeter) {
00024
00025 COUNTS_PER_METER = countsPerMeter;
00026 }
00027
00028 string _error = "";
00029 public string Error {
00030 get { return _error; }
00031 }
00032
00033 string _navigationBuffer = "";
00034 public string NavigationBuffer {
00035 get { return _navigationBuffer; }
00036 set { _navigationBuffer = value; }
00037 }
00038
00039
00040 public double getRealAcc(double acc, double offset) {
00041 return ((AD_MULTIPLIER * acc - ACCELEROMETER_NULL) / V_PER_G) + offset;
00042 }
00043
00044 int _xAcc = 0;
00045 public int XAcc {
00046 get { return _xAcc; }
00047 set { _xAcc = value; }
00048 }
00049
00050 int _yAcc = 0;
00051 public int YAcc {
00052 get { return _yAcc; }
00053 set { _yAcc = value; }
00054 }
00055
00056 int _zAcc = 0;
00057 public int ZAcc {
00058 get { return _zAcc; }
00059 set { _zAcc = value; }
00060 }
00061
00062
00063 public double XAccGs {
00064 get { return getRealAcc(_xAcc, X_OFFSET); }
00065 }
00066
00067 public double YAccGs {
00068 get { return getRealAcc(_yAcc, Y_OFFSET); }
00069 }
00070
00071 public double ZAccGs {
00072 get { return getRealAcc(_zAcc, Z_OFFSET); }
00073 }
00074
00075
00076 long _encoderCounts = 0;
00077 public long EncoderCounts {
00078 get { return _encoderCounts; }
00079 set {
00080 _encoderCounts = value;
00081 _meters = (double)_encoderCounts / COUNTS_PER_METER;
00082 }
00083 }
00084
00085
00086 short _deltaEncoderCounts = 0;
00087 public short DeltaEncoderCounts {
00088 get { return _deltaEncoderCounts; }
00089 set { _deltaEncoderCounts = value; }
00090 }
00091
00092
00093 double _meters = 0;
00094 public double Meters {
00095 get { return _meters; }
00096 set { _meters = value; }
00097 }
00098
00099
00100 #region STEERING_AND_THROTTLE_PULSEOUT_VALUES:
00101
00102 const int STEERING_ZERO = 1406, THROTTLE_ZERO = 1501;
00103
00104 int _steeringPulseDuration = 0;
00105 public int SteeringPulseDuration {
00106 get { return _steeringPulseDuration; }
00107 set {
00108 _steeringPulseDuration = value;
00109 _steering = convertPulseToByte(value - STEERING_ZERO);
00110 }
00111 }
00112
00113 int _throttlePulseDuration = 0;
00114 public int ThrottlePulseDuration {
00115 get { return _throttlePulseDuration; }
00116 set {
00117 _throttlePulseDuration = value;
00118 _throttle = convertPulseToByte(value - THROTTLE_ZERO);
00119 }
00120 }
00121
00122 int convertPulseToByte(int pulse_width) {
00123 return (int)Math.Ceiling((double)pulse_width / 3.19);
00124 }
00125
00126
00127 int _throttle = 0;
00128 public int Throttle {
00129 get { return _throttle; }
00130 }
00131
00132 int _steering = 0;
00133 public int Steering {
00134 get { return _steering; }
00135 }
00136
00137 #endregion
00138
00139 #region STEERING_AND_THROTTLE_SETPOINTS:
00140
00141 int _steeringSetpoint = 0;
00142 public int SteeringSetpoint {
00143 get { return _steeringSetpoint; }
00144 set { _steeringSetpoint = value; }
00145 }
00146
00147 int _throttleSetpoint = 0;
00148 public int ThrottleSetpoint {
00149 get { return _throttleSetpoint; }
00150 set { _throttleSetpoint = value; }
00151 }
00152
00153 #endregion
00154
00155
00156
00157 int _runMode = 0;
00158 public int RunMode {
00159 get { return _runMode; }
00160 set { _runMode = value; }
00161 }
00162
00163 bool _deadMan = true;
00164 public bool DeadMan {
00165 get { return _deadMan; }
00166 set { _deadMan = value; }
00167 }
00168
00169 string _status = "not initialized";
00170 public void setStatus(string status) {
00171 _status = status;
00172 }
00173 public string Status {
00174 get { return _status; }
00175 }
00176 }
00177 }