Hello everybody.
Help is needed!

We remake control system jig grinding machine 32K84SF4 USSR production. This machine has 5 main axes.

3 axis is the coordinate ( "X, Y, Z" DC motors) are controlled through the driver, voltage +/- 10V. The measurement takes place via the optical linear encoder.
Another axis ( "A" DC motor) is a planetary spindle (rotary axis) that rotates around the axis "Z"), which is also controlled via the driver, voltage +/- 10V. The measurement takes place via rotary encoder.
Another axis ( "B" hydraulic cylinder (linear axis) moves parallel to the Z axis), the axis moves the tool reciprocating motion (down <-> up - cycles) by a predetermined distance, the hydraulic cylinder is controlled by an electromagnetic directional hydraulic control valve through a relay. The measurement takes place through an optical linear encoder.
The axes X, Y, Z, we have set up, checked the A axis, but have not yet set, the axis checked in and proceeded to set up, but faced with a problem. We need to hydraulic cylinder axis is moved by a predetermined distance (down <-> up - cycles).

The algorithm is as follows:
In KmotionCNC are editing the value field and two buttons (start and stop).

When a worker enters a value in the edit box and presses the start button, this value is passed to the file "name.c" which recorded the cycle of movement of the hydraulic cylinder, further:
Checks for a condition
If the value (which introduced the work)> 0;
then
Enable relay 0; (Axis moves in the up position)
If the axis position (the value of the optical linear encoder) = 0;
then
Turn OFF the relay 0 and turn ON the relay 1;
If the axis position (the value of the optical linear encoder) = value (which introduced the worker);
then
Turn OFF the relay 1 and turn ON the relay 0;
end.

Stop button
If the axis position (the value of the optical linear encoder)> 0;
then
Turn OFF the relay 0 and turn ON the relay 1;
end.


My problem is that I do not know how to implement it, because there is no knowledge in programming.
I would be grateful for any help.