User Tools

Site Tools


lego_dynamixel_2d_plotter

This is an old revision of the document!


Dynamixel Control with NXT (IN PROGRESS)

Author: Norberto Torres-Reyes Email: torresre@unlv.nevada.edu
Date: Last modified on 04/10/19
Keywords: kinematics, planar, robotic arm, 2 link, lego, NXC, NXT, mindstorm, dynamixel, plotting

Motivation and Audience

This tutorial is for anyone who wishes to create a 2-link plotting robotic arm using LEGO Mindstorm, NXC software, and Dynamixel RX-28 servos. This tutorial will also reinforce theoretical knowledge about 2-link planar mechanisms, serial communication, and servo control. Readers of this tutorial are recommended to have the following background and interests:

*Previous experience with LEGO Mindstorm
*Matlab and/or C-based programming experience
*Knowledge of linear algebra
*Some knowledge in serial communcation
*Experience with using servos

The rest of the tutorial is presented as follows:

Parts List

LEGO NXT parts list is given in full detail in the Build Plans section. Most parts can be obtained from the Mindstorm kit, although some extra parts will be needed from LEGO's Technic line of bricks. A few parts for controlling the Dynamixels will also be needed as well as a part used to communicate between the NXT Brick and the Dynamixel.

Dynamixel RX28
https://www.trossenrobotics.com/dynamixel-rx-28-robot-actuator.aspx
PHOTO
Lego BreadBoard Adapter
http://www.mindsensors.com/ev3-and-nxt/58-breadboard-connector-kit-for-nxt-or-ev3
PHOTO
SMPS2Dynimxel
http://www.robotis.us/smps2dynamixel/
PHOTO
(Optional) HiLetgo USB Logic Analyzer
https://www.amazon.com/gp/product/B077LSG5P2/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1
PHOTO

Other Parts Needed:

  • NXT Cable

PHOTO

  • Dynamixel Connector Cables

PHOTO

  • USB A-to-C cable

PHOTO

  • 12V 2-Amp Power Supply

PHOTO

Theoretical Background

The theoretical background can be subdivided into three parts:

  • 2-Link Arm Kinematics
  • RS-485 Serial Communication
  • Dynamixel Communication

2-Link Arm Kinematics
PHOTO
A concise introduction to 2-link arm kinematics can be found here. This introduction covers the mathematical calculations required to calculate the position of the end-effector from a given set of joint angles and the joint angles required to obtain a specific end-effector position. Along with a review of homogeneous transformations, it also covers numerical and graphical simulations using MatLab.


RS-485 Serial Communication

PHOTO

RS-485 is an EIA/TIA standard for serial communication. This standard is an improvement on the older RS-232 which will not be discussed here. Several improvements include faster speeds, the ability to transmit data at a length of about 4000 feet (1200 meters), the ability to connect up to 32 devices, and good noise immunity. The data rates depend on the length of the cable and can range from 100 kbits/sec at 1200 meters to 10 Mbits/sec at 10 meters.

PHOTO OF RS-485 BUS

The good noise immunity comes from the differential signal between the two data lines. Using this method, any noise or ground level shifts can be avoided, reducing the chance of data corruption.

PHOTO OF DIFFERENTIAL SIGNALS

In this tutorial we will be using half-duplex communication although full-duplex can also be used. Half-duplex communication consists of sending and receiving data in only one direction at a time. Specifically, a serial communication protocol known as UART (Universal Asynchronous Receiver/Transmitter) is used. This method is called asynchronous because instead of having a clock signal to synchronize the transmitter and receiver, a preset data rate is agreed upon by both devices. The image below shows how a signal would look like for transmitting the hexadecimal value 0x55 (ascii “U”, decimal 85, binary 01010101).

PHOTO OF UART “U”

The signal consists of several different sets of bits. The first bit is the start bit “1” and signifies the beginning of an incoming signal. The subsequent 8 bits are the actual data bits; In our case “01010101”. An optional parity bit can go next, otherwise a stop bit “1” is used to signify the end of the transmission.

Dynamixel Communication

Communication with the Dynamixel RX-28 servos require several parameters. A tutorial about NXT communication with the RX-28 servos can be found here. The RX-28 datasheet is also very useful reference that should be looked at as well.

IMAGE

Preliminaries

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

//Norberto Torres-Reyes
//04/06/2019
//Writes ID to a Dynamixel RX-28 with NXT

#include "Dynamixel2.h"
#define ID 90  //ID that you want to write to servo



task main()
{
 UseRS485();
 RS485Enable();
 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);
 }
 
 setID(ID);
 Wait(100);
 
 ClearScreen();
 TextOut(0,LCD_LINE3, FormatNum("ID NEW: %d" ,ID));
 Wait(2000);
 }

Each Dynamixel ID can be changed individually. The ID's can range from 0x01 to 0xFD, where 0xFE is a universal ID that will communicate to all servos at once.

Testing Rotation
Each servo should also be tested for proper operation before beginning the project. 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.

//Dynamixel RX-28 Servo Control
//Created by: Norberto Torres-Reyes
//Date: 03/30/19
//Version 1.0
//Dynamixel2.h modified from
//http://www.daslhub.org/unlv/wiki/doku.php?id=lego_nxt_dynamixel&s[]=dynamixel

#include "Dynamixel2.h"
#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()
{
 UseRS485();
 RS485Enable();
 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){
 ClearLine(LCD_LINE5);
 TextOut(0,LCD_LINE1,"Angle Control");
 TextOut(0,LCD_LINE3,"Right CW");
 TextOut(0,LCD_LINE4,"Left CCW");
 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);
 }
 }
}

Build Plans

NXC Code

Running and Analysis

Conclusions

lego_dynamixel_2d_plotter.1555186060.txt.gz · Last modified: by ntorresreyes