Fighting with computers

Computers are not always friendly.

Saturday, October 31, 2015

Banging my head with Java line separator

One of the most unpleasant experiences with computers is having to solve a problem you already fixed when you
realize the old solution is no longer working for reasons unknown.

The problem this morning was quite silly, actually. One piece of code created a text file. I did not care much about the way newlines were represented but when  I sent the file to to a colleague that uses Windows he complain notepad was making a mess out of it.

It was clear notepad was doing this because my file, created on a unix system, did not honor Windows end of line convention of CR plus LF characters (0x0d + 0x0a). I have solved that in the past just changing the System property called line.separator. You could do that with System.setProperty("line.separator","\r\n") but apparently not anymore. Of course, no error message or exception is raised, so you are left alone, in the dark, trying to figure out what is wrong and why what worked before does not work now.

I could not make much sense out of it, but I hate these changes that make me waste my time for no known good reason. It just seems the JVM ignores my changes to the property, still named the same way, for the same purpose. It vaguely mentions that a SecurityManager might be needed but I did not explore the problem further, I just learned that, without changing the code, I could use java -Dline.separator=$'\r\n' MyProgram to get it working with the new value for line separator property, so I did and got the problem solved, or almost all.

A few lines of my text file came from a configuration file that, again, did not follow Windows convention. So as I wanted to get the problem sorted out for all the lines and not only those generated from Java code, I had to figure out how to, easily, use vi to replace the LF end of lines by the real deal CR LR. I guess I did that once or twice years ago but I could not remember how to do it now. Long story short: %s/\n/\^M\r/g and please note that for obtaining ^M you need to press Ctrl+V and then Ctrl+M. I am thankful the backslash preceding ^M was mentioned in stackoverflow as its need was unclear to me.

A simpler way of getting a Windows-friendly text file from vi is to use the command :set fileformat=dos


Sunday, October 25, 2015

The right interface

When I was a teenager I was an avid reader of electronics magazines. What was available at home at first and later what I could afford. I remember that my favorite ones was Elektor magazine, that grew from a German-only magazine to be distributed to other languages and countries, mine included. They have this great summer edition that included over a hundred different small circuits.

Over the years I have almost stopped buying magazines (not because they are bad but because they use shelf space and I have not much time to read them). The last paper copies I bought were from Circuit Cellar Ink, but these same guys decided that a digital edition will ease their business, and for those abroad it will be be much cheaper. Selling bits is a good idea that seems to be making Google and many others much good. I even wrote several articles for Circuit Cellar magazine about different projects I made.

A few years ago I learned that Circuit Cellar Ink was acquired by a European group that handled Elektor magazine too. I was invited to a couple of meetings in Germany, together with other international authors, where the future of magazines was discussed. I guess there is an ongoing battle between paper and digital copies, the latter being painfully easy to copy. But at the same time, I found myself not very happy with the way I would browse a digital magazine.

Business like Zinio pop up, offering a better protected distribution than just a bare PDF, but as a I user I always felt these DRM platforms will make my accessing to the content I paid more difficult should I have to renew my computer.

When nobody expected the iPad, the tablet revolution brought a new type of computer that was definitely more friendly to be used for browsing magazines. Apple saw the opportunity and created their own news stand on the Apple store. Later with iBooks they offer an easy tool to create richer documents, but being old fashion I am closer to PDF format for magazine contents. Google did a similar thing for Android.

For me, what is wrong with browsing a magazine in my computer screen is the latter, I mean the screen, which is exactly the wrong format for portrait magazine content. Unfortunately, the first iPad did not worked well with the PDF files that I was receiving from Circuit Cellar magazine at the time.

But I am writing this today because I found myself browsing an Elektor magazine PDF on a not so new Samsung tablet with no problem at all, while sitting on the coach. It is definitely a much better experience than using a modern laptop with a beautiful display but with the wrong format for the content.

So for me, the tablet is the right interface for magazine content and I love it because no matter how many issues are stored, it does not grow my shelf space needs!!

Wednesday, October 14, 2015

First impressions on bq's Hephestos 2

I was asked to be a beta-tester of this new machine sold in kit form by Spanish firm bq.  It's a bit hard to keep the experience to myself while the testing was taking place. I won't say it is great and rosy but their approach was a bold one and I think it stands out of the crowd.

So what is it?

Hephestos 2 is a 3D printer kit to be assembled by the user. While it might find its routes in Josef Prusa iteration 3 model, this time it is just a faded image. That was entirely the case with the former Hephestos that shared most of Prusa i3 features with a few of exceptions: no heated bed, a couple of cable chains and a very well engineered extruder/hotend combo.

But the Hephestos 2 breaks with the Reprap tradition and includes no printed parts and a body made of powder colored folded metal parts. Only Y-axis uses 8mm diameter smooth rods and linear bearings but Z and X-axis use miniature Hiwin linear rails for extra accuracy. A new electronics board integrates an ATmega 2560 plus five DRV8825 drivers with electronic current control (no potentiometers to fiddle with) and a large LCD monochrome graphic display that enables autonomous printing off an SD card.

Not having a heated bed keeps the power supply requirements low so a brick type power supply comes with the kit. By the way, the bed is A4 size (297x210mm) and max print height is said to be 220mm (I haven't printed parts that tall).

Firmware is based on Marlin and source code should be available and it uses a custom-developed inductive bed sensor for automatic bed calibration (tramming).

How it works?

The machine prints PLA very nicely at 40mm/s and Filaflex at 25mm/s. Both speeds can be increased by a fair amount and still get decent prints. The machine insists on doing things its own way so those of you with another printer may wonder why homing requires heating up the nozzle, but these are minor details (that are in fact done for a reason). 

Printing quality has been great in my opinion but what captured my attention mostly was the extruder/hotend combo that is even better than the former Hephestos, now with a dual hobbed gear (a la Bondtech, but direct drive). 

Printer is not noisy but at  a point extruder fans are.

There are some quirks in the beta firmware that made the time between prints not not very reliable, but once a part started printing it always finished ok. I have been using hairspray on the glass bed with great results, but I have not attempted parts with are really large base. I would prefer to have a choice of heating up the bed but I have got excellent results with the cold bed.

What about the build process?

Let me start by saying that my build was a bit of a mess because it started before the manual was available, so I made a few wrong guesses that I needed to undo later in the build. I have been told a trained person can do it in less than two hours (and this has been shown in the product presentation) but I would say it can be done in a morning or evening by one person, though it is always better if you get some help (I was lucky my friend Ruben helped me out and despite all my mistakes the printer was finished in less than four hours). 

I cannot elaborate on the final user manual but the document I used was very detailed so I guess people would have no trouble building the printer. 

The electronics is well thought out and using a combination of color coded calbles and different types of sockets we got a working printer at the first attempt (almost, I messed up the z-probe, but that was again my mistake). 

I just loved the fact all the wires were already inserted into the cable chains. The bed is held by two quick-fit levers (getting them into the threads was most likely the more difficult part of the build).

Conclusion

I will not doubt for a second to name the Hephestos 2 a quantum leap from its predecessor. It feels solid, it looks good and, specially, it prints beautifully. 

Bed is large and that allows large objects to be printed but it means more mass is moving too, and it is not light, so the machine will not be a speed demon. The printer looks good and has a clean design, electronics uses no fan and it can print from SD or from USB. 

Unfortunately I have not been able to use it with Pronterface or Slic3r but used Cura instead that was the manufacturer's software of choice. I tried not to create more noise during the beta testing of the firmware but I hope the final version will play nicely with these fine programs too. 

Did I say it prints Filaflex great, let me say it again. If you are for printing flexible parts mostly, look no further, this is your printer!



Monday, October 12, 2015

More on DC motor "stepper emulation"

The code I developed a while ago for using a DC motor (or a BLDC) to replace a stepper has got quite an interest among youmagine users. Over time I realized that some of the quick and dirty things I did were preventing the easy exploration of system parameters for users. Using different PID parameters required a recompile and of the sketch.

I recently received a Printrbot Simple from Brook Drum with the goal of testing with that printer my closed-loop solution.  As usual, simple things (in theory) become tougher that initially expected. First of all, it took forever for the printer to clear through customs and while Printrbot provided and shipped the printer for free, the taxman wanted its cut no matter what, and it took more than too weeks for that to be worked out.

We settled on the Simple because it had more room for the motors to fit in though carriages might be heavier than the Play.



At the time I did not know the CAD of both models was available on Youmagine, so I only had a vague idea of the potential problems of fitting the DC motors I was planning to use on each model.

Once I downloaded the Simple CAD model and imported into Onshape I was able to redesign one of the plates so it will fit the DC motor instead of the stepper.
That part will help attaching the motor to Y-axis of the Simple but there was no may I can make that while I keep Z-axis threaded rod in place. They do that with the stepper because it has a long shaft but that is not the case with the DC motor I am using. Ok, time to think about it. Maybe I will use some fishing line and a couple of pulleys to have a crane-like Z-axis. For now, let's focus on the drive. While the original part was made of metal, I though I will save some time just 3D printing that part. On hindsight that was not a wise move as the plastic part does not help motor heat to spread to the rest of the metal body, so heat becomes a problem. 

I knew that the axis was heavy so the first test was to determine whether or not the motor could handle the load. I learned that 12V might be a bit on the low torque side but a few more volts in the supply voltage will make the same tiny motor to get much more authority. Same driver electronic could do with a higher voltage so no big deal.

Next problem was to replace the axis belt as unfortunately my motor came with MXL pulley. I managed to get an acceptable setup, but due to my pulley lacking a belt guide I later needed to add a big washer to one of the bearings so the belt could not derail on fast moves.

But once everything was up and running I realized how inconvenient was to need a recompile every time I wanted to test a new set of PID parameters. So what I did was to include some additional serial commands so I could set parameters on-the-fly using the serial port. 

And then, I realized that once you have set the right set of values, it will be great if you can save them so they are not lost when you power cycle the controller. EEPROM was the logical choice and after a bit of fiddling with the EEPROM library (as I have an old iMac I cannot update due to a SMART harddisk error, which forces me to still using an old Arduino IDE) I get the thing working nicely.

Not only you can select P, I and D values, but you can also check current encoder value, output value and target location, command manual moves or set a sequence of random moves, plus you can store current parameters into Arduino EEPROM so next time you power it on it will remember them. 

While all previous code was just uploaded to youmagine, this time I created a github repository so hopefully that will make collaborators life easier.

Meanwhile I still need to figure out how to get another DC motor to X-axis.