Shop OBEX P1 Docs P2 Docs Learn Events
Wait for AX-12 action — Parallax Forums

Wait for AX-12 action

I've been playing w/ a Dynamixel servo and have found that if the servo action is slowed down and the program doesn't have a long enough WAITCNT in it, the program over rides w/ a new instruction and does not finish the previous.

Is there a way to let the servo finish before a new action is started"

There is a register in RAM called MOVING $2E, but I'm unsure how to use it.
This is my attempt (inserted after
dy.setsrvpos(id,position)
PUB waitax | c
  
  waitcnt(clkfreq/8+cnt)  'let movement be started
  c:=1                    'initialize c to non zero
  
  repeat until  c==0      'wait till not moving
    c:=dy.ReadData(1, $2e, 1)  'read $2E (MOVING) register
        
The program seems to end too soon though.

Thanks
Aaron

Comments

  • ErNaErNa Posts: 1,752
    ?
  • It's been awhile since I've used my dynamixel servos. IIRC, I'd make sure not to send commands to the same servo more than once every 20ms. I think you kind of need to treat them like a hobby servo with a refresh rate of 50Hz. Not that you need to refresh the servos but you don't want to send commands more often than once every 20ms.

    BTW, you can avoid needing to set a variable to a value prior to a loop by placing the condition at the end of the loop.
      c:=1                    'initialize c to non zero
      
      repeat until  c==0      'wait till not moving
        c:=dy.ReadData(1, $2e, 1)  'read $2E (MOVING) register      
    

    The above code could have been written:
      repeat 
        c:=dy.ReadData(1, $2e, 1)  'read $2E (MOVING) register      
      until  c==0      'wait till not moving
    

    Or:
      repeat 
        c:=dy.ReadData(1, $2e, 1)  'read $2E (MOVING) register      
      while  c      'wait while moving
    

    But in light of what I just said, I'd use:
      repeat 
        c:=dy.ReadData(1, $2e, 1)  'read $2E (MOVING) register    
        waitcnt(clkfreq / 50 + cnt)  
      while  c      'wait while moving
    

    Sorry, but I don't recall if register $2E is really doing what you want. I think you're using it correctly but I'm not sure.



  • JonnyMacJonnyMac Posts: 9,105
    edited 2016-01-24 01:00
    The up-side of Dynamamixels is that you don't have to refresh -- just send the command and let it fly. I did a project with a friend (Terminator bust) using Dynamixels to move the head. It turned out very well but the project stopped there. I've attached my Dynamixel object in case you find anything useful in it.

    I would do something like this:
      repeat
        if (dy.rd_byte(1, dy#P_MOVING) == 0)
          quit
        time.pause(50)
    
    By using quit you break out of the wait loop as soon as the P_MOVING register is $00.

  • JonnyMac wrote: »
    The up-side of Dynamamixels is that you don't have to refresh -- just send the command and let it fly.

    I thought I learned you shouldn't be sending commands to the Dynamixels more frequently than 50Hz from you?

    I was wrong about 50Hz. Here's the quote I was thinking of:
    JonnyMac wrote: »
    After chatting with Kyle at Trossen robotics I came away with the impression that Dynamixels really don't want to deal with more than about 30 packets per second.
  • Thanks Jon & Duane!

    I've gotten it working but with an occasional hiccup. That timing could be the trick. I'll try it.

    Aaron
Sign In or Register to comment.