lego_dynamixel_control_xl320
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lego_dynamixel_control_xl320 [2019/05/16 20:29] – [Preliminaries] ntorresreyes | lego_dynamixel_control_xl320 [2019/06/06 23:03] (current) – [NXC Code] ntorresreyes | ||
---|---|---|---|
Line 115: | Line 115: | ||
\\ | \\ | ||
\\ | \\ | ||
- | {{: | + | {{: |
\\ | \\ | ||
\\ | \\ | ||
Line 126: | Line 126: | ||
**INSTRUCTION: | **INSTRUCTION: | ||
\\ | \\ | ||
- | {{: | + | {{: |
\\ | \\ | ||
**PARAMETERS: | **PARAMETERS: | ||
Line 138: | Line 138: | ||
**Setting Default Baud Rate** | **Setting Default Baud Rate** | ||
\\ | \\ | ||
- | The default baud rate for | + | 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:// |
\\ | \\ | ||
+ | \\ | ||
+ | **RS485 to TTL** | ||
+ | \\ | ||
+ | The XL-320 uses TTL logic levels (0 to 5v) for communication. Since the NXT uses RS485 communication, | ||
+ | \\ | ||
+ | \\ | ||
+ | {{: | ||
+ | \\ | ||
+ | \\ | ||
+ | The MAX485 chip offers some simplicity over using an off the shelf converter although many higher level features are not included. Nevertheless, | ||
+ | \\ | ||
+ | *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, | + | Some simple tests can first be completed with the NXT and the Dynamixel servos before running the finished program. Occasionally, |
\\ | \\ | ||
< | < | ||
//Norberto Torres-Reyes | //Norberto Torres-Reyes | ||
- | //04/06/2019 | + | //05/16/2019 |
- | //Writes ID to a Dynamixel | + | //Writes ID to a Dynamixel |
- | #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 169: | Line 188: | ||
} | } | ||
- | setID(ID); | + | SetID(ID); |
| | ||
Line 182: | 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. | + | |
< | < | ||
- | // | + | // |
//Created by: Norberto Torres-Reyes | //Created by: Norberto Torres-Reyes | ||
- | // | + | // |
//Version 1.0 | //Version 1.0 | ||
- | // | ||
- | // | ||
- | #include "Dynamixel2.h" | + | #include "DynamixelXL320.h" |
#define ID 0XFE | #define ID 0XFE | ||
- | // | ||
- | int angleRaw = 0; //Raw 10-bit value for servo angle | ||
- | float angleRes = 1023/ | ||
- | int angleStep = 1023*100/ | ||
- | float angleVal = 0; //degree value converted from raw | ||
- | int rotateSpeed = 50; | ||
- | float offsetVal = 0; | ||
task main() | task main() | ||
Line 207: | Line 216: | ||
| | ||
| | ||
- | | ||
- | | ||
- | { | ||
- | TextOut(0, | ||
- | TextOut(0, | ||
- | TextOut(0, | ||
- | Wait(10); | ||
- | } | ||
- | | ||
- | //0 to 300(1023). | ||
| | ||
- | ClearLine(LCD_LINE5); | + | Wait(1000); |
- | | + | Servo(ID,500,100); |
- | | + | Wait(1000); |
- | | + | Servo(ID,0,100); |
- | | + | |
- | | + | |
- | Wait(200); | + | |
- | + | ||
- | | + | |
- | | + | |
- | angleRaw = (angleRaw + angleStep); | + | |
- | if(angleRaw >= 1023){ | + | |
- | angleRaw = 1023; | + | |
- | } | + | |
- | servo(ID,angleRaw,rotateSpeed); | + | |
- | | + | |
- | TextOut(0, | + | |
- | | + | |
- | } | + | |
- | + | ||
- | if(ButtonPressed(BTNLEFT, | + | |
- | | + | |
- | angleRaw = (angleRaw - angleStep); | + | |
- | if(angleRaw <= 0){ // | + | |
- | angleRaw = 0; | + | |
- | } | + | |
- | servo(ID,angleRaw, | + | |
- | angleVal = (angleRaw/ | + | |
- | TextOut(0,LCD_LINE5, NumToStr((angleVal))); | + | |
- | Wait(200); | + | |
- | } | + | |
} | } | ||
} | } | ||
- | |||
</ | </ | ||
Line 258: | 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: | + | {{:torres:xl320_codev2.zip|}} |
\\ | \\ | ||
**Controlling Multiple Dynamixels** | **Controlling Multiple Dynamixels** | ||
Line 264: | 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. | ||
< | < | ||
- | #define ID1 90 | + | #define ID1 01 |
- | #define ID2 91 | + | #define ID2 02 |
</ | </ | ||
\\ | \\ | ||
- | Next, each Dynamixel should be initialized with the " | ||
- | < | ||
- | setMode(ID1, | ||
- | setMode(ID2, | ||
- | </ | ||
\\ | \\ | ||
- | 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 280: | Line 246: | ||
// | // | ||
//By: Norberto Torres-Reyes | //By: Norberto Torres-Reyes | ||
- | // | + | // |
//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 308: | Line 274: | ||
Wait(10); | Wait(10); | ||
} | } | ||
- | | ||
- | | ||
| | ||
Line 326: | Line 290: | ||
angleRaw = 0; | angleRaw = 0; | ||
} | } | ||
- | | + | |
angleVal = (angleRaw/ | angleVal = (angleRaw/ | ||
TextOut(0, | TextOut(0, | ||
Line 338: | Line 302: | ||
angleRaw = 0; | angleRaw = 0; | ||
} | } | ||
- | | + | |
angleVal = (angleRaw/ | angleVal = (angleRaw/ | ||
TextOut(0, | TextOut(0, | ||
Line 346: | Line 310: | ||
} | } | ||
</ | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
====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:// | + | Running the code is straight forward. Ensure that the NXT is connected to the computer via the USB cable and the [[http:// |
\\ | \\ | ||
- | 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 | + | 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 |
\\ | \\ | ||
**Video:** | **Video:** | ||
\\ | \\ | ||
- | {{youtube> | + | {{youtube> |
\\ | \\ | ||
\\ | \\ | ||
**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:// | + | 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:// |
\\ | \\ | ||
{{: | {{: | ||
Line 372: | 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, | + | In Conclusion, this tutorial has provided a brief introduction into RS-485 serial communication, |
lego_dynamixel_control_xl320.1558063761.txt.gz · Last modified: by ntorresreyes