Added Interlock
Fixed PID regulation functionality git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@250 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -24,6 +24,7 @@ ARFLAGS = rs
|
||||
|
||||
OBJECTS = \
|
||||
DisplayDevice.o \
|
||||
Interlock.o \
|
||||
IODevice.o \
|
||||
KeyboardDevice.o \
|
||||
Logger.o \
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file Interlock.h
|
||||
/// @brief File description
|
||||
// -----------------------------------------------------------------------------
|
||||
// Micro-Key bv
|
||||
// Industrieweg 28, 9804 TG Noordhorn
|
||||
// Postbus 92, 9800 AB Zuidhorn
|
||||
// The Netherlands
|
||||
// Tel: +31 594 503020
|
||||
// Fax: +31 594 505825
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2015 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @defgroup {group_name} {group_description}
|
||||
/// Description
|
||||
|
||||
/// @file Interlock.h
|
||||
/// @ingroup {group_name}
|
||||
|
||||
#ifndef INC_INTERLOCK_H_
|
||||
#define INC_INTERLOCK_H_
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#include "stm32f10x_exti.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct InterlockElement
|
||||
{
|
||||
struct Gpio* io;
|
||||
EXTI_InitTypeDef ioEXTI;
|
||||
};
|
||||
|
||||
struct Interlock
|
||||
{
|
||||
struct InterlockElement NO;
|
||||
struct InterlockElement NC;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Interlock_construct
|
||||
* Description of function
|
||||
*
|
||||
* @param self
|
||||
* @param NO
|
||||
* @param NOEXTI
|
||||
* @param NC
|
||||
* @param NCEXTI
|
||||
*
|
||||
* @return ErrorStatus
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus Interlock_construct(struct Interlock* self, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Interlock_getStatus
|
||||
* Get the current status of the interlock
|
||||
*
|
||||
* @param self Interlock object
|
||||
* @param command Interrupt status
|
||||
* @param NO value on GPIO NO
|
||||
* @param NC value on GPIO NC
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void Interlock_getStatus(struct Interlock* self, FunctionalState* command, int* NO, int* NC);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Interlock_isClosed
|
||||
* Check for interlock closed. Scans both I/Os
|
||||
*
|
||||
* @param self The interlock object
|
||||
*
|
||||
* @return bool TRUE is NC=1 and NO=0
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern bool Interlock_isClosed(struct Interlock* self);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Interlock_setEXTI
|
||||
* Description of function
|
||||
*
|
||||
* @param self
|
||||
* @param command
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void Interlock_setEXTI(struct Interlock* self, FunctionalState command);
|
||||
|
||||
#endif /* INC_INTERLOCK_H_ */
|
||||
@@ -39,7 +39,7 @@
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define PID_FIXED_POINT_FACTOR (1000)
|
||||
#define PID_FIXED_POINT_FACTOR (10000)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
@@ -92,6 +92,6 @@ extern ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd, int i
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern int PID_calculate(struct Pid* self, int input, int error);
|
||||
extern int PID_calculate(struct Pid* self, int error);
|
||||
|
||||
#endif /* INC_PID_H_ */
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file Interlock.c
|
||||
/// @brief Description
|
||||
// -----------------------------------------------------------------------------
|
||||
// Micro-Key bv
|
||||
// Industrieweg 28, 9804 TG Noordhorn
|
||||
// Postbus 92, 9800 AB Zuidhorn
|
||||
// The Netherlands
|
||||
// Tel: +31 594 503020
|
||||
// Fax: +31 594 505825
|
||||
// Email: support@microkey.nl
|
||||
// Web: www.microkey.nl
|
||||
// -----------------------------------------------------------------------------
|
||||
/// $Revision$
|
||||
/// $Author$
|
||||
/// $Date$
|
||||
// (c) 2017 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @file Interlock.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "Interlock.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ErrorStatus Interlock_construct(struct Interlock* self, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
if (!self->initialized)
|
||||
{
|
||||
self->NO.io = NO;
|
||||
self->NO.ioEXTI = NOEXTI;
|
||||
self->NC.io = NC;
|
||||
self->NC.ioEXTI = NCEXTI;
|
||||
self->initialized = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void Interlock_getStatus(struct Interlock* self, FunctionalState* command, int* NO, int* NC)
|
||||
{
|
||||
*command = self->NO.ioEXTI.EXTI_LineCmd;
|
||||
|
||||
IODevice_read((struct IODevice*)self->NO.io, (char*)NO, 1, NULL);
|
||||
IODevice_read((struct IODevice*)self->NC.io, (char*)NC, 1, NULL);
|
||||
}
|
||||
|
||||
|
||||
bool Interlock_isClosed(struct Interlock* self)
|
||||
{
|
||||
bool returnValue;
|
||||
|
||||
char no;
|
||||
char nc;
|
||||
|
||||
IODevice_read((struct IODevice*)self->NO.io, &no, 1, NULL);
|
||||
IODevice_read((struct IODevice*)self->NC.io, &nc, 1, NULL);
|
||||
|
||||
if ((no != 0) && (nc == 0))
|
||||
{
|
||||
returnValue = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = false;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
void Interlock_setEXTI(struct Interlock* self, FunctionalState command)
|
||||
{
|
||||
self->NO.ioEXTI.EXTI_LineCmd = command;
|
||||
EXTI_Init(&self->NO.ioEXTI);
|
||||
|
||||
self->NC.ioEXTI.EXTI_LineCmd = command;
|
||||
EXTI_Init(&self->NC.ioEXTI);
|
||||
}
|
||||
@@ -89,20 +89,18 @@ ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd, int iMin, in
|
||||
}
|
||||
|
||||
|
||||
int PID_calculate(struct Pid* self, int input, int error)
|
||||
int PID_calculate(struct Pid* self, int error)
|
||||
{
|
||||
int returnValue = 0;
|
||||
|
||||
int dTerm;
|
||||
int pTerm;
|
||||
|
||||
input *= PID_FIXED_POINT_FACTOR;
|
||||
error *= PID_FIXED_POINT_FACTOR;
|
||||
|
||||
if (self->initialized)
|
||||
{
|
||||
// Calculate integral
|
||||
self->iTerm += (self->Ki * error);
|
||||
|
||||
// Control integrator
|
||||
if (self->iTerm > self->iMax)
|
||||
{
|
||||
@@ -114,14 +112,14 @@ int PID_calculate(struct Pid* self, int input, int error)
|
||||
}
|
||||
|
||||
// Calculate differential
|
||||
dTerm = (input - self->input_d1) * self->Kd;
|
||||
dTerm = ((error - self->input_d1) * self->Kd);
|
||||
|
||||
// Calculate proportional
|
||||
pTerm = self->Kp * error;
|
||||
|
||||
pTerm = (self->Kp * error);
|
||||
LOGGER_WARNING(mainLog, "pTerm %d, Kp %d, error %d", pTerm, self->Kp, error);
|
||||
|
||||
returnValue = (self->iTerm + dTerm + pTerm) / PID_FIXED_POINT_FACTOR;
|
||||
self->input_d1 = input;
|
||||
self->input_d1 = error;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -69,7 +69,6 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
||||
static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
|
||||
static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column);
|
||||
static ErrorStatus clear(const struct DisplayDevice* self);
|
||||
static ErrorStatus clearLine(const struct DisplayDevice* self, size_t row);
|
||||
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness);
|
||||
static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast);
|
||||
|
||||
@@ -95,7 +94,7 @@ ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* devic
|
||||
ddParameters.brightnessMax = NHD0420_BRIGHTNESS_MAX;
|
||||
ddParameters.contrastMin = NHD0420_CONTRAST_MIN;
|
||||
ddParameters.contrastMax = NHD0420_CONTRAST_MAX;
|
||||
DisplayDevice_construct(&self->displayDevice, &ddParameters, NULL, setState, write, clear, clearLine, setBrightness, setContrast, NULL);
|
||||
DisplayDevice_construct(&self->displayDevice, &ddParameters, NULL, setState, write, clear, NULL, setBrightness, setContrast, NULL);
|
||||
|
||||
self->initialized = true;
|
||||
NHD0420_sendData(self, "Hallo", 5);
|
||||
@@ -422,37 +421,6 @@ static ErrorStatus clear(const struct DisplayDevice* self)
|
||||
}
|
||||
|
||||
|
||||
static ErrorStatus clearLine(const struct DisplayDevice* self, size_t row)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if (self->initialized)
|
||||
{
|
||||
// Set cursor on display
|
||||
returnValue = NHD0420_setCursorToPosition((const struct NHD0420*)self, row, 1);
|
||||
|
||||
char buffer[self->parameters.numberOfColumns];
|
||||
|
||||
int loopcounter;
|
||||
for (loopcounter = 0; loopcounter < self->parameters.numberOfColumns; loopcounter++)
|
||||
{
|
||||
buffer[loopcounter] = 0x20;
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
returnValue = NHD0420_sendData((const struct NHD0420*)self, buffer, self->parameters.numberOfColumns);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness)
|
||||
{
|
||||
if (self->initialized)
|
||||
|
||||
Reference in New Issue
Block a user