Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 17 of 17

Thread: Teensy 4.0 and Dynamixel

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    2

    Teensy 4.0 and Dynamixel

    I am trying to get a Teensy and Dynamixel AX motor working together without a chip to switch RX and TX but I cant seems to find a proper library that just works.

    Some libraries that state are for Teensy are not even compiling, is there something ready or I need to get around the source of DynamixelSDK and get some functions out?

    I see these examples https://github.com/ROBOTIS-GIT/OpenC.../ping/ping.ino but still trying to insall the proper way.

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    I am probably going to convert my stuff to new library by robotis. Dynamixel2Arduino, but default stuff depends on transmit enable pin... I have my own library https://github.com/KurtE/BioloidSerial which I earlier did some t4 testing on. Don’t remember if I added the 54 half duplex support or not

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    2
    Quote Originally Posted by KurtE View Post
    I am probably going to convert my stuff to new library by robotis. Dynamixel2Arduino, but default stuff depends on transmit enable pin... I have my own library https://github.com/KurtE/BioloidSerial which I earlier did some t4 testing on. Don’t remember if I added the 54 half duplex support or not
    Oh cool, I mean I dont mind using the chip to select the output, I just struggle to get a library that makes the telemetry works.

    At the moment I managed to use this https://github.com/jumejume1/AX-12A-servo-library and force to use Serial2 but it doesnt seems to decode the incoming messages, I can print out the bytes but it looks like there is an error coming out. I probably need to read the manual and see what it is suppose to send and receive.

    I will have a look at your library

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    @max246 - For a long time, I never used a buffer chip(s) to work with AX servos from a Teensy 3.x.

    However, most of the time I do now.

    Why, a couple of reasons, which arguably may not be totally valid, but since I had some doubts, I went to buffer(s)

    a) Dynamixel Spec shows that they are expecting 5v TTL. I never had issues I could pin on the fact that The T3.x and now T4 output 3.3v. I did run into issues where at times one or more AX servos would reset their ID to ID #1. Enough so, that some of the software I have for example to run a 3DOF hexapod, avoids Servo ID #1, and at sketch startup time, it searches for all of the servo IDs it expects. If it finds that one is missing and now servo ID #1 exists, it automatically changes the servo with ID #1 to the missing servo ID... If it finds that multiple servos are missing it does not do this... I personally think the resetting the servo to #1 is probably more an issue of power going into the servos and maybe they have a brown out...

    b) The IO pins on the T3.6 and now T4 (earlier T3) are NOT 5v tolerant. So again depending on HOW a servo (or other devices you might put on your Dynamixel chain), generates it's response (does it drive signal high and low, or only pull low), I was afraid that maybe something will generate 5V and damage the Teensy...

    Warning since I am mostly a tinkerer, I have played around doing this a few different ways. Often never fully testing the hardware, before I am off doing other things. But I plan to get back to trying my own T4 boards soon. However I am currently doing testing and making suggestions to Robotis to their library (and Arduino code) geared around their OpenCM9.04 boards. But I am doing this with the idea of better supporting the Teensy.

    Example board, which I still need to try to fully assemble one and test out the connections for servos... I was tinkering with idea of making a simpler one, that removed some of the complexities. Like maybe don't worry about SD connections, or in the case of this one I had a setup for a wireless module, which could be removed...

    Click image for larger version. 

Name:	t4-breakout-top.jpg 
Views:	4 
Size:	32.5 KB 
ID:	17999

    Problem is I get too many distractions to finish my previous distraction.

  5. #5
    Junior Member
    Join Date
    Jul 2017
    Posts
    5
    Hi everyone!

    I'm starting a project using some (more than 20...) dynamixel XM and I was wondering if the teensy 4 will be enough to control that at a good frame rate.
    Reading a SD card txt file with all the position and sync writing that to all of them.

    Does robotis have a more powerful solution (like the CM or CR boards)?
    Also very interested to see how far the DynamixelSDK has been ported to the teensy environment.

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    Hi @xoxu - I am not sure if there is any easy answer to your set of questions. But I will do my $.02 worth of stuff.

    I have used several boards over the years to control typically up to about 20 servos. 3 DOF Hexapod, plus Pan and Tilt. I have a 4dof hexapod (RC servos run with SSC-32), but others have done 4dof Hexapods so about 26 servos. With some of these setups the main thing driving the servos was an 8 bit AVR board. So almost any of these others can control that number of servos.

    A lot of things depend on your needs and what all else you wish to do and where...

    First off Robotis boards: First off they are already setup to be able to handle DXL servo.
    a) openCM boards are nice initial setup for simple things. The hexapod runs just fine on these. However they don't directly hook up to XL or XM servos. You can get the OpenCM485 expansion board, which adapts them to AX servos, and then you can use an AX To XL cable to connect up to X servos.
    b) OpenCR - Works nicely more powerful than OpenCM direct X servo connectors.

    Teensy 4 has lots going for it, with High speed and memory... Can it handle it. Sure, so can T3.5/6 and in fact I have earlier boards with T3.2 which do great.
    There are others how much demos of hexapods and the like using a Teensy. Such as ones done by the user Zenta. Example:
    https://www.youtube.com/watch?v=aH07qF_bhgA

    Note: most of my earlier stuff, I used my own version of the Bioloid (Trossen Robotics) library, that I adapted to work with Teensy boards. It is up in my github projects (BioloidSerial)
    I did/do have a version of Dynamixel SDK that I added Teensy (and AVR) support, but Robotis did not want to incorporate it.

    However they are now working on some alternate libraries, that started off when they came out with the DynamixelShield. They have a library DynamixelShield that was directly coupled to AVR boards, but then to make it based on another new library Dynamixel2Arduino, which I have been working with some of their developers to allow us to easily sub-class it to allow support for other processors. You can currently install this library using Arduino library manager, or from github (https://github.com/ROBOTIS-GIT/Dynamixel2Arduino). I am mainly using github version, as working with their developer (OpusK) in a secondary branch, where we are trying out some different ideas, like APIS for SyncRead and SyncWrite...


    The most interesting thing of Frame Rates, is mainly dictated by how fast stuff can go out over the Serial port. That is I typically run them at 1mhz. Could go faster... But lots of this all depends on what you are wanting the Teensy to do? Are you using it with a primary process (PC, RPI, ...), and what is the work break down...

    hope that helps a little...

    Kurt

  7. #7
    Junior Member
    Join Date
    Nov 2019
    Posts
    2
    Hey,

    I’ll join this topic because I have a similar problem.

    I try to run some XL320 and 2XL430-W250-T with a Teensy 3.6. Currently I´m using the following library: https://github.com/hackerspace-adelaide/XL320/tree/bene. By using an external circuit (http://nerdralph.blogspot.com/2014/0...ware-uart.html) I divide the servos RX/TX data line to be able to receive data via the teensy´s rx pin. While this approach more or less works fine with the XL320, I have problems using the 2XL430, which may be caused by the relatively old library.

    Now, with the Dynamixel2Arduino library released, I’m thinking about switching.

    What I currently don’t understand is how to use the “direction pin”. As far as I understand, it´s necessary to divide the rx/tx data, so it does the same as I do with the external circuit mentioned above. But I don´t really know how to use it.
    Maybe I should mention that I try to control the servos with only the Teensy 3.6, no other boards involved.

    @KurtE: As you seem to be working with a Teensy and the Dynamixel2Arduino library, is there a chance you can provide some example code and a quick setup plan of how to use it?

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    As for the Circuit - I have not used that form of circuit with a teensy.

    I either use the built-in teensy half duplex support or I use a driver chip(or chips)... Both are supported by my older bioloidSerial library: https://github.com/KurtE/BioloidSerial

    Note: For built in T3.x half duplex support you connect up to the TX pin of the Serial port.

    My current board(s) that I am playing with I borrowed a circuit design from the member @jwatte, which you can see in the Trossen Robotics Thread posting:
    http://forums.trossenrobotics.com/sh...5055#post95055

    One of the main reasons I currently prefer using the driver chips, is that the Teensy outputs 3.3v, which has worked fine for me (I think). But the specs for Dynamixels say 5V. Also with the T3.6 and T4, their pins are NOT 5V, tolerant. So having driver between, gives me a comfort level.


    Dynamixel2Arduino: Allow for different code to handle serial port. Note Some of this may change, with some of the stuff we are playing with in the WIP branch, but try looking at the
    example sketch: add_custom_SerialPortHandler.ino under advanced.

    Right now each actual write waits until complete (does a flush) and then changes the direction pin... This can easily be changed to instead change IO registers to use native half duplex support.

    As for your library working with xl320 but not XL430... I would guess that your library only supports Protocol 1, where the newer servos are running using Protocol 2.

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    Quick update: I thought I would try some of it out with the recent T4 board I assembled...

    Found out I screwed up on the board and when I did a copy and paste of a couple of resistors, I forget to edit the values so I built the board with 2 wrong resistors, instead of begin something like 4.7KOhm, they were supposed to be 47 and 333 ohm...

    Luckily I was able to remove the resistors and use some that were reasonably close to these values and now a servo respond...

    I tried plugging in one AX-12 and did a quick set of pings to see if it would find it.

    I then did a quick move the servos a little, which appears to move. Although not as smooth as I would expect... But may be simple issue with Quick and dirty test...


    Code:
    #include <Dynamixel2Arduino.h>
    
    // Kurt's T4-T36 board
    #define DXL_SERIAL   Serial2
    const uint8_t DXL_DIR_PIN = 6; // OpenCR Board's DIR PIN.
    
    class NewSerialPortHandler : public DYNAMIXEL::SerialPortHandler
    {
      public:
        NewSerialPortHandler(HardwareSerial& port, const int dir_pin = -1)
          : SerialPortHandler(port, dir_pin), port_(port), dir_pin_(dir_pin)
        {}
    
        virtual size_t write(uint8_t c) override
        {
          size_t ret = 0;
          digitalWrite(dir_pin_, HIGH);
    
          ret = port_.write(c);
    
          port_.flush();
          digitalWrite(dir_pin_, LOW);
    
          return ret;
        }
    
        virtual size_t write(uint8_t *buf, size_t len) override
        {
          size_t ret;
          digitalWrite(dir_pin_, HIGH);
    
          ret = port_.write(buf, len);
    
          port_.flush();
          digitalWrite(dir_pin_, LOW);
    
          return ret;
        }
    
      private:
        HardwareSerial& port_;
        const int dir_pin_;
    };
    
    Dynamixel2Arduino dxl;
    NewSerialPortHandler dxl_port(DXL_SERIAL, DXL_DIR_PIN);
    uint8_t id = 0xff;
    float     goal_pos = 512.0;
    float     max_delta = 128.0;
    float     incr = 1.0;
    float     center_pos;
    
    
    void setup() {
      // put your setup code here, to run once:
    
      // Use Serial to debug.
      while (!Serial && millis() < 5000) ;
      Serial.begin(115200);
    
      // Set Port instance
      dxl.setPort(dxl_port);
      // Set Port baudrate to 1000000. This has to match with DYNAMIXEL baudrate.
      dxl.begin(1000000);
      // Set Port Protocol Version. This has to match with DYNAMIXEL protocol version.
      Serial.println("Setup completed");
      Serial.flush();
    }
    
    uint8_t findServo() {
      Serial.println("Search for a Servo");
      Serial.println("First try Protocol 1");
      dxl.setPortProtocolVersion(1.0);
      for (uint8_t servo_id = 0; servo_id < 253; servo_id++) {
        if (dxl.ping(servo_id) == true) {
          Serial.printf("Found ID:%u Model Number:%u\n", servo_id, dxl.getModelNumber(servo_id));
          center_pos = goal_pos = 512.0;
          max_delta = 128.0;
          incr = 1.0;
          return servo_id;
        }
      }
      Serial.println("Now try Protocol 2");
      dxl.setPortProtocolVersion(2.0);
      for (uint8_t servo_id = 0; servo_id < 253; servo_id++) {
        if (dxl.ping(servo_id) == true) {
          Serial.printf("Found ID:%u Model Number:%u\n", servo_id, dxl.getModelNumber(servo_id));
          center_pos = goal_pos = 2048.0;
          max_delta = 256.0;
          incr = 2.0;
          return servo_id;
        }
      }
      Serial.println("No Servos found");
      return 0xff;
    }
    
    void loop() {
      if (id == 0xff) {
        id = findServo();
        if (id == 0xff) {
          delay(1000);
          return;
        }
        dxl.torqueOn(id);
      }
      goal_pos += incr;
      if (goal_pos >= (center_pos + max_delta)) incr = -incr;
      if (goal_pos <= (center_pos - max_delta)) incr = -incr;
      dxl.setGoalPosition(id, goal_pos);
      if (Serial.available()) {
        Serial.println("Paused");
        while (Serial.read() != -1);
        while (Serial.read() == -1);
        while (Serial.read() != -1);
      }
    }

  10. #10
    Junior Member
    Join Date
    Nov 2019
    Posts
    2
    Awesome.

    I played around a bit, but it was really easy. Totally unexpected, everything works absolutely fine.

    I still use the circuit as written in my previous post. Then adapted the SerialPortHandler as you suggested.

    Code:
    const uint8_t DXL_DIR_PIN = -1; // Do not use dir pin
    
    
    class NewSerialPortHandler : public DYNAMIXEL::SerialPortHandler
    {
      public:
        NewSerialPortHandler(HardwareSerial& port, const int dir_pin = -1)
        : SerialPortHandler(port, dir_pin), port_(port), dir_pin_(dir_pin)
        {}
    
        virtual size_t write(uint8_t c) override
        {
          size_t ret = 0;
          ret = port_.write(c);
          port_.flush();
          return ret;
        }
    
        virtual size_t write(uint8_t *buf, size_t len) override
        {
          size_t ret = 0;
          ret = port_.write(buf, len);
          port_.flush();
          return ret;     
        }
    
      private:
        HardwareSerial& port_;
        const int dir_pin_;
    };
    Tested it with a XL320 and a 2XL430. And of course, you were right. When I said I didn´t use any other boards I forgot to mention that I in fact use a level shifter to shift the 5V to 3.3V, so Teensy doesn´t take damage. The circuit mentioned is on the 3.3V side of the data line.

    So thank you very much KurtE!! Made my life a lot easier

  11. #11
    Junior Member
    Join Date
    Jul 2017
    Posts
    5
    Thank you KurtE, I started to look at the Dynamixel2Arduino library, seems to be the one that will have the most support for the moment and the most compatibility with the dynamixel range and controllers.
    I plan to use Maya to do the animation, export to mov files and excelify that to transfer to sd card, not something that will change dynamically, more like a static loop display sort.
    But I need smooth motion, so probably a frame rate around 50ms with maybe an interpolator for smooth travel.

  12. #12
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    Still playing with it...

    With my own board, which I hopefully fixed some of the issues I was having running the Servos. Like wrong resistors, maybe cold solder...
    And what may be a bad AX servo, I plugged in an XL430-W250 servo,

    And my simple loop which increments the servos position and outputs the new location was updating > 800 times per second... So it appears to work.. Not to say there are not other issues...

    I believe the current Dynamixel2Arduino only supports by default 16 servos unless you are on some specific controller, like OpenCR. The branch I am working on, I have been working with OpusK (Robotis) and I think the mapping of servos to types now support all 253 servo IDs...

    The main reason for limits was to do with how the current release does things like Sync Read and Write, which is the part we are now experimenting with. Hopefully we will have a stable version that supports enough servos for the things we are talking about.

    ---
    @xoxu - I am not at all knowing of things like Maya, Nor the formats that you will be generating, or to what level.

    As how fast you can run things and how often you may need/want to tell servos stuff, really depends on how your stuff is organized and how things are done.

    Example you could potentially try to store for each instant of time the exact servo positions, which could be very precise, but might take lots of space on SDCard... Then your code is as simple as reading SDCARD and directly generate a sync-write from it.

    Or you could save something like: I wish to move all the servos from their current position X, the their new positions Y in time Z, and then let the driver code (or servos) handle the details, like, I am doing N updates per second, example 100. And if I wish to move a servo 50 units in a .1 seconds, than this move will take 10 servo cycles and so update the servo by 5 units per cycle...

    Or maybe you are using some of the smarter servos, and you can have them do a lot of this work, by not only telling them their new positions but also telling them what velocity that should get there and control some of this by setting up some of their other parameters.

    Or maybe your code is setup to do something like inverse kinematics, where you might be able to say move the unit such that the tip is at some world coordinate, and then you convert this into the angle each servo needs and then do the interpolation...

    And again how fast you can update the servos depends on lots of things like:
    a) What Baud rate you are using.
    b) How you have the servos configured. Example return delay time which defaults to value 250 (500us), I set this to 0 so no delay. Another is the Status Return level (which you can set to 1 instead of 2) and it will not send back a status packet on commands like register writes. (Does not mater with Sync write)
    c) are you only writing out information or are you also polling the servos back for information, like their current position, or load, or temp, or...

  13. #13
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    hello i also want to control dynamixel using teensy
    I was very difficult to find TC7WT241FU, so I tried to use a circuit and library like https://savageelectronics.com/blog/a...teca-dynamixel but it didn't work. previously I used the same circuit and the same library used arduino mega and it worked. will you help me to get the right circuit and the right library to be able to control dynamixel.

  14. #14
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    Hi and welcome @Fikri - Might help to know which Teensy... For now I will assume T3.x, TLC, or T4... (ie. not T2), and also which servos. i.e. some libraries only support Protocol 1, so if your servos use protocol 2...

    As for the TC7WT241FU I am trying them out on my current new board... Not sure yet if I like them or not. Will see... As one circuit worked for Mega but not Teensy, maybe check to see if the parts you were trying worked with 3.3v signals or required 5v signals... And/Or that the library has code in it that works with Teensy... A

    As for hardware to hook up there are a lots of different ways one can do it...

    Depending on how safe you wish it to be and or within specs. Some (including myself) have gotten away driving the servos with 3.3v signals. And for example the libraries I have used: (github.com/kurte/BioloidSerial) supports both protocols, and it will support the Teensy using half duplex support built into the Serial ports. (you just need to connect to the TX pin of the Serial port)... Note: for T4, I am not sure I put in full support yet for this mode.

    Next level up from this, is you could setup to use a bidirectional level shifter on the TX pin for 5v... .

    Another way that I have used and may return to, is to use a setup like Robotis used on their OpenCM485 expansion board: Look at the schematic: http://support.robotis.com/en/baggag...ncm_485exp.pdf

    Which uses two different level shifter/buffers, one for each direction which has difference for enable (74LVC1G125, and SN74LVC1G126) chips

    As a way to go down to a smaller count of parts, I am playing with TC7WT241FU, earlier I tried a different large chip which had something like 8 level shifters, with 4 with enable and 4 with NOT enable... Which worked and easy to solder, but big...

    Libraries - The one I mentioned I have used up till now.

    I have had a hacked up version of Dynamixel SDK supporting it.

    And now the Dyanamixel2Arduino is setup (and still improving) to allow it.

  15. #15
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    thx for your attention KurtE
    I forgot to say that I will use Teensy 4.0 for fast data processing and 18 Dynamixel AX-18A for Hexapod. I see a schematic of the expansion board. but i don't understand what is meant by AVRC5S chip. Is that logic level?
    Click image for larger version. 

Name:	Capture.PNG 
Views:	0 
Size:	8.6 KB 
ID:	18344
    but I am not sure if using 74126 (buffer) and 7404 (not) will be safe in teensy 4.0. because when I use arduino due to control dynamixel using that circuit, my arduino is damaged. I have to be careful using teensy 4.0 because it's quite difficult to find these boards in my country

  16. #16
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,751
    I believe the AVRC5S is simply another level of protection. For EMI and ESD... I have not used them yet on my own boards... http://www.1688eric.com/upload/pdf/2...05Q050100R.pdf

    My guess if the circuit that you used that damaged the Arduino Due would also not be good for T4 (maybe ok for T3.2 or 3.5), my guess is that it fed +5v signal to the RX pin... But again guessing without seeing the actual circuit... And again I am mainly a software guy who has fun playing with hardware. But I would double check that whatever circuit that feeds your RX pin is somehow in the range of 3.3v...

  17. #17
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    hi kurtE.
    I have done some of the suggestions you gave before.
    I have used a buffer circuit to drive Dynamixel AX-12 using teensy 4.0 with the following scheme.
    Click image for larger version. 

Name:	Capture.PNG 
Views:	1 
Size:	7.8 KB 
ID:	18443
    I use pin 0 as RX, pin 1 as TX and pin 2 as controller. in the 74125 buffer I use a power supply of 3.3v and in 74126 I use a power supply of 5v.
    I have also tried several libraries such as BioloidSerial and Dynamixel2Arduino.

    previously I had adjusted the ID on dynamixel to 18 using U2D2 and it worked, but after I uploaded my program, dynamixel still didn't work.

    can you help me to solve the problem above

Posting Permissions

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