📜 ⬆️ ⬇️

We manage the machine on Groovy / Java. As a CNC machine in the home workshop does not turn into a cartoon character "two of the casket"

Let's talk on topics from labor and work, machine tools, automation on java / groovy to predictions about the future of mankind.

You will learn about personalized automated production in the home workshop, how the creator's idea turns into a finished product. Consider the approach of sending G-code instructions from JVM and groovy / java to a CNC machine for automating what is not in the out-of-box system.


I hope this publication will be informative for programmers working with JVM, those who are interested in the IoT theme, who are not alien to tinkering, who are thinking about buying a 3D printer, who made the prototype of a system and run the software on Raspberry PI / Beagleboard Black. I will tell you something about this, you can repeat using open source software and open hardware.

Content


  1. Foreword
  2. CNC Machines
  3. From model to G-code
  4. Program management
  5. Manage machine from java and groovy
  6. Beautiful far ...
  7. findings

Based on my mini-report at the Software Development Conference (SECR-2016) . As well as experience in both hardware and software.
')
Video of the report ...
Many thanks to Stas Fomin belonesox for professional video recording and quick editing !!!


Foreword


Appeal to the audience.
Good morning, dear listeners. Thank you all for waking up and coming in the morning of the day off. I am glad to see you in the hall! We don’t have much time for the report, so there will not be a question and answer section in the hall, but you can come and ask questions after the report. On the last slide there is an email address to which I will also reply.

I really appreciate your opinion on the report. In the near future I plan to hold a mitap, where practically it will be possible to try to do something about which I will now theoretically tell and control the CNC. This will be an open / free event and who will be in Moscow, can join. I hope to find a room in the near future, I will prepare examples and at meetup.com I will post information about the venue. To whom it is interesting, you can write to the email address and I will send you an alert about the event. Note to the article: of course, I will publish the results of this meeting for habrahabr readers and you can participate in it.

We will start the report on the topic “How to use a CNC machine in a home workshop not to turn into a cartoon of“ two of a casket ”heroes”. Who watched and remembers what this cartoon?

Voices from the audience: “Everyone watched”

Great, then you know about what I will talk about. And in the end of the report we will try to programmatically control the automaton in Java and Groovy.

Another question to the hall. Who constantly uses CNC machines, who works as an engineer, designer, production technologist? I hear negative answers from the audience. So it will be much easier for me and do not potroll. People who use these technologies in the industry every day can become ridiculous from the cost of the toolkit, the depth of immersion in the subject and my style of presentation.

CNC Machines


What do we know about work with you? Work and work of a person always happened in two ways.



Either you control those who work, or harnessed and do the work together with everyone - together pull one "strap".

This picture did not take into account that more convenient tools appeared thanks to inventors and engineers.



Technologies that simplify work, make life much more pleasant and allow people to engage in intellectual things, and leave the work to machines.

Everyone probably remembers how the boy from the animated film “Vovka in the Tridentary Kingdom” wanted his wishes to be fulfilled, but he didn’t want to do anything himself and didn’t want to learn anything.



In the far-off kingdom he came to two of the caskets, the same from the face. They were executive and did everything for him, but not at all as he needed .

Also, you probably remember these two.



The griffin called an ostrich with him to where there is a lot of tasty. When the ostrich ran, the vulture stopped it and said the phrase “It’s better to lose a day, then fly in five minutes.” Doing often repetitive work you need to think is not it easier to lose the "day" on its automation.

The technologies we are going to talk about now are the seventieth years of the 20th century. These are machines that are controlled by programs that are stored in memory. Previously, these were punched cards, recently it is flash drives. In the production of machines are of various sizes, different kinematic schemes and can be equipped with various tools that perform material processing.



In the home workshop all the more prosaic. Basically, machines are the range from AliExpress or our importers of “manufacturers” of the rebranding from heaven. You can buy anything, and you can assemble yourself by buying spare parts.



If you feel sorry for the time and money, there is no experience and access to machines for the manufacture of the frame and the portal, it is easier to buy ready. On the other hand, collecting yourself is a very interesting experience. There are also projects Shapeoko, MechMate CNC Router, Zenbot CNC, etc.

What can be done on the CNC machine and why it may be needed in the workshop? You can perform woodwork, make decorative panels for repair. Or you have a creative thought and its result is not sold in finished form. You can still make the item for the repair of any household equipment. For example, a spare part for a kettle or a steamer made of non-ferrous metals and spare parts for repair are not available for sale and service centers. You can make spare parts for another CNC on one machine as in the case of a 3D printer, but not limited to plastic as a material for the manufacture of parts.

From a software point of view, there is almost no difference between a CNC, a 3D printer or a plotter. The working tool is different, but at the same time many 3D printers are controlled like large industrial machines in the same command language.

Remembering the cartoon, where the ostrich ran and could not fly. Grief says that the wings are better, the ostrich says that the legs. At the end of the cartoon, a lizard appears and says that the main thing is the tail. Her tail saved her life in the beginning. When you work with CNC, I ask you to remember the dangers of life and health and to observe safety precautions! The CNC contains cutting tools, massive moving and rotating parts.



The electric drive is fraught with danger when in contact with the case, if the insulation is broken. Do not even try to extinguish a working electric drive with water without de-energizing it.




From model to G-code


Almost every CNC machine is controlled by G-code. This is a text format for commands and data, which is accepted as an international standard. But specific implementations for automata from different manufacturers contain extensions that can make control programs not portable to another automaton.



The control program on this slide mills a triangle on a plane.

G21 says that the units in the program will be in millimeters.
M3 Includes a spindle with a given rotation speed S.
G0 moves the working tool at idle with linear interpolation from the current coordinate to those specified in the command.
G1 also uses linear interpolation, but this is the processing mode, where F indicates the feed rate.
M5 stops the spindle.
M2 ends the program

There is nothing difficult in this example, but in practice it is rarely written by hand in practice. Usually, a model is created in some form and a control program is created on its basis.

You can create outlines in a vector editor, such as Inkskape, and with the help of opensource GCodeTools software turn it into a g-code program for the machine. This approach is convenient for designers.



For those who are used to working in Blender, you can turn the 3D model into a 2.5D relief using the opensource BlenderCAM.


For industrial use are not available industrial CAD systems, worth tens and hundreds of thousands of dollars. But you can use opensource software FreeCAD.



While it is not comparable in terms of convenience and functionality with expensive CAD / CAM packages, but in simple tasks it may well be enough for design.

Its fork HeeksCAD is more developed in the CAM part and allows you to create control programs based on the model / drawing.



Program management


What directly controls the coordinate table, mill, or other tool of the machine?



These are specialized CNC DSP controllers to which you can connect a usb flash drive and machine. Either these are expansion cards for a single board computer (Raspberry PI, BeagleBoard) for controlling the electric drive and the spindle. Either it is an ordinary personal computer with an LPT port or a PCI / PCIe expansion card for interfacing with the machine’s electronics.

The hero for this report is a personal computer. Because you can control the machine, interpret g-code using the opensource LinuxCNC program.



The software runs on the real-time linux kernel. For single-board computers Raspberry PI, BeagleBoard Black uses its fork Machinekit for ARM as a ready-made iso image. There is a build Machinekit for $ 9 single board CHIP.

LinuxCNC is a constructor and, based on its configuration, almost any configuration can be assembled. This program controls hobby machines and huge CNC manufacturing. It is used both in the modernization of industrial electronics CNC, and in the newly designed machines.



Some of its components operate in a real-time process, the less critical part works in an environment with unpredictable delays. You can extend the internal logic of reaction to events in LinuxCNC using LD diagrams and even shell scripts or console programs.

Manage machine from java and groovy


Instead of its GUI component, we will try to control the CNC and transfer the commands to the interpreter through the external API using the software development technologies we are used to. For anyone interested in this idea, you can find the PoC Apache Camel component and library for JVM camel-gcode on github.

There are many solutions for the “Internet of things” that are based on java, often these are servers for IoT gateways. Now it is possible to integrate the control of the machine on LinuxCNC into complex "cloud" automation scripts with access to the Internet. Using Eclipse Kura, Apache Camel and assemble with this designer a working solution of hundreds of ready-made components will not be easy. You can integrate machine vision libraries and add recognition components, as well as tools for capturing images from a camera or network.

Let's start with a small java example using the API, which allows you to send commands to control the machine. Under the hood, the library sends telnet commands to the linuxcncrsh process from LinuxCNC / Machinekit.

//maven dependency com.github.igor-suhorukov:camel-gcode:0.1 import com.github.igorsuhorukov.gcode.GCodeClient; public class Gcode { public static void main(String[] args) throws Exception { String hostname = "beaglebone.local"; int port = 5007; try (GCodeClient gCodeClient = new GCodeClient(hostname, port)) { System.out.println(gCodeClient.login("EMC", "JVM", "1.0")); gCodeClient.sendCommand("set mode manual"); gCodeClient.sendCommand("set estop off"); gCodeClient.sendCommand("set machine on"); for (int axis = 0; axis < 4; axis++) gCodeClient.sendCommand("set home " + axis); System.out.println(gCodeClient.sendCommand("get abs_act_pos")); gCodeClient.sendCommand("set mode mdi"); gCodeClient.sendCommand("set mdi g0 x3 y4"); gCodeClient.sendCommand("set mdi g0 x5 y2"); } } } 

This example moves the machine portal with the maximum idling speed, first to the coordinates (3; 4), and then to (5; 2).

The following sample program on Groovy is based on the Apache Camel framework and the component for sending commands to the machine com.github.igor-suhorukov: camel-gcode

 @Grab('com.github.igor-suhorukov:camel-gcode:0.1') @Grab('org.apache.camel:camel-groovy:2.18.0') @Grab('org.apache.camel:camel-core:2.18.0') @Grab('org.apache.camel:camel-jetty:2.18.0') @Grab('org.slf4j:slf4j-simple:1.6.6') import org.apache.camel.builder.RouteBuilder import org.apache.camel.impl.DefaultCamelContext import com.github.igorsuhorukov.smreed.dropship.MavenClassLoader def camelContext = new DefaultCamelContext() camelContext.setName("I'll be back") camelContext.addRoutes(new RouteBuilder() { def void configure() { from('jetty:http://0.0.0.0:9090/moveTo').routeId('CamelCNC') .process{ it.in.body = ("set mdi g0 x${Math.round(Math.random()*10)} y${Math.round(Math.random()*10)} z1") } .to('gcode:?host=beaglebone.local&port=5007&autoHomeAxisCount=4') } }) addShutdownHook{ camelContext.stop() } camelContext.start() def HawtIo = MavenClassLoader.usingCentralRepo() .forMavenCoordinates('io.hawt:hawtio-app:2.0.0').loadClass('io.hawt.app.App') Thread.currentThread().setContextClassLoader(HawtIo.getClassLoader()) HawtIo.main('--port','10090') 

You can run the example using java -jar groovy-grape-aether-2.4.5.4.jar CamelCNC.groovy





In this example, the Groovy application connects the components jetty, gcode, creates a route to the groovy DSL camel and loads and launches the web console for monitoring HawtIo. Every time a http request is sent to HOST: 9090 / moveTo, a new command is created with moving to random coordinates along the X and Y axes and sent to LinuxCNC and the machine to execute, and the generated command is returned to the client as http response. Web console listens at HOST : 10090 / hawtio

Quite complicated things are easy to do with the magic of Apache Camel, Groovy and HawtIo.

Beautiful far ...


We can guess about the future.
There is a trend that everything that can be automated and economically feasible to do so is automated. The other day there was news about Foxconn in China and 40,000 automatic machines for their production, reducing the number of jobs in the enterprise. Most of the parts of the machines they do on their own, as well as the control electronics.

Although I am not Nostradamus, but now it is becoming clear that because of automation, jobs will disappear in the future. It is also clear that the need for industrial automation will only increase with time. And people who understand these technologies will be even more in demand in the labor market, but until a certain point ... And personal production at the CNC will penetrate into each workshop.

What exactly will be the future?

Porobot or destroy human robots?



Or humans will also control the robots.



It all depends on us today !!!

findings


Many things that we do by hand and such repetitive work can often be automated. In this case, we must begin with the creation of the model. The next step is the transformation of this model into a control program for an automaton. These commands will perform a certain CNC mechanism and everything in the production process that there is a sense to automate needs to be automated. Using including machine vision technology and feedback sensors. You definitely shouldn't run with a flash drive between a computer and a machine, you need to send commands over the network. Let all the work does automatic. But in order for the CNC not to turn into a casket in two, you will still have to learn technologies and understand the details of the process. Otherwise, you will have to share resources with those who understand and receive as a result not always what they wanted from the beginning.

Links


Who doesn’t matter whether the CAD open source is a product, if only the software can be legally used for free, read the publication and video courses by DIHALT

Source: https://habr.com/ru/post/314462/


All Articles