Hello Guest it is June 15, 2025, 08:33:56 AM

Author Topic: Is it possible to map ‘continuous’ jogging to an analog input?  (Read 11051 times)

0 Members and 1 Guest are viewing this topic.

Hi all,

I have an ESS with a pokeys 57E that i am using for additional i/o.  I was wondering how i could map a pair of the analog inputs (with a potentiometer joystick connected) to work as continuous jogging. 

I’m not looking for super precision, as i have an MPG for that.  I’m wanting to do coarse movement with the analog input joystick and fine movements with the pendant.  (This one axis at a time stuff is getting old).

There is a tutorial from Pokeys on how to map an analog input to the FRO, and i was looking to adapt that for the jogging but I can’t figure out where to look for the continuous jogging command.
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #1 on: January 06, 2023, 04:42:35 PM »
Hi,
I suspect what you want to do can be done....but you need to break it into two parts.

First part is that you need to be able to use Mach to continuous jog....at a given speed. Just how that speed is derived is another matter.
Lets assume that you have a register, or at least some other variable, that represents the continuous jog speed, it may be a percentage, or it may
be a real number on the range 0-1.

What you need to do is write code that would allow Mach to jog, presumably using keyboard entry, or maybe joystick inputs, at that given speed.

The second part would be to have the PoKeys to measure the analog voltage from your potentiometer or joystick, and convert that into numeric form
and in turn populate the speed register/variable with it.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #2 on: January 07, 2023, 12:32:52 PM »
Yes, that's what I was thinking as well.  I was poking around in the screen editor and found the commands I think.

There is a functionality in the pokeys that allows you to map the analog input to a percentage, I was going to use that to set the jog speed.

The one sticking point I still see is how to update the speed as the joystick at runtime.  Ideally i would want something like this:

- enable joystick jogging (another input)
While enabled:
- read joystick position, if not "0" (centered), convert to %
- jog in direction indicated (keyboard/gui command) at % of rapid traverse speed

Continue the while loop until joystick jogging is disabled.

If I use siglib to monitor the register and input, is it safe to assume that it will update at the 50ms rate?  That should be fast enough for reasonable manual control.

Seem reasonable?
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #3 on: January 07, 2023, 01:49:12 PM »
Hi,
I follow your general idea and it sounds OK.

Quote
If I use siglib to monitor the register and input, is it safe to assume that it will update at the 50ms rate?  That should be fast enough for reasonable manual control.

No, this is incorrect. Mach4 has dozens of signals, many of them internal but also external input signals for example.
Any time ANY ONE of those signals' changes state the SigLib table is triggered. If the signal has an entry in the SigLib table then
that functionality is triggered. None of these signals are 'polled'. That is to say that the only time the functionality is triggered is if that signal
changes state.

What you want is a polled signal. This is the prime use of the PLC script. It runs every few milliseconds, typically 12.5ms by default. If there is an
input, the joystick for example, that you wish to monitor on a regular basis then the PLC is the place to put the monitoring code.

Note also that Mach4 has ladder logic called the PMC module. It runs every millisecond or so, and thus could just about be considered realtime
and would be very useful for this project.

Can you tell us more about the joystick? I thought the majority of gaming joysticks just had four contacts, one at each carinal point. I would have thought
that a joystick would have been the ideal device to get the directional on/off switching signals rather than the jog speed. The jog speed is best done with
a single potentiometer.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #4 on: January 07, 2023, 02:47:09 PM »
Good info! sounds like more than one way to skin the cat.  I think polling is better as well, as the Pokeys will be sampling on some interval anyway to update the register (via modbus TCP).

I wanted cheap proportional control without alot of low level coding, so I went analog: https://www.amazon.com/dp/B09JZ8ZV4L?psc=1&ref=ppx_yo2ov_dt_b_product_details

It is basically just 2 potentiometers, one per axis.  Not as robust as digital hall effect, but since the wire length will be <2cm inside a mostly shielded enclosure I figured it would be good enough.  I can build it a little faraday cage if necessary.

I'm mostly intimidated by getting Mach to see things (as I don't yet have alot of experience with the more advanced Mach stuff).   I could actually write the code to get an arduino-style uC to see this, but then getting mach to talk to it would be a project in itself! (too many mini-projects in this scratch-built 5 axis router already!)
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #5 on: January 07, 2023, 02:55:42 PM »
I want directional jog plus proportional velocity (think electric wheelchair control joystick: the farther you push in a direction vector, the faster you go that way). 

Perhaps there is a better way to do it.  I was thinking that the only way to dynamically control the movement speed was via the jog rate.

I'm picturing each register/data packet/etc would have X, Y  and direction (+/-) with % max velocity for each.   

I actually think this would be useful for alot of people if it works well enough.  (I have one of those Xhc pendants that has questionable functionality for the precise movements...)
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #6 on: January 07, 2023, 08:58:39 PM »
Hi,

Quote
I want directional jog plus proportional velocity (think electric wheelchair control joystick: the farther you push in a direction vector, the faster you go that way).

I think that could be done but would require some electronics.

With the joystick centralized, ie no input then the center contact of each pot would be 1/2 the resistance of the pots. If say 12V were applied to each pot
then the center contact of each would be 6V. If you move the joystick North, 1/2 value then the NS center contact would be 9V while the EW center contact would
remain 6V.

Some electronic circuitry would result in four switching outputs, one each for N,E,S,W.  The speed would be some combination of the absolute value of the voltage
difference between 6V and the center contact of each pot.

For the situation described, namely te joystick at the 1/2 North position I would expect the outputs to be:
N= high
E= low
S= low
W= low
Speed= ABS(9-6) + ABS(6-6)
         =3V

Note that the speed is the sum of the deviation from central of both NS and EW axes.

How are your electronic skills?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #7 on: January 07, 2023, 10:08:08 PM »
Definitely much better than my software skills! But this one is easy enough.

I was actually thinking to make it even easier by doing it in software.  You can map the center position voltage of each pot to ‘0%’ and the voltage at maximum travel going each way to either positive or negative directions by checking if the measured voltage is above or below the 0%

Any values below would be mapped to motion in negative direction, and any above mapped to positive.

Probably impossible to understand from my description,  but super easy in C code (think of reading an analog crossfader, same concept)

Now in LUA? Who knows. But i think you can use C in LUA so we’ll see….
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #8 on: January 08, 2023, 02:56:51 AM »
Hi,
yes that would work just as well or better.

I was thinking that you'd need some hysteresis around the center, both NS and EW, otherwise any noise would cause the machine to start to jog.

Lua has a syntax 'only a mother could love' (Smurph's quote not mine) but for this sort of thing is great.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Is it possible to map ‘continuous’ jogging to an analog input?
« Reply #9 on: January 08, 2023, 01:22:57 PM »
Yea, this is the command in arduino:  i’ll have to dig around to see the Lua analog, but it must exist. 

https://www.arduino.cc/reference/en/language/functions/math/map/

Thats a good point about the hysteresis.  I could put some simple logic in there to ignore everything below 10% or so.