Shop OBEX P1 Docs P2 Docs Learn Events
two axis diagonal joging steper program — Parallax Forums

two axis diagonal joging steper program

OwenOwen Posts: 100
edited 2007-01-23 15:50 in Propeller 1
Can anyone lead me in the right direction in the programing of a jog mode i'm building in a stepper motor aplication? I want to be able to control two stepper motors one for Xaxis and one for the Yaxis that pan and tilt a camera. The jog is controlled by a realbasic program from my computer through a serial connection. I have been able to write a program that will jog move the camera either X or Y but not both at the same time (to create a diagonal move). the next catch is I also need to return the number of steps each moter has taken so my control program can keep track of the current XY position, which works in my current program but only one axis at a time. Any one tried somthing similar? shouldn't be any different than joging x and y at the same time on a CNC i think. I included my toplevel object and the Joging modes object in case anyone has some time to look over it. Any help would be much apreciated

many thanks,
Owen

Comments

  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-01-23 12:44
    what exactly is the problem? If you just want 45 degree moves then just make them step together and select the appropriate direction levels. If you want them to move add some abitrary angle then you need to work out the ratio of steps between the two. If it was going to move a diagonal that took it 100 in x and 10 in y you would pulse y once every ten x steps etc.

    Keep track of the position by having a variable with the running total of step pulses, add for + direction subtract for - direction.

    Graham

    p.s. No IDE on this PC
  • lnielsenlnielsen Posts: 72
    edited 2007-01-23 13:39
    Is there a reason you want stepper motors instead of servos?

    I don't know who big of camera you want to mount but before you reinvent the wheel check out http://www.servocity.com/html/spt200_pan___tilt_system.html. It is suppose to work on camera up to two pounds.

    Another idea for you that could help if you want to build your own is http://www.austriamicrosystems.com/03products/products_detail/AS5040/description_AS5040.htm This way you always know the current position without counting steps (what happens after a reset when you don't know where you are pointing?)

    I guess one final suggestion is the Robotis Dynamixel servos like the AX-12 or the DX-117. You can control both of the servos you will need using a single half-duplex serial port and you can pre-program both servos with a speed and destination position and then start them at the same time. I am planning to modify the new proto board to support both servos for some robots I want to build
  • T ChapT Chap Posts: 4,223
    edited 2007-01-23 14:39
    Set a cog for each motor. Each cog is looping, waiting for any new position. Send positions from the RB app in sequence, X then Y, or individually. The Propeller receives the strings, converts the strings to integers and updates the variables for X and Y. The cog for each motor is always looping, checking for updates, if a new position is rec'd, the motor goes to the new position. This way, all motors move when they get new position data. You don't need to return the value from the motors, since you sent a position, your app always knows where it is. If you must have no chance of error, use encoders and read the counts, send the count back at the end of every move for verification. Sending back on every pulse would be too much to track via serial.

    On boot up, you home all motors to a limit switch or current sense trigger of a hard stop. The reference to home should set all variables to 0.

    Send X a string of 10000, the motors moves 10000 steps, of course you have to write a ramp and decel, so for example ramp for 1000, run for 8000, decel for 1000.

    Or, send X = 10000 followed by Y = 10000. What I do is send a tab delimited string with motor ID plus position followed by CR. The Propeller identifies the ID, and updates the variables for each motor.

    Here is a RB method that could be on a button for example:

    MoveX
    MoveY
    MoveZ
    MoveR

    MoveX
    dim x as integer
      dim y as integer
      dim z as integer
      dim r as integer
      Dim OutputString As String
      Dim Tab, Space, CR as String
      Dim SliderValueX as integer
      Dim SliderValueY as integer
      Dim SliderValueZ as integer
      Dim SliderValueRot as integer
      Tab=Chr(9)
      Space=Chr(32)
      CR=Chr(13)
      X = Xslider.Value
      Y = Yslider.Value
      Z = Zslider.Value
      R = Rotslider.Value
      Xsent = X 
      Ysent = Y
      Zsent = Z
      Rsent = R
      moveEna = 0
      //XID = 4270   
      //YID = 4370
      //ZID = 4470
      //RID = 3670
      OutputString = "XID" + TAB + str(X) + CR
      Serial1.Write outputString
      Serial1.XmitWait
      
    
    



    You can have a slider set with your prefered range of steps for each motor, say from 0 to 100000. When you change a slider, write on ValueChanged something like this below. I set it so if I have a button pressed called AutoMove, the change of a slider will send it's new position value out. The values can also be sent by a button called Send All for example.

    XText.text = str(me.Value)
      
      if AutoMove.value = True  then
        Xsend
        XCheck
      end if
    



    Then, on the Propeller side, read the strings, convert to decimal, apply a case statement to the ID's. The main cog updates X position, the X cog picks up the new position and moves the motor autonomously. When in motion, the X cog is still looking to see if any new position has arrived, if so, it acts accordingly, if the position is in the other direction, a decel is applied, and a move to the position takes place.

    You can assign arrow keys to the RB app so that it scans the keyboard so many mS. You assign the keys to update a slider value for example add 50 for each timer iteration. A timer period of 33ms is good. Create a timer that loops a method like this called navKeys, and run each motor from the arrow keys:

      // scan keyboard to control the cameras
      if Keyboard.AsyncKeyDown(&h45)  then        'or Keyboard.AsyncKeyDown(&h18) then     // +  close
        SerialPortPopup.ZSlider.Value = SerialPortPopup.ZSlider.Value + 50
        ZText.text = str(SerialPortPopup.ZSlider.Value)
        SerialPortPopup.ZSlider.Value =  SerialPortPopup.ZSlider.Value
        
      elseif Keyboard.AsyncKeyDown(&h4E)  then      'or Keyboard.AsyncKeyDown(&h1B) then // -   away
        SerialPortPopup.ZSlider.Value = SerialPortPopup.ZSlider.Value - 50
        ZText.text = str(SerialPortPopup.ZSlider.Value)
        SerialPortPopup.ZSlider.Value =  SerialPortPopup.ZSlider.Value
      end if
    
    

    Post Edited (originator) : 1/23/2007 3:09:00 PM GMT
  • OwenOwen Posts: 100
    edited 2007-01-23 15:47
    my camera rig is already built and easily supports cameras over 10lbs and runs just fine with my stepper motors. I'm using a worm drive so unless the stepper moves the position of the camera stays the same. i'm also in the process of configuring it with optical switches to give it a constant zero point to aid in a coordinate system.

    in regards to Grahm's post, my problem wasn't isn't the math to make it move at 45 degrees it's the way to comunicate from my serial comunication to the main object to the object controlling the stepper motors. The dificulty for me is that I am sending a serial command to move the motors and when the toplevel object gets that command it starts the object to manualy control the motors in two new cogs one for each axis. and when the motors are to stop a serial command is sent to the object conrolling the motors to stop.

    I just solved my problem about 30 min ago
    I know my questions have been a bit general but if anyone has any example of somthing similar they have tried to do or ideas to simplifiy or improve what I have already done and has the time, I would be interested. I'm new to this and all the examples and input everyone has given me has gone a long way.

    this is a great forum and thanks for everyones help,
    Owen
  • OwenOwen Posts: 100
    edited 2007-01-23 15:50
    thank you!!!
    I must have been posting as originators post came in
    this realy helps me

    Thank you
Sign In or Register to comment.