Re: Jog wheel



any ideas on how to shoehorn something like this into EMC ?

I would like to see it as a module so that it could be used with any of the
existing user interfaces rather than having to change all of them to support
these functions

Brian

<-------------- begin untested code snippet -------------->

//EMC handwheel jog module for the gameport

/*!
the game port pinouts for machine jog controls

power and ground ,two of these are commonly used for the MIDI port
check the docs on your port from the motherboard or soundcard manual
and break them out seperatly so the MIDI port is still available later on
pins 1,8,9,15 = +5V (both outermost pairs)
pins 4,5,12 = gnd (three in the center)

analog pins are not used
pin-3 = analog-1 = bit-0 of port 0x201
pin-6 = analog-2 = bit-1
pin-11 = analog-3 = bit-2
pin-13 = analog-4 = bit-3

the four digital pins on upper nibble are used
but must be shifted over and masked off in the code
these pins are normaly open (pulled up) the buttons should close to GND
pin-2 = digital-1 = bit-4                 axis select button
pin-7 = digital-2 = bit-5                 jog increment select button
pin-10 = digital-3 = bit-6               encoder ch-A
pin-14 = digital-4 = bit-7               encoder ch-B

the axis and jog increment selection buttons are used to scroll thru a list 
of values shown on
the screen by the GUI
the handwheel encoder is polled and compaired to its last value to test for
step and direction changes
a CUI RE20NC25C20RA (Digi-Key Part Number 102-1012-ND) 25 line encoder 
would be fine for this
note do not use the inexpensive detented encoders as they only have 25 detents
instead build the detents (100 of them) into the pannel knob and use the
non-detented 25 line encoders
/*

        /*set the port address */
#define GAMEPORT 0x201

/*we need a function to read the port for Linux we can use this*/
get_joystatus(int port)
{
unsigned char ch;
ioperm(port,1,1);
ch=inb(port);
return ch;
}

//set up variables
unsigned char joystatus ,last_joystatus ,handwheel ,last_handwheel ,axis_btn 
,incr_btn;

static double jogIncrement = 0.0001;
static double jogSpeed = 60.0;
static int axisSelected =0;

//=====================================================================
//activate in manual mode only
if (emcStatus->task.mode == EMC_TASK_MODE_MANUAL)
{
/* first initialize joystatus and handwheel */
        {
        last_joystatus = get_joystatus(GAMEPORT);
        last_handwheel=(last_joystatus>>0x06) & 0x03 ;
        }

/*then in the jog loop*/

joystatus=(get_joystatus(GAMEPORT));
if (joystatus!= last_joystatus) /*something has changed*/
        {
        //set to jog incremental
        jogMode = JOG_INCREMENTAL;
        // get current values for increment and axis select buttons and 
handwheel state
        axis_btn=(joystatus>>0x04) & 0x01
        incr_btn=(joystatus>>0x05) & 0x01
        handwheel=(joystatus>>0x06) & 0x03
        }

// check the buttons first -button pressed=0 open=1
// and scroll thru values
if ( !axis_btn) {
                        axisSelected++
                        if (axisSelected < 0 || axisSelected >= 
EMCMOT_MAX_AXIS)
                                {
                                axisSelected=0;
                                }
                        }

if ( !incr_btn){
                        jogIncrement *= 10.0;
                        if (jogIncrement >= 0.1)
                                {
                                jogIncrement = 0.0001;
                                }
                        }


// test for handwheel change
if (handwheel != last_handwheel)
                {
                        switch (handwheel){
                                case 0x00:
                                        if(last_handwheel == 0x03)
                                        jogSpeed = jogSpeed;   /*fwd*/
                                        else if(last_handwheel == 0x01)
                                        jogSpeed = -jogSpeed;  /*rev*/
                                        else // should never get here
                                        jogSpeed=0.0;   /*error -do nothing*/
                                break;
                                case 0x01:
                                        if(last_handwheel == 0x00)
                                        jogSpeed = jogSpeed;
                                        else if(last_handwheel == 0x02)
                                        jogSpeed = -jogSpeed;
                                        else
                                        jogSpeed=0.0;
                                break;
                                case 0x02:
                                        if(last_handwheel == 0x01)
                                        jogSpeed = jogSpeed;
                                        else if(last_handwheel == 0x03)
                                        jogSpeed = -jogSpeed;
                                        else
                                        jogSpeed=0.0;
                                break;
                                case 0x03:
                                        if(last_handwheel == 0x02)
                                        jogSpeed = jogSpeed.;
                                        else if(last_handwheel == 0x00)
                                        jogSpeed = -jogSpeed;
                                        else
                                        jogSpeed=0.0;
                                break;
                                default :// should never get here
                                jogSpeed=0.0;
                                }
                        last_handwheel=handwheel; // store value for next time

       // pass the new values to EMC
        emc_axis_incr_jog_msg.serial_number = ++emcCommandSerialNumber;
        emc_axis_incr_jog_msg.axis = axisSelected;
        emc_axis_incr_jog_msg.vel =jogSpeed / 60.0;
        emc_axis_incr_jog_msg.incr =  jogIncrement;
        emcCommandBuffer->write(emc_axis_incr_jog_msg);
                }
}




Date Index | Thread Index | Back to archive index | Back to Mailing List Page

Problems or questions? Contact