ROBOTIS DYNAMIXEL Shield for Arduino MKR Series Examples

From Lofaro Lab Wiki
Revision as of 22:33, 21 April 2021 by Dlofaro (Talk | contribs)

Jump to: navigation, search

Prerequisites

This tutorial assumes that you have the following:

  • 1x DYNAMIXEL Shield for Arduino MKR Series
  • 1x Arduino MKR compatible device. Note: This tutorial uses the Arduino MKR1000
  • 1x Compatible 1S LiPo battery with a JST2.0 connector. (Please check for proper polarity)
  • Nx DYNAMIXEL XL330-M288-T ROBOTIS actuators where N >= 1

Examples

This shows examples on how to use the DYNAMIXEL Shield for MKR with the DYNAMIXEL XL330-M288-T ROBOTIS actuators.

Ping

The first step is to make sure you can ping your actuator. This will let you know if you can connect to your actuator.

Wiring

Do the following steps to hook up the system for this test:

  1. Firmly place the DYNAMIXEL Shield on top or below the Arduino MKR1000. Note there may be about 0.5cm (0.2in) of headers still showing.
  2. Attach one end of the wire that came in the XL330's box wo one of the three ports on the shield that it fits into. Please noted that it is keyed. If it does not fit in easily you may be trying it backwards.
  3. Attach the other end of the wire from the previous step to the XL330 actuator.
  4. Attach the fully charged 1S battery to the JST2.0 battery port on the MKR shield. This will power the actuator. Do NOT hook it up to the JST2.0 port on the Arduino MKR1000. Please note that if you hook it up to the battery port on the Arduino side it will NOT power the actuator.
  5. If the actuator has factory setting it will blink one when it is powered on. Additionally it will have the following attributes:
ID: 1
Protocol: DYNAMIXEL Protocol 2.0
BAUD: 57600

To program the device you need to plug in the USB cable into your computer.

Code

Include the DYNAMIXEL Protocol Headers

If you have not installed the DYNAMIXEL Protocol Headers for Arduino please install them now. This example used the library found here: Dynamixel2Arduino-master.zip

 #include <Dynamixel2Arduino.h>

Setup your serial ports

Note that the DXL_DIR_PIN is on pin A6, this allows the system to turn the full-duplex communication of the Arduino into the required half-duplex of the actuator.

 #define DXL_SERIAL   Serial1
 #define DEBUG_SERIAL Serial
 const uint8_t DXL_DIR_PIN = A6; // DYNAMIXEL Shield DIR PIN 

Define protocol, baud, and ID

This step assumes that your actuator is at the default settings.

 const uint8_t DXL_ID = 1;
 const float DXL_PROTOCOL_VERSION = 2.0;
 const int DXL_BAUD = 57600;

Create the DYNAMIXEL communications object

 Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);

Setup the control table

This namespace is required to use Control table item names

 using namespace ControlTableItem;

Inside your setup() function

The next part is inside your setup function, you will start your serial for the actuators and the serial for debugging as well as set the DYNAMIXEL Protocol version

Debug Serial:

 DEBUG_SERIAL.begin(115200);

DYNAMIXEL Com port:

 dxl.begin(DXL_BAUD);


Set Protocol for DYNAMIXEL:

 dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);


Inside your loop() function

The next part is inside your loop function, here you will ping the ID specified above and print out if you get a response or not. The system will delay 500ms (0.5sec) between pings.

 if(dxl.ping(DXL_ID) == true) DEBUG_SERIAL.println("success");
 else DEBUG_SERIAL.println("error");
 delay(500);

Full Code

This will ping the actuator with ID=1 and a baud of 57600. It will return "success" if it see the actuator and "error" if it does not.

  1. #include <Dynamixel2Arduino.h>
  2.  
  3. #define DXL_SERIAL   Serial1
  4. #define DEBUG_SERIAL Serial
  5. const uint8_t DXL_DIR_PIN = A6;
  6.  
  7. const uint8_t DXL_ID = 1;
  8. const float DXL_PROTOCOL_VERSION = 2.0;
  9. const int DXL_BAUD = 57600;
  10. Dynamixel2Arduino dxl(DXL_SERIAL, DXL_DIR_PIN);
  11. using namespace ControlTableItem;
  12.  
  13. void setup() {
  14.   DEBUG_SERIAL.begin(115200);
  15.   dxl.begin(DXL_BAUD);
  16.   dxl.setPortProtocolVersion(DXL_PROTOCOL_VERSION);
  17. }
  18.  
  19. void loop() {
  20.   if(dxl.ping(DXL_ID) == true) DEBUG_SERIAL.println("success");
  21.   else DEBUG_SERIAL.println("error");
  22.   delay(500);
  23. }