Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ICE-Application/src/ConfigurationHandler/Controls/SetpointControl.h@0:61364762ee0e, 2017-01-24 (annotated)
- Committer:
- jmarkel44
- Date:
- Tue Jan 24 19:05:33 2017 +0000
- Revision:
- 0:61364762ee0e
Port from IAR to Nucleo-F412 board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 0:61364762ee0e | 1 | /****************************************************************************** |
jmarkel44 | 0:61364762ee0e | 2 | * |
jmarkel44 | 0:61364762ee0e | 3 | * File: SetpointControl.h |
jmarkel44 | 0:61364762ee0e | 4 | * Desciption: ICE Timer Control Class |
jmarkel44 | 0:61364762ee0e | 5 | * |
jmarkel44 | 0:61364762ee0e | 6 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 7 | #ifndef SETPOINTCONTROL_H |
jmarkel44 | 0:61364762ee0e | 8 | #define SETPOINTCONTROL_H |
jmarkel44 | 0:61364762ee0e | 9 | |
jmarkel44 | 0:61364762ee0e | 10 | #include <string> |
jmarkel44 | 0:61364762ee0e | 11 | #include <stdio.h> |
jmarkel44 | 0:61364762ee0e | 12 | |
jmarkel44 | 0:61364762ee0e | 13 | typedef enum { |
jmarkel44 | 0:61364762ee0e | 14 | SETPOINT_CONTROL_OK, |
jmarkel44 | 0:61364762ee0e | 15 | SETPOINT_CONTROL_UNK_STATE, |
jmarkel44 | 0:61364762ee0e | 16 | SETPOINT_CONTROL_ERROR, |
jmarkel44 | 0:61364762ee0e | 17 | SETPOINT_CONTROL_DESTROY |
jmarkel44 | 0:61364762ee0e | 18 | } SetpointControlError_t; |
jmarkel44 | 0:61364762ee0e | 19 | |
jmarkel44 | 0:61364762ee0e | 20 | // A setpoint control is a control based on a process variable with respect |
jmarkel44 | 0:61364762ee0e | 21 | // to a user defined control band. The output of this control object is a |
jmarkel44 | 0:61364762ee0e | 22 | // true/false decision (for a relay, true means power on the relay). |
jmarkel44 | 0:61364762ee0e | 23 | |
jmarkel44 | 0:61364762ee0e | 24 | //! SetpointControl - implements a setpoint control |
jmarkel44 | 0:61364762ee0e | 25 | class SetpointControl |
jmarkel44 | 0:61364762ee0e | 26 | { |
jmarkel44 | 0:61364762ee0e | 27 | private: |
jmarkel44 | 0:61364762ee0e | 28 | std::string controlFile; // name of the control file |
jmarkel44 | 0:61364762ee0e | 29 | std::string id; // control identifier |
jmarkel44 | 0:61364762ee0e | 30 | int priority; // control priority |
jmarkel44 | 0:61364762ee0e | 31 | std::string input; // control input |
jmarkel44 | 0:61364762ee0e | 32 | std::string output; // control output |
jmarkel44 | 0:61364762ee0e | 33 | double setpoint; // setpoint value |
jmarkel44 | 0:61364762ee0e | 34 | double productFactor; |
jmarkel44 | 0:61364762ee0e | 35 | bool actingDir; // acting direction, 1 direct - pH, 0 indirect - inhibitor |
jmarkel44 | 0:61364762ee0e | 36 | #if 0 |
jmarkel44 | 0:61364762ee0e | 37 | double highAlert; |
jmarkel44 | 0:61364762ee0e | 38 | double lowAlert; |
jmarkel44 | 0:61364762ee0e | 39 | double highFailsafe; |
jmarkel44 | 0:61364762ee0e | 40 | double lowFailsafe; |
jmarkel44 | 0:61364762ee0e | 41 | #endif |
jmarkel44 | 0:61364762ee0e | 42 | double tolerance; // the error margining |
jmarkel44 | 0:61364762ee0e | 43 | enum State { |
jmarkel44 | 0:61364762ee0e | 44 | STATE_INIT, |
jmarkel44 | 0:61364762ee0e | 45 | STATE_STARTUP, |
jmarkel44 | 0:61364762ee0e | 46 | STATE_CONTROL_OFF, |
jmarkel44 | 0:61364762ee0e | 47 | STATE_CONTROL_ON, |
jmarkel44 | 0:61364762ee0e | 48 | STATE_DISABLE, |
jmarkel44 | 0:61364762ee0e | 49 | STATE_RELOAD, |
jmarkel44 | 0:61364762ee0e | 50 | STATE_MAX |
jmarkel44 | 0:61364762ee0e | 51 | }; |
jmarkel44 | 0:61364762ee0e | 52 | State currentState; |
jmarkel44 | 0:61364762ee0e | 53 | |
jmarkel44 | 0:61364762ee0e | 54 | bool validateControlData(const char *buf); |
jmarkel44 | 0:61364762ee0e | 55 | void copyControlData(const char *buf); |
jmarkel44 | 0:61364762ee0e | 56 | |
jmarkel44 | 0:61364762ee0e | 57 | bool underLimit(); // check if reading is under the limit |
jmarkel44 | 0:61364762ee0e | 58 | bool overLimit(); // check if reading is over the limit |
jmarkel44 | 0:61364762ee0e | 59 | |
jmarkel44 | 0:61364762ee0e | 60 | void startFeed(void); // start a feed |
jmarkel44 | 0:61364762ee0e | 61 | void stopFeed(void); // stop a feed |
jmarkel44 | 0:61364762ee0e | 62 | |
jmarkel44 | 0:61364762ee0e | 63 | bool isVirtualOutput; // output is virtual |
jmarkel44 | 0:61364762ee0e | 64 | public: |
jmarkel44 | 0:61364762ee0e | 65 | /// create a setpoint control |
jmarkel44 | 0:61364762ee0e | 66 | SetpointControl() { |
jmarkel44 | 0:61364762ee0e | 67 | currentState = STATE_INIT; |
jmarkel44 | 0:61364762ee0e | 68 | }; |
jmarkel44 | 0:61364762ee0e | 69 | /// destroy a setpoint control |
jmarkel44 | 0:61364762ee0e | 70 | ~SetpointControl() { |
jmarkel44 | 0:61364762ee0e | 71 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 0:61364762ee0e | 72 | } |
jmarkel44 | 0:61364762ee0e | 73 | |
jmarkel44 | 0:61364762ee0e | 74 | /// load setpoint control data from a JSON configuration file |
jmarkel44 | 0:61364762ee0e | 75 | bool load(std::string filename); |
jmarkel44 | 0:61364762ee0e | 76 | |
jmarkel44 | 0:61364762ee0e | 77 | /// unregister a setpoint control from the output thread |
jmarkel44 | 0:61364762ee0e | 78 | void unregisterControl(void); |
jmarkel44 | 0:61364762ee0e | 79 | |
jmarkel44 | 0:61364762ee0e | 80 | /// start a setpoint control instance |
jmarkel44 | 0:61364762ee0e | 81 | void start(void); |
jmarkel44 | 0:61364762ee0e | 82 | |
jmarkel44 | 0:61364762ee0e | 83 | /// update a setpoint control instance |
jmarkel44 | 0:61364762ee0e | 84 | SetpointControlError_t update(void); |
jmarkel44 | 0:61364762ee0e | 85 | |
jmarkel44 | 0:61364762ee0e | 86 | //display the pertinents |
jmarkel44 | 0:61364762ee0e | 87 | void display(void); |
jmarkel44 | 0:61364762ee0e | 88 | |
jmarkel44 | 0:61364762ee0e | 89 | std::string getControlFile(void) const { |
jmarkel44 | 0:61364762ee0e | 90 | return controlFile; |
jmarkel44 | 0:61364762ee0e | 91 | } |
jmarkel44 | 0:61364762ee0e | 92 | std::string getId(void) const { |
jmarkel44 | 0:61364762ee0e | 93 | return id; |
jmarkel44 | 0:61364762ee0e | 94 | } |
jmarkel44 | 0:61364762ee0e | 95 | unsigned int getPriority(void) const { |
jmarkel44 | 0:61364762ee0e | 96 | return priority; |
jmarkel44 | 0:61364762ee0e | 97 | } |
jmarkel44 | 0:61364762ee0e | 98 | std::string getInput(void) const { |
jmarkel44 | 0:61364762ee0e | 99 | return input; |
jmarkel44 | 0:61364762ee0e | 100 | } |
jmarkel44 | 0:61364762ee0e | 101 | std::string getOutput(void) const { |
jmarkel44 | 0:61364762ee0e | 102 | return output; |
jmarkel44 | 0:61364762ee0e | 103 | } |
jmarkel44 | 0:61364762ee0e | 104 | float getProductFactor(void) const { |
jmarkel44 | 0:61364762ee0e | 105 | return productFactor; |
jmarkel44 | 0:61364762ee0e | 106 | } |
jmarkel44 | 0:61364762ee0e | 107 | int getActingDir(void) const { |
jmarkel44 | 0:61364762ee0e | 108 | return actingDir; |
jmarkel44 | 0:61364762ee0e | 109 | } |
jmarkel44 | 0:61364762ee0e | 110 | float getSetpoint(void) const { |
jmarkel44 | 0:61364762ee0e | 111 | return setpoint; |
jmarkel44 | 0:61364762ee0e | 112 | } |
jmarkel44 | 0:61364762ee0e | 113 | |
jmarkel44 | 0:61364762ee0e | 114 | State getCurrentState(void) const { |
jmarkel44 | 0:61364762ee0e | 115 | return currentState; |
jmarkel44 | 0:61364762ee0e | 116 | } |
jmarkel44 | 0:61364762ee0e | 117 | }; |
jmarkel44 | 0:61364762ee0e | 118 | |
jmarkel44 | 0:61364762ee0e | 119 | #endif |