PC joystick to (Servo or Stepper) STEP/DIRECTION


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    I had been playing with the idea of reading a PS2 mouse but that became cumbersome. When I realized that an old joystick had the pots directly available at the connector, it seemed like it was worth a try.

    Actually there are two answers to your question, I have two tables. One is a small one, roughly 6"x 6" x 6" that uses steppers without feedback. Built it primarily for engraving nameplates and printed circuit boards. Mostly proof of concept. it currently runs 200 step motors at 1/2 step, and I don't need to control that one manually.It uses some kit stepper drives that I built. but I may upgrade to Gecko 201's and have a fractional step choice later.

    The larger one is a 4' x 6' gantry with servos. Both tables are primarily controlled by PC running Mach3, but on the gantry, I wanted a way to do some manual moves for artistic uses. I could use a Manual Pulse Generator through Mach3, but this seemed an interesting way to experiment and have a intuitive way to control 2 axises at once. The beauty of the drive system that I have built is that either one uses Step/Direction control. The servo table uses Gecko 340 drives.

    Timing on the PIC is "whatever works". Since the 18F2331 will run at 40MHz, I should have enough. I was thinking about the 500 range on either side also. Seems to give some deadband without wasting too much control. The third pot (trim on the joystick) will be used as a modifier in the math to control the overall speed so that I can tailor the response to the job at hand.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default

    There are joystick and "gamepad" control plugins available for Mach3 in case you end up not wanting to get it done with a PIC.

    /Henrik.

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Sometimes I must laugh at myself. I know I read the third pot was to adjust the speed, but I still keep thinking about it as the more you move the joystick, the faster you go.

    OK, re-read the original post and have my brain going the right direction.
    grab the analog and determine if the X and Y are above or below center and set a direction pin to 1 or 0.
    that is what threw me. center point can't determine direction, because if you are right of center and you need to move left, joystick will still be right of center. Direction needs to be determined by pot vaule being higher or lower then the last value.

    So controlling it this way, I would not worry about "trimming the speed" and still use the third pot for Z. The speed will be controlled by how fast you move the joystick. Something to keep in mind here, with 6' of travel, moving 3' will take 3.6 seconds (@ max jog of 10"/sec). So for realtime control, you will have to move the joystick very slowly.

    now for some math:
    to move 72 inches you need to make 72/2.375= 30.315 rev of the motor
    at 1440 pulses per rev thats 30.315*1440=43653.6 pulses.
    now divide 43654/1024=42.63 pulse resolution.

    So for each bit of the A/D value you have to output 42.63 pulses for the 6' travel.
    and for the 4' axis you need to output 28.42 pulses.

    I would approach it like this: pulse output will always be at 6000 pps. I would set up a timer to run so it takes 166uS to roll over. (@ 4Mhz clock, you could use an 8 bit timer preloaded with 90 for 166uS)
    on each timer rollover, reload clock,check position and toggle if necessary.

    Now for the pulse streams:

    To make things much easier on the coding, I would make home be a corner so all my positions are in the positive X,Y direction.

    Multiply the A/D by 42.63 for the 6' and 28.42 for the 4' axis. this is your target position in pulses. Current position is a counter which is keeping number of pulses sent from the time you said everything was zero (homed). If current pos = target pos then no toggle. If current pos<target then toggle with dir=1 If current pos > target pos then toggle with dir = 0.
    (Of course dir may be backwards, all depends on your setup). If you decide to use the third pot as Z, just fill in the travel (in inches) above for the Z multiplier.

    For your drift control and to accomdate for hand jitter, maybe have a control check to say, no movement unless A/D value changed by more then 2 points. of course that will decrease resolution, but right now thats all I can think of.

    Of course you could just get the plugin Henrik is talking about, But to me there is value in having a way to move the machine with out the control. Of course, Mach will not know the machine is moving so you won't be able to use this as a jog device per say. I assume you will unplug the puter input to the drives and plug in your "jog Stick"
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    1 more thing to think about. Homing. when the pic is reset or on startup, you need to home the drives of course. I would do this by jumping to my "home routine" first and wait for a button press from 1 of the 4 on the jog stick. Now if you have home switches installed, you can just run a loop to send pulses at a fixed rate and check for the switch after each pulse. then when all axis are on switches set current pos to zero and goto main.

    if you don't have switches, maybe do something like hold 1 switch for confirmation and hold 1 of the remaining switches for each axis to travel in the direction of home. when you are where you want to be, release both then press 1 again to confirm that axis. do this for each axis.

    You main loop will just have to get A/D values(all 3) and check for timer overflow. and if you have limit switches, watch for them here also.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    I will have to study your reply more when I have a bit more time, but for clarification, I need to give a few more details.

    The intent of the analog of the joystick is to variably control the speed in each axis in 0-500 counts of the A/D in the respective direction: ie 0-500 = max speed to 0 in the - direction, 501-527 = no movement even though the DIR bit has changed, 528-1028 will drive 0 to max in the + direction. It will still control speed. The trim, or "Z" will control the gain for both channels. For instance, when the gain is low, the max deflection in any direction will be very small (read: slow). When the trim is full, the full deflection of the stick will drive in the respective direction as quickly at the device is able.

    I only quickly read your post because I need to go, but if I misread it, I apologize and will look at it in a few hours.

    Thanks for your feedback.
    bo

  6. #6
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    More reading.... I'm thinking we are looking at this a bit differently.

    For normal CNC, I can control the position accurately with Mach3 with limits and such. What the joystick is for is relative movement and is basically freehand. The limits will be in effect for protection, but are not needed for normal positioning. The closed loop with the joystick is the person with his hand on it. On this specific application, the Z axis is actually a separately controlled process. Specifically, when the trigger on the joystick is activated, it starts an operation at the X-Y location that you manually positioned it to. Later additions will inhibit the X-Y movement when this process starts, but for now it just needs to position the head. Think "Helicopter". More stick, more pronounced movement. If you want it to stop, center the stick, pull the trigger, and the magic happens right where you want it. when it is done, move the stick to the new location and do it again. You are only controlling direction and speed.

    OK, I hope that adds some clarification.

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Ok, I know I can be a bit dense at times, but I think I finally have it. All you really want to do is jog x,y to a point, fire the trigger(this will invoke cycle start or run), a program will run in mach, when done you will jog to a new position and run again. And I get that the trim will be used to set the full scale speed of for the stick. ie: trim in 1 position, full stick may be 200pps max, while another position will be 400 pps max. full trim will set full stick to 6000 pps max, and all the numbers in between. Do I finally have it?

    I think with a small bit of rearranging, my posts still apply in concept, just not in operation. I did realize the person is closing the loop, but I know on my mills and lathes, it it far too easy to jog right onto a limit, without which it would crash.

    What I did not realize was you are planning to have mach still be able to run also. To me, the software side for the pic is pretty stright forward, but I am not sure how you will interface the 2 (joy stick and mach). How you will be doing this might have bearing on your program.

    After you have time to read over all the babbling I did, feel free to keep asking questions. I enjoy helping on things like this as I love puzzles.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts