Pseudo Code To Convert To Apex Program - A Technical Challenge :)

Ben Pedersen

Valuable Member
View Badges
Joined
Jun 7, 2018
Messages
1,050
Reaction score
953
Rating - 0%
0   0   0
I have written some Pseudo code and would like to convert it to Apex. Please take a look and let me know how. I have included a picture to help.

C165B512-9147-4612-80F7-86634E3407B8.png


Pseudo Code:

# System Variable(s)
Variable System-Time

# Sensor Variable(s)
Variable Sensor-ATO-AWC-Level-Normal
Variable Sensor-ATO-AWC-Level-High
Variable Sensor-ATO-Reservoir-Level
Variable Sensor-AWC-Reservoir-Level
Variable Sensor-AWC-Remove-Level-Normal
Variable Sensor-AWC-Remove-Level-Low

# Pump Variable(s)
Variable Pump-ATO-Add
Variable Pump-AWC-Add
Variable Pump-AWC-Remove

# Switch Variable(s)
Variable Switch-ATO-Process
Variable Switch-Reset-ATO-Process
Variable Switch-AWC-Process
Variable Switch-AWC-Remove-Process
Variable Switch-AWC-Add-Process
Variable Switch-Reset-AWC-Process
Variable Switch-Force-AWC-Process


#########################################
# Kick Off ATO Process
#########################################
IF(Sensor-ATO-AWC-Level-Normal == Off && Sensor-ATO-AWC-Level-High = Off && Switch-AWC-Process !== "Failed"){

# Call Do ATO Process
Call SUB Do-ATO-Process();

}


#########################################
# Kick Off AWC Process
#########################################
IF((System-Time == 4:00PM || Switch-AWC-Process == "Started" || Force-AWC-Process == True) && Switch-AWC-Process !== "Failed"){

# Call Do AWC Process
Call SUB Do-AWC-Process();

}


#########################################
# Reset ATO Process After Failure
#########################################
IF(Switch-Reset-ATO-Process == "True"){

# Reset AWC Process To Enable Process For Next Run
Set Switch-ATO-Process = "";
Set Switch-Reset-ATO-Process == ""

}

#########################################
# Reset AWC Process After Failure
#########################################
IF(Switch-Reset-AWC-Process == "True"){

# Reset AWC Process To Enable Process For Next Run
Set Switch-AWC-Process = "";
Set Switch-AWC-Remove-Process = "";
Set Switch-AWC-Add-Process = "";
Set Switch-Reset-AWC-Process == ""

}

#########################################
# AWC Process
#########################################
SUB Do-AWC-Process(){

# Set AWC In Process Switch
Set Switch-AWC-Process = "Started";

# If AWC Reservoir Has Water
IF(Sensor-AWC-Reservoir-Level == On){

# If Water Level Is Low And Water Level Is Not High
IF(Sensor-ATO-AWC-Level-Normal !== On && Sensor-ATO-AWC-Level-High !== On){

# Turn On ATO Process To Fill Water To Normal Level
Call SUB Do-ATO-Process ();

}
# ATO Level Is Normal Or High
ELSE{

# If ATO Fill Level Is Normal
IF(Sensor-ATO-AWC-Level-Normal == On && Sensor-ATO-AWC-Level-High !== On){

# If AWC Remove Water Process Not Equal To Complete
IF(Switch-AWC-Remove-Process !== "Complete"){

# Call Remove Water For AWC Process
Call SUB Do-AWC-Remove-Water-Process();

}

# If AWC Add Water Process Not Equal To Complete
IF(Switch-AWC-Remove-Process == "Complete"){

# Call Add Water For AWC Process
Call SUB Do-AWC-Add-Water-Process();

}
}
# ATO Fill Level Is High
ELSE{

# Send Error Notification - Water Level To High
Send Notification: "Could Not Complete AWC Because Water Level Is Too High";

# Set AWC Process To Failed
Set Switch-AWC-Process = "Failed";
Set Variable Switch-AWC-Remove-Process = "";
Set Variable Switch-AWC-Add-Process = "";

}
}
}
# AWC Reservoir Does Not Have Enough Water
ELSE{

# Send Error Notification - Low AWC Water Level
Send Notification: "Could Not Complete AWC Because Reservoir Water Level Was Low";

# Set AWC Process To Failed
Set Switch-AWC-Process = "Failed";
Set Variable Switch-AWC-Remove-Process = "";
Set Variable Switch-AWC-Add-Process = "";

}
}


#########################################
# ATO Process
#########################################
SUB Do-ATO-Process(){

# Set ATO Process To Started
Set Switch-ATO-Process = "Started";

# If ATO Reservoir Has Water
IF(Sensor-ATO-Reservoir-Level == On){

# Turn On ATO Add Water Pump Until Water Level Up To Normal Or High Sensor
Turn On Pump-ATO-Add UNTIL (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On);

# Turn On ATO Add Water Pump Until Water Level Up To Normal Or High Sensor
if(Switch-ATO-Process == "Started" && (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On)){

# Set AWC Remove Water Process To Complete
Set Switch-ATO-Process = "Complete";

}
}
# ATO Reservoir Does Not Have Enough Water
ELSE{

# Send Error Notification - Low ATO Water Level
Send Notification: "Could Not Complete ATO Because Reservoir Water Level Was Low";

# Update ATO Process To Failed
Set Switch-ATO-Process = "Failed";

}
}


#########################################
# AWC Remove Water Process
#########################################
SUB Do-AWC-Remove-Water-Process(){

# Set AWC Remove Water Process To Started
Set Switch-AWC-Remove-Process = "Started";

# Turn On AWC Remove Water Pump Until Water Level Down To Normal Or Low Sensor
Turn On Pump-AWC-Remove UNTIL (Sensor-AWC-Remove-Level-Normal == Off || Sensor-AWC-Remove-Level-Low == Off);

# If AWC Level Normal Or ATO Level High
if(Switch-AWC-Remove-Process == "Started" && (Sensor-AWC-Remove-Level-Normal == Off || Sensor-AWC-Remove-Level-Low == Off)){

# Set AWC Remove Water Process To Complete
Set Switch-AWC-Remove-Process = "Complete";

}
}


#########################################
# AWC Add Water Process
#########################################
SUB Do-AWC-Add-Water-Process(){

# Set AWC Add Water Process To Started
Set Switch-AWC-Add-Process = "Started";

# Turn On AWC Add Water Pump Until Water Level Up To Normal Or High Sensor
Turn On Pump-AWC-Add UNTIL (Sensor-AWC-Add-Level-Normal == On || Sensor-AWC-Add-Level-High == On);

# If AWC Add Started And Normal Or High Water Level Sensor Is On
if(Switch-AWC-Add-Process == "Started" && (Sensor-ATO-AWC-Level-Normal == On || Sensor-ATO-AWC-Level-High == On)){

# Rest AWC Switch Variables For Next Run
Set Switch-AWC-Process = "";
Set Switch-AWC-Remove-Process = "";
Set Switch-AWC-Add-Process = "";

}
}
 
I have done this on the Hydros but not Apex. The only difference I see in how I do it is I do not use a lower AWC normal sensor. I run the drain pump for 11 minutes. I use dosing pumps for the Drain, Fill and ATO. The system will disable the ATO and start the drain pump and it runs for 11 minutes. When the drain turns off the fill pump will run until the full sensor is wet. Then the ATO is enabled. That is pretty much it other than the other sensors and outputs that will stop the water change if there is an issue.
 
It would be better for you to word this in plain English rather than pseudo code. Its way too hard to follow as is. The apex is not capable of doing things like calling subfunctions.

Also impossible to convert this to code without knowing OPEN vs CLOSED state of switches.
 
It would be better for you to word this in plain English rather than pseudo code. Its way too hard to follow as is. The apex is not capable of doing things like calling subfunctions.

Also impossible to convert this to code without knowing OPEN vs CLOSED state of switches.
Woops.... Ya.... On equals Open and Off equals closed. There is a human readable comment on each line of code. It does t help that the code lost it's formatting when displayed in the post.

Ya... APEX does not have concepts like else if or else.. nor even variable declaration and set, but was hoping someone with a technical background could translate it. :)
 
Woops.... Ya.... On equals Open and Off equals closed. There is a human readable comment on each line of code. It does t help that the code lost it's formatting when displayed in the post.

Ya... APEX does not have concepts like else if or else.. nor even variable declaration and set, but was hoping someone with a technical background could translate it. :)
Here is one example of a drain then fill AWC I helped someone else program a while ago.


Some other things that might be helpful for someone with a technical background.

AND logic

If condition 1 Then ON
If opposite condition 2 Then OFF


Latching OFF timer
When ON > xxx:xx Then OFF


Also helps if you remember that this is a sequential scripting language and more or less forget everything you know about when, while, subfunctions, and arrays.
 
Here is one example of a drain then fill AWC I helped someone else program a while ago.


Some other things that might be helpful for someone with a technical background.

AND logic

If condition 1 Then ON
If opposite condition 2 Then OFF


Latching OFF timer
When ON > xxx:xx Then OFF


Also helps if you remember that this is a sequential scripting language and more or less forget everything you know about when, while, subfunctions, and arrays.
Just read your post on the APEX site... looks good.. I will use it. I may have a question or 2.. if you dont mind. :)
 

IF YOU HAD TO TAKE A REEFING EXAM, WOULD YOU PASS?

  • Yes!

    Votes: 32 45.7%
  • Not yet, but I have one that I want to buy in mind!

    Votes: 9 12.9%
  • No.

    Votes: 26 37.1%
  • Other (please explain).

    Votes: 3 4.3%
Back
Top