Inhalt
Topic=.Java2C.ExamplePositionCtrl.
As an example for a program in Java to implement in C, there is a position control. The sources in Java are disposed in the following packages:
The package org.vishia.exampleJava2C.java4c
contains that code, which should translated to C. The java4c means java for c. There is a PID-controller in 16-bit-arithmetic as standard algorithm, a MainController for the organization of the position (move) control, and a set value generator to generate set values for a way.
The package org.vishia.exampleJava2C.emulationEnv
contains the environment for the example control. It includes the simulation of the environment, the emulation of threads and sampling times (interrupts) of the controller and reports, logs etc. to protocol the procedures.
The package org.vishia.byteData
contain a class that helps to convert values in Java to binary data. It is used to produce an output in a simple 16-float-Format to show values with a special graphical viewer.
The packages org.vishia.mainCmd
and org.vishia.util
contains some helpers.
At the opposite side, C, there are the following Folders:
gensrc_c: This folder contains the generated C-sources from Java2C. There are secondary sources, the real sources are in the package org.vishia.exampleJava2C.java4c
. To produce this sources, you must call the batchfile java2C_example.bat
for windows.
src_c: There are the simulation environment, directly written in C. If we would have no simulation, only the real embedded control system, we need a system environment of the embedded hardware in C.
CRuntimeJavalike: It is not a part of the example but the basic for all functionality from Java standards. There is contained a C-struct ObjectJc
with some methods and so on. Please read the comments there.
The example is not so complex. In this pass there is only one thread. The principles should be shown.
The controller may be run in the embedded reality in a interrupt time. In each cycle time the method step()
is called. In the simulation step()
is called therefore in a while
-loop.
The set value generator generates a movement to target points. An actual target point is given, and a next target point is stored. From outside (from the simulation) next target points are try to set. There are realized if the next target of the MainController is free.
There is used a new
Statement to create the instances to store the next target points. The new
statement with garbage collection should be worked proper in C.
In the future there will be used a LinkedList to store more as one next target.
In the future there should be added a second controlling system for positioning a second one, and the both positioning things should be coupled together, it may be with a distance, an elastic force or other. This enhancement of the example should be shown, that a complexly problem is better treatable in Java as in C or C++