Skip to content

Commit

Permalink
Import from SourceForge.net
Browse files Browse the repository at this point in the history
  • Loading branch information
voloda committed Sep 24, 2014
1 parent fab08c9 commit b55c602
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 79 deletions.
69 changes: 60 additions & 9 deletions kernel-library/include/cresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Author: Vladimir Kloz <[email protected]>
* Project home: http://sourceforge.net/projects/softwareplc
* Version: $Revision: 1.10 $
* Version: $Revision: 1.11 $
*/

#ifndef _RTL_PLC_CRESULT
Expand Down Expand Up @@ -66,7 +66,7 @@
* @param dt Specified data type
* @param op Implemented operator (+,-,/ ....)
*/
#define CResultOp(dt, op) case DT_##dt: InternalData.m_##dt##_Value op##= Value.InternalData.m_##dt##_Value; break;
#define CResultOp(dt, op) case DT_##dt: this->InternalData.m_##dt##_Value op##= Value.Result##dt(); break;

/**
* Macro for short implementation of comparing operators
Expand All @@ -75,7 +75,7 @@
* @param dt Specified data type
* @param op Implemented operator (<,<=,==, ...)
*/
#define CResultCmpOp(dt, op) case DT_##dt: return(InternalData.m_##dt##_Value op Value.InternalData.m_##dt##_Value); break;
#define CResultCmpOp(dt, op) case DT_##dt: return(InternalData.m_##dt##_Value op Value.Result##dt()); break;

/**
* Macro for short implementation when getting
Expand All @@ -85,6 +85,7 @@
* @param dt Internaly stored data type
*/
#define CResultGV(dt) case DT_##dt: Var = (DataType) InternalData.m_##dt##_Value; break;

/**
* Macro for short implementation when getting
* negated current result into CVariable<> or CProperty<>
Expand All @@ -93,13 +94,46 @@
* @param dt Internaly stored data type
*/
#define CResultNegGV(dt) case DT_##dt: Var = ~((DataType) InternalData.m_##dt##_Value); break;
/**

/**
* Macro for short implementation when getting internaly
* stored value in operators
*
* @param idt Internal data type stored in result
* @param rdt Requested data type into which convert result
*/
#define CResultDT(idt, rdt) case DT_##idt: return ((rdt) (this->InternalData.m_##idt##_Value)); break;
/**
* Macro for short implementation when getting current
* value of result converted to specified datatype
*
* @param dt Requested datatype
*/
#define ImplementResult(dt) dt Result##dt(void) const \
{\
switch(m_iStoredDataType) \
{\
CResultDT(SINT, dt);\
CResultDT(INT, dt);\
CResultDT(DINT, dt);\
CResultDT(USINT, dt);\
CResultDT(UINT, dt);\
CResultDT(UDINT, dt);\
CResultDT(REAL, dt);\
CResultDT(TIME, dt);\
CResultDT(BYTE, dt);\
CResultDT(WORD, dt);\
CResultDT(DWORD, dt);\
}\
return ((dt)0);\
}
/**
* This class implements result functionality for PLC
* IL language operations.
* All operations (comparisions, additions, multiplications...)
* are defined here as operators
*
* @version $Revision: 1.10 $
* @version $Revision: 1.11 $
* @author Voloda <[email protected]>
*/
class CResult
Expand Down Expand Up @@ -127,10 +161,27 @@
TOD m_todValue;
DT m_dtValue;
*/
BYTE m_bValue;
WORD m_wValue;
DWORD m_dwValue;
BYTE m_BYTE_Value;
WORD m_WORD_Value;
DWORD m_DWORD_Value;
} InternalData;

/*
* Implementation of functions, which returns
* internal value converted into specified datatype
*/
ImplementResult(SINT);
ImplementResult(INT);
ImplementResult(DINT);
ImplementResult(USINT);
ImplementResult(UINT);
ImplementResult(UDINT);
ImplementResult(REAL);
ImplementResult(TIME);
ImplementResult(BYTE);
ImplementResult(WORD);
ImplementResult(DWORD);

/**
* Contain information about current data type
* stored in result object as defined in
Expand Down Expand Up @@ -278,7 +329,7 @@
* kernel space. Returns current value
* stored in result
*/
if (InternalData.m_REAL_Value == 0)
if (Value.ResultINT() == 0)
{
rtl_printf("SoftwarePLC: Division by zerp detected, returned result is wrong!");
return (*this);
Expand Down
36 changes: 20 additions & 16 deletions plc/library/pid.plc
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
(* Outputs: *)
(* AV - action variable *)
(* *************************************** *)
(* Include: max.plc, min.plc *)
FUNCTION_BLOCK pid
VAR_INPUT
P: DINT := 0;
I: DINT := 0;
D: DINT := 0;
ISAT: DINT := 16#0fff_ffff_ffff_ffff;
PV: DINT := 0;
P: REAL := 0;
I: REAL := 0;
D: REAL := 0;
ISAT: DINT := 16#0fff_ffff_ffff_ffff;
PV: REAL := 0;
END_VAR
VAR_OUTPUT
AV: UDINT := 0; (* Action Variable *)
AV: REAL := 0; (* Action Variable *)
END_VAR
VAR
OLD_PV: DINT := 0;
INTEGRATION: DINT := 0;
TMPSAT: DINT;
OLD_PV: REAL := 0;
INTEGRATION: REAL := 0;
TMPSAT: REAL;
END_VAR

(* Calculate P part of controler *)
Expand All @@ -48,20 +47,25 @@ FUNCTION_BLOCK pid
(* Calculate I part of controler *)
LD PV
ADD INTEGRATION
ST INTEGRATION

min ISAT
LE ISAT
JMPC test_minsat

ST INTEGRATION
LD 0

LD ISAT

JMP compute_int

test_minsat:
LD ISAT
MUL -1
ST TMPSAT

LD INTEGRATION
max TMPSAT
LE INTEGRATION
JMPC compute_int

LD 0
compute_int:
ST INTEGRATION

MUL I
Expand Down
23 changes: 12 additions & 11 deletions plc/motorek/motorek.plc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ FUNCTION_BLOCK pwm

LD pwmval
LT 0

ST runback

JMPCN runpwm
Expand Down Expand Up @@ -109,7 +110,6 @@ PROGRAM prg_motorek
RPS: DINT;
END_VAR


LD P
ST controler.P
LD I
Expand All @@ -119,7 +119,8 @@ PROGRAM prg_motorek
LD ISAT
ST controler.ISAT

LD SP
LD 1.3
MUL SP
SUB RPS

ST controler.PV
Expand Down Expand Up @@ -219,7 +220,7 @@ PROGRAM prg_RPS
ADD OtOld
DIV 2
ST OtOld
MUL 200
MUL 20
DIV 16
ST RPS

Expand Down Expand Up @@ -249,20 +250,20 @@ CONFIGURATION motorek
(* TRUE - otaceni vpred, FALSE - otaceni vzad *)
Direction: BOOL := FALSE;

(* Constants for PID controler *)
P: DINT := 1;
I: DINT := 2;
D: DINT := 2;
(* Constants for PID controler 3, 0.5 *)
P: REAL := 3;
I: REAL := 0.5;
D: REAL := 0;

ISAT: DINT := 100;
END_VAR

RESOURCE xx ON yy
TASK rustTask(INTERVAL:=T#0.1ms);
TASK measureRotationTask(INTERVAL:=T#0.05ms);
TASK measureRPSTask(INTERVAL:=T#5ms);
TASK controlTask(INTERVAL:=T#0.1ms, PRIORITY := 20);
TASK measureRotationTask(INTERVAL:=T#0.05ms, PRIORITY := 50);
TASK measureRPSTask(INTERVAL:=T#50ms, PRIORITY := 30);

PROGRAM p1 WITH rustTask: prg_motorek();
PROGRAM p1 WITH controlTask: prg_motorek();
PROGRAM p2 WITH measureRotationTask: prg_otacky();
PROGRAM p3 WITH measureRPSTask: prg_rps();
END_RESOURCE
Expand Down
7 changes: 5 additions & 2 deletions plc2cpp/holders/ccontainerconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Author: Vladimir Kloz <[email protected]>
* Project home: http://sourceforge.net/projects/softwareplc
* Version: $Revision: 1.6 $
* Version: $Revision: 1.7 $
*/

#include "include/ccodeprocessor.h"
Expand Down Expand Up @@ -107,7 +107,10 @@ void CContainerConfiguration :: GenerateCode(int iType)
// generate module initialization routine
// ---
CurrentOutput << "\n\nint init_module(void)\n{\n";
CurrentOutput << "\tint iRetv = 0, iCount = 0;\n\n\t__do_global_ctors_aux();\n\n";
CurrentOutput << "\tint iRetv = 0, iCount = 0;\npthread_attr_t\tattr;\n\n\t__do_global_ctors_aux();\n\n";

CurrentOutput << "\tpthread_attr_init(&attr);\n\tpthread_attr_setfp_np(&attr, 1);\n\n";

// generate code for task thread
// initializations (module initialization)
m_pPCalls->GenerateCode(1);
Expand Down
4 changes: 2 additions & 2 deletions plc2cpp/holders/ccontainerpcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Author: Vladimir Kloz <[email protected]>
* Project home: http://sourceforge.net/projects/softwareplc
* Version: $Revision: 1.10 $
* Version: $Revision: 1.11 $
*/

#include <iostream>
Expand Down Expand Up @@ -159,7 +159,7 @@ void CContainerPCall :: GenerateCode(int iCodePart)
break;
// generates program call thread initialization
case 1:
CurrentOutput << "\tiRetv += pthread_create(&threads[iCount++], NULL, PCall" << m_sBlockName.c_str() << ", NULL);\n";
CurrentOutput << "\tiRetv += pthread_create(&threads[iCount++], &attr, PCall" << m_sBlockName.c_str() << ", NULL);\n";
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion plc2cpp/plc2cpp.y
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extern FILE *yyin;

void help(void)
{
cout << "plc2cpp 0.01a\n\n";
cout << "plc2cpp 1.01\n\n";
cout << " --target [-t] directory Target directory for converted PLC sources\n";
cout << " --source [-s] file Name of source file in PLC IL language\n";
cout << " --project [-p] file Name of project file\n";
Expand Down
3 changes: 2 additions & 1 deletion visualisation/include/visualisationcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Author: Vladimir Kloz <[email protected]>
* Project home: http://sourceforge.net/projects/softwareplc
* Version: $Revision: 1.2 $
* Version: $Revision: 1.3 $
*/

#ifndef _CVisualisationCanvas_H_
Expand All @@ -41,6 +41,7 @@
wxFrame *m_pParent;

void DrawAxes(wxDC& dc);
void WriteText(wxDC &dc, const wxString &sText, int iYMiddle, int iXMax);
void OnSize(wxSizeEvent& event);
void OnTimer(wxTimerEvent &event);

Expand Down
3 changes: 1 addition & 2 deletions visualisation/include/visualisationmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Author: Vladimir Kloz <[email protected]>
* Project home: http://sourceforge.net/projects/softwareplc
* Version: $Revision: 1.2 $
* Version: $Revision: 1.3 $
*/

#ifndef _CVisualisationMain_H_
Expand All @@ -43,7 +43,6 @@

wxSpinCtrl *m_RotPerSec;
CVisualisationCanvas *m_Canvas;
wxStaticText *m_RotPerSecAct;

DECLARE_EVENT_TABLE()
};
Expand Down
12 changes: 9 additions & 3 deletions visualisation/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Author: Vladimir Kloz <[email protected]>
* Project home: http://sourceforge.net/projects/softwareplc
* Version: $Revision: 1.2 $
* Version: $Revision: 1.3 $
*/

#include <sys/types.h>
Expand Down Expand Up @@ -70,7 +70,7 @@ void CMeasureThread :: ResetDriver(void)
write(m_iControl, &Control, sizeof(Control));

Control.Command = PLC_SEND_SET_TIME;
Control.iTime = 20;
Control.iTime = 50;

write(m_iControl, &Control, sizeof(Control));
}
Expand Down Expand Up @@ -115,9 +115,15 @@ void *CMeasureThread :: Entry()
}
else if (pBuff[0] == 'O')
{
int iValue;

iValue = *(int *)(pBuff + 1);

m_pProcessVariable->Lock();
m_pProcessVariable->AddValue(*((int *) (pBuff + 1)));
m_pProcessVariable->AddValue(iValue);
m_pProcessVariable->Unlock();

// cout << "Value: " << iValue << "\n";
}
else
ResetDriver();
Expand Down
Loading

0 comments on commit b55c602

Please sign in to comment.