Re: Jog wheel (with code attached)


On Monday 03 June 2002 10:46 pm, you wrote:

> I tried to compile handwheel.c on my BDI 2.14 pc and got a whole stack of
> errors.  Since I am mostly c illiterate I'll send these on in the hopes
> that someone can make sense of them.

I fixed up the few issues (file attached) that caused those errors and I got 
it down to:

[mshaver-at-linux handwheel]$ gcc -Wall -O inb.c handwheel.c -o handwheel.o
In file included from handwheel.c:37:
emc.hh:80:18: rcs.hh: No such file or directory
emc.hh:81:49: posemath.h: No such file or directory
emc.hh:82:65: canon.hh: No such file or directory
emc.hh:83:48: emcglb.h: No such file or directory
emc.hh:84:20: emcpos.h: No such file or directory

Note that you might have to change:

#include "locsysio.h"
#include "emc.hh"

to:

#include <locsysio.h>
#include <emc.hh>

I couldn't continue because I didn't have it in the right build environment 
and it fails trying to find things that emc.hh wants.

> If you plan to launch this code into the public domain or GPL, am I correct
> that this file should go into the emc/src/emcio directory and that we
> should add a line to the makefile there so that it is compiled with the
> rest of the EMC?
>
> When we get this working, the script to start it should only take a very
> few lines.  Handwheel already tests for manual mode and uses reported axis,
> increment, and jogspeed so IMHO the script can just be an on/off toggle and
> a loop.

I haven't got a clue how to integrate this into the EMC ;)... Should it be a 
function like "void handwheel()"? Is it installed from emc.ini? A loadable 
module? What calls it?

Enquiring minds want to know,

Matt

//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
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

*/
#include "locsysio.h"
#include "emc.hh"
/*set the port address */
#define GAMEPORT 0x201

/*we need a function to read the port for Linux we can use this*/
int
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
//void
//handwheel ()
//{
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