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

    Thanks for the hint Walter, After some sleep, I will study it and see what I can learn. I remember seeing that post once, but didn't study it or think to apply his solution to my problem. He's using Step/Direction, so I'm sure there some answers there.

    After a few hours of looking at my original problem, it became apparent that I was going to have to find out how to generate 2 independent pulse trains that had variable frequency in order to move the motors in two axises. I am currently looking at the timers, CCP's, and the HWPWM for a clean way to do that. At first glance, I overlooked that it was considerably different than varying the width of pulses over a constant period (ie.. PWM). I seem to remember where someone did the calculations with a formula on the fly. I'm going to see if I can do that with the PR2 register and get somewhere with 2 timers.

    I will keep this post updated as I learn more.

    Bo

    BTW, better up your sampling rate, you're not even near Nyquist!

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


    Did you find this post helpful? Yes | No

    Default

    Some prelimary questions: How fast do you want max jog to be? how many steps per rev? This info will drive how you toggle the output pins for the steps. My first thought is intrupt based toggle. But it really depends on the speed you want to achieve, and how precise you want that speed.

    If you think about the a/d answer being the modifer for a delay between toggles, I am not sure you have much math to do.

    Lets assume 10 bit A/D, with 24 bits of dead band. so you have 500 possibilties for the speed. So 0 max, and 500 is stop. This is because 0 delay would be full speed.

    Now we just need to know osc speed for the rest of the math

    If you use 2 counters as the delay, your A/D answer can change the count needed to toggle. Then establish a duration for what a count represents and load that into the timer. when the timer rolls over, update both counters. If either or both have reached their count, toggle the pin for that motor.
    Last edited by cncmachineguy; - 28th October 2010 at 16:53.
    -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!

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


    Did you find this post helpful? Yes | No

    Default

    I'm coming up with about 6000 pulses per second for max travel speed (2.375" travel/rev, 360cpr encoder X 4, 10"/sec Max jog), so that is about 167uS as the quickest pulse repetition.

    That helps me focus on a target. I'm going to see if I can monkey poke tonight and come up with something.

    Thanks for helping me clarify my thoughts.
    Bo

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


    Did you find this post helpful? Yes | No

    Default

    are you using steppers with encoders?
    the step/dir implies using steppers, the 360 cpr x 4 encoder suggests encoders. I ask for 2 reasond, 1 just because its pretty cool if you are closing the loop, but more important is if you are reading the encoder for 2 axis and generating the steps for 2 steppers, timing will become important. how fast is your pic running?

    If you are using steppers, how many steps per rev are they? Is your drive running full step, half step,...

    I'm actually very intrested in this concept. I never thought of a joystick for a jog control
    -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 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.

  6. #6
    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.

  7. #7
    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!

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