Mori sl-4 turret location decode

More
11 Jul 2012 13:39 - 11 Jul 2012 13:44 #21785 by clkeck1
I need a little help decoding the turret locations on the lathe. I could do it with a bunch of ands and convert it to binary then use a weighted sum to output a s32 value. but i was hoping for a simpler way.

Any ideas?

################
# Decode for turret locations
################
# Turret ..1 2 3 4 5 6 7 8 9 10
# LS8 ......1 0 0 0 0 1 0 0 0 1
# LS9 ......1 1 0 0 0 0 1 0 0 0
# LS10 ....0 1 1 0 0 0 0 1 0 0
# LS11 ....0 0 1 1 0 0 0 0 1 0
# LS12 ....0 0 0 1 1 0 0 0 0 1
# LS13 ....0 0 0 0 1 1 1 1 1 0
################

Thanks
Cory
Last edit: 11 Jul 2012 13:44 by clkeck1.

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 14:06 #21786 by PCW
Where do these numbers come from? (thats a lot of bits for just 6 locations)
I guess I would be tempted to write hal comp that just used a big case statement to encode these into location numbers. If you can just use a few numbers (not sure if thats safe) then bits 7,8, and 9 encode all the states

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 14:11 #21787 by clkeck1
Sorry for the confusion.
It is a 10 position turret and those are the factory 6 limit switches that determine turret position.

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 14:29 #21788 by PCW
OK I was reading rows instead of columns
so theres a unique 6 bit code for each of the 10 turret positions
(with perhaps some other codes in in between positions)

I still think the case statement HAL comp is probably the simplest
way to decode/encode this

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 14:44 #21789 by clkeck1
Is there an example somewhere? When it comes to programing language its over my head right now.

Thanks
Cory

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 15:40 - 11 Jul 2012 15:44 #21792 by PCW
I usually just look through the existing components for inspiration...

git.linuxcnc.org/gitweb?p=linuxcnc.git;a...fs/heads/v2.5_branch
Last edit: 11 Jul 2012 15:44 by PCW. Reason: sp

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 15:43 - 11 Jul 2012 15:47 #21793 by ArcEye
Hi

This toolchanger component I wrote for an Orac lathe shows one way of doing it.
wiki.linuxcnc.org/cgi-bin/wiki.pl?Contri...oolchanger_component

It decodes a truth table from a 3 optic switch greyscale disk to arrive at the tool position

Using a similar conditional structure starts to get a bit clunky however with 6 switches to check,
it will take longer the higher the tool position.

But on the plus side, nothing else happens during a tool change and clunky is probably just a split second more in computing time on a rt thread.

eg.
             if(LS8 && LS9 && !LS10 && !LS11 && !LS12 && !LS13) 
                    position = 1;
              else if(!LS8 && LS9 && LS10 && !LS11 && !LS12 && !LS13)
                    position =  2;
             else if(!LS8 && !LS9 && LS10 && LS11 && !LS12 && !LS13) 
                    position =  3;
            ....
            ....  etc
             else
                    position = 0;

regards
Last edit: 11 Jul 2012 15:47 by ArcEye.

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 17:09 #21796 by clkeck1
Arceye

I went ahead and modified the comp you provided. Can someone see if this is even close?

turret is all hydraulic. I have clamp, unclamp, forward, reverse, and high outputs to the machine
I also need to add the turret clamped prox switch somewhere to the code.

Right now im only working with forward rotation. here is the order of functions i would like to happen

1. turret unclamp
2. wait for delayturretdone
3. rotate with high and forward until one position away from requested tool
4. rotate with forward until requested tool
5. turret clamp
6. wait for delayturretdone
7. output toolchange completed

I'm not sure with the way this is written how high will work with changing one tool in the direction of rotation.

Once i get this figured out ill work on determining forward or reverse by requested vs current tool

Thanks
Cory

FUNCTION(_)
{
    switch (progress_level)
        {
        case 0:  // idle waiting for toolchange request
                 // axis does not remember the current tool number, so prompt for it once homed    
                if((!currenttoolnumber && !bWarn)&&(ishomedX)&&(ishomedZ))
                    {
                    bWarn = true;  // just warn once, its not an error as such but INFO won't display unless debugging is set 3+
                    rtapi_print_msg(RTAPI_MSG_ERR, "No tool selected. Use M6Tx to set current tool");
                    break;  
                    }
                if(toolchange && !toolchanged)  // prevent cycling after change done 
                    {
                    if(currenttoolnumber && toolnumber != currenttoolnumber && toolnumber > 0 && toolnumber < 11) // if a valid number
                        {
                        forward = false; // switch off motor if already on
                        reverse = false;
                        tnumber = toolnumber - 1;   
                        if(tnumber = 1)             // subtract 1 for turrest slow condition
                            tnumber = tnumber + 10;  

                        high = false;
                        sleeptime = 0;
                        progress_level = 1;
                        break;
                        }
                    else    // if tool requested is out of range set the toolchanged flag and exit
                            // should only get this if tool table has more tools than ATC can have
                            // otherwise emc will error the M6 command
                        {
                        progress_level = 5;
                        forward = false;                // switch off motor if already on
                        reverse = false;
                        high = false;
                        }
                    }
                 if(!toolchange && toolchanged)
                     toolchanged = false;           // reset once toolchange flag reset by system
                     
                 if(toolchange && !currenttoolnumber) // if no tool is set in axis - set axis to tool requested so that can work next time
                     {                                
                     forward = false;
                     reverse = false;
                     high = false;
                     progress_level = 5;
                     }
                 break;
                 

        case 1: // programmed delay to allow relays time to change over
                 if(sleeptime < times)  
                    {
                    sleeptime++;
                    break;
                    }
                clampturret = false;
                unclampturret = true;
                delayturret = true;
                 if(delayturretdone)                 // wait for turret delay
                    {
                    high = true;
                    forward = true;
                    progress_level = 2;
                    }
                break;
                      
        case 2: // Forward move - read the truth table to determine position
                if(LS8 && LS9 && !LS10 && !LS11 && !LS12 && !LS13) 
                    position =  1;
                else if(!LS8 && LS9 && LS10 && !LS11 && !LS12 && !LS13)
                    position =  2;
                else if(!LS8 && !LS9 && LS10 && LS11 && !LS12 && !LS13) 
                    position =  3;
                else if(!LS8 && !LS9 && !LS10 && LS11 && LS12 && !LS13) 
                    position =  4;
                else if(!LS8 && !LS9 && !LS10 && !LS11 && LS12 && LS13) 
                    position =  5;
                else if(LS8 && !LS9 && !LS10 && !LS11 && !LS12 && LS13) 
                    position =  6;
                else if(!LS8 && LS9 && !LS10 && !LS11 && !LS12 && LS13) 
                    position =  7;
                else if(!LS8 && !LS9 && LS10 && !LS11 && !LS12 && LS13) 
                    position =  8;
                else if(!LS8 && !LS9 && !LS10 && LS11 && !LS12 && LS13) 
                    position =  9;
                else if(LS8 && !LS9 && !LS10 && !LS11 && LS12 && !LS13) 
                    position =  10;
                else
                    position = 0;

                if(!position)  // if returning 0 something is wrong
                    {
                    rtapi_print_msg(RTAPI_MSG_ERR, "Error - opto inputs do not match truth table");
                    progress_level = 12; // doesn't exist so will go to default, output msg and then sit in level 10
                    break;
                    }
                    
                if(position != tnumber)  // wait for next tool - 1 to come around
                    break;
                    
                high = false;
                forward = true;


                if(position != toolnumber)  // wait for toolnumber to come around
                    break;
                    
                high = false;
                forward = false;

                sleeptime = 0;
                delaystart = true;
                progress_level = 3;
                break;
                
        case 3: // programmed delay to allow relays time to change over
                if(sleeptime < times)  
                    {
                    sleeptime++;
                    break;
                    }
                unclampturret = false;
                clampturret = true;
                delayturret = true;
                 if(delayturretdone)                 // wait for turret delay
                    {
                    delaystart = true;
                    progress_level = 5; // after first toolchange or update of tool number this is default
                    }
                break; 
                
        case 5: // clean up ready for next toolchang
                toolchanged = true;   // signal finished
                break;
                
        case 10:   break;  // should never get here but if we do then loop endlessly doing nothing
                
        default:    
                progress_level = 10;
                rtapi_print_msg(RTAPI_MSG_ERR, "Error state in oracchanger - now disabled - unload oracchanger");            
                break;
        }
 
}

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 20:02 #21803 by ArcEye
Hi

At a quick glance, the delayturretdone sections need to go into separate progress states.
They use the timedelay component which outputs once counted down, so it can idle awaiting that.

It's evening here, I will have a proper look tomorrow and get back to you.

regards

Please Log in or Create an account to join the conversation.

More
11 Jul 2012 23:33 - 11 Jul 2012 23:33 #21808 by andypugh
clkeck1 wrote:

# Turret ..1 2 3 4 5 6 7 8 9 10
# LS8 ......1 0 0 0 0 1 0 0 0 1
# LS9 ......1 1 0 0 0 0 1 0 0 0
# LS10 ....0 1 1 0 0 0 0 1 0 0
# LS11 ....0 0 1 1 0 0 0 0 1 0
# LS12 ....0 0 0 1 1 0 0 0 0 1
# LS13 ....0 0 0 0 1 1 1 1 1 0


That's just plain strange.

try:
www.linuxcnc.org/docs/html/hal/comp.html
and
component mori "decode mori turret";

pin in bit in-#[6] "input bits";
pin out signed out "output position";
pin out unsigned i;

license "GPL";
author "Andy Pugh";

function _ ;

;;

FUNCTION(_){
    i = in(0) + 2*in(1) + 4*in(2) + 8*in(3) + 16*in(4) + 32*in(5);
    switch(i){
        case 3:
            out = 1;
            break;
        case 6:
            out = 2;
            break;
        case 12:
            out = 3;
            break;
        case 24:
            out = 4;
            break;
        case 48:
            out = 5;
            break;
        case 33:
            out = 6;
            break;
        case 34:
            out = 7;
            break;
        case 36:
            out = 8;
            break;
        case 40:
            out = 9;
            break;
        case 21:
            out = 10;
            break;
        default: 
            out = -1;
    }
}
Last edit: 11 Jul 2012 23:33 by andypugh.

Please Log in or Create an account to join the conversation.

Moderators: cncbasher
Time to create page: 0.170 seconds
Powered by Kunena Forum