Interrupt Driven Rotary Table controller

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
The buttons are soldered parallel to the LCD shield buttons. I haven't changed anything in the code, so I imagine A0 is the default for the LCD shield. The buttons work perfectly fine browsing through the menus and the jog function works just like it used to and so does the continous running function.

I'm only having problems with the division and angle programs. After selecting the number of divisions or the angle and pressing select to start, the program starts running and no button will stop it. I have to reset to get it to stop. This was not an issue with the original script. Only now that I replaced the goDivide routine with the new one, this problem appeared.
 
Ive been following this thread loosely since its start. I haven't commented much due to no hardware to even try anything out on. However i have noticed people having problems with floating point. This is not uncommon in the Computer Sciences industry as there are all sorts of gotchas.

This has me wondering if any body has tried using integers to count arbitrary numbers of fractional degrees? This can be likened to how banking apps count in cents via integers values instead of using floating point. So you take a circle and divide it up into one hundredths or one thousands of a degree and do you calculations based on the fractional degrees you selected.

So if you want to work in 1/100ths of a degree you effectively have 36000 parts in a circle. Gear reductions impact this as do steeper counts per rev and could result in Integer overflow and may require 32 bit integers. The goal though is one count equals 1/100th of a degree.

Frankly guys my algebra is rusty! I just have to wonder if floating point in your calculations is worth the trouble they cause. There are whole books written on the use of floating point in computers due to all the things that must be considered to get the right results.

I hope this doesn't distract i just don't gave hardware to test any thing I'm thinking about right now.
 
For S&G while awaiting for the freetronixs shield to arrive, tried the Sainsmart button shield. It init's by the lcd library the same [LCD() : LiquidCrystal(8, 9, 4, 5, 6, 7)], has the same button return values, however, to quote "the program starts running and no button will stop it."


Shall see what comes up when the freetronics shield arrives . . .
 
It looks like I had a misplaced closing bracket as these two lines were outside of the while loop.

Code:
      setSteps((stepsPerDiv + adjustSteps) * 2, 1);
      printDivideVals(thisDiv,gAngle);
In the original code, these lines were both repeated in each case statement but if I had of left the code this way I would have two fairly large blocks of repeated code so I did not want to waste the memory. So by setting a flag in the case statements, I added another if statement that can be used for both case statements (eg for both left and right buttons).


So try this:
Code:
void goDivide(long gAngle)
{
   long thisDiv = 1; 
   int event = LCD_BUTTON_NONE;
   int flag = 0;
   float tmpSTEPS_PER_REV = (float)globals.stepsPerRev;
   float remainder;
   float divLeftOver = 0.0;
   long adjustSteps = 0;
   
   stepsPerDiv = (long)(tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder = (float) (tmpSTEPS_PER_REV *((float)gAngle/(float)MINUTES_IN_CIRCLE));
   remainder -= (float)stepsPerDiv;
   divisions = (long)((float) MINUTES_IN_CIRCLE / (float) gAngle);
   printDivideVals(thisDiv,gAngle);
   while(event != LCD_BUTTON_SELECT){
      event = lcd.getButton();
      switch(event){
        case LCD_BUTTON_LEFT:
          flag++;
          thisDiv--;
          divLeftOver -= remainder;
          if(thisDiv < 1)
            thisDiv = divisions;
          digitalWrite( globals.DirPin, ANTICLOCKWISE );
          break;
        case LCD_BUTTON_RIGHT:
          flag++;
          thisDiv++;
          divLeftOver += remainder; 
          if(thisDiv > divisions)
            thisDiv = 1;          
          digitalWrite( globals.DirPin, CLOCKWISE );
          break;       
    }
    if(flag){ 
      if(abs(divLeftOver) >= 1.0){
        adjustSteps = 1;
        if(abs(divLeftOver) == divLeftOver)  
          divLeftOver -= 1.0;    // Positive value >= 1.0
        else
            divLeftOver += 1.0;  // Negative Value <= 1.0
      } else
          adjustSteps = 0;
      setSteps((stepsPerDiv + adjustSteps) * 2, 1);
      printDivideVals(thisDiv,gAngle);
    }   
    flag = 0;
  }
}
 
Have operation with my little testing platform
From: "the program starts running and no button will stop it."
To: "the program starts running and the button will stop it."

Question is: The <Contin> UP/DWN Starts menu choice is one direction only, plus being slow I don't really get the item. You have the Jog function which also has a Cont choice that runs both directions . . .

Next thing to do is to load it to the rotary table gizmo and see how she does . .
 
Have operation with my little testing platform
From: "the program starts running and no button will stop it."
To: "the program starts running and the button will stop it."

Question is: The <Contin> UP/DWN Starts menu choice is one direction only, plus being slow I don't really get the item. You have the Jog function which also has a Cont choice that runs both directions . . .

Next thing to do is to load it to the rotary table gizmo and see how she does . .

Glad we made progress. We do need it attached to a RT to test for lost steps. Where is Captain_Obvious?

If you have problems, try replacing
Code:
 if(abs(divLeftOver) == divLeftOver)
with
Code:
 if(divLeftOver > 0.0)

The <Contin> menu allows you to change direction with the left and right arrow buttons. This is consistent with the divide functions (that allow you to go backwards in case you have another operation (or forgot one). Use carefully as backlash could be a problem.
 
@200 steps per rev and 36:1 table ratio seems to perform repeatable jogs . . . Your program resolution exceeds the accuracy of my little rotary so a missed step be like picking a grain of salt from the sugar shaker. Captain_Obvious is set up for the fine measurements . . . Captain_Obvious ?

<Contin> Kicked it, now she is working -

Jog Angle XX0 - 00 - 00 XX not changing - Left-Right moves cursor, Up-Down no change from zero.

DSCF0169_zpsplsej6vh.jpg
 
Hi, I've been a bit busy for the past few days, but I tried the new script and the division seems to work perfectly now. I tried divisions 3, 21, 37, 61 and 360. All holes lined up.

I'll do some more testing later and I will write down the results but for now it seems that we have nothing to worry about. Again, thanks a bunch for the effort, rodw!
 
Thanks guys, I really appreciate your testing. I will update the zip file at the beginning of this thread and post here when I'm done

Foozer, I suspect your keyboard problem could be due to different resistance values between my Freetronics and your sainsmart keyboards. You may need to tweak the values in the LCD library class to suit your hardware. Thats not my code so you are on your own.....

Also, I've found that the keys on these displays wear out very quickly so it could be a sticking or faulty button. The keyboard code has been tested, is rock solid and has not been touched
 
I put my lathe dividing head together as it will be from now on and did some (hopefully) final testing. All functions of the script seem to work as intended. No problems with button functionality or anything else. I tried several divisions, 4, 7 ,10, 21, 36, 43, 45 and 61. I had no problems with any of them. I also tried a few angle programs and they worked fine. Jog and continuous running work fine as well.

The setup is basically the same, a cast iron backplate on the lathe spindle with a piece of paper glued to it. Poking holes in the paper with a small carbide needle attached to the tool holder of the lathe. Circle diameter roughly 100mm or so. I saw no division errors looking through a 5x eye loupe.

Since I've been having trouble with this setup from day one, I'm not through testing it yet, but it certainly looks very promising so far. However it seems my main problem in the beginning was a bunch of poor quality stepper drivers that eventually died or started malfunctioning otherwise. Now I have Leadshine drivers and generally higher quality components in the system instead of the cheapest possible Chinese clone crud.
 
Foozer, I suspect your keyboard problem could be due to different resistance values between my Freetronics and your sainsmart keyboards.

Mayhaps be, it's just that one place config - jog step - jog angle that declines to cooperate on the first two digits. [10's & 100's]. Have a freetronics shield coming so shall see . . Sheets say the resistor values are the same - But have murphys law following me the past week or so, truck tans blew a bearing, brides car blew a cam position sensor, my [cough] hot rod blew the ignition ignitor - I got the laughter of a mad man in lock up - - Looked at the LCD cpp file, of course, the button differentiation is determined by a map, say what? Guess I could alter it to some
if(analogRead(pin) == value stuff or just go with a glitch I need not worry about.
Like Obvious have a paper set up waiting for me to poke some holes in.

Hey it's the 4th, what else is there to do but have some fun . .
 
Not the best camera for this, for this, tis terrible . . .
Don't realize how different the setups are until you do change overs. Started with my own script that uses Chucks math engine wrapped with a NES controller for input [CNC Shield controller], then to Chucks directly [button shield, easy driver], then to Rods [button shield, easy driver]. Picked odd number 39 for testing first three tries then 78 for the last . . . Straight edge across the radials lines up. Easy Driver gave up the smoke during last pass, borderline running the stepper @ .7a
All in all, holes started and ended where they should have, appear evenly spaced and the 78 run put one 'tween the others as expected . . .
...
[couple spots in the backing plate had existing holes so piercing looks funny . . ]


DSCF0172_zpsto934tyb.jpg
 
Foozer, This old post explains how to modify the LCD code for the sainsmart
http://www.homemodelenginemachinist.com/showpost.php?p=273830&postcount=219


Thanks, the lcd.cpp file is perty straighforward, 'cept for the
// Button mapping table generated by genlookup.c
static unsigned char const buttonMappings[] PROGMEM = {
2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0};

Part of me wants to know what that actually means, the other part say's forget it, stick in the verbose coding . . That can be changed to suit variance in resistor values. Up/Down button reads work every place 'cept that for that one usage.

Any event if this dunderhead can get your sketch to run, anyone can get it to run . . .
 
Thanks, the lcd.cpp file is perty straighforward, 'cept for the
// Button mapping table generated by genlookup.c
static unsigned char const buttonMappings[] PROGMEM = {
2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0};

Part of me wants to know what that actually means, the other part say's forget it, stick in the verbose coding . . That can be changed to suit variance in resistor values. Up/Down button reads work every place 'cept that for that one usage.

Any event if this dunderhead can get your sketch to run, anyone can get it to run . . .

Foozer, Sorry I missed this. The original author of the LCD library published his source on github. Chack th esource and you'll probbaly find the URL. From memory, he used a program to generate that code (and the source for the generator was in his repository).
 
Foozer, Sorry I missed this. The original author of the LCD library published his source on github. Chack th esource and you'll probbaly find the URL. From memory, he used a program to generate that code (and the source for the generator was in his repository).


Thanks, I'll take a look . .

Robert
 
Hi from Belgium,
RodW, i upload your software to an Uno chinese clone, seems to work perfectly but, after 32 seconds (tested 5 times) without touching any key, the characters disappear and i may see just a blue screen ? Touching any key, display is back and all is OK ?

The blind keyboard (4+1) is not very user friendly for this application, to say a minimum.

Anyway, good software job.

Jacques

Please, forgot my comment, very easy to remove this "ScreenSaver" ;-)
 
Back
Top