Example position control for Java2C

Example position control for Java2C

Inhalt


1 Example position control

Topic:.Java2C.ExamplePositionCtrl.

pStyle=std tableStyle=stdTable

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:

At the opposite side, C, there are the following Folders:

The example is complex enough to show and test some principles. The next picture shows an object-model-diagram (UML, Created by IBM-Rhapsody) of the controller:


Bild: ObjectModelDiagram Example PositionControl - controller

From where comes the actual values of position and where are the output values of the controller?


Bild: ObjectModelDiagram Example PositionControl - in/output simulation

The figure shows it. There are two interfaces, for act values and for output values. The controller calls getWay() or setMotorVoltage() to its known associations. Their types are interfaces. The associations refers to the implementation, but the methods are called from the interfaces. The associations to the act-value and the output-value implementors are aggregations which are set in the build phase of the application (on startup).

In a real embedded application the implementor-methods accesses the hardware or they handle with bus communication data from field bus for sensors and actuators. In the simulation environment, for Java, and for the translated C-code too, there is the class SimPC. This class contains a inner class WaitThread, which implements the waitCycle()-method of the shown interface. Instead only waiting for a notification of an interrupt this implementation calculates the behaviour of the outside process. In this example the motor voltage is integrated to increment the position value. But there is a disturbance too, to make the controlling more interesting...

The interfaces for WaySensor and WayActuator are implemented in an anonymous inner class inside SimPc. This kind of implementation can't be shown yet in the UML-diagram, because the converter Java2XMI should be inproved yet. The UML-diagram shows the composition to the interface instead the composition to the anomymous implementor class yet. The implementor is a non-static inner class of SimPc. It means that the interface-implementor can access all private variabe of SimPc. There is the calculated position (variable way1) and the variable voltage1 which stores the output value from the controller. Both variable are get respectively set.

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++

Inspect the controller:

The working of the controller can be visited. The controller sends some values in a middle cycle time via socket-communication. Therefore the InterProcessComm is used, which is present in Java: javasrc:_org/vishia/communication/InterProcessComm and in adapted form in C: vishia/Jc/html/InterProcessComm.html. A localhost-communication to a fix port is used. It may be parametrize-able too. The visitor is a GUI-application, which can be started with Java2C-download:examples/positionControl/run_Viewer.bat. It receives the UDP-telegrams at the declareted port and shows the values. The sources of this application are not an essentiel part of this download, but they are given here too. The Viewer-application is configurable with a text file given in Java2C-download:examples/positionControl/GUI/gui.cfg. The image shows a snap-shot of the viewer:


Bild: Snapshot of viewer