User Tools

Site Tools


lego_dynamixel_control_xl320

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lego_dynamixel_control_xl320 [2019/05/16 21:39] – [Preliminaries] ntorresreyeslego_dynamixel_control_xl320 [2019/06/06 23:03] (current) – [NXC Code] ntorresreyes
Line 143: Line 143:
 **RS485 to TTL** **RS485 to TTL**
 \\ \\
-The XL-320 uses TTL logic levels (0 to 5v) for communication. Since the NXT uses RS485 communication, an RS485-to-TTL converter must be used. This can be done using a MAX485 chip, as seen in **this** tutorial or with an off the shelf converter such as [[https://www.amazon.com/DROK-Adapter-Module-Converter-Indicator/dp/B075V2NMV8/ref=sr_1_3?keywords=rs485+to+ttl&qid=1558067804&s=gateway&sr=8-3|this one]].+The XL-320 uses TTL logic levels (0 to 5v) for communication. Since the NXT uses RS485 communication, an RS485-to-TTL converter must be used. This can be done using a [[https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=7&ved=2ahUKEwip-ILdzdbiAhWQup4KHYefCGwQFjAGegQIBhAC&url=https%3A%2F%2Fdatasheets.maximintegrated.com%2Fen%2Fds%2FMAX1487-MAX491.pdf&usg=AOvVaw3BFaoKg2WHoZayW5LHwFD5|MAX485 chip]], as seen below or with an off the shelf converter such as [[https://www.amazon.com/DROK-Adapter-Module-Converter-Indicator/dp/B075V2NMV8/ref=sr_1_3?keywords=rs485+to+ttl&qid=1558067804&s=gateway&sr=8-3|this one]].
 \\ \\
 \\ \\
 +{{:torres:image6.jpg?300|}}
 +\\
 +\\
 +The MAX485 chip offers some simplicity over using an off the shelf converter although many higher level features are not included. Nevertheless, it is definitely enough for this tutorial at a fraction of the cost and zero extra added components. The pin layout is as follows:
 +\\
 +   *1 - TTL Output
 +   *2 - LOW (GND)
 +   *3 - LOW (GND)
 +   *4 - Not Connected
 +   *5 - GND
 +   *6 - SDA (From NXT)
 +   *7 - SCL (From NXT)
 +   *8 - 5 volts
 **Writing Dynamixel ID's** **Writing Dynamixel ID's**
 \\ \\
Line 216: Line 229:
 The NXC code files as well as the header file is included below in a .zip file: The NXC code files as well as the header file is included below in a .zip file:
 \\ \\
-{{:torres:tutorials:nxt_dynamixel:nxt_code.zip|}}+{{:torres:xl320_codev2.zip|}}
 \\ \\
 **Controlling Multiple Dynamixels** **Controlling Multiple Dynamixels**
Line 222: Line 235:
 When controlling multiple Dynamixels, only a few more steps are required. First, each Dynamixel should have its own ID as described in the preliminary section. When controlling multiple Dynamixels, only a few more steps are required. First, each Dynamixel should have its own ID as described in the preliminary section.
 <code> <code>
-#define ID1 90 +#define ID1 01 
-#define ID2 91+#define ID2 02
 </code> </code>
 \\ \\
-Next, each Dynamixel should be initialized with the "setMode()" function. 
-<code> 
-setMode(ID1, SERVO, minAngle1, maxAngle1); 
-setMode(ID2, SERVO, minAngle2, maxAngle2); 
-</code> 
 \\ \\
-Finally, when using the "servo()" function, make sure the correct ID for the correct Dynamixel is used.+Finally, when using the "Servo()" function, make sure the correct ID for the correct Dynamixel is used.
 \\ \\
 The following code is an example of how two Dynamixels can be controlled by the NXT: The following code is an example of how two Dynamixels can be controlled by the NXT:
Line 238: Line 246:
 //2_Dynamixel_Control //2_Dynamixel_Control
 //By: Norberto Torres-Reyes //By: Norberto Torres-Reyes
-//Date: 04/18/19+//Date: 05/16/19
 //Controls two different Dynamixels using the left and right buttons. //Controls two different Dynamixels using the left and right buttons.
  
-#include "Dynamixel2.h"+#include "DynamixelXL320.h"
 #define ID1 90 #define ID1 90
 #define ID2 91 #define ID2 91
Line 266: Line 274:
   Wait(10);   Wait(10);
  }  }
- setMode(ID1,SERVO,0,1023);        //servo mode with angle limits of 
- setMode(ID2,SERVO,0,1023);        //0 to 300(1023). 
  
  while(true){  while(true){
Line 284: Line 290:
     angleRaw = 0;     angleRaw = 0;
     }     }
-  servo(ID1,angleRaw,rotateSpeed);+  Servo(ID1,angleRaw,rotateSpeed);
   angleVal = (angleRaw/angleRes - offsetVal);   angleVal = (angleRaw/angleRes - offsetVal);
   TextOut(0,LCD_LINE5, NumToStr((angleVal)));   TextOut(0,LCD_LINE5, NumToStr((angleVal)));
Line 296: Line 302:
     angleRaw = 0;     angleRaw = 0;
     }     }
-  servo(ID2,angleRaw,rotateSpeed);+  Servo(ID2,angleRaw,rotateSpeed);
   angleVal = (angleRaw/angleRes - offsetVal);   angleVal = (angleRaw/angleRes - offsetVal);
   TextOut(0,LCD_LINE5, NumToStr((angleVal)));   TextOut(0,LCD_LINE5, NumToStr((angleVal)));
Line 304: Line 310:
 } }
 </code> </code>
- 
- 
- 
- 
- 
  
 ====Running and Analysis==== ====Running and Analysis====
-Running the code is straight forward. Ensure that the NXT is connected to the computer via the USB cable and the [[http://bricxcc.sourceforge.net/|"Bricx Command Center"]] is running. Make sure that the code can compile properly without any errors. Connect the NXT cable to the "S4" port and connect the other end to breadboard adapter. +Running the code is straight forward. Ensure that the NXT is connected to the computer via the USB cable and the [[http://bricxcc.sourceforge.net/|"Bricx Command Center"]] is running. Make sure that the code can compile properly without any errors. Connect the NXT cable to the "S4" port and connect the other end to breadboard adapter. The data lines from the adapter should then be connected to the RS485-to-TTL converter.
 \\ \\
-For a single servo control, connect one of the Dynamixel cables to the power supply and another to the breadboard adapter. If using two or more, one cable goes from the breadboard adapter to the first Dynamixel. Another cable is connected from the first servo to the next servo and so on. The last servo connects to the power supply. The 12v 2 amp adapter is then connected to the power converter.+For a single servo control, connect one of the Dynamixel cables to the TTL output. If using two or more, one cable goes from the TTL output to the first Dynamixel. Another cable is connected from the first servo to the next servo and so on.
 \\ \\
 **Video:** **Video:**
 \\ \\
-{{youtube>LSfvN1XR01Q?medium}}+{{youtube>ODi75v3P31c?medium}}
 \\ \\
 \\ \\
 **Logic Analyzer (OPTIONAL)** **Logic Analyzer (OPTIONAL)**
 \\ \\
-The logic analyzer can be connected to the +5V, GND, SDL, SDA pins on the breadboard adapter before connecting to a dynamixel. Instruction on using the logic analyzer with your computer can be found [[https://www.youtube.com/watch?v=Gx0Qo5n-x_4|here]]. When running the single servo control code, pressing the left or right arrow should give you a signal similar to the one shown below:+The logic analyzer can be connected to the +5V, GND, SDL, SDA pins on the breadboard adapter before connecting to a dynamixel. Instruction on using the logic analyzer with your computer can be found [[https://www.youtube.com/watch?v=Gx0Qo5n-x_4|here]]. Below is an example of an instruction packet as seen from the logic analyzer. 
 \\ \\
 {{:torres:tutorials:nxt_dynamixel:logiccapture_instructionpacketservo_trimmed.png?nolink&900|}} {{:torres:tutorials:nxt_dynamixel:logiccapture_instructionpacketservo_trimmed.png?nolink&900|}}
Line 330: Line 331:
 This tool is useful in debugging any errors that may arise when communicating with the Dynamixels that may otherwise be impossible to catch. This tool is useful in debugging any errors that may arise when communicating with the Dynamixels that may otherwise be impossible to catch.
 ====Conclusions==== ====Conclusions====
-In Conclusion, this tutorial has provided a brief introduction into RX-485 serial communication, UART communication protocols, Dynamixel communication, and NXT control of single and multiple Dynamixels. The NXT code provided allows for ID reconfiguration of a Dynamixel and accurate angle control of multiple Dynamixels. The hope is that the reader can use the information and examples provided to apply to more advanced tasks. Such tasks can be combined with LEGO structures to create various useful mechanisms. It is also possible to use the information in this tutorial and expand the Dynamixel controls for use with other micro-controllers. +In Conclusion, this tutorial has provided a brief introduction into RS-485 serial communication, UART communication protocols, Dynamixel communication, and NXT control of single and multiple Dynamixels. The NXT code provided allows for ID reconfiguration of a Dynamixel and accurate angle control of multiple Dynamixels. The hope is that the reader can use the information and examples provided to apply to more advanced tasks. Such tasks can be combined with LEGO structures to create various useful mechanisms. It is also possible to use the information in this tutorial and expand the Dynamixel controls for use with other micro-controllers. 
lego_dynamixel_control_xl320.1558067987.txt.gz · Last modified: by ntorresreyes