00001 using System;
00002 using System.Collections;
00003 using System.Collections.Generic;
00004 using System.Linq;
00005 using System.Text;
00006 using RS232Port;
00007
00008 namespace PlatformController {
00009 public class PlatformData {
00010
00011 public readonly double MAGNETIC_DECLINATION;
00012
00013
00014 public PlatformData(double magDec) {
00015 MAGNETIC_DECLINATION = magDec;
00016 }
00017
00018
00019 int _compassHeading = 0;
00020 public int CompassHeading {
00021 get { return _compassHeading; }
00022 set {
00023 _compassHeading = value;
00024 _compassHeadingDouble = getRealCompassHeading(value);
00025 }
00026 }
00027
00028 double _compassHeadingDouble = 0;
00029 public double CompassHeadingDouble {
00030 get { return _compassHeadingDouble; }
00031 }
00032
00033 public double getRealCompassHeading(double heading) {
00034 heading /= 100.0;
00035 heading += MAGNETIC_DECLINATION;
00036 if (heading >= 360.0) heading = heading - 360.0;
00037 if (heading < 0) heading = 360.0 + heading;
00038 return heading;
00039 }
00040
00041 #region BATTERY_ADC_VALUES:
00042
00043
00044 const double AD_MULTIPLIER = 3.3 / 65472.0;
00045 const double DIVIDOR_RATIO = 2.17 / (2.17 + 11.87);
00046
00047 int _systemBatteryRaw = 0;
00048 public int SystemBatteryRaw {
00049 get { return _systemBatteryRaw; }
00050 set {
00051 _systemBatteryRaw = value;
00052 _systemBatteryVolts = convertAdcToVolts(value);
00053 }
00054 }
00055
00056 int _microBatteryRaw = 0;
00057 public int MicroBatteryRaw {
00058 get { return _microBatteryRaw; }
00059 set {
00060 _microBatteryRaw = value;
00061 _microBatteryVolts = convertAdcToVolts(value);
00062 }
00063 }
00064
00065 double convertAdcToVolts(int adc_reading) {
00066 return (double)adc_reading * AD_MULTIPLIER / DIVIDOR_RATIO;
00067 }
00068
00069 double _systemBatteryVolts = 0.0;
00070 public double SystemBatteryVolts {
00071 get { return _systemBatteryVolts; }
00072 }
00073
00074 double _microBatteryVolts = 0.0;
00075 public double MicroBatteryVolts {
00076 get { return _microBatteryVolts; }
00077 }
00078
00079 #endregion
00080
00081 #region INFRARED_ADC_VALUES:
00082
00083
00084
00085
00086
00087 const double A = -26.13019157;
00088 const double B = 153.7504349;
00089 const double C = -312.5940834;
00090 const double D = 250.6868629;
00091
00092
00093 double x = 0.0;
00094
00095 int _infraredLeftRaw = 0;
00096 public int InfraredLeftRaw {
00097 get { return _infraredLeftRaw; }
00098 set {
00099 _infraredLeftRaw = value;
00100 _infraredLeftCm = convertAdcToCm(value);
00101 }
00102 }
00103
00104 int _infraredRightRaw = 0;
00105 public int InfraredRightRaw {
00106 get { return _infraredRightRaw; }
00107 set {
00108 _infraredRightRaw = value;
00109 _infraredRightCm = convertAdcToCm(value);
00110 }
00111 }
00112
00113
00114 double convertAdcToCm(int adc_reading) {
00115 x = (double)adc_reading * AD_MULTIPLIER;
00116 return A * Math.Pow(x, 3.0) + B * Math.Pow(x, 2.0) + C * x + D;
00117 }
00118
00119 double _infraredLeftCm = 0.0;
00120 public double InfraredLeftCm {
00121 get { return _infraredLeftCm; }
00122 }
00123
00124 double _infraredRightCm = 0.0;
00125 public double InfraredRightCm {
00126 get { return _infraredRightCm; }
00127 }
00128
00129 #endregion
00130
00131 #region SONAR_RANGEFINDER_VALUES:
00132
00133
00134
00135
00136
00137
00138 const double CM_PER_US = 0.0343;
00139
00140
00141
00142 int _sonarRangefinderLeft = 0;
00143 public int SonarRangefinderLeft {
00144 get { return _sonarRangefinderLeft; }
00145 set {
00146 _sonarRangefinderLeft = value;
00147 _sonarRangefinderLeftCm = convertPulseToCm(value);
00148 }
00149 }
00150
00151 int _sonarRangefinderCenter = 0;
00152 public int SonarRangefinderCenter {
00153 get { return _sonarRangefinderCenter; }
00154 set {
00155 _sonarRangefinderCenter = value;
00156 _sonarRangefinderCenterCm = convertPulseToCm(value);
00157 }
00158 }
00159
00160 int _sonarRangefinderRight = 0;
00161 public int SonarRangefinderRight {
00162 get { return _sonarRangefinderRight; }
00163 set {
00164 _sonarRangefinderRight = value;
00165 _sonarRangefinderRightCm = convertPulseToCm(value);
00166 }
00167 }
00168
00169 double convertPulseToCm(int pulse_duration) {
00170 return pulse_duration / 2 * CM_PER_US;
00171 }
00172
00173 double _sonarRangefinderLeftCm = 0.0;
00174 public double SonarRangefinderLeftCm {
00175 get { return _sonarRangefinderLeftCm; }
00176 }
00177
00178 double _sonarRangefinderCenterCm = 0.0;
00179 public double SonarRangefinderCenterCm {
00180 get { return _sonarRangefinderCenterCm; }
00181 }
00182
00183 double _sonarRangefinderRightCm = 0.0;
00184 public double SonarRangefinderRightCm {
00185 get { return _sonarRangefinderRightCm; }
00186 }
00187
00188 #endregion
00189
00190 #region BUMPER_SWITCH_VALUES:
00191
00192 bool _bumperLeft = false;
00193 public bool BumperLeft {
00194 get { return _bumperLeft; }
00195 set { _bumperLeft = value; }
00196 }
00197
00198
00199 bool _bumperRight = false;
00200 public bool BumperRight {
00201 get { return _bumperRight; }
00202 set { _bumperRight = value; }
00203 }
00204
00205 #endregion
00206
00207 #region RESET_AND_RCMODE_SWITCH_VALUES:
00208
00209 bool _resetSwitch = false;
00210 public bool ResetSwitch {
00211 get { return _resetSwitch; }
00212 set { _resetSwitch = value; }
00213 }
00214
00215
00216 bool _radioControlModeSwitch = false;
00217 public bool RadioControlModeSwitch {
00218 get { return _radioControlModeSwitch; }
00219 set { _radioControlModeSwitch = value; }
00220 }
00221
00222 #endregion
00223
00224 #region RED_AND_GREEN_LED_STATES:
00225
00226 bool _redLedValue = false;
00227 public bool RedLedValue {
00228 get { return _redLedValue; }
00229 set { _redLedValue = !value; }
00230 }
00231
00232 bool _greenLedValue = false;
00233 public bool GreenLedValue {
00234 get { return _greenLedValue; }
00235 set { _greenLedValue = !value; }
00236 }
00237
00238 #endregion
00239
00240 #region STEERING_AND_THROTTLE_CALCULATED_VALUES:
00241
00242 int _steeringCalculatedValue = 0;
00243 public int SteeringCalculatedValue {
00244 get { return _steeringCalculatedValue; }
00245 set { _steeringCalculatedValue = value; }
00246 }
00247
00248 int _throttleCalculatedValue = 0;
00249 public int ThrottleCalculatedValue {
00250 get { return _throttleCalculatedValue; }
00251 set { _throttleCalculatedValue = value; }
00252 }
00253
00254 #endregion
00255
00256 bool _autoAvoiding = false;
00257 public bool AutoAvoiding {
00258 get { return _autoAvoiding; }
00259 set { _autoAvoiding = value; }
00260 }
00261
00262 string _status = "not initialized";
00263 public void setStatus(string status) {
00264 _status = status;
00265 }
00266 public string Status {
00267 get { return _status; }
00268 }
00269
00270 string _platformBuffer = "";
00271 public void setBuffer(string buffer) {
00272 _platformBuffer = buffer;
00273 }
00274 public string PlatformBuffer {
00275 get { return _platformBuffer; }
00276 }
00277 }
00278 }