Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ApplicationCore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ChimeraTK Mirror
ApplicationCore
Commits
718d575d
Commit
718d575d
authored
8 years ago
by
Martin Christoph Hierholzer
Browse files
Options
Downloads
Patches
Plain Diff
make the example a bit more sensible and dynamic
parent
f501feaa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
example/demoApp.cc
+59
-23
59 additions, 23 deletions
example/demoApp.cc
with
59 additions
and
23 deletions
example/demoApp.cc
+
59
−
23
View file @
718d575d
...
...
@@ -13,65 +13,101 @@
namespace
ctk
=
ChimeraTK
;
class
MyFirst
Module
:
public
ctk
::
ApplicationModule
{
class
Automation
Module
:
public
ctk
::
ApplicationModule
{
public:
SCALAR_ACCESSOR
(
int
,
s
etpoint
,
ctk
::
VariableDirection
::
input
,
"MV/m"
,
ctk
::
UpdateMode
::
p
ush
);
SCALAR_ACCESSOR
(
int
,
feedforward
,
ctk
::
VariableDirection
::
output
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
SCALAR_ACCESSOR
(
double
,
operatorS
etpoint
,
ctk
::
VariableDirection
::
input
,
"MV/m"
,
ctk
::
UpdateMode
::
p
oll
);
SCALAR_ACCESSOR
(
double
,
loopSetpoint
,
ctk
::
VariableDirection
::
output
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
void
mainLoop
()
{
feedforward
=
10
0
;
feedforward
.
write
();
loopSetpoint
=
0
;
loopSetpoint
.
write
();
while
(
true
)
{
setpoint
.
read
();
feedforward
=
42
*
setpoint
;
std
::
cout
<<
"FirstModule: feedforward = "
<<
feedforward
<<
std
::
endl
;
operatorSetpoint
.
read
();
if
(
operatorSetpoint
>
loopSetpoint
)
loopSetpoint
++
;
if
(
operatorSetpoint
<
loopSetpoint
)
loopSetpoint
--
;
std
::
cout
<<
"AutomationModule: operatorSetpoint = "
<<
operatorSetpoint
<<
std
::
endl
;
std
::
cout
<<
"AutomationModule: loopSetpoint = "
<<
loopSetpoint
<<
std
::
endl
;
loopSetpoint
.
write
();
usleep
(
200000
);
feedforward
.
write
();
}
}
};
class
MySecond
Module
:
public
ctk
::
ApplicationModule
{
class
ControlLoop
Module
:
public
ctk
::
ApplicationModule
{
public:
SCALAR_ACCESSOR
(
int
,
feedforward
,
ctk
::
VariableDirection
::
input
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
SCALAR_ACCESSOR
(
int
,
readback
,
ctk
::
VariableDirection
::
output
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
SCALAR_ACCESSOR
(
double
,
setpoint
,
ctk
::
VariableDirection
::
input
,
"MV/m"
,
ctk
::
UpdateMode
::
poll
);
SCALAR_ACCESSOR
(
double
,
readback
,
ctk
::
VariableDirection
::
input
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
SCALAR_ACCESSOR
(
double
,
actuator
,
ctk
::
VariableDirection
::
output
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
void
mainLoop
()
{
while
(
true
)
{
feedforward
.
read
();
std
::
cout
<<
"SecondModule: feedforward = "
<<
feedforward
<<
std
::
endl
;
readback
=
feedforward
/
21
;
readback
.
read
();
setpoint
.
read
();
actuator
=
10.
*
(
setpoint
-
readback
);
std
::
cout
<<
"ControlLoopModule: setpoint = "
<<
setpoint
<<
std
::
endl
;
std
::
cout
<<
"ControlLoopModule: readback = "
<<
readback
<<
std
::
endl
;
std
::
cout
<<
"ControlLoopModule: actuator = "
<<
actuator
<<
std
::
endl
;
actuator
.
write
();
usleep
(
200000
);
readback
.
write
();
}
}
};
class
SimulatorModule
:
public
ctk
::
ApplicationModule
{
public:
SCALAR_ACCESSOR
(
double
,
actuator
,
ctk
::
VariableDirection
::
input
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
SCALAR_ACCESSOR
(
double
,
readback
,
ctk
::
VariableDirection
::
output
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
SCALAR_ACCESSOR
(
double
,
readback2
,
ctk
::
VariableDirection
::
output
,
"MV/m"
,
ctk
::
UpdateMode
::
push
);
double
lastValue
{
0
};
void
mainLoop
()
{
while
(
true
)
{
actuator
.
read
();
readback
=
(
100
*
lastValue
+
actuator
)
/
101.
;
lastValue
=
readback
;
std
::
cout
<<
"SimulatorModule: actuator = "
<<
actuator
<<
std
::
endl
;
std
::
cout
<<
"SimulatorModule: readback = "
<<
readback
<<
std
::
endl
;
readback2
=
readback
;
readback2
.
write
();
readback
.
write
();
usleep
(
200000
);
}
}
};
class
MyApp
:
public
ctk
::
Application
{
public:
MyFirstModule
firstModule
;
MySecondModule
secondModule
;
AutomationModule
automation
;
ControlLoopModule
controlLoop
;
SimulatorModule
simulator
;
void
initialise
()
{
mtca4u
::
BackendFactory
::
getInstance
().
setDMapFilePath
(
"dummy.dmap"
);
firstModule
.
feedforward
.
connectToDevice
(
"Dummy0"
,
"/MyModule/Variable"
,
ctk
::
UpdateMode
::
poll
);
secondModule
.
feedforward
.
connectToDevice
(
"Dummy0"
,
"/MyModule/Variable"
,
ctk
::
UpdateMode
::
poll
);
//firstModule.feedforward.connectTo(secondModule.feedforward);
automation
.
operatorSetpoint
.
publish
(
"MyLocation/setpoint"
);
automation
.
loopSetpoint
.
connectTo
(
controlLoop
.
setpoint
);
controlLoop
.
actuator
.
connectToDevice
(
"Dummy0"
,
"/MyModule/Variable"
,
ctk
::
UpdateMode
::
poll
);
simulator
.
actuator
.
connectToDevice
(
"Dummy0"
,
"/MyModule/Variable"
,
ctk
::
UpdateMode
::
poll
);
simulator
.
readback
.
connectTo
(
controlLoop
.
readback
);
firstModule
.
setpoint
.
publish
(
"MyLocation/setpoint"
);
secondModule
.
readback
.
publish
(
"MyLocation/readback"
);
simulator
.
readback2
.
publish
(
"MyLocation/readback"
);
}
virtual
~
MyApp
()
{};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment