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

Next revision
Previous revision
lego_dynamixel_control_xl320 [2019/05/16 19:58] – created ntorresreyeslego_dynamixel_control_xl320 [2019/06/06 23:03] (current) – [NXC Code] ntorresreyes
Line 54: Line 54:
 http://www.robotis.us/u2d2/ http://www.robotis.us/u2d2/
 \\ \\
-{{:torres:tutorials:nxt_dynamixel:image3.jpg?300|}}+{{:torres:tutorials:image3.jpg?300|}}
 \\ \\
 **(Optional) HiLetgo USB Logic Analyzer** **(Optional) HiLetgo USB Logic Analyzer**
Line 109: Line 109:
 {{:torres:tutorials:nxt_dynamixel:capture1.png?700|}} {{:torres:tutorials:nxt_dynamixel:capture1.png?700|}}
 \\ \\
-Communication with the Dynamixel RX-28 servos require several parameters. A tutorial about NXT communication with the RX-28 servos can be found [[lego_nxt_dynamixel|here]]. The RX-28 [[http://www.hizook.com/files/users/3/RX-28_Robotis_Dynamixel_Servo_UserGuide.pdf|datasheet]] is also very useful reference that should be looked at as well.+Communication with the Dynamixel XL-320 servos require several parameters. A tutorial about NXT communication with the RX-28 servos (similar, but a different protocol is used) can be found [[lego_nxt_dynamixel|here]]. The XL-320 [[http://emanual.robotis.com/docs/en/dxl/x/xl320/#control-table-of-eeprom-area|datasheet]] is also very useful reference that should be looked at as well.
 \\ \\
 \\ \\
Line 115: Line 115:
 \\ \\
 \\ \\
-{{:torres:tutorials:nxt_dynamixel:capture2.png?600|}}+{{:torres:tutorials:image5.jpg?800|}}
 \\ \\
 \\ \\
-**0xFF:** These two bytes are used to signal an incoming packet.+**Header/Reserved:** These four bytes are used to signal an incoming packet; they always remain the same.
 \\ \\
 **ID:** This byte is the Dynamixel ID, which can be an individual ID or if 0xFE is used, the packet is sent to all Dynamixels. **ID:** This byte is the Dynamixel ID, which can be an individual ID or if 0xFE is used, the packet is sent to all Dynamixels.
 \\ \\
-**LENGTH:** This is the message length which is calculated by the number of parameters(N) + 2.+**LENGTH:** This is the two bit message length which is calculated by the number of parameters(N) + 2.
 \\ \\
 **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:nxt_dynamixel:capture3.png?nolink&600|}}+{{:torres:tutorials:image4.jpg?800|}}
 \\ \\
-**PARAMETERS:** The first parameter is 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.
 \\ \\
-**CHECKSUM:** The checksum is determined by ~(ID + Length + Instruction + Parameter1 + ... + ParameterN). The "~" symbol is the Not Bit Operator.+**CRC:** These two bits are the calculated cyclic redundancy check value. This is a more complicated recursive algorithm than the previously used checksum. The CRC is used to detect any message errors that could have occurred during transmission.
  
  
Line 136: Line 136:
  
 ====Preliminaries==== ====Preliminaries====
 +**Setting Default Baud Rate**
 +\\
 +The default baud rate for the XL-320 is 1 mbps. The NXT is not able to communicate at these speeds. To be able to reduce the default baud rate, one must use the Dynamixel Wizard software found within the [[http://www.robotis.us/roboplus1/|RoboPlus 1.0 suite]] as well as the U2D2 communication converter. Follow the instructions [[http://emanual.robotis.com/docs/en/software/rplus1/dynamixel_wizard/|here]] for communicating with the Dynamixel. You will have to use jumper cables and a breadboard to connect the U2D2 TTL channel to the XL-320 since the servo cable is too small. Change the default baud rate to 57600 baud. You can also change other parameters if desired.
 +\\
 +\\
 +**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 [[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 RX-28'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>
 //Norberto Torres-Reyes //Norberto Torres-Reyes
-//04/06/2019 +//05/16/2019 
-//Writes ID to a Dynamixel RX-28 with NXT+//Writes ID to a Dynamixel XL-320 with NXT
  
-#include "Dynamixel2.h" +#include "DynamixelXL320.h" 
-#define ID 90  //ID that you want to write to servo+#define ID 02  //ID that you want to write to servo
  
  
Line 165: Line 188:
  }  }
    
- setID(ID);+ SetID(ID);
  Wait(100);  Wait(100);
    
Line 178: Line 201:
 **Testing Rotation** **Testing Rotation**
 \\ \\
-\\ +Each servo should be tested for proper operation. The following code will rotate a servo to a certain angle and back in a loop. Once again, "DynamixelXL320.h" must be included in the same folder when running the code.
-Each servo should be tested for proper operation. The following code will rotate a servo at 100 degree intervals from 0 to 300 degrees by pushing the left and right arrow buttons. Once again, "Dynamixel2.h" must be included in the same folder when running the code.+
 <code> <code>
-//Dynamixel RX-28 Servo Control+//Dynamixel XL-320 Servo Control
 //Created by: Norberto Torres-Reyes //Created by: Norberto Torres-Reyes
-//Date: 03/30/19+//Date: 05/16/19
 //Version 1.0 //Version 1.0
-//Dynamixel2.h modified from 
-//http://www.daslhub.org/unlv/wiki/doku.php?id=lego_nxt_dynamixel&s[]=dynamixel 
  
-#include "Dynamixel2.h"+#include "DynamixelXL320.h"
 #define ID 0XFE #define ID 0XFE
-                   //Dynamixel ID 
-int angleRaw = 0;           //Raw 10-bit value for servo angle 
-float angleRes = 1023/300;   //10 bit resolution over 300 degrees of movement 
-int angleStep = 1023*100/300;  //10-degree step increment 
-float angleVal = 0;    //degree value converted from raw 
-int rotateSpeed = 50; 
-float offsetVal = 0; 
  
 task main() task main()
Line 203: Line 216:
  RS485Enable();  RS485Enable();
  RS485Uart(HS_BAUD_57600, HS_MODE_8N1);    //57600 baud, 8bit, 1stop, no parity  RS485Uart(HS_BAUD_57600, HS_MODE_8N1);    //57600 baud, 8bit, 1stop, no parity
- Wait(100); 
  
- while(!ButtonPressed(BTNCENTER, FALSE))   //display msg until center button pressed 
- { 
-  TextOut(0,LCD_LINE1, "Press Orange" ); 
-  TextOut(0,LCD_LINE2, "Button" ); 
-  TextOut(0,LCD_LINE3, "To Begin:" ); 
-  Wait(10); 
- } 
- setMode(ID,SERVO,0,1023);        //servo mode with angle limits of 
-                                  //0 to 300(1023). 
  while(true){  while(true){
- ClearLine(LCD_LINE5); + Wait(1000); 
- TextOut(0,LCD_LINE1,"Angle Control"); + Servo(ID,500,100); 
- TextOut(0,LCD_LINE3,"Right CW"); + Wait(1000); 
- TextOut(0,LCD_LINE4,"Left CCW"); + Servo(ID,0,100);
- angleVal = (angleRaw/angleRes - offsetVal);      //maps 0-1023 to 0-300 with offset +
- TextOut(0,LCD_LINE5,NumToStr((angleVal)));  //displays angle on screen +
- Wait(200); +
- +
- if(ButtonPressed(BTNRIGHT,FALSE))      //increments angle CW by 10 degrees +
-                                      //if right button is pressed +
-  angleRaw = (angleRaw + angleStep); +
-  if(angleRaw >= 1023){                //limits max CW value to 1023 +
-    angleRaw = 1023; +
-    } +
-  servo(ID,angleRaw,rotateSpeed); +
-  angleVal = (angleRaw/angleRes - offsetVal); +
-  TextOut(0,LCD_LINE5, NumToStr((angleVal))); +
-  Wait(200); +
- +
-  +
-  if(ButtonPressed(BTNLEFT,FALSE))    //increments angle CCW by 10 degrees +
-                                    //if left button is pressed +
-  angleRaw = (angleRaw - angleStep); +
-  if(angleRaw <= 0){                 //Limits CCW min value to 0 +
-    angleRaw = 0; +
-    } +
-  servo(ID,angleRaw,rotateSpeed); +
-  angleVal = (angleRaw/angleRes - offsetVal); +
-  TextOut(0,LCD_LINE5, NumToStr((angleVal))); +
-  Wait(200); +
- }+
  }  }
 } }
- 
 </code> </code>
  
Line 254: 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 260: 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 276: 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 304: 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 322: 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 334: 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 342: 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 368: 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.1558061915.txt.gz · Last modified: by ntorresreyes