Contain mission module with related structures and functions. More...
Data Structures | |
struct | pidData_t |
structure for holding PID related data More... | |
struct | measuredData_t |
structure for holding measured data values More... | |
struct | missiondata_t |
structure for holding mission specific data More... | |
struct | mission_t |
structure for mission related structures and data values More... | |
struct | logFile_t |
structure for log file related data More... | |
struct | missionLog_t |
structure for data values written to log file More... | |
struct | pid_controller |
Structure that holds PID all the PID controller data, multiple instances are posible using different structures for each controller. More... | |
Macros | |
#define | PID_kP 0.04 |
Default Kp term. More... | |
#define | PID_kI 0.0015 |
Default Ki term. More... | |
#define | PID_kD 0.05 |
Default Kd term. More... | |
#define | PID_kI_THRESHOLD 1.0 |
Default Ki threshold - When measured depth is further away than threshold Ki term is not part of pid calculation. More... | |
#define | PID_LIMIT_MIN 0 |
PID min limit = minimum piston position of 0.0 cm - End limit switches will stop motor at 0.0xx cm. More... | |
#define | PID_LIMIT_MAX 0.055 |
PID max limit = maximum piston position of 5.5 cm - End limit switches will stop motor at 5.1xx cm. More... | |
#define | MAX_DEPTH 50.0 |
Maximum allowable depth [m]. More... | |
#define | MIN_DEPTH 0.0 |
minimum allowable depth [m] More... | |
#define | PSI_RANGE 100.0 |
Differential sensor range: 14,7 psi to 114,7 psi. More... | |
#define | MEASURED_OFFSET 0.19 |
A measured pressure offset of ~ 0.19 psi. More... | |
#define | PSI_WEATHER_OFFSET 0.123 |
current offset barometric pressure in PSI. More... | |
#define | PSI_1ATM_PRESSURE 14.7 |
Standard barometric pressure in PSI. More... | |
#define | BAR_RANGE 5.89475728 |
Differential sensor range: 1 bar to 6,89475728 bar. More... | |
#define | SAADC_MAX 16320.0 |
#define | SAADC_MIN 1730 |
#define | PSI_TO_MH2O 0.703070 |
Convert PSI to Water column (MeterH2O) More... | |
#define | PSI_TO_PASCAL 6894.76 |
Convert PSI to pascal. More... | |
#define | SAADC_VOLTAGE_ERROR 0.022 |
Average error from calculated SAADC value to actual SAADC value. More... | |
#define | PASCAL_MAX 790828.66 |
Maximum pressure value in pascal. More... | |
#define | PASCAL_MIN 101352.90 |
Minimum pressure value in pascal. More... | |
#define | PRESSURE_VOLTAGE_MAX 4.5 |
Maximum pressure value in volts. More... | |
#define | PRESSURE_VOLTAGE_MIN 0.5 |
Minimum pressure value in volts. More... | |
#define | PRESSURE_VOLTAGE_RANGE 4.0 |
Pressure sensor voltage output range. More... | |
#define | MAX_NR_OF_MISSIONS 4 |
The maximum number of missions to be configured. More... | |
#define | DEFAULT_M1_DEPTH 1.5 |
Default mission1 depth in meter. More... | |
#define | DEFAULT_M1_TIME 180 |
Default mission1 time in seconds. More... | |
#define | DEFAULT_M2_DEPTH 1.0 |
Default mission2 depth in meter. More... | |
#define | DEFAULT_M2_TIME 180 |
Default mission1 depth in seconds. More... | |
#define | EMA_alpha 0.1 |
Exponential Moving Average 'alpha' Coefficient. More... | |
#define | TICK_SECOND 32768UL |
Instead of using systick, RTC is use, which run at 32,768 kHz. More... | |
Typedefs | |
typedef struct pid_controller * | pid_t |
Enumerations | |
enum | pid_control_directions { E_PID_DIRECT, E_PID_REVERSE } |
Defines if the controler is direct or reverse. More... | |
Functions | |
void | missionInit (void) |
Initialize mission module. More... | |
void | prepareMission () |
More... | |
void | runMission () |
More... | |
void | CalcPressureAndDepth (void) |
More... | |
void | missionLogInit () |
More... | |
void | updateMissionLog () |
More... | |
pid_t | pid_create (pid_t pid, float *in, float *out, float *set, float kp, float ki, float kd) |
Creates a new PID controller. More... | |
bool | pid_need_compute (pid_t pid) |
Check if PID loop needs to run. More... | |
void | pid_compute (pid_t pid) |
Computes the output of the PID control. More... | |
void | pid_tune (pid_t pid, float kp, float ki, float kd) |
Sets new PID tuning parameters. More... | |
void | pid_sample (pid_t pid, uint32_t time) |
Sets the pid algorithm period. More... | |
void | pid_limits (pid_t pid, float min, float max) |
Sets the limits for the PID controller output. More... | |
void | pid_auto (pid_t pid) |
Enables automatic control using PID. More... | |
void | pid_manual (pid_t pid) |
Disables automatic process control. More... | |
void | pid_direction (pid_t pid, enum pid_control_directions dir) |
Configures the PID controller direction. More... | |
Variables | |
bool | motorStopped |
Flag to signal motor stopped. More... | |
bool | bottomLimit |
Flag to signal when bottom limit switch is reached. More... | |
bool | SAADCdataReady = false |
Flag to signal SAADC data is ready to be read and calculated, and to run PID. More... | |
bool | sampleSensorData = false |
Flag to signal sampling battery, pressure, and TMP117. More... | |
bool | missionLogUpdated = false |
Flag to signal mission log is updated. More... | |
bool | TMP117dataReady = false |
Flag to signal TMP117 data is ready to be read. More... | |
bool | receiveTMP117 = false |
Flag to signal that data is expected to be received from TMP117. More... | |
float | EMA_state = 0.0 |
global filter output variable More... | |
missionLog_t | missionLog |
Create mission log instance. More... | |
struct pid_controller | ctrlData |
Create PID controller control data instance. More... | |
pid_t | pid |
Create PID controller instnace. More... | |
const float | SAADC_pressure_range = SAADC_MAX - SAADC_MIN |
const float | bar_pr_saadcValue = BAR_RANGE/SAADC_pressure_range |
const float | pascal_range = PASCAL_MAX-PASCAL_MIN |
const float | pascal_pr_volts = pascal_range/(PRESSURE_VOLTAGE_MAX-PRESSURE_VOLTAGE_MIN) |
mission_t | mission |
mission structure instance More... | |
Contain mission module with related structures and functions.
Contain TWI/I^2C module with related structures and functions.
#define BAR_RANGE 5.89475728 |
Differential sensor range: 1 bar to 6,89475728 bar.
#define DEFAULT_M1_DEPTH 1.5 |
Default mission1 depth in meter.
#define DEFAULT_M1_TIME 180 |
Default mission1 time in seconds.
#define DEFAULT_M2_DEPTH 1.0 |
Default mission2 depth in meter.
#define DEFAULT_M2_TIME 180 |
Default mission1 depth in seconds.
#define EMA_alpha 0.1 |
Exponential Moving Average 'alpha' Coefficient.
#define MAX_DEPTH 50.0 |
Maximum allowable depth [m].
#define MAX_NR_OF_MISSIONS 4 |
The maximum number of missions to be configured.
#define MEASURED_OFFSET 0.19 |
A measured pressure offset of ~ 0.19 psi.
#define MIN_DEPTH 0.0 |
minimum allowable depth [m]
#define PASCAL_MAX 790828.66 |
Maximum pressure value in pascal.
#define PASCAL_MIN 101352.90 |
Minimum pressure value in pascal.
#define PID_kD 0.05 |
Default Kd term.
#define PID_kI 0.0015 |
Default Ki term.
#define PID_kI_THRESHOLD 1.0 |
Default Ki threshold - When measured depth is further away than threshold Ki term is not part of pid calculation.
#define PID_kP 0.04 |
Default Kp term.
#define PID_LIMIT_MAX 0.055 |
PID max limit = maximum piston position of 5.5 cm - End limit switches will stop motor at 5.1xx cm.
#define PID_LIMIT_MIN 0 |
PID min limit = minimum piston position of 0.0 cm - End limit switches will stop motor at 0.0xx cm.
#define PRESSURE_VOLTAGE_MAX 4.5 |
Maximum pressure value in volts.
#define PRESSURE_VOLTAGE_MIN 0.5 |
Minimum pressure value in volts.
#define PRESSURE_VOLTAGE_RANGE 4.0 |
Pressure sensor voltage output range.
#define PSI_1ATM_PRESSURE 14.7 |
Standard barometric pressure in PSI.
Weight of air pushing on the water
#define PSI_RANGE 100.0 |
Differential sensor range: 14,7 psi to 114,7 psi.
#define PSI_TO_MH2O 0.703070 |
Convert PSI to Water column (MeterH2O)
#define PSI_TO_PASCAL 6894.76 |
Convert PSI to pascal.
#define PSI_WEATHER_OFFSET 0.123 |
current offset barometric pressure in PSI.
Weight of air pushing on the water
#define SAADC_MAX 16320.0 |
#define SAADC_MIN 1730 |
#define SAADC_VOLTAGE_ERROR 0.022 |
Average error from calculated SAADC value to actual SAADC value.
#define TICK_SECOND 32768UL |
Instead of using systick, RTC is use, which run at 32,768 kHz.
typedef struct pid_controller* pid_t |
void CalcPressureAndDepth | ( | void | ) |
Calculate pressure and current depth based on raw pressure from SAADC.
< Exponential Moving Average (EMA) filtering
void missionInit | ( | void | ) |
Initialize mission module.
Set data structures to NULL and populate with default data values. Create pid and configure pid regulator.
void missionLogInit | ( | ) |
Initialize mission log by setting the structure to zero.
void pid_auto | ( | pid_t | pid | ) |
Enables automatic control using PID.
Enables the PID control loop. If manual output adjustment is needed you can disable the PID control loop using pid_manual(). This function enables PID automatic control at program start or after calling pid_manual()
pid | The PID controller instance to enable |
void pid_compute | ( | pid_t | pid | ) |
Computes the output of the PID control.
This function computes the PID output based on the parameters, setpoint and current system input.
pid | The PID controller instance which will be used for computation |
Creates a new PID controller.
Creates a new pid controller and initializes it�s input, output and internal variables. Also we set the tuning parameters
pid | A pointer to a pid_controller structure |
in | Pointer to float value for the process input |
out | Poiter to put the controller output value |
set | Pointer float with the process setpoint value |
kp | Proportional gain |
ki | Integral gain |
kd | Diferential gain |
void pid_direction | ( | pid_t | pid, |
enum pid_control_directions | dir | ||
) |
Configures the PID controller direction.
Sets the direction of the PID controller. The direction is "DIRECT" when a increase of the output will cause a increase on the measured value and "REVERSE" when a increase on the controller output will cause a decrease on the measured value.
pid | The PID controller instance to modify |
direction | The new direction of the PID controller |
void pid_limits | ( | pid_t | pid, |
float | min, | ||
float | max | ||
) |
Sets the limits for the PID controller output.
pid | The PID controller instance to modify |
min | The minimum output value for the PID controller |
max | The maximum output value for the PID controller |
void pid_manual | ( | pid_t | pid | ) |
Disables automatic process control.
Disables the PID control loop. User can modify the value of the output variable and the controller will not overwrite it.
pid | The PID controller instance to disable |
bool pid_need_compute | ( | pid_t | pid | ) |
Check if PID loop needs to run.
Determines if the PID control algorithm should compute a new output value, if this returs true, the user should read process feedback (sensors) and place the reading in the input variable, then call the pid_compute() function.
Sets the pid algorithm period.
Changes the between PID control loop computations.
pid | The PID controller instance to modify |
time | The time in milliseconds between computations |
void pid_tune | ( | pid_t | pid, |
float | kp, | ||
float | ki, | ||
float | kd | ||
) |
Sets new PID tuning parameters.
Sets the gain for the Proportional (Kp), Integral (Ki) and Derivative (Kd) terms.
pid | The PID controller instance to modify |
kp | Proportional gain |
ki | Integral gain |
kd | Derivative gain |
void prepareMission | ( | void | ) |
prepare mission related settings.
Called before each new dive to calculate the number of missions based on configuration, clear previously stored data, and start/stop timers
< Enable PID controller.
void runMission | ( | ) |
run mission - measure data, calculate pid, and set piston position accordingly.
< If x meters away from target, run as PD regulator, otherwise run as PID regulator. This is so that it regulates quicker towards target
<Check for and handle RTC wrap around
< Divide 128 counts pr/ 1 *C
< In case bottom limit switch is already triggered
void updateMissionLog | ( | void | ) |
update mission log structure.
In order to get a consisten data set with values represented at the same time instance the mission log is updated with a snapshot of relevant data, then written to SD card.
const float bar_pr_saadcValue = BAR_RANGE/SAADC_pressure_range |
bool bottomLimit |
Flag to signal when bottom limit switch is reached.
struct pid_controller ctrlData |
Create PID controller control data instance.
float EMA_state = 0.0 |
global filter output variable
mission_t mission |
mission structure instance
mission structure instance
missionLog_t missionLog |
Create mission log instance.
bool missionLogUpdated = false |
Flag to signal mission log is updated.
bool motorStopped |
Flag to signal motor stopped.
Flag to signal motor stopped.
const float pascal_pr_volts = pascal_range/(PRESSURE_VOLTAGE_MAX-PRESSURE_VOLTAGE_MIN) |
const float pascal_range = PASCAL_MAX-PASCAL_MIN |
pid_t pid |
Create PID controller instnace.
bool receiveTMP117 = false |
Flag to signal that data is expected to be received from TMP117.
Flag to signal waiting for data from TMP117 temmperature sensor is ready to be read.
bool SAADCdataReady = false |
Flag to signal SAADC data is ready to be read and calculated, and to run PID.
Flag to signal SAADC is ready to be read.
bool sampleSensorData = false |
Flag to signal sampling battery, pressure, and TMP117.
bool TMP117dataReady = false |
Flag to signal TMP117 data is ready to be read.
Flag to signal data from TMP117 temmperature sensor is ready to be read.