This invention relates to improvements in an electric discharge machining method and apparatus for performing machining (rocking machining) while rocking an electrode with respect to a workpiece in a plane vertical to a machining feed direction. 
Electric discharge machining is machining for generating an electric discharge between an electrode and a workpiece (hereinafter called xe2x80x9cbetween themxe2x80x9d) to melt and remove the workpiece.  Thus, unless work scraps occurring between them due to the melt and removal of the workpiece are eliminated by some means, repeats of insulation recovery and electric discharge between them cannot be kept in a normal state, and bad effects such as a decrease in machining efficiency and a deterioration of work surface properties occur. 
As one of elimination means of such work scraps between them, a rocking function of increasing efficiency of the elimination of the work scraps through stirring by performing machining while rocking the electrode relatively to the workpiece in a plane vertical to a machining feed direction has been known.  Parameters about this rocking function include a locus of relative movement between an electrode and a workpiece (hereinafter called xe2x80x9crocking shapexe2x80x9d), the amount of relative movement (hereinafter called xe2x80x9crocking radiusxe2x80x9d), a relative movement speed (hereinafter called xe2x80x9crocking speedxe2x80x9d), and the number of divisions of the rocking shape and a division shape in the case of using means for dividing the rocking shape on making a determination of completion. 
FIG.  7 is a diagram showing a configuration of a conventional electric discharge machining apparatus disclosed in JP-A-126540/1994 and in the drawing, numeral 1 is an electrode, and numeral 2 is a workpiece, and numeral 3 is a voltage detection part between the electrode and the workpiece, and numeral 4 is a calculation part, and numeral 5 is memory, and numeral 6 is a position check part, and numeral 7 is a rocking speed calculation part, and numeral 8 is a rocking speed table in which correspondence between an average voltage between the electrode 1 and the workpiece 2 and a rocking speed suitable for the voltage is previously registered.  Also, FIG.  8 shows a situation in which an orbit path of a square rocking shape is divided into 12 portions, and in the drawing, numeral 9 is a rocking shape, and numeral 10 is one area divided.  In FIG.  7, a machining voltage is applied between them from a voltage source (not shown), and the voltage between them is detected by the voltage detection part 3 between them.  The calculation part 4 obtains a weighted average of a voltage between them detected by the voltage detection part 3 and previous calculation data (gap data) of the area.  All the gap data about all the divided areas of the orbit path of the rocking shape are stored in the memory 5.  The position check part 6 receives information from a motor control part (not shown) at the time of orbiting the next rocking shape, and checks the present position of the electrode, and checks whether it is positioned in any the divided area 10 of the rocking shape 9 of the electrode of FIG.  8, and gap data corresponding to an address of the checked position area is read from the memory 5, and supplies the gap data to the rocking speed setting part 7.  The rocking speed setting part 7 reads out gap data before one orbit of the area stored in the memory 5, and sees the rocking speed table 8, and sets a rocking speed corresponding to the gap data read from the memory 5, and outputs the rocking speed to the motor control part as rocking speed data. 
In the invention disclosed in JP-A-126540/1994 thus, the optimum rocking speed is set every machining area and electric discharge machining with stability and high accuracy is performed.  However, a change in the rocking speed or a determination of completion is made by the average voltage between the electrode and the workpiece and in a method of detecting the average voltage between them to control rocking movement, it was difficult to detect an exact state of electric discharge every electric discharge pulse, and it was difficult to force machining conditions such as pause time at the time of stable electric discharge (for example, it means that pause time is reduced to force a value of the pause time in order to improve machining efficiency, and hereinafter called xe2x80x9cforced machining at the time of stable machiningxe2x80x9d) or take avoidance at the time of abnormal electric discharge.  Further, control of a rocking function is performed by a machining shape or the amount of machining, but bite control (also known as chamfer control) at the beginning of machining and forced machining control after the machining is once completed are not performed. 
Also, when an operator inputs a machining state and sets parameters about a rocking function, there were problems that skill of the operator is required while the operator needs to monitor the machining state from beginning to end of the machining. 
This invention is implemented to solve the problems as described above, and an object of the invention is to obtain an electric discharge machining method and apparatus capable of automatically making a parameter setting about a rocking function according to a detected electric discharge state without compelling an operator to make the parameter setting about the rocking function and achieving improvement in machining efficiency and stabilization of the machining. 
With an electric discharge machining method in accordance with the invention, in an electric discharge machining method for performing machining while relatively rocking an electrode and a workpiece in a plane vertical to a machining feed direction, an electric discharge state is detected by detecting a short-circuit frequency between the electrode and the workpiece, a defective electric discharge frequency and a position of the electrode, and parameters about a rocking function are set according to the electric discharge state. 
Also, an initial setting of a rocking speed is changed according to a combination of the electrode and the workpiece, a shape of the electrode or a rocking shape. 
Also, in an electric discharge machining method for performing machining while relatively rocking an electrode and a workpiece in a plane vertical to a machining feed direction, an electric discharge state is detected by detecting a short-circuit frequency between the electrode and the workpiece, a defective electric discharge frequency and a position of the electrode, and a rocking speed is set to a speed higher than that of a stable machining state when the detected electric discharge state is an abnormal electric discharge continuation state and a rocking speed is set to a speed lower than that of a stable machining state when the detected electric discharge state is a stable continuation state. 
Also, in an electric discharge machining method for performing machining while relatively rocking an electrode and a workpiece in a plane vertical to a machining feed direction, when bite control or forced machining control is set, a rocking speed is set to a speed higher than a value before the setting of the bite control or the forced machining control. 
Also, a rocking radius is set to a value smaller than a value before the setting of the bite control or the forced machining control. 
With an electric discharge machining apparatus in accordance with the invention, in an electric discharge machining apparatus for performing machining while relatively rocking an electrode and a workpiece in a plane vertical to a machining feed direction, there are provided electric discharge state detection means for detecting a short-circuit frequency between the electrode and the workpiece, a defective electric discharge frequency and a position of the electrode, and rocking function setting means for setting parameters about a rocking function according to the electric discharge state detected by the electric discharge state detection means. 
Also, there is provided rocking function setting means for changing an initial setting of a rocking speed according to a combination of the electrode and the workpiece, a shape of the electrode or a rocking shape. 
Also, in an electric discharge machining apparatus for performing machining while relatively rocking an electrode and a workpiece in a plane vertical to a machining feed direction, there are provided electric discharge state detection means for detecting a short-circuit frequency between the electrode and the workpiece, a defective electric discharge frequency and a position of the electrode, and rocking function setting means for setting a rocking speed to a speed higher than that of a stable machining state when the electric discharge state detected by the electric discharge state detection means is an abnormal electric discharge continuation state and setting a rocking speed to a speed lower than that of a stable machining state when the electric discharge state detected by the electric discharge state detection means is a stable continuation state. 
Also, in an electric discharge machining apparatus for performing machining while relatively rocking an electrode and a workpiece in a plane vertical to a machining feed direction, there is provided rocking function setting means for setting a rocking speed to a speed higher than a value before the setting of bite control or forced machining control when the bite control or the forced machining control is set. 
Also, there is provided rocking function setting means for setting a rocking radius to a value smaller than a value before the setting of the bite control or the forced machining control. 
Since the invention is constructed as described above, an exact electric discharge state every electric discharge pulse can be detected, and forced machining at the time of stable machining by the rocking movement or avoidance at the time of abnormal electric discharge can be performed.  Therefore, there is an effect capable of achieving improvement in machining efficiency and stabilization of the machining. 
Also, there is an effect capable of achieving improvement in machining efficiency and stabilization of the machining more by changing an initial setting of a rocking speed according to a combination of an electrode and a workpiece, an electrode shape or a rocking shape. 
Further, there is an effect capable of performing bite control and forced machining control. 
Furthermore, there is an effect capable of automatically making a parameter setting about a rocking function according to a detected electric discharge state without compelling an operator to make the parameter setting about the rocking function.