Skip to content

Commit

Permalink
Added Vessel Output options
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyanush committed Jan 22, 2012
1 parent d9f7e18 commit 7bd2e7d
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 33 deletions.
Binary file modified .DS_Store
Binary file not shown.
13 changes: 12 additions & 1 deletion BTNIC_PROTOCOL_NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ Set Valve Profile Status -- b
User 1 profile:
From architecture wiki, User 1 bit mask = 131072
to Activate --> http://address/btnic.cgi?b&131072&1
to DeActivate --> http://address/btnic.cgi?b&131072&0
to DeActivate --> http://address/btnic.cgi?b&131072&0

Set/Get Output Settings -- D / N (HAS BUG!)

From wiki, the parameter for PID Cycle time should be set and received in units of Seconds, but it is actually done in tenths of seconds
EXAMPLE -->
If we have the PID cycle time for the HLT set to 1.0 seconds on the BT (checked via LCD) and call http://address/btnic.cgi?D0
we would expect to receive a response like ["timestamp", "D0", "HEATTYPE", "1", "PGAIN", "IGAIN", "DGAIN", "HYSTERESIS"]
but in reality we receive ["timestamp", "D0", "HEATTYPE", "10", "PGAIN", "IGAIN", "DGAIN", "HYSTERESIS", "UNKNOWN", "UNKNOWN"]

Also from wiki, the N command requires 6 parameters, but if you pass the N command with only 6 parameters the BT will return "#", "N0" indicating invalid parameters
in order to use the N command you must pass it 8 parameters, of which the last two have unknown functions.
2 changes: 1 addition & 1 deletion CSS/Panels.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@

.tempTarget {
position: relative;
left: 60px;
left: 70px;
top: 10px;
width: 200px;
text-shadow: 2px 3px 1px #FFFFFF;
Expand Down
19 changes: 17 additions & 2 deletions CSS/SettingsWindow.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@

#vesselSettings {
position: absolute;
top: -200px;
height: 195px;
top: -500px;
height: 290px;
width: 400px;
overflow: hidden;
background-color: rgba(121, 121, 121, .85);
box-shadow: 2px 3px 7px 3px #000;
border: solid 2px rgba(5, 5, 70, 0.80); border-radius: 12px; -webkit-border-radius: 12px; -moz-border-radius: 12px;
Expand Down Expand Up @@ -142,6 +143,15 @@ div.valveSetCheckBox > div:last-child {
margin-top: 0px !important;
}

/* Rules for the VesselSettings window*/
#PIDSettings {
display: none;
}

.vesselSettingsPIDEnabled {
height: 390px !important;
}

input[type="checkbox"] {
display: none;
}
Expand All @@ -164,6 +174,11 @@ input[type="checkbox"]:checked + label {
background-position: -3px 0;
}

input[type="checkbox"]:disabled + label {

opacity: .3;
}

.fieldsetWrapper {

margin: 10px 10px 10px 10px;
Expand Down
12 changes: 10 additions & 2 deletions JS/Classes/BrewTroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ function BrewTroller() {
if (hltDisp && (hlt.display.style.display == "none")){
hlt.show();
}
else if (!hltDisp && (hlt.display.style.display =! "none")){
else if (!hltDisp && (hlt.display.style.display != "none")){
hlt.hide();
}

if (mltDisp && (mlt.display.style.display == "none")){
mlt.show();
}
else if (!mltDisp && (mlt.display.style.display =! "none")){
else if (!mltDisp && (mlt.display.style.display != "none")){
mlt.hide();
}

Expand Down Expand Up @@ -211,6 +211,9 @@ function BrewTroller() {
this.initSync = function() {
BrewTroller.setVersion();
BrewTroller.updateVessels();
for (i = 0; i < BrewTroller.Vessels.length; i++){
BrewTroller.Vessels[i].initSync();
}
BrewTroller.valves.updateAllConfig();
BrewTroller.valves.updateStatus();
};
Expand Down Expand Up @@ -271,6 +274,11 @@ function BrewTroller() {
}
};

//Method sends command to BT to scan for temp sensors, and returns the address of the first unassigned sensor as an array of bytes
this.scanForTempSensor = function(){

};

this.initSetup = function() {

//run initSetup() for each vessel
Expand Down
183 changes: 165 additions & 18 deletions JS/Classes/Vessel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@ function Vessel(Index) {

//Private Class Variables

//Vessel IDs
var vesselIndex = Index;
var vesselName;

//indicates if the vessel's panel is visible in the viewport
var visible = true;

//indicates if the vessel has volume sensing implemented
var hasVolumeSensing = true; //default to true

//vessel volume parameters
var vesselCapacity;
var vesselDeadSpace;
var volumeTarget = 0;
var volumeconfigs = new Array(10);

//vessel output parameters
var PIDMode;
var PIDCycle;
var PIDGainP;
var PIDGainI;
var PIDGainD;
var hysteresis;

//vessel temperature parameters
var currenttemp;
var temperatureSetPoint = 0;
var tempSensorAddress = new Array(8);

//task for autoUpdate
var updateTask = {
Expand All @@ -27,13 +43,14 @@ function Vessel(Index) {
var autoUpdate = false;
var updateID;

//command parameter variables
//BrwTroller command parameter variables
var getTemp = 'q';
var getVol = 'p';
var getHeat = 's';
var getSetPoint = 't';

var setSetPoint = 'X';
var getOutput = 'D';
var setOutput = 'N';

// reference to this Vessel Instance's display wrapper div
this.display;
Expand Down Expand Up @@ -156,6 +173,103 @@ function Vessel(Index) {
return vesselCapacity;
};

//Method to enable or disable PID Mode, option argument is a BOOL
this.setPIDMode = function(option) {
if (PIDMode == undefined){
PIDMode = option;
}
else {
if (PIDMode != option){
PIDMode = option;
BrewTroller.communicate(BrewTroller.getAddress() + setOutput + vesselIndex + '&' + Number(PIDMode) + '&' + (PIDCycle*10) + '&' + PIDGainP + '&' + PIDGainI + '&' + PIDGainD + '&' + (hysteresis*10) + '&0&0', function(){});
}
}
}

this.getPIDMode = function() {

return PIDMode;
}

//Method to Set the PID Cycle Time
this.setPIDCycle = function(cycleTime) {

if (PIDCycle == undefined){
PIDCycle = cycleTime;
} else {
PIDCycle = cycleTime;
BrewTroller.communicate(BrewTroller.getAddress() + setOutput + vesselIndex + '&' + Number(PIDMode) + '&' + (PIDCycle*10) + '&' + PIDGainP + '&' + PIDGainI + '&' + PIDGainD + '&' + (hysteresis*10) + '&0&0', function(){});
}
}

this.getPIDCycle = function() {

return PIDCycle;
}

//Method to set the PID P Gain
this.setPIDPGain = function(newValue) {
if (PIDGainP == undefined){
PIDGainP = newValue;
} else {
PIDGainP = newValue;
BrewTroller.communicate(BrewTroller.getAddress() + setOutput + vesselIndex + '&' + Number(PIDMode) + '&' + (PIDCycle*10) + '&' + PIDGainP + '&' + PIDGainI + '&' + PIDGainD + '&' + (hysteresis*10) + '&0&0', function(){});
}
}

this.getPIDPGain = function() {

return PIDGainP;
}

//Method to set the PID I Gain
this.setPIDIGain = function(newValue) {

if (PIDGainI == undefined){
PIDGainI = newValue;
} else {
PIDGainI = newValue;
BrewTroller.communicate(BrewTroller.getAddress() + setOutput + vesselIndex + '&' + Number(PIDMode) + '&' + (PIDCycle*10) + '&' + PIDGainP + '&' + PIDGainI + '&' + PIDGainD + '&' + (hysteresis*10) + '&0&0', function(){});
}
}

this.getPIDIGain = function() {

return PIDGainI;
}

//Method to set the PID D Gain
this.setPIDDGain = function(newValue) {

if (PIDGainD == undefined){
PIDGainD = newValue;
} else {
PIDGainD = newValue;
BrewTroller.communicate(BrewTroller.getAddress() + setOutput + vesselIndex + '&' + Number(PIDMode) + '&' + (PIDCycle*10) + '&' + PIDGainP + '&' + PIDGainI + '&' + PIDGainD + '&' + (hysteresis*10) + '&0&0', function(){});
}
}

this.getPIDDGain = function() {

return PIDGainD;
}

//Method to set the ON/OFF hysteresis value
this.setHysteresis = function(newValue) {

if (hysteresis == undefined) {
hysteresis = newValue;
} else {
hysteresis = newValue;
BrewTroller.communicate(BrewTroller.getAddress() + setOutput + vesselIndex + '&' + Number(PIDMode) + '&' + (PIDCycle*10) + '&' + PIDGainP + '&' + PIDGainI + '&' + PIDGainD + '&' + (hysteresis*10) + '&0&0', function(){});
}
}

this.getHysteresis = function() {

return hysteresis;
}

//sets the value for the setpoint window and then calls BTUI.viewPort.showTempSetPoint() to show it
this.changeSetPoint = function() {

Expand Down Expand Up @@ -192,16 +306,6 @@ function Vessel(Index) {
this.tempTargetDisplay.textContent = temperatureSetPoint + String.fromCharCode(186);
}

//Set the temperature range of the Temperature Gauge chart
this.setTemperatureRange = function(newMin, newMax) {

var tempGauge = this.display.down('#tempGauge' + vesselIndex);

tempGauge.axes.items[0].minimum = newMin;
tempGauge.axes.items[0].maximum = newMax;
tempGauge.redraw();
}

//Get last temperature reading from store
this.getTemperature = function() {

Expand All @@ -225,6 +329,13 @@ function Vessel(Index) {
var update = document.getElementById('vesselAutoUpdate');
var updateFreq = document.getElementById('vesselUpdateFrequency');
var settingsTitle = document.getElementById('vesselSettingsTitle');
var pidModeSwitch = document.getElementById('vesselPIDMode');
var hysteresisEl = document.getElementById('OnOffHysteresis');
var pGain = document.getElementById('PIDPGain');
var iGain = document.getElementById('PIDIGain');
var dGain = document.getElementById('PIDDGain');
var pidCycle = document.getElementById('PIDCycleTime');


//Set the window's title to reflect the selected vessel
settingsTitle.firstElementChild.textContent = vesselName + ' Settings';
Expand All @@ -233,17 +344,30 @@ function Vessel(Index) {
update.checked = autoUpdate;
updateFreq.value = updateTask.interval;

//Set the settings window's data-vessel-index attribute to this vessel's index
settingsWindow.dataset.vesselIndex = vesselIndex;
//Set the heat output settings to match current values
pidModeSwitch.checked = this.getPIDMode();
pidModeSwitch.onchange(); //manually fire the onchange event to make sure it carries out the function

pGain.value = this.getPIDPGain();
iGain.value = this.getPIDIGain();
dGain.value = this.getPIDDGain();
pidCycle.value = this.getPIDCycle();
hysteresisEl.value = this.getHysteresis();

//Show the vessel settings window
BTUI.viewPort.showVesselSettings();
//Set the settings window's data-vessel-index attribute to this vessel's index
settingsWindow.dataset.vesselIndex = vesselIndex;
};

this.saveSettings = function() {

var update = document.getElementById('vesselAutoUpdate').checked;
var updateFreq = document.getElementById('vesselUpdateFrequency').value;
var pidModeSwitch = document.getElementById('vesselPIDMode');
var hysteresis = document.getElementById('OnOffHysteresis');
var pGain = document.getElementById('PIDPGain');
var iGain = document.getElementById('PIDIGain');
var dGain = document.getElementById('PIDDGain');
var pidCycle = document.getElementById('PIDCycleTime');

//set update frequency
if (updateFreq != this.getUpdateFrequency()){
Expand All @@ -261,6 +385,13 @@ function Vessel(Index) {
}
}

//Set output options
this.setPIDMode(pidModeSwitch.checked);
this.setHysteresis(hysteresis.value);
this.setPIDPGain(pGain.value);
this.setPIDIGain(iGain.value);
this.setPIDDGain(dGain.value);
this.setPIDCycle(pidCycle.value);
};

this.updateVessel = function(){
Expand Down Expand Up @@ -356,10 +487,26 @@ function Vessel(Index) {

//Link the settings and refresh buttons with this instance
this.display.getElementsByClassName('update')[0].onclick = function(){BrewTroller.Vessels[vesselIndex].manualUpdate();};
this.display.getElementsByClassName('settings')[0].onclick =function(){BrewTroller.Vessels[vesselIndex].settings();};
this.display.getElementsByClassName('tempset')[0].onclick = function(){BrewTroller.Vessels[vesselIndex].changeSetPoint();};
};

//Method called on initial synchronization with BrewTroller, here we pull down options like heat ouput settings, temp sensor addresses
this.initSync = function() {

var outputCallback = function(vesselIndex, xhr){
var resp = JSON.parse(xhr.responseText);
var vessel = BrewTroller.Vessels[vesselIndex];
vessel.setPIDMode(Boolean(Number(resp[2]))); //We must first typecast this as a number then a BOOL, as it is parsed as a string
vessel.setPIDCycle(Number(resp[3])/10);
vessel.setPIDPGain(Number(resp[4]));
vessel.setPIDIGain(Number(resp[5]));
vessel.setPIDDGain(Number(resp[6]));
vessel.setHysteresis(Number(resp[7])/10);
}

BrewTroller.communicate(BrewTroller.getAddress() + getOutput + vesselIndex, outputCallback, vesselIndex);
}

this.setVesselName();

}
Loading

0 comments on commit 7bd2e7d

Please sign in to comment.