Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Taking a journey with python3

  1. Taking a journey with python3

    Please direct me to the correct place if I am posting wrong.

    I am using an Arbotix-M running pypose to control the Dynamixel AX-12A. Now this is going to be for an autonomous arm running off of python 3 and from what i can tell there havent been any (documented) projects doing this. Everything is python 2, and ive been trying to read and trace what the PyPose GUI is doing to be able to command the arm in python 3. My question, then, is what exactly are the index, checksum, param, and length variables, and what are they used for?

    For example in driver.py:
    Code:
    def execute(self, index, ins, params):
            """ Send an instruction to a device. """
            self.ser.flushInput()
            length = 2 + len(params)
            checksum = 255 - ((index + length + ins + sum(params))%256)
            self.ser.write(chr(0xFF)+chr(0xFF)+chr(index)+chr(length)+chr(ins))
            for val in params:
                self.ser.write(chr(val))
            self.ser.write(chr(checksum))
            return self.getPacket(0)

  2. #2
    Join Date
    May 2016
    Location
    White Plains, NY
    Posts
    122
    Images
    1
    Rep Power
    9

    Re: Taking a journey with python3

    The routine appears to be constructing and sending a command to a servo. If you look at the Dynamixel AX-12 servo documentation the actions of the code will become more clear. You'll want the standard interface, not the Mode II interface.

    Note that some commands cause the servo to send a reply, and some don't. Your code example seems to imply that no response is expected to be received from the servo in response to the command being sent...

  3. Re: Taking a journey with python3

    What do you mean the "standard interface"? I have been using http://support.robotis.com/en/techsu...x_actuator.htm
    to learn about the motor and coms protocol but I am getting lost.

    Something ive tried but isnt causing movement:
    Code:
    port = '/dev/ttyUSB0'
    baud = 38400
    
    
    ser = serial.Serial(port, baud)
    ser.flushInput()
    
    
    ser.write(bytes(0xff,'UTF-8'))            # start1
    ser.write(bytes(0xff,'UTF-8'))            # start2
    ser.write(bytes(0xfe,'UTF-8'))            # ID 253 is all, current motor-5
    ser.write(bytes(0x02,'UTF-8'))            # len
    ser.write(bytes(AX_WRITE_DATA,'UTF-8'))   # Instruction
    ser.write(bytes(0x1e,'UTF-8'))            # Parameters
    ser.write(bytes(0x64,'UTF-8')) 
    ser.write(bytes(0xff,'UTF-8')) 
    
    ser.close()
    Is there something wrong there?

  4. #4

    Re: Taking a journey with python3

    Quote Originally Posted by robotsurgery View Post
    What do you mean the "standard interface"? I have been using http://support.robotis.com/en/techsu...x_actuator.htm
    to learn about the motor and coms protocol but I am getting lost.

    Something ive tried but isnt causing movement:
    Code:
    port = '/dev/ttyUSB0'
    baud = 38400
    
    
    ser = serial.Serial(port, baud)
    ser.flushInput()
    
    
    ser.write(bytes(0xff,'UTF-8'))            # start1
    ser.write(bytes(0xff,'UTF-8'))            # start2
    ser.write(bytes(0xfe,'UTF-8'))            # ID 253 is all, current motor-5
    ser.write(bytes(0x02,'UTF-8'))            # len
    ser.write(bytes(AX_WRITE_DATA,'UTF-8'))   # Instruction
    ser.write(bytes(0x1e,'UTF-8'))            # Parameters
    ser.write(bytes(0x64,'UTF-8')) 
    ser.write(bytes(0xff,'UTF-8')) 
    
    ser.close()
    Is there something wrong there?
    I am not a python person, so can not fully answer your question, but your output packet looks wrong.
    I believe you are trying to set the GOAL Position two bytes for all servos. Correct?

    First issue, the Length field, is not the number of bytes you are outputting, but the count of bytes that are output after this point in the packet...

    2nd Issue I see is I don't see a checksum byte being calculated and output. Here is a function from one of the Arduino libraries:
    Code:
    void ax12SetRegister2(int id, int regstart, int data){
        setTX(id);
        int checksum = ~((id + 5 + AX_WRITE_DATA + regstart + (data&0xFF) + ((data&0xFF00)>>8)) % 256);
        ax12writeB(0xFF);
        ax12writeB(0xFF);
        ax12writeB(id);
        ax12writeB(5);    // length
        ax12writeB(AX_WRITE_DATA);
        ax12writeB(regstart);
        ax12writeB(data&0xff);
        ax12writeB((data&0xff00)>>8);
        // checksum =
        ax12writeB(checksum);
        setRX(id);
        //ax12ReadPacket();
    }
    Now disregard the setTX/setRX as this has to do with handling the HALF duplex on an Arduino board. But it does show the length, plus checksum stuff...

    Edit: Also not sure about your goal position? Since it is LSB, MSB you are saying go to: 0xff64 = 65380 Which is probably not valid.
    Maybe you have them reversed and want 0x64ff? 25855 ? Still does not feel correct? Maybe you are only outputting the Low byte? and the second FF was supposed to be the checksum?
    Last edited by KurtEck; 12-15-2017 at 09:25 AM.

  5. Re: Taking a journey with python3

    Okay I did some updating because I found a source that explains it better, but it seems the problem might be how im sending the info? Ive simplified what I want it to do to just turn on the Servo LED. Ive been trying different methods of input such as bytes.fromhex(), bytes (from above), .encode('UTF-8'), and the below method. Nothing has been successful.

    I think Ive been getting the length right now.

    Code:
    port = '/dev/ttyUSB0'
    baud = 38400
    
    
    ser = serial.Serial(port, baud)
    ser.flushInput()
    ser.flushOutput()
    
    
    ser.write(b'0xff')
    ser.write(b'0xff')
    ser.write(b'0xfe')
    ser.write(b'0x04')
    ser.write(b'0x03')
    ser.write(b'0x19')
    ser.write(b'0x01')
    ser.write(b'0xf8')
    
    ser.close()
    Actually in the above code I wasnt sure what the checksum was so i put xff. I have an actually calculated value in this updated code using:
    checksum = 255 - ((index + length + ins + num of param)%256)

    edit: what exactly is the regstart value? isnt that just the first param?
    Last edited by robotsurgery; 12-15-2017 at 10:59 AM.

  6. #6

    Re: Taking a journey with python3

    Sorry, again I am not a Python person, but have edited a few Python Ros modules before...

    But again hard to give any real advice here without knowing the whole picture. That is What code is running on the Arbotix-m? I assume it is some simple forwarder Arduino sketch, but again could be wrong...

    Or is it some complete custom set of code? If custom you have the option of making any serial interface between this board and your Arbotix you want.

    Again not sure what you are running on the the Arbotix? My assumption is that most Arbotix sketches would assume the baud rate is the same as it is going to the servos. So example your 38400 looks suspect to me. I would have thought 1000000. This baud rate must match whatever was used in the Arduino sketch.

    If it were me, I would probably try out with c++... Don't know what Linux you are using... But if it were me I would first verify I can talk to the Arbotix using something that works... Again if me I would use my code up on github (kurte\Raspberry_pi) and build the ax test program and see if I can talk there...

    But again just guessing.

  7. Re: Taking a journey with python3

    So ive been using the arbotix-m examples and setup and what-not. So the arduino code running on the arbotix is the pypose sketch so that it can talk to the PyPose.py GUI program that sets motor positions, which works perfectly fine. Thing is that the pypose program is written in python 2 and im trying to get my system running on python 3. I figure i dont need to touch the arduino pypose sketch just communicate with it. The python2 pypose uses 38400 thats why im using it. Im on a Raspberry pi.

  8. #8

    Re: Taking a journey with python3

    Again if you look at the c++ code above for checksum:
    int checksum = ~((id + 5 + AX_WRITE_DATA + regstart + (data&0xFF) + ((data&0xFF00)>>8)) % 256);
    Code:
    ser.write(b'0xff')
    ser.write(b'0xff')
    ser.write(b'0xfe')
    ser.write(b'0x04')
    ser.write(b'0x03')
    ser.write(b'0x19')
    ser.write(b'0x01')
    ser.write(b'0xf8')
    From this I see (fe+4+3+19+1)%256 0xff= 0x1f and Not of the is E0...
    You might see if my quick math works and change the F8 to E0

    Edit: Looked like you did not include the ID in your case 0xfe in your calculation

    Edit 2: Did this in python on Windows 10
    Code:
    >>> print 255 - ((0xfe + 4 + 3 + 0x19 + 0x1)%256)
    224
    >>> print hex(224)
    0xe0
    >>>
    Last edited by KurtEck; 12-15-2017 at 12:13 PM.

  9. Re: Taking a journey with python3

    Yeah still didnt work Thanks for trying. I just dont understand why py3 and py2 have to be so different at this point

  10. #10

    Re: Taking a journey with python3

    Again I don't know python... But quick 2 second look again at pyserial reference, sounds like it is the same for Python2 and 3...

    And if your code is really like:
    Code:
    port = '/dev/ttyUSB0'
    baud = 38400
    
    
    ser = serial.Serial(port, baud)
    ser.flushInput()
    ser.flushOutput()
    
    
    ser.write(b'0xff')
    ser.write(b'0xff')
    ser.write(b'0xfe')
    ser.write(b'0x04')
    ser.write(b'0x03')
    ser.write(b'0x19')
    ser.write(b'0x01')
    ser.write(b'0xe0')
    
    ser.close()
    My first guess is that your data has not actually been sent! That is close, says it closes it immediately

    you might try adding: flush...

    Code:
    port = '/dev/ttyUSB0'
    baud = 38400
    
    
    ser = serial.Serial(port, baud)
    ser.flushInput()
    ser.flushOutput()
    
    
    ser.write(b'0xff')
    ser.write(b'0xff')
    ser.write(b'0xfe')
    ser.write(b'0x04')
    ser.write(b'0x03')
    ser.write(b'0x19')
    ser.write(b'0x01')
    ser.write(b'0xe0')
    ser.flush()
    ser.close()

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Dan's ROS Journey
    By TXBDan in forum ROS - Robot Operating System
    Replies: 10
    Last Post: 08-26-2016, 11:52 AM
  2. Question(s) designing board - taking 3.3V from the OPEN CM9?
    By fabrice in forum Arbotix, Microcontrollers, Arduino
    Replies: 1
    Last Post: 04-28-2016, 12:24 PM
  3. Project Project BETH aka Dan's journey into a lot of things.
    By TXBDan in forum Humanoids, Walkers & Crawlers
    Replies: 32
    Last Post: 02-14-2014, 09:15 AM
  4. Big Congrats to lnxfergy for taking Gold on Mech Warfare!
    By DresnerRobotics in forum Mech Warfare
    Replies: 6
    Last Post: 06-16-2009, 10:07 PM
  5. News/Announcement Now taking Pre-Orders on the Bioloid Boomerang Zigbee Controller!
    By DresnerRobotics in forum Humanoids, Walkers & Crawlers
    Replies: 6
    Last Post: 10-25-2008, 09:51 AM

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
  •