Author Topic: DIY DRO for lathe or mill  (Read 7686 times)

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
DIY DRO for lathe or mill
« on: May 10, 2020, 05:51:33 PM »
A week or so ago, a shiny new DRO unexpectedly(ish) arrived at my workshop.... OK, not that unexpected really; it's for my old Edgwick lathe. It's also not the story for this thread - I'll document the fitting, and some of the hoops I had to jump through, elsewhere, when it's closer to being done.

My original plan, before the Chinese manufacturer (Ditron - via AliExpress - good crowd, based on my experience) heavily discounted the DRO readout for me, was to just buy the scales, and use an Arduino to read them. Initially, I'll be using the supplied DRO head, which is actually surprisingly usable.... but long term I still want to make my own, with the features I want in it...

Also - due to impending arrival of first child - I'm about to lose most of my workshop access privileges (and time!), which means much more time sat around at home with a relative paucity of tools... so I plan to fall back to plan "B" and use my software skillz to write the DRO head software for the DRO I want. And it also occurred to me, that you, gentle reader, might have some ideas of what makes a good DRO for you that I haven't thought of....

So, the overall plan looks like this:
 - Each axis will be connected to a cheap Arduino clone (Mini Pro, probably, as I have a bag full of them). One per scale, because with the 1 micron scales I've bought, they can't reliably keep up with more than one - and also, the system needs to track both A & B channels fully, in order to get the 1 micron resolution.
- Each axis will communicate its scale position to a Raspberry Pi, which will be running the DRO software
- A 7" touchscreen will provide the primary interface.
- I may also add some real buttons, if it turns out that regularly jabbing a touch screen with oily fingers doesn't work too well...

So far, I've "built" (the word is massively over-used in this regard) a one-scale reader, which appears to work fine. Yes, you can trick it if you move the scale too quickly.... the only part of a normal lathe/mill I can see this potentially being a problem is on a quill-mounted DRO, where it's possible to move it faster (I think - haven't tried) than the Arduino can count. I'm wondering about the carriage too, I can move that pretty quickly on the lathe. If it is an issue, there are faster boards out there than the Arduino.

Anyway.... with the basic principle established, now's the time to start designing the features. So far, I have:

Readout:

- Obviously, the basic "N" axis readouts are essential. In addition to the usual switchable decimal inches/metric; I think I could display both simultaneously (primary and secondary, secondary being smaller). Not sure how useful that would be.

- For our American friends, I wonder, would an inch fractional readout be useful? Maybe down to 64ths, with the secondary readout showing the usual thousands or tenths.

- Ability to re-name/move around each axis in software. So if you don't like the conventional "Z-Y" on a lathe, you can rename them "Carriage" and "Cross-slide", for example. Or "Tailstock". Or whatever Tailstock is in your first language.

- Nice big numbers that are easy to read. Actually, the Ditron scale is excellent in that regard, I will shamelessly copy it. But also allow the user to configure the colours.

- All-axes reset from a single button (with undo). Again, the Ditron partly does that (you can undo a zero press), but to zero all four axes requires four button presses. And really, who has the time for that, eh?  :scratch:


Features:

Some ideas below for things the DRO can do.

- The usual Chinese DRO functions: Bolt pattern, 1/2 function being the two that instantly spring to mind.

- The ability to combine two axes. e.g. on a mill, the Knee/column "Z" axis, could be paired with the quill "z" axis, to give a unified read. So now, move either the table/column OR the quill, and your "Z" reading moves as appropriate. On a lathe, you could combine the main carriage + compound slide axes so you can accurately bore to a certain depth using the compound, even if you accidentally moved the carriage last time you measured it (don't ask me why I bring THAT specific example up!). It also occurs to me that, with a smidgeon of trigonometry, you could accurately cut a depth even if the compound is at an angle, if you can type that angle in somewhere. Or have a rotary encoder on the compound slide too! :D

- Targeting with audio alert: By which I mean... let's say you want to bore a hole exactly 1" deep. Rather than watch the DRO, wouldn't it be nice if it beeped at you as you got close to your target depth; the beeps getting faster & eventually becoming a solid tone as you reached depth. Almost exactly the same as reversing sensors work on cars... Just means you don't need to keep watching the DRO instead of the workpiece.

- Switchable diameter/radius mode (for lathe cross-slides). No more having to remember to half the depth of cut to hit a specific diameter.

- Tool library (I think most Chinese DROs implement this in some form. I've watched This Old Tony going through his DRO functions, and I reckon I can make it an order of magnitude easier to use). This won't be much use on my lathe, as my toolpost is not particularly repeatable. Plus I don't have anything like enough tool holders.

- Angular readout: If I ever find a cheap dividing head on eBay (or maybe make one?) that I can experiment with fitting a rotary encoder to... it would make gear cutting a more straightforward operation. That said, if one is going to that much trouble, maybe it'd be easier to just make an "cnc-esque" dividing head with a stepper motor & remote control. Still, it'd be cool if the DRO could control it, wouldn't it?

That's all I can think of right now... but I should have a decent amount of time to incorporate any scope-creep that might come along; and if there's any feature you can think of that I could sensibly add.... feel free to suggest it.

I'm also happy, once the basic principle is proven out & the software is at a point where it could be considered useful, to build a DRO unit for any madmodder, for the basic cost of the parts & postage. i.e. no labour & no fee for the s/w, if anyone is interested? Note that at this time, I have pretty much zero idea how much the parts will cost! Although I do expect the screen to be the most expensive bit, at around £45.

PS: I'll also do a proper (and I mean, proper) write up of the plans and designs for all the parts (except the scales themselves), so you could build your own from the plans if you preferred). The S/W I will make freely available under one of the open source licences.
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline WeldingRod

  • Sr. Member
  • ****
  • Posts: 400
Re: DIY DRO for lathe or mill
« Reply #1 on: May 10, 2020, 07:21:10 PM »
Being able to type in a specific number is super valuable!  I do it all the time after I measure something on the lathe.
I can't see any machinist being interested in fractional readout.
Putting a scale on a cross slide is quite a trick...  I did manage it on my old lathe :-)  angular encoding would be even more miraculous.  I could imagine a super thin pcb pattern glued to the carriage with a caliper type capacitive reader.  Hmmmmm
Saving the position on power loss is a perk!

I could imagine either a visual bar graph approach indicator and/or a separate flashing light.  Maybe a button for "I'm going back here a bunch of times".  Maybe three separate "here" locations?  Choice of approach direction or default both ways?

I like your list!

Sent from my SM-G892A using Tapatalk


Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: DIY DRO for lathe or mill
« Reply #2 on: May 11, 2020, 02:53:41 AM »
I’ve had DROs on my Bridgeport for ages from BM Electronics that use a stainless wire wrapped round a spring loaded drum passing over a spool with an encoder. All this enclosed in a small die cast box.

 One of the calibrations they offered was for angular measurement by wrapping the external end of the wire round (say) the degree drum of the top slide.

I have to say I have been very impressed with them, especially as they were the cheapest DRO that I could buy at the time , this was before the Far East flooded the market.

Andrew Mawson
East Sussex

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #3 on: May 11, 2020, 04:23:33 AM »
Not to put you off but... (BTDT using VB5 and my own microchip PIC interfaces)

Have a look at Touch DRO for andriod (works fine even on old tablets like HUDL etc) - it uses bluetooth or serial to connect to the scale interface devices (arduino etc.) and will save you a whole pile of grief writing software (at least until you see exactly what you want from the DRO)

For a Pi  you might want to look at Python and Kivy - I'm currently using it for a automated test system project , and once you get your head around the thing , it works nicely (doesn't require the Debian desktop overhead - see picture below)

One thing I really liked on my VB5 DRO  that I haven't seen on other DROs is analogue displays of fractional inches (and simultaneous display of inch and metric) . If you work in both systems it's so much easier than switching scales.

Bill

Offline Sea.dog

  • Full Member
  • ***
  • Posts: 232
  • Country: gb
  • Up Spirits!
Re: DIY DRO for lathe or mill
« Reply #4 on: May 11, 2020, 04:55:27 AM »
I’ve had DROs on my Bridgeport for ages from BM Electronics that use a stainless wire wrapped round a spring loaded drum passing over a spool with an encoder.

That's interesting, Andrew. I was considering something along the same lines when trying to work out how best to fit a DRO to my Boxford. What worried me about that solution was the effects of temperature change on the accuracy.

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: DIY DRO for lathe or mill
« Reply #5 on: May 11, 2020, 07:48:15 AM »
Not to put you off but... (BTDT using VB5 and my own microchip PIC interfaces)

Have a look at Touch DRO for andriod (works fine even on old tablets like HUDL etc) - it uses bluetooth or serial to connect to the scale interface devices (arduino etc.) and will save you a whole pile of grief writing software (at least until you see exactly what you want from the DRO)

Hi Bill,

Thanks for the link to TouchDRO - I have seen that site once before, a long time ago; I wonder if some subliminal memory is at work, as I (quite independently, I might add!) seem to have come up with many similar requirements to his own...

As for "the grief of writing software" - I've been professionally writing software for the last 25 years, and as an amateur/student for almost 10 years prior to that - so it's not really "grief" for me, more of a challenge. Especially as I'll probably have to do it in QT C++ (which I've never used before), if I want the Raspberry Pi to boot in any kind of sensible time frame. Around 5 seconds appears to be achievable, which is plenty fast enough for a DRO (on the other hand, the standard 30-60 seconds isn't). So lots of new things to learn and play with.


For a Pi  you might want to look at Python and Kivy - I'm currently using it for a automated test system project , and once you get your head around the thing , it works nicely (doesn't require the Debian desktop overhead - see picture below)


I'll check that out, thanks!


One thing I really liked on my VB5 DRO  that I haven't seen on other DROs is analogue displays of fractional inches (and simultaneous display of inch and metric) . If you work in both systems it's so much easier than switching scales.

As you can see from my list, simultaneous output of mm & inch (or vice versa) was on my list; I hadn't considered having the fractional readout simultaneous as well. One to add to the options list ;) FWIW, the main criteria of the readout, for me, is that it's clearly visible when I'm at the other end of the lathe peering through a cloud of smoke and trying to dodge red-hot chips :D

My 7" screen is due to arrive today (a day earlier than originally quoted), so with a bit of luck I'll get some Pi code done tonight  :thumbup:
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #6 on: May 11, 2020, 09:15:49 AM »
Quote
As for "the grief of writing software" - I've been professionally writing software for the last 25 years

Clearly you've not been doing it long enough yet (I wrote my first program in 1968 ;-))
Bill

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: DIY DRO for lathe or mill
« Reply #7 on: May 11, 2020, 09:51:25 AM »
Quote
As for "the grief of writing software" - I've been professionally writing software for the last 25 years

Clearly you've not been doing it long enough yet (I wrote my first program in 1968 ;-))

1968? I guess you know COBOL then? Seems its back in demand (again)...

In fairness to me, I wasn't even born then.... the first computer I saw was a BBC "B", must have been 1982. Our Local Education Authority had either one or two of them, and they toured the primary schools on strict rotation - 2 weeks in each school. I was hooked from the first time I used it...  In autumn 1984, we got a Sinclair QL (one of the first of the second batch - the first batch that actually more-or-less worked properly), and I battered that machine for the next 6 years, until I went to University (I took it with me... wrote all my lecture notes on a Tandy TRS-102 I'd bought, and transferred them to the QL via a homebrew serial link, re-formatted them in Quill (the QL's word processor). I probably have a disc, somewhere, with all that stuff still on it.

Anyway, long story short(ish), I've never been far from a computer since...
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #8 on: May 11, 2020, 10:21:20 AM »
Fortran or c&g (school kids language -pretty much assembler) punch cards or soft pencil cards when you couldn't get a punch .
Bill

Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: DIY DRO for lathe or mill
« Reply #9 on: May 11, 2020, 08:18:25 PM »
I've just added DROs to my rose engine on the X and Z axes.  Changing tools usually changes the actual cutter tip quite a bit.  While I can reset zero at any time, what I'd like to be able to do is set an offset to zero.  In other words, press the zero button, then enter an offset.

I think fractions and DROs have no place together  :bugeye:  Fractions require far too much rounding to be accurate.  My DROs do show fractions but fortunately the text is really small and dim so they're easy to ignore.

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: DIY DRO for lathe or mill
« Reply #10 on: May 12, 2020, 02:29:59 AM »
Usually, the "zero offset" is done using a tool library, are you thinking along the lines that having changed tool, you'd go into "offset mode", touch off the tool, then back to "normal mode" and the machine carries on as before? Or would you prefer to say "I've put in tool #73" and the machine knows the offset already, because you already programmed it?

Regarding fractions - I agree that, on a metal machine, fractions are probably not that useful. Could be handy for woodworkers though? I can also see it being useful if you've got, say, a bolt pattern to drill & the dimensions are given in inch fractional... Rounding shouldn't be too big an issue on one micron scales, and if you're working to the nearest 1/4", what's the odd tenth between friends? :)
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #11 on: May 12, 2020, 04:24:49 AM »
Fractional inches are not uncommon, hardinge parts are often multiples 1/64 , just like metric parts tend to stick to integer mm. A fractional display avoids the need for decimal conversion.
Bill

Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: DIY DRO for lathe or mill
« Reply #12 on: May 12, 2020, 04:27:16 AM »
The rose engine is a little different than a lathe in that the headstock can move side to side as well as along the Z axis. The cross slide also floats on the bed, so it can be set at any angle to or distance from the headstock.  There's no concept of touching off (but I'll have to think about that a bit more to see if it's practical). 

One of the recurring tasks is to cut a tenon on the end of the workpiece in order to machine the inside of a lid.  After starting to cut the tenon, it would be nice to be able to measure the diameter, then set zero based on that measurement. 

I think that if you allow data entry in fractions, then the actual decimal values should be displayed. How will you decide what the smallest fraction denominator will be?

My rose engine project uses stepper motors for the spindle as well as for the X, Z, and B axes.  I'm using a Teensy 3.5  (Arduino compatible) and a Nextion touch screen.   


 

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #13 on: May 12, 2020, 06:53:26 AM »
Quote
I think that if you allow data entry in fractions, then the actual decimal values should be displayed. How will you decide what the smallest fraction denominator will be?

You don't need to decide , the fraction is a simple division function. Data entry in fractions is common in CAD/CAM (as is unit specific entry - solidworks will allow you to enter 1/27" while working in metric or even 1/4mm if you so wish )

On my analogue 'inch' meters, the option is set as part of the VB object's display parameters  , I chose 1/64 as it is about the smallest division in common use .

As I said above I found it very useful and would include it in another DRO .(see video below)

https://drive.google.com/open?id=1mp6jvlf6PH_2U3VWnIHgY3bB39XeZ_37
Bill

Offline djc

  • Jr. Member
  • **
  • Posts: 85
Re: DIY DRO for lathe or mill
« Reply #14 on: May 12, 2020, 07:01:49 AM »
A couple of things:

Presumably you are aware of how you can use native AVR assembly instructions as well as AVR C within the Arduino environment. This can considerably speed things up as the Arduino programming language has a lot of overhead built in (canonical example, how to toggle a pin).

If you know the pulse speed it can reliably read, monitor it and it it is exceeded by 10%, flash something up on screen to warn that there is a possibility of position loss (like the temperature light in your car: your engine will not blow up the minute it lights up, but Bad Things will happen if you ignore it).

On your reversing sensor, I maybe question why you would not want to look at the DRO. I certainly do not want my lathe beeping at me. The trouble with a digital count down is you have no sense of how fast it is progressing. If you could replicate on screen the analogue clock gauge we have on the carriage, that would be a winner. You can see how fast the hand is sweeping and how close it is to zero. Bigger the better on screen.

What of ability to move between machines?

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: DIY DRO for lathe or mill
« Reply #15 on: May 12, 2020, 09:44:57 AM »
Some really good ideas coming through, thanks :) Hope to make this the DRO for Everyone (on Madmodder at least!) :D

Some specifics:
 
Bill - I do like your vertically scrolling fractional indications! That's a far better solution than the one I had in my head (where it just displayed the nearest /64th, or simplification thereof). With enough gap between each reading, you could very accurately creep up on a specific fraction. I'd probably change the colour when you were bob on (to +/- the nearest micron or tenth maybe), as a visual cue that you're on dimension. Obviously the digital readouts would confirm. With your permission, I'd like to steal that idea...

Regarding the entry of fractions (e.g. the 1/27" mentioned); you'd type that in, the machine stores it as 0.9407mm. This converts back to 0.0307" (to the nearest 10th); the fractional display would indicate it was somewhere between 1/32nd and 3/64ths, using the slider style per Bill's video.

To the speed of the Arduino - yep, going "bare metal" is definitely an option, although at the moment it seems that the Arduino is good for a fairly fast speed (80mm/sec seems OK). I could also look to using a Teensy - a bit more costly, but they seem to have some serious horsepower for not a lot of bucks ($20 for the latest Teensy 4.1). I've never tried a Teensy, this seems like a perfect excuse :D

I like your "overspeed" indicator idea as well. I may have mentioned there's an "R" signal as well, which I *think* is a pulse every Xmm (the manual is vague to the point of silence about this); but if there is an overspeed, I might be able to use the "R" pulses as a way of getting the scale back to a known good value... although if you're determined, you'll still be able to spoof it. Plus, if it misses one, it'll make matters worse.

Regarding the beeper: You'll be able to turn it off :)

Swapping between machines? Don't see why not. Storage is cheap, the DRO could easily have any number of "personalities". From a hardware POV, having an interface box which stayed on the machine with the scales, with a one-cable connection to the display unit, is easy peasy. There'd only be four wires: Power, ground, I2C. It would also open up the possibility of having a number of different DRO heads (with different capabilities) which would all attach to the same base unit... Scope creep! I like it!  :palm:  :)



------

Another one for the feature list:

 - Automatic edge-finder offset. Guess who had to do some edge finding this morning :) Now, this is easy enough when I'm working in Imperial (just preset the DRO to +/- 0.100" depending on which way the table is moving, presto). Much more of a pain with Metric - I have to edge-find in Imperial, move to zero-zero, THEN switch to mm. Why don't edge finder sets have 1 or 2 imperial edge finders and 1 or 2 metric edge finders, instead of mix/matching 1/2", 3/8" (with 0.200" indicator barrel), and the pointy ones that no-one ever uses? The way I see this function working is; you find your edge; press "Edge", choose the tool you're edge-finding with, choose the edge you just found on a graphic on the screen, and the appropriate axis gets set with the correct +/- offset.
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #16 on: May 12, 2020, 02:20:04 PM »
Re scrolling display. Ok by me:-)

I should have the source code somewhere,if it would help.
Bill

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: DIY DRO for lathe or mill
« Reply #17 on: June 08, 2020, 08:09:06 PM »
Update: Progress is being made.... I gave up with Python (horrid language), and Gtk (even more horrid)...

I've also decided (just now) to not use the Arduino; I finally bought me a Teensy 4.0, for the princely sum of around $20. Good GRIEF that thing is fast! Using the boggo Encoder library, and about a dozen lines of code, I can now read the encoder so quickly that I just can't make it miss steps! Mind you, I daren't REALLY slam it from one end to the other in case I damage it (they're not cheap, you know!). Not that surprising, the Arduino was doing "OK" (but could easily be provoked into losing position), and the Teensy 4.0 is around 600 times faster. Yes - six HUNDRED.

Mental...

SO... the current plan is:

- Teensy to read the axis (possibly one will now do all four axes, this has yet to be proven)
- Raspberry Pi running a Go service routine, to read the encoder via I2C, and output a stream of Server Sent Events over http.
- Also on the Pi - a React website (possibly served via the Go program), which provides the UI.
- It will run in a Chromium browser running full-screen in Kiosk mode.

Why React? Because I can do it, and because desiging a GUI in HTML/CSS is literally one point seven seven three two million percent easier than trying to figure out GTK.

The only fly in the ointment is - I don't yet know if the React app on the Pi will be fast enough. On my dev machine (which is old and not very fast), it needs the server events to be throttled down to 50Hz, or it gets laggy. Still, 50 updates a second is more than enough, I reckon anything down to 20Hz will be acceptable.

Oh, yeah, and in React, it took me about 2 hours to get the "tape measure" fractional display working. 3 days in Gtk and I couldn't even find out how to show a part of an image in a box...
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #18 on: June 09, 2020, 09:31:04 AM »
Quote
Python (horrid language), and Gtk (even more horrid)...
Python has plenty of good points but it is quirky and takes a while to get used-to.

Gtk (also Tkinter ) yes really is horrid , it mixes C++ with python in a' WTF did they do that?' kind of way. BUT I've built a few applications with it and it works ok

Kivy is also horrid , though mainly because it is trying to be all things to all systems. BUT is useful because it is all things to all systems.

If you want fast for £20 look at sipeed Maix Dock dual 64bit core  risc-V @600Mhz , wifi display, camera ,digital audio , and a hardware neural network ! - has a reasonable IDE for windows and Linux  - documentation is - not all it could be ...

Bill

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #19 on: June 09, 2020, 10:34:04 AM »
Quote
I couldn't even find out how to show a part of an image in a box...

I couldn't remember how I did mine - just checked .
I used a few of VB Label controls (three for fractions :current, positive and negative) drawn on a picture box control, updated the label.caption text on the fly  then cropped and positioned them to give the appearance of motion 

Code: [Select]
Public Sub InitScale(Div As Integer)
'fractional scale is divided into Div parts
'e.g. if Div = 4 then scale = ---- 1/4, 1/2, 3/4 ----
Divisions = Div
Dim n As Integer, Y As Integer
Dim F As String
Dim Scl As PictureBox
Dim DivY As Integer 'height between scale divisions

    Set Scl = picSclFrac
    Scl.Cls
    DivY = Scl.TextHeight("1/2") + 50 '
    ActiveScaleHeight = DivY * Div
    Scl.Height = ActiveScaleHeight + (DivY * 4)
    'draw zeroline
    Y = (UserControl.ScaleHeight / 2)
    UserControl.Line (0, Y)-(UserControl.ScaleWidth, Y)
   
    'draw scale lines
    Y = DivY
    F = Format(Div - 1) & "/" & Format(Div)
    Scl.Line (0, Y)-(Scl.ScaleWidth, Y)
    Scl.CurrentX = (Scl.ScaleWidth / 2) - (Scl.TextWidth(F) / 2)
    Scl.CurrentY = Y - (Scl.TextHeight("1/2") / 2)
    Scl.Print F
   
    Y = DivY * 2
    Scl.Line (0, Y)-(Scl.ScaleWidth, Y)
    Scl.CurrentX = (Scl.ScaleWidth / 2) - (Scl.TextWidth("0") / 2)
    Scl.CurrentY = Y - (Scl.TextHeight("1/2") / 2)
    Scl.Print "0"
   
    For n = 1 To Div - 1
        'draw scale lines
        Y = DivY * (n + 2)
        F = strProperFraction(n, Div) 'Format(n) & "/" & Format(Div)
        Scl.Line (0, Y)-(Scl.ScaleWidth, Y)
        Scl.CurrentX = (Scl.ScaleWidth / 2) - (Scl.TextWidth(F) / 2)
        Scl.CurrentY = Y - (Scl.TextHeight("1/2") / 2)
        Scl.Print F
    Next n
   
    Y = DivY * (Div + 2)
    Scl.Line (0, Y)-(Scl.ScaleWidth, Y)
    Scl.Line (0, Y)-(Scl.ScaleWidth, Y)
    Scl.CurrentX = (Scl.ScaleWidth / 2) - (Scl.TextWidth("0") / 2)
    Scl.CurrentY = Y - (Scl.TextHeight("1/2") / 2)
    Scl.Print "0"
   
    Y = DivY * (Div + 3)
    F = "1/" & Format(Div)
    Scl.Line (0, Y)-(Scl.ScaleWidth, Y)
    Scl.CurrentX = (Scl.ScaleWidth / 2) - (Scl.TextWidth(F) / 2)
    Scl.CurrentY = Y - (Scl.TextHeight("1/2") / 2)
    Scl.Print F
    Scl.Refresh
    'calculate offset
    SclOffset = (UserControl.ScaleHeight / 2) - (DivY * 2)

    PositionScale 0
End Sub

Private Function strProperFraction(Numerator As Integer, Divisor As Integer) As String
'return correctly formatted proper fraction
Dim n As Integer
Dim nr As Single
Dim dr As Single

    For n = Numerator To 1 Step -1
        nr = Numerator / n
        dr = Divisor / n
        If (nr - Int(nr)) = 0 And (dr - Int(dr)) = 0 Then
            strProperFraction = Format(nr) & "/" & Format(dr)
            Exit Function
        End If
    Next n
   
End Function

Public Sub PositionScale(POS As Single)
'position picsclfrac
Dim IntPos As Integer
Dim FracPos As Single
IntPos = Int(POS)
FracPos = POS - IntPos
' set integer labels
labFracInte(2).Caption = Str(IntPos - 1) & " -"
labFracInte(1).Caption = Str(IntPos) & " -"
labFracInte(0).Caption = Str(IntPos + 1) & " -"
labFracInte(1).Top = (UserControl.ScaleHeight / 2) - (labFracInte(1).Height / 2) - (labFracInte(1).Height * FracPos)
labFracInte(2).Top = labFracInte(1).Top - labFracInte(1).Height
labFracInte(0).Top = labFracInte(1).Top + labFracInte(0).Height
picSclFrac.Top = SclOffset + (0 - (ActiveScaleHeight * FracPos))

End Sub
« Last Edit: June 09, 2020, 12:43:07 PM by BillTodd »
Bill

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: DIY DRO for lathe or mill
« Reply #20 on: June 09, 2020, 06:22:17 PM »
Hi Bill,

That's pretty much what I'd wanted to do with the Python/Gtk (also tried TkInter, but fell out with that one as well - Qt didn't look any better); just building and positioning the controls was an absolute nightmare, never mind moving them on the fly, or cropping them inside a viewport...

Rather than use labels for the fractions, I just use a giant PNG file (6400px & change tall, 50px wide, about 5k in size), which I build with an ImageMagick script (which is itself built with a Bash script); this covers +/- 1" in 64ths (with /128th marks, but no legend). I simply use this as a background image on a fixed-sized div, and change the position to show the correct bit. Had to go with + and - sections, otherwise the tape effect "bounced" between +ve and -ve readings instead of continuing to roll in the same direction...

Your whole number is better than mine at the moment (which is just a fixed display), I'll use a similar technique to yours I think for that - an absolute-positioned field, which gets rolled up/down as the next number comes into play.

I just need to transfer the UI/browser app to the Pi, to see if I'm going to need to use a Pi4 to get enough performance, or whether a 3+ will suffice. I'm hoping the latter will do.

Reliability seems good - I've had the thing running on my desk for several days, powered via the computer's USB port, and it's worked flawlessly - but, then, most of the complex stuff isn't there yet!

Cheers,
Ade.
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline BillTodd

  • Hero Member
  • *****
  • Posts: 1096
  • Country: 00
  • Colchester Essex (where the lathes were made)
Re: DIY DRO for lathe or mill
« Reply #21 on: June 10, 2020, 05:13:07 AM »
Quote
positioning the controls was an absolute nightmare,

GTK and kivy have a completely different paradigm for form design compared to MS (windows) absolute position: the controls are placed and sized automatically and are only influenced by size-hints (proportions) . There are ways to place and position using co-ordinates but without any Wysiwyg IDE (that I've found),  it's a PITA to design exactly what you want.

I was going to look into recreating the dial in kivy , but got distracted by an email from Doug Self about a German  book publisher wanting to use a still from one of my engine animations  to illustrate a Horse gait  !  to which I had to reply with this:

https://drive.google.com/file/d/1pAxOsuQEV9IGkRlEPe2Rhh5Sbauc1p1t/view?usp=sharing
Bill

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: DIY DRO for lathe or mill
« Reply #22 on: June 10, 2020, 05:21:08 AM »
I tried using Glade to design the Gtk layout - but even that's a pig to get everything lined up; and (from what I recall) you then use the output from Glade + a library to generate your UI on the fly.

All in all, none of the UIs I've tried for Linux, are really suitable for doing a fixed-layout on a fixed-screen; they're all designed to be flexible - which is great 99% of the time, but this is the 1%...

I'm hoping to get to the point where I can try the entire app end-to-end on the Pi today; if so, that'll give me an idea if I'll got the performance I need out of the Pi3+,
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...