baseline build

Dependencies:   FastPWM mbed-os mbed

Committer:
jrhodes5150
Date:
Mon Jun 19 15:55:51 2017 +0000
Revision:
0:8a420ac6394e
initial build - baseline;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jrhodes5150 0:8a420ac6394e 1
jrhodes5150 0:8a420ac6394e 2 #include "DeviceProperties.h"
jrhodes5150 0:8a420ac6394e 3
jrhodes5150 0:8a420ac6394e 4 DeviceProperties Device;
jrhodes5150 0:8a420ac6394e 5
jrhodes5150 0:8a420ac6394e 6 DeviceConfig::DeviceConfig(void)
jrhodes5150 0:8a420ac6394e 7 {
jrhodes5150 0:8a420ac6394e 8 // Control Parameters
jrhodes5150 0:8a420ac6394e 9 outputMode = OMRamp;
jrhodes5150 0:8a420ac6394e 10 constantVoltage = 0;
jrhodes5150 0:8a420ac6394e 11 constantPower = 0;
jrhodes5150 0:8a420ac6394e 12 kp = 0;
jrhodes5150 0:8a420ac6394e 13 ki = 0;
jrhodes5150 0:8a420ac6394e 14 kd = 0;
jrhodes5150 0:8a420ac6394e 15 voltageCal = 1;
jrhodes5150 0:8a420ac6394e 16 currentCal = 1;
jrhodes5150 0:8a420ac6394e 17 vLim = 0;
jrhodes5150 0:8a420ac6394e 18 iLim = 0;
jrhodes5150 0:8a420ac6394e 19 hvLim = 8;
jrhodes5150 0:8a420ac6394e 20 // Activation Parameters
jrhodes5150 0:8a420ac6394e 21 pwmFrequency = 400;
jrhodes5150 0:8a420ac6394e 22 msOpenLoopDuration = 50;
jrhodes5150 0:8a420ac6394e 23 TotalDurationSeconds = 4000;
jrhodes5150 0:8a420ac6394e 24 msRampDuration = 1000;
jrhodes5150 0:8a420ac6394e 25 rampStartPower = 1;
jrhodes5150 0:8a420ac6394e 26 rampEndPower = 10;
jrhodes5150 0:8a420ac6394e 27 startVoltage = 30;
jrhodes5150 0:8a420ac6394e 28 msSamplePeriod = 10;
jrhodes5150 0:8a420ac6394e 29 doneBit = 0;
jrhodes5150 0:8a420ac6394e 30 pwrCalLow =1;
jrhodes5150 0:8a420ac6394e 31 pwrCalHigh =1;
jrhodes5150 0:8a420ac6394e 32 vCalLow = 1;
jrhodes5150 0:8a420ac6394e 33 vCalHigh = 1;
jrhodes5150 0:8a420ac6394e 34 PID_GOOD = false;
jrhodes5150 0:8a420ac6394e 35 voltageSensed = 0;
jrhodes5150 0:8a420ac6394e 36 currentSensed = 0;
jrhodes5150 0:8a420ac6394e 37 sensedResistance = 0;
jrhodes5150 0:8a420ac6394e 38 sensedPower = 0;
jrhodes5150 0:8a420ac6394e 39 }
jrhodes5150 0:8a420ac6394e 40
jrhodes5150 0:8a420ac6394e 41 DeviceProperties::DeviceProperties(void)
jrhodes5150 0:8a420ac6394e 42 {
jrhodes5150 0:8a420ac6394e 43 acquisitionSampleCount = 0;
jrhodes5150 0:8a420ac6394e 44 acquisitionNumber = 0;
jrhodes5150 0:8a420ac6394e 45 }
jrhodes5150 0:8a420ac6394e 46
jrhodes5150 0:8a420ac6394e 47 int DeviceProperties::GetAcquisitionNumber(void)
jrhodes5150 0:8a420ac6394e 48 {
jrhodes5150 0:8a420ac6394e 49 mutex.lock();
jrhodes5150 0:8a420ac6394e 50 int result = acquisitionNumber;
jrhodes5150 0:8a420ac6394e 51 mutex.unlock();
jrhodes5150 0:8a420ac6394e 52 return result;
jrhodes5150 0:8a420ac6394e 53 }
jrhodes5150 0:8a420ac6394e 54
jrhodes5150 0:8a420ac6394e 55 int DeviceProperties::GetAcquisitionSampleCount(void)
jrhodes5150 0:8a420ac6394e 56 {
jrhodes5150 0:8a420ac6394e 57 mutex.lock();
jrhodes5150 0:8a420ac6394e 58 int result = acquisitionSampleCount;
jrhodes5150 0:8a420ac6394e 59 mutex.unlock();
jrhodes5150 0:8a420ac6394e 60 return result;
jrhodes5150 0:8a420ac6394e 61 }
jrhodes5150 0:8a420ac6394e 62
jrhodes5150 0:8a420ac6394e 63 void DeviceProperties::AddAcquisitionSample( AcquisitionData &data)
jrhodes5150 0:8a420ac6394e 64 {
jrhodes5150 0:8a420ac6394e 65 mutex.lock();
jrhodes5150 0:8a420ac6394e 66 if (acquisitionSampleCount < MAX_ACQUISITION_SAMPLES)
jrhodes5150 0:8a420ac6394e 67 acquisitionData[acquisitionSampleCount++] = data;
jrhodes5150 0:8a420ac6394e 68 mutex.unlock();
jrhodes5150 0:8a420ac6394e 69 }
jrhodes5150 0:8a420ac6394e 70
jrhodes5150 0:8a420ac6394e 71 void DeviceProperties::ClearAcquisitionData(void)
jrhodes5150 0:8a420ac6394e 72 {
jrhodes5150 0:8a420ac6394e 73 mutex.lock();
jrhodes5150 0:8a420ac6394e 74 ++acquisitionNumber;
jrhodes5150 0:8a420ac6394e 75 acquisitionSampleCount = 0;
jrhodes5150 0:8a420ac6394e 76 mutex.unlock();
jrhodes5150 0:8a420ac6394e 77
jrhodes5150 0:8a420ac6394e 78 }
jrhodes5150 0:8a420ac6394e 79
jrhodes5150 0:8a420ac6394e 80 AcquisitionData DeviceProperties::GetAcquisitionSample(int acquisition, int sample)
jrhodes5150 0:8a420ac6394e 81 {
jrhodes5150 0:8a420ac6394e 82 mutex.lock();
jrhodes5150 0:8a420ac6394e 83 AcquisitionData result;
jrhodes5150 0:8a420ac6394e 84 if (acquisitionNumber==acquisition) {
jrhodes5150 0:8a420ac6394e 85 if (sample>=0 && sample<acquisitionSampleCount)
jrhodes5150 0:8a420ac6394e 86 result = acquisitionData[sample];
jrhodes5150 0:8a420ac6394e 87 }
jrhodes5150 0:8a420ac6394e 88 mutex.unlock();
jrhodes5150 0:8a420ac6394e 89 return result;
jrhodes5150 0:8a420ac6394e 90
jrhodes5150 0:8a420ac6394e 91 }
jrhodes5150 0:8a420ac6394e 92
jrhodes5150 0:8a420ac6394e 93 double DeviceProperties::GetActualPWMFrequency(void) const
jrhodes5150 0:8a420ac6394e 94 {
jrhodes5150 0:8a420ac6394e 95 mutex.lock();
jrhodes5150 0:8a420ac6394e 96 double result = actualPwmFrequency;
jrhodes5150 0:8a420ac6394e 97 mutex.unlock();
jrhodes5150 0:8a420ac6394e 98 return result;
jrhodes5150 0:8a420ac6394e 99 }
jrhodes5150 0:8a420ac6394e 100
jrhodes5150 0:8a420ac6394e 101
jrhodes5150 0:8a420ac6394e 102 void DeviceProperties::SetActualPWMFrequency(double frequency)
jrhodes5150 0:8a420ac6394e 103 {
jrhodes5150 0:8a420ac6394e 104 mutex.lock();
jrhodes5150 0:8a420ac6394e 105 this->actualPwmFrequency = frequency;
jrhodes5150 0:8a420ac6394e 106 mutex.unlock();
jrhodes5150 0:8a420ac6394e 107 }
jrhodes5150 0:8a420ac6394e 108
jrhodes5150 0:8a420ac6394e 109
jrhodes5150 0:8a420ac6394e 110
jrhodes5150 0:8a420ac6394e 111