Both sides previous revisionPrevious revisionNext revision | Previous revision |
lego_dynamixel_control_xl320 [2019/05/16 21:37] – [Preliminaries] ntorresreyes | lego_dynamixel_control_xl320 [2019/06/06 23:03] (current) – [NXC Code] ntorresreyes |
---|
\\ | \\ |
\\ | \\ |
{{:torres:tutorials:image5.jpg?700|}} | {{:torres:tutorials:image5.jpg?800|}} |
\\ | \\ |
\\ | \\ |
**INSTRUCTION:** The figure below shows the different set of instructions that can be sent, in this case it's "Write Data". | **INSTRUCTION:** The figure below shows the different set of instructions that can be sent, in this case it's "Write Data". |
\\ | \\ |
{{:torres:tutorials:image4.jpg?700|}} | {{:torres:tutorials:image4.jpg?800|}} |
\\ | \\ |
**PARAMETERS:** The first one or two parameters are the specific command, the remaining parameters are the bytes associated with that parameter. Some parameters require two bytes for one value, for example, for the base 10 number 950 the low (L) byte would be "10110110" and the high (H) byte would be "00000011". The datasheet has the complete list of all parameters. | **PARAMETERS:** The first one or two parameters are the specific command, the remaining parameters are the bytes associated with that parameter. Some parameters require two bytes for one value, for example, for the base 10 number 950 the low (L) byte would be "10110110" and the high (H) byte would be "00000011". The datasheet has the complete list of all parameters. |
**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** |
\\ | \\ |
Some simple tests can first be completed with the NXT and the Dynamixel servos before running the finished program. Occasionally, it may be required to change the ID's of the servos. The factory default ID for the XL-320's is 0x01. It is necessary to provide separate ID's for each servo or else communication with multiple servos will not work. The following code provides a simple way to change a Dynamixel ID with the NXT. The header file "Dynamixel2.h" must be located in the same folder as the code | Some simple tests can first be completed with the NXT and the Dynamixel servos before running the finished program. Occasionally, it may be required to change the ID's of the servos. The factory default ID for the XL-320's is 0x01. It is necessary to provide separate ID's for each servo or else communication with multiple servos will not work. The following code provides a simple way to change a Dynamixel ID with the NXT. The header file "DynamixelXL320.h" must be located in the same folder as the code |
\\ | \\ |
<code> | <code> |
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** |
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: |
//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 |
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){ |
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))); |
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))); |
} | } |
</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|}} |
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. |