ROBOTC.net forums
http://www.robotc.net/forums/

Wii Nunchuck Operated, Servo Controlled Lego Zamor Cannon!
http://www.robotc.net/forums/viewtopic.php?f=15&t=1800
Page 1 of 1

Author:  sparramc [ Mon Aug 17, 2009 3:06 am ]
Post subject:  Wii Nunchuck Operated, Servo Controlled Lego Zamor Cannon!

This is my Wii Nunchuck Operated, Servo Controlled Zamor Cannon. This is my first project using the Simply Modified Servos Motors that I mentioned in a previous forum post :arrow: . It uses the MindSensor 8 Channel Servo Controller for the NXT, the NXTServo-v2.

The Cannon uses two 9gram Servos for Altitude and rotation, and one 43gram Servo to control firing. A 9gram Servos was capable of controlling the direct drive firing pin, but they were at their very limits, so I used Big Brother instead. Amazing, motion and Not a single Lego motor in sight!

Image
It's Strange to see the NXT Brick with only a single cable attached!

The Servo Controller requires an external 4.5-6 volt power supply to power the Servos. In this project with only the 3 Servos I used 4.5Volts supply. I've found in order to control more than 4 Servos you really need the 6volt supply as they work better and there's less current draw (Remember Mr. Ohm told us that "V=IR").

The Servo Controller is a dream to program and use and the fact you can drive 8 at a time means there are a million possible projects. I'm now trying to come up with a project that I can use all 8 servos, my 2 Mindsensor RCX Motor Multiplexer for NXT controlling 8 Lego Mini Motors as well as the 3 Lego NXT Motors. I also have my own home-brew I2C 8 Touch Switch multiplexer and the MindSensor RCX Sensor multiplexer for NXT, the RXMux for use with 4 RCX Sensors. The only thing holding me back is my Programming abilities and some imagination.

Here's the Source Code for my Wii Nunchuck Operated, Servo Controlled Zamor Cannon for those interested.

Code:
///////////////////////////////////////////////////////////////////////////////////////////////////////
//
//        "Mindsensors Servo Controller & Wii Nunchuck Controlled Zarmor Cannon"
//
//                  Ray McNamara August 2009 - sparra_mc@liliums.org
//
///////////////////////////////////////////////////////////////////////////////////////////////////////

#include "NXTServo-lib.c"   // MindSensor NXT Servo Controller Library
#include "Nunchuk-lib.c"    // Wii Nunchuck Controller Library

//
//  Register Task Vairable Names
//

void initializeCannon();
void fireCannon();
void finalizeCannon();
#pragma fileExtension("rtm")
#pragma platform("NXT")

//
//  Monitor Nunchuck Controller to Position & Fire the Cannon
//

task CannonControl()
{
  while (true)
  {
    NunchukGetParamter(S1, 0x00);               //Set Nunchuk i2c Port
    if (sizeof(outbuf)==6)    {
      nxtDisplayTextLine(6, "NXT   = %dmV", nAvgBatteryLevel);  // Display NXT's Battey Level
      nxtDisplayTextLine(7, "Servo = %dmV", Get_Batt_V());      // Display Servo Controller's Battey Level

      NXTServo_Quick_Servo_Setup(2, (outbuf1[1]-0x1E)+30);      //  Joystick - Up:Down
      NXTServo_Quick_Servo_Setup(3, (outbuf1[0]-0x1E)+50);      //  Joystick - Left:Right

//      NXTServo_Quick_Servo_Setup(2, (outbuf1[3]-0x1E)+30);      //  Use Motion Sensor - Up:Down
//      NXTServo_Quick_Servo_Setup(3, (outbuf1[2]-0x1E)+50);      //  Accelerometer - Left:Right


      if ((outbuf1[5]&0x01)==0) {                               //  Z-Button Pressed
        PlaySoundFile("Watch Out.rso");         // Warning Cannon Firing Message
        fireCannon();
       }
       if ((outbuf1[5]&0x02)==0) {finalizeCannon();}           //  C-Button Pressed
    }
    wait1Msec(100);                             // Don't Hog CPU
  }
}


//
//  Begin the NXT Zamor Cannon Program
//

task main()
{
  PlaySoundFile("Hello.rso");                   // Welcome Audio Message
  nI2CBytesReady[kSc8Port] = 0;                 // Select Sensor Port
  SensorType[kSc8Port] = sensorI2CCustom9V;     // Set Sensor Port Mode
  eraseDisplay();                               // Grab LCD screen and initialize display
  nxtDisplayBigTextLine(1, "ZAMOR");
  nxtDisplayBigTextLine(3, " CANNON");
  initializeCannon();                           // Ready Cannon
  PlaySoundFile("Robot.rso");                   // Cannon is Ready Audio Message
  PlaySoundFile("Start.rso");
  StartTask(CannonControl);                     // Monitor the 'Wii Nunchuck' Cannon Controller
}

//
//  Ready the Cannon for Use
//

void initializeCannon()
{
  NXTServo_Quick_Servo_Setup(1, 250);           // Move Servo to Start Position
  wait10Msec(100);                              // Wait for Servo to Complete Operation
  NXTServo_Quick_Servo_Setup(1, 0);             // Put Servo 1 in Neutral
  NXTServo_Quick_Servo_Setup(2, 150);           // Move Servo to Start Position
  wait10Msec(100);                              // Wait for Servo to Complete Operation
  NXTServo_Quick_Servo_Setup(2, 0);             // Put Servo 2 in Neutral
  NXTServo_Quick_Servo_Setup(3, 150);           // Move Servo to Start Position
  wait10Msec(100);                              // Wait for Servo to Complete Operation
  NXTServo_Quick_Servo_Setup(3, 0);             // Put Servo 3 in Neutral
  return;
}

//
//  Fire the Cannon at Target
//

void fireCannon()
{
  NXTServo_Quick_Servo_Setup(1, 50);            // Fire Cannon Ball
  wait10Msec(100);                              // Wait for Servo to Complete Operation
  NXTServo_Quick_Servo_Setup(1, 250);           // Reset Cannon Ready for Firing
  wait10Msec(100);                              // Wait for Servo to Complete Operation
  NXTServo_Quick_Servo_Setup(1, 0);             // Put Servo 1 in Neutral
  return;
}

//
//  Set Servos to Coast Mode & Terminate Program
//

void finalizeCannon()
{
  NXTServo_Quick_Servo_Setup(1, 0);             // Put Servo 1 in Neutral
  NXTServo_Quick_Servo_Setup(2, 0);             // Put Servo 2 in Neutral
  NXTServo_Quick_Servo_Setup(3, 0);             // Put Servo 3 in Neutral
  PlaySoundFile("Stop.rso");                    // Cannon Shutdown Audio Message
  PlaySoundFile("Goodbye.rso");
  wait10Msec(1000);                             // Wait for Auto Power Off Cancelation
  powerOff();                                   //  Turn Power Off on NXT Brick
}




:breakcomputer: Instructions for modify the Wii Nunchuck controller can be found in the RobotC Forums. It requires 2 X 33kohm 1/8Watt Resistors, a NXT Compatible Male Plug from Mindsensors, a small screw driver, Soldering Iron and 15 minutes of your time. With a little care and patients, it will end up looking like it came with you MindStorms NXT Kit originally.

Image

At this stage it looks like I'll have the Cannon built up for a while as my three+ year old Son won't let me dismantle it. We now have two Zamor Cannons for the same reason. The second one was built using standard NXT Motors. The Servo version is the simplest, easiest to build and most reliable!

Attachments:
File comment: This is the Wii Nunchuck Controller Library file, "Nunchuk-lib.c" which is need to compile the program and to use the Controller.
Nunchuk-lib.c [1.65 KiB]
Downloaded 708 times

Author:  mightor [ Mon Aug 17, 2009 3:39 am ]
Post subject:  Re: Wii Nunchuck Operated, Servo Controlled Lego Zamor Cannon!

Sparra,

Nice job! Make a small video, host it on YouTube and then mail deepak@mindsensors.com about this. I'm pretty sure it'll be featured on their website.

Regards,
Xander

Author:  sparramc [ Tue Aug 18, 2009 7:05 am ]
Post subject:  YouTube Video - For the Servo Controlled Lego Zamor Cannon!

I finally found a camera and time to edit a quick video of my Servo Controlled Lego Zamor Cannon in action and posted it on YouTube.

Visit http://www.youtube.com/v/SCh0CfU-nxE&hl=en&fs=1 to see my Robot in Action without a Single Lego Motor Insight!

Author:  Atlantisbase [ Tue Aug 18, 2009 1:54 pm ]
Post subject:  Re: Wii Nunchuck Operated, Servo Controlled Lego Zamor Cannon!

Looks cool. Now all you have to do is put it on wheels and you've got yourself a regular tank.

Author:  sparramc [ Fri Aug 21, 2009 12:37 am ]
Post subject:  Re: Wii Nunchuck Operated, Servo Controlled Lego Zamor Cannon!

I wasn't worried about mobility as it was purely and exercise in understanding the Mindsensor Servo Controller and it's programming.

The follow-up project, the NXT-Ant will have mobility using the Mindsensor Servo Controller with 8 Servos and 3 NXT Motors. At this stage it will be armed with a set of jaws but, I may put a sting in it's tail at a later date! I've posted an image in the discussion area of this Robot-C Forum of NXT-Ant Mark I.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/