profmason.com

May 22, 2013

Robotic Light Saber Battle using the CM900

Filed under: Daily — profmason @ 3:42 am

For makerfaire I wanted to make an impressive exhibit that kids would have a great time playing with.  After some brainstorming with a past student and one of the Robotis team, we decided to build a pair of Wii nun-chuk controlled robot arms that would wield light sabers.

A picture of the first revision is shown at right.  All parts are available from Trossen Robotics in the US or Robosavvy in the Europe.  Here is a break down of what was used in revision 1 of the build:

  • CM-900 microcontroller  $20
  • 4 AX-12+ Dynamixel Servos $180
  • 2x Bioloid Frame F8   $4
  • 2x Bioloid Frame F3  $3
  • 1x Bioloid Frame F4 $2
  • 1x Bioloid Frame F1 $2
  • 4x Bioloid Frame F10 $5
  • 1x Bioloid Frame F2 $2
  • 12″ x 12″ piece of MDF $2
  • Misc screws etc.
  • Light saber (I will look up the model but ~$20)

The entire build is about $250 in this configuration.

Click on the picture at right to see how the parts were assembled.  The light saber was held on with two zip-ties through the F1 bracket and this provided a surprisingly secure mounting.   The MDF plate was fabricated by cutting to size, rounding the edges with a belt sander and then routing a 1cm slot in the middle to serve as a wire tray. The lower F8 bracket was screwed to the MDF plate using small wood screws.  Art work was a collaboration with my nine year old daughter.    This design was tested extensively as can be seen in the video below:

While revision 1 did a good job of moving the light saber around, there were two flaws.  First the upper F8 bracket was only attached by two screws.  These worked themselves out during testing.  Second the bottom servo was carrying a tremendous amount of torque from the entire arm assembly.  Four solutions were discussed.

  1. Use double AX-12 servos to replace the single AX-12 bottom Pivot.
  2.  Reverse the geometry of the arm so that the lightsaber would be better balanced over the center of the arm.
  3. Pre-load the arm with springs.
  4. Replace the AX-12 servo with a higher end RX servo.

Due to time constraints we implemented 2 and 4.  This resulted in the final design shown at right. This design also allowed us to prove that AX and RX servos could be integrated on the same bus with the CM-900.  This integration worked flawlessly.

The lightsabers ran through two days of makerfaire with hundreds of kids having mock lightsaber battles.  A game was proposed that grew in depth as the event progressed.

Initially it was proposed that each side would have an animal army.  The light saber wielder who could knock their opponents animals to the floor while protecting their own animal army would be declared the victor.  The picture below shows a lightsaber with its animal army arrayed at the ready.

A second light saber was built up that was identical to the first and they were tested at the Robotics Society of Southern California(RSSC) meeting on Saturday,  May 11th.  Below is an excerpt from the first demo featuring a battle between two RSSC members.

Finally, we took both sabers to maker faire and let the kids at it.  Here is a short video of one of the many battles that took place over two days.

Below is the CM-900 Code for the project:

*
* Robotic Light Sabers
* http://www.profmason.com
* Be sure to pull up your two I2C ports with ~2K resistors to the 3.3V line.
 * By default using the pins 14 and 15 for SDA and SCL.
 */
#define uint8_t int
#define SHOULDERPIVOT 6  //These are the servos used in the Arm
#define SHOULDERANGLE 1
#define ELBOW 4
#define WRIST 9
#include "Wire.h"
#include "WiiChuk.h"

WiiChuck chuck = WiiChuck();

void setup() {
  SerialUSB.begin();
  chuck.begin(14,15);  //Specify SDA, SCL for this nunchuck
  chuck.update();
  chuck.calibrateJoy();
  Dxl.begin(1);
  delay(100);
  setServoPos(SHOULDERPIVOT,512,400);
  setServoPos(SHOULDERANGLE,480,400);
  setServoPos(ELBOW,312,400);
  setServoPos(WRIST,512,400);
}

void waitForComplete()
{
  while(chuck.buttonC)
  {
  chuck.update();
  delay(20);
  }

}

void slashRight()
{
  setServoPos(SHOULDERPIVOT,312,400);
  setServoPos(SHOULDERANGLE,480,400);
  setServoPos(ELBOW,312,400);
  setServoPos(WRIST,312,400);
  waitForComplete();
  setServoPos(SHOULDERPIVOT,512,400);
  setServoPos(SHOULDERANGLE,500,400);
  setServoPos(ELBOW,412,400);
  setServoPos(WRIST,512,400);
  waitForComplete();
}

void slashLeft()
{
  setServoPos(SHOULDERPIVOT,712,400);
  setServoPos(SHOULDERANGLE,480,400);
  setServoPos(ELBOW,312,400);
  setServoPos(WRIST,712,400);
  waitForComplete();
  setServoPos(SHOULDERPIVOT,512,400);
  setServoPos(SHOULDERANGLE,500,400);
  setServoPos(ELBOW,412,400);
  setServoPos(WRIST,512,400);
  waitForComplete();
}

void loop() {
  delay(20);
  chuck.update();  //Update the values from the nunchuk
  if (chuck.buttonC)  //If the top button is pressed check for a special combo move
  {
    if (chuck.readJoyX()>100)  //If the joystick is pressed to the right execute slash right combo
    {
    slashRight();
    }
    else if (chuck.readJoyX()    {
    slashLeft();
    }
  }
  else
  {
  if (chuck.buttonZ) //If the lower button is pressed, move the lower shoulder pivot
  {
    setServoPos(SHOULDERPIVOT,512+2*chuck.readJoyX(),250);
  }
  else{  //Else move the wrist pivot
    setServoPos(WRIST,512-2*chuck.readJoyX(),250);
  }
  setServoPos(ELBOW,300-chuck.readJoyY()/2,250);
  int shoulderOut = 500+chuck.readJoyY()*1.5;
  if (shoulderOut  {
  shoulderOut =400;
  }
  setServoPos(SHOULDERANGLE,shoulderOut,250);
  }
}

void setServoPos( short servo, int position, int speed ){
  Dxl.writeWord( servo, 30, position );
  Dxl.writeWord( servo, 32, speed );
}

void testNunChuk()
{
  SerialUSB.print(chuck.readJoyX());
  SerialUSB.print(", ");
  SerialUSB.print(chuck.readJoyY());
  SerialUSB.print(", ");

  if (chuck.buttonZ) {
    SerialUSB.print("1");
  }
  else  {
    SerialUSB.print("0");
  }

  SerialUSB.print(", ");

  if (chuck.buttonC) {
    SerialUSB.print("1");
  }
  else  {
    SerialUSB.print("0");
  }

  SerialUSB.println();
}

All in all this was a great project. The major problems we had were in overheating in one of the CM900 engineering sample boards.  I had used an engineering sample as it already had the header pins soldered in.  This particular board had some problems that led to intermittent problems with the I2C interface with the nunchuk.  The lightsaber built with the release board ran successfully and logged at least 8 hours of continual use driving servos in a very rigorous fashion.  The other point of failure was the upper F8 bracket which we had noticed during the design phase.  We ended up breaking two of these brackets during the competition.  We found that there were some minor servo heating issues, which required us to shutdown the arms every 10 to 15 minutes, but these were welcome breaks for the makers running the exhibit as well.
Thank you to Robotis for making this project possible!

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress