Posts

Using a tablet to control a CNC machine

Image
I do have some CNC routers using Arduino Mega and Marlin as pulse generators and g-code interpreters. Usually they are connected to a computer for selecting and streaming g-code files to the machine. Lately I was testing a new machine and I found an old Android tablet laying around, so I wondered if it could be used for the task of controlling the machine. I am aware of programs like Octoprint that can do exactly that using a RaspberryPi and I have seen it does a great job. However, unless some more hardware is added to the mix, no display or user input is possible. But a tablet already has the display and touch screen that can be used for that purpose, plus Wifi and Bluetooth for wireless communication. What was needed was a USB connection but for that a cheap OTG USB cable was all that I needed. Well, once the hardware side is solved, you need some software and after checking and testing different options I ended up with GcodePrintr . A software that is designed for controlling ...

Closed-loop motor control for 3D printers

Image
It is been a while since I brought this topic in my blog. I recently bumped into this thread on element14 about the same topic too. I was naive enough to assume that what shows up on eBay or Aliexpress can be available for quite a long time. It appears that some the units just pop up for a while to never be seen again. That has been the case with some of the motors I have been doing tests with. Since I realized that steppers could in fact be replaced in our 3D printers by a closed-loop DC motor I have been tinkering. One of the key ideas was to find a steady supply of motors that would enable anyone interested into building the same contraption. And while the brushed motors I used worked as expected and were cheap enough, they seemed a bit too weak (not enough torque for higher accelerations) and I was quite worried about how long they will last. On one hand there is the argument that if inket printers replaced steppers by closed-loop brushed DC motors, we could do the same and ...

Minimizing tool air-time

Image
For a CAM software I wrote, intended for milling foam sheets, I needed a way to improve machining time, so once the feed rates are raised to the limit, the next step is to reduce any wasted time. On an initial approach, our tool was finishing parts one after the other, so there was a bit of the tool going back and forth within the same part. While it may seem the whole problem is like a big TSP (travelling salesman problem) and the way to optimize the used time is to connect all the dots with the shortest possible path, it is not exactly so. On a milling operation, the tool path has been carefully calculated so it will remove the proper amount of material by following a certain path. Changing such a path will alter the finish of the part and we do not want to go there. So what we really have is something like two different sets of movements, one that corresponds to the actual cutting operations and a second one that moves the tool over the air to start a new cutting operation....

Importing OpenSCAD designs into Onshape

Image
After using Onshape CAD software for a while I am really fond of it. So one natural thing to do, specially once they have released the Instructor's kit is to start using it in the classroom too. But one thing I was not so sure how to do was to use old designs I made using OpenSCAD. It does not mean I am completely quitting using OpenSCAD but suddenly I can see I can do assemblies in Onshape that will look quite nice for showing and documentation purposes if only I could easily import from OpenSCAD. I am glad to report that the route OpenSCAD --> FreeCAD --> Onshape worked brilliantly. Even more when a few tricks were applied. While some people suggest to import CSG files from OpenSCAD to FreeCAD, I have had more success by directly importing SCAD files into FreeCAD. One trick that worked well for me was to get rid of $fn references, so now circles become real circles (or cylinders) in FreeCAD. If a part keeps some $fn references then your cylinders or circles wi...

Decoding barcodes from scanned pages

Image
A while ago I created a tool that would send the marked exams to my students by email. I used adhesive stickers with a QR barcode they put in the first exam page once they are done. The system kind of works and even some colleagues have started using it too. The problem is that once we have the pile of marked exams scanned as a single PDF file, barcodes need to be read reliably. It is not that the scanned images are bad. I usually scanned it at 200dpi grayscale. The problem is that even if I set the black to the strongest setting is not good enough for ZXing library to decode it properly. And of course if the code is not decoded properly all the system goes under. For a while I have been cranking up the black color using Imagemagick command line tool and when that was not good enough I realized that blurring the document would also helped. While I get that working, the exam itself became not so nice to read after that. Anyway, after a bit more of testing I realized that ...

Making sense of toolpaths

Image
On my CAM project I am using the intersection of a part with a given plane to determine later the proper tool-path for three-axis machining. But sometimes, parts are such that the intersection line contains some concavity. So I detect whenever the tool cannot reach that line and create a suitable solution. In the picture the red line in the top removes any concavity as seen from Z-axis top, converting that polyline into another that might be machined from the top. It is interesting to note that one extra point needed to be created and appears marked with a dashed circle, though strictly speaking both bottom corners of the red line are new points too, but they are not over any of the original polyline space. A second problem appeared once I obtained not one polyline but several of them as a result of objects that contain holes or several domains with respect to the cutting plane as it is shown in the image below. In this other case, the different polylines need to ...

Getting the hang of it

Image
I have been using for a couple of weeks the web-based CAD system OnShape . I did this robot just as test to see how to use the different tools. I have been using OpenSCAD for quite some time and I was not very keen on using some fancy CAD systems like Inventor or Solid Works because I could not afford them but also because they would force me to use Windows, which I prefer not to. But even if AutoCAD can do OSX besides Windows, I do use Linux most of the time. So when I learned that there was a new game in town that was based I was first skeptical that a browser could to the job, but after some testing I am now a believer. And I love to be able to jump from a Linux workstation to a Mac to continue editing my designs. The free version of the service has certain limitations in the number of private projects you can have, storage and something else, but given the fact that can not only import but it exports to popular CAD formats like STEP or IGES it means your work is not locked ...

Rookie mistake with Makercam

Image
This morning I was in the lab of a digital manufacturing subject and I showed my students how they could do simple designs and turn them into a 2D manufacturing g-code without installing any software in their computers or tablets. I did show them the terrific OnShape.com online service that I have found very easy to learn and yet very powerful 3D design package. I performed a simple design. And later I showed how that could be exported as a DXF file and with the help of Inkscape it was written into a SVG file that Makercam.com online CAM software can handle. I selected metric units (though I would expected MM instead of CM but I guess it is ok for grid size purposes) and I proceeded to show the different machining operations available and how we will be cutting the thing. So minutes later we have g-code file ready to be loaded into our CNC router equipped with LinuxCNC software. After setting the whole thing up the process started and seemed to be working ok, though I had the i...

Getting more data from your PID controller

Image
Just knowing the steady-state error of your controller may not be enough for you to figure out how well your manual adjustment for your PID gains is working. In order to get a better picture of it you need to gather information while the loop is reacting to an input change.  However, just sending back information over the serial port while the loop is working may alter the very timing of things within the loop. So what I have done is to delay the monitoring information transfer till the loop reaches the steady state. That means actual position is recorded every millisecond and stored in an array so it is later transmitted once the motion is performed. Thanks to that I can see the system response quite nicely whether the response does have an overshoot or it is dampened properly enough. It really comes in handy when trying to set the P, I and D gains by hand.  The problem, however is that for doing this you need to have enough RAM memory and Arduino UNO is a bit shor...

One Arduino controlling two brushless DC motors

Image
After some changes I have been able to get it working reliably with two motors. But one of the changes I have made is to use a new type of motor that I reckon is better suited to the task. Instead of using brushed motors that are cheaper, I have found other brushless motors that have several advantages:  Being brushless, there is no other wear than the bearings They have built-in driving electronics, so they can be controlled with the Arduino digital outputs, which simplifies things and reduces interface costs.  Motors have built-in encoder disks, too, but the one they carry is just 100 lines per revolution (a bit poor, in my opinion) that can turn into 400 "steps" per revolution with the 4x decoding of the program. The lower number of lines per revolution puts less stress on the Arduino interrupt code, which may be one of the reasons it works ok now. I have moved all the encoder signals to pins that are monitored with the interrupt on pin change, and I have reserved...

Moshidraw: pain on every laser cut

Image
I have been using a [cheap] laser cutter machine. You can see which one on the following video.   Till now it kind of works but what is really annoying is the software you have to use to be able to cut and engrave. It is called Moshidraw and for reasons I cannot really understand it comes with a USB dongle for protection (it will not run without it).  Not in a million years I would like to copy such a program. This is what I have learned so far that causes trouble: If you DXF file contains curves, the operation will fail randomly (suddenly the cut will take an unexpected route and it will ruin your stock material). If you import a DXF and fail to select the part, the cut will did not work properly. If you have several parts in DXF, it may fail at any point (mostly when it is almost finished and all your stock material will be ruined). Best results and lower risk if you do multiple parts one at a time. There not seem to be a way to force inside cuts first, so some ...

3D Tool path generation

Image
I needed for a project to create a parallel finishing tool path similar what many CAM software does. There is nothing wrong with existing CAM software but what fun would be to just buy and use the software. The basic idea is that you can use a swipe plane across the mesh representing your volume and get the top part of each slice to be the tool path. A similar idea is used for 3D printing, but there the swipe plane is an horizontal one and object is built from the bottom up. The problem is that you cannot use the slice you just obtain from the mesh as milling bit (or extruded filament if 3D printing) has a non-null dimension. Because of that, just following the contour of the object will create a smaller result than the model. For 2.5D milling you can do a waterline finishing, doing flat passes on XY-plane. Thus a simple polygon offsetting operation can help you get the part dimensions right. But for 3D milling, the tool compensation becomes more difficult. The solution I opted...

Barcode listings with data

Image
A few weeks ago I mentioned a new tool I created for (allegedly) making my life easier when delivering marked exams to my students. Then I covered the process that happens after the exam. But one key element it was not mentioned is what it needs to do in advance. For my system I needed a set of labels. My prototype used Code-128 barcode that can handle ASCII code to encode each student email using barcode command-line program for Linux. The only problem with that was the lack of additional information being added to the label, such as the student name. Looking around I found a very handy tool by AVERY company, that helps you creating labels on-line for all their range of labels. What is even better is the tool will allow you to upload an excel file with data columns, like names and addresses to create a custom listing you designed and export it as PDF (they offer to print it for you to and deliver the labels to your office too). After some tweaks and, the most difficult part, di...

Maple Mini looking good

Image
This week I received a real bargain I wanted to test as a better candidate to be able to control several DC motors in closed loop. I have already tested the STM Nucleo 401 board and I get one 32 bit, signed, hardware encoder input on timer 2 and three more unsigned, 16-bit hardware encoder inputs on other timers. Unfortunately timer 5 was taken by the mbed library I was using. Nucleo is a solid platform and using the cloud IDE actually is not big deal for me. But now I have got a Maple Mini for $4  and I have to tell you I am totally sold. It is so much faster compared to an ATMega Arduino that I am positive it can do the work for controlling two DC motors closed-loop and most likely it can do four or more. The board can handle up to 16 external interrupts, enough for 8 encoders, and it can produce 12 PWM 16-bit resolution outputs (a far cry from 8 bit PWM from Arduino, though I am not sure that will have any impact on the system performance) plus plenty of memory (128K flash...

A better mousetrap so to speak

Image
Once in a while I need to mark exams. Exams do not tend to please students and marking exams is rarely a task anyone enjoys doing. But I cannot change that. What we do later is what I was trying to change for a while: For some years I have been using Scribd as a platform to make available the marked exams to my students. As I did not have a better tool, I started by doing the scan of the big pile of exams to later make it available as a document they can browse on the web (but not download). Making all the exams available to all the students is a liability that created me no trouble so far, but I can see privacy concerns plus fear of putting too much information in the hands of the students. To address the privacy concerns I did not made the document visible or public, but private so only those with the secret URL could browse it. On top of that, marked exams were kept available for a couple of weeks before being deleted. The idea of a student being able to review the whole marki...

Sometimes you get lucky, sometimes not

Image
I have wasted a fair amount of time today with a problem I solved the way I recommend to others: use a library. I needed to do a polygon offsetting in a program and I used what has worked for me in the past, the Java Topology Suite. I did my thing and it almost worked perfectly: However, I noticed a minor artifact once in a while. After some time I found that offset would sometimes did not work well as a weird line would appear crossing (line between to small circles) my beloved pumpkin instead or remaining on the outside (horizontal crossing was expected though). I as not trying to do a full offset but only of the part whose normals is between 0 and 180 degrees, as this project is related to 3d milling.  After a few hours of testing it all came down to a defect on the library (as far as I can tell) because with the same input data, but a smaller offset value, the operation was succesful as you can see below: I was unable to find a proper forum to ask other us...

Do more with less

Image
Following my previous post about using an Arduino for controlling a DC motor with an encoder in a closed-loop fashion some people have asked me if one Arduino per motor was not too expensive. Well, if you use an Arduino Pro Mini it can be less than $2 each. However, I do feel too that maybe we can do better. The main reason of my initial approach was that I had several signals that need to be handled fast-enough. On one hand, the quadrature encoder of the motor provides two pulsing signals that are used to know the current location of the motor shaft. This is accomplished by counting pulses, if not done fast enough, missed pulses will translate into position errors (and we are going closed-loop instead of using steppers to avoid exactly this same problem). On the other hand, the motor controller has to be able to receive pulses from the main controller (an Arduino Mega running Marlin) that control the motion of the motor. These pulses can be quite short and frequent (up to 40K...

Closed-loop DC motor to act as a stepper motor

Image
One of the things that I hate the most about 3D printing is that these machines are usually working in open loop and, sometimes, a tiny error happens that ruins a long print. Most 3D printers use one or more stepper motors to move each axis. Steppers are a good solution to the problem, they are easy to control and have lots of torque (compared to similar sized DC motors) but they may skip a step occasionally. The problem then is the print head is no longer where it is supposed to be but slightly off. From there on the print is misaligned and most likely will be useless. Any type of motor can be equipped with an encoder to check its location at any time. However that adds an additional cost to the equipment and requires extra software to handle this new information. One idea that has been mentioned many times in RepRap forums is that if steppers were replaced by DC motors with encoders that will allow the accurate position control that offer the steppers, the machines could be mad...

Loading TinyG2 in the Arduino DUE

Image
I have been intrigued for a while with TinyG controller and their S-shaped speed curves. It is an evolution from simpler trapezoidal speed patterns used by GRBL software and by most 3D printer firmwares out there too. However, TinyG (besides a South Korean music group) is not designed to work on a regular Arduino but over more powerful Atmel processors, the XMega series. While the software is open source, it does not help if you do not have the right processor. But lately I am giving a course where I have borrowed an Arduino DUE, which happens to be supported by TinyG project too. Uploading the code has been a bit of challenge, partly due to my attempt of using a USB cable with broken data wires (I did not know that as I use it for charging my cellphone). But even with a good cable, the upload process, at least using OSX was a bit of a challenge. It all comes down to a not entirely cooked script from their github . As I am not familiar with ARM development conventions, I see ...

Another one bitten by the bug

Image
While I have been doing electronics since I was a kid I never owned an oscilloscope before. At a local meeting of Arduino users a colleague mentioned me there was a very good offer of a four channel sampling oscilloscope. Not that I need to use it very often but I was curious enough to see how instruments have evolved lately I decided it was about time to have my own scope so it was kind of a birthday gift I bought to myself (if that makes any sense). First thing I have measured, just because it's right next to me is the the ringing of my 3D printer's hotend PID regulator output. It has been mentioned voltages can get pretty high over there in RAMPS boards and boy, that is true. At around a 50-volt spike is produced when the load is switched off. And the real value can only be appreciated if you freeze the sampled signal and expand widely the time axis, as the spike duration is below 1us. I guess total energy is so small the MOSFET is not really damaged (as it has been sitt...