Author Topic: Wii Nunchuck Controlled Robot  (Read 93791 times)

0 Members and 1 Guest are viewing this topic.

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Wii Nunchuck Controlled Robot
« on: December 15, 2007, 02:47:56 PM »
My robot Charlie with a Wii Nunchuck R/C system

[youtube=425,350]rFN0P7389O8[/youtube]

I sound weird on a mic.

EDIT: I posted code and such a few posts after this one

Other videos on my Youtube account
http://youtube.com/frank26080115

More better neater photos on my flickr
http://www.flickr.com/photos/frank26080115/2125780153/
« Last Edit: February 19, 2008, 10:15:58 AM by frank26080115 »

Offline Mega

  • Full Member
  • ***
  • Posts: 88
  • Helpful? 0
    • MegaBot Blog
Re: Wii Nunchuck Controlled Robot
« Reply #1 on: December 15, 2007, 02:54:34 PM »
Very cool!
Where can I find more info on Charlie?
Visit my robotics blog at http://megabotblog.blogspot.com/

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Wii Nunchuck Controlled Robot
« Reply #2 on: December 15, 2007, 04:24:40 PM »
Nice!!!

post some code!

Offline ed1380

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
Re: Wii Nunchuck Controlled Robot
« Reply #3 on: December 15, 2007, 05:24:53 PM »
awesome
Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #4 on: December 15, 2007, 05:44:01 PM »
The Nunchuck reading code is an improvement upon the code from http://www.windmeadow.com/node/42

This is all done with the Arduino environment

You need one of my custom library (some weird functions i find handy), and you need to modify the existing Wire library with the steps in http://www.windmeadow.com/node/42

my library file is named basic.h, place it in /arduino-0010/hardware/libraries/basic/
i've attached this file to this post

the controller side uses the file inside my "charlie_wii_nunchuck.zip" attached to this post
I found that instructions here http://www.windmeadow.com/node/42 for the connection is not so reliable, I really think you should use a 3.3V regulator, PLUS 10K pull up resistors
Read this http://www.sparkfun.com/commerce/present.php?p=Sensor-Interfacing

The radio transmitter is one of those cheap RF modules Spark Fun sells, except mine only costs $5 each, not $15,
it is connected to the TX pin on the MCU
Don't bother with 4800 baud even though it's the speed the modules are advertised at, use 2400
http://www.robotshop.ca/home/products/robot-parts/communication-control/data-telemetry/on-shine-low-cost-tx-rx.html

the robot has pins defined to the various servos, the pin definitions can be changed in the code (file is servo.pde), the radio receiver is connected to the RX pin, the file is "charlie_advanced_rc.zip"
(I got lazy and used a bunch of switch cases instead of simply calculating out the servo pulse widths, floating point wasn't working right)

OH, and I made a connector to avoid cutting the nunchuck's cables, it's a stick of double sided copper clad board etched with 3 lines to match the inside of the connector, and i made a plastic housing so everything stays nicely together, it's great! The screws I used even lets the connector to "click in"

The pinouts of the connector is here:
http://www.hardwarebook.info/Wiimote_Expansion_Port
« Last Edit: February 19, 2008, 10:13:51 AM by frank26080115 »

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Re: Wii Nunchuck Controlled Robot
« Reply #5 on: December 15, 2007, 07:24:17 PM »
Very cool    ;D
 
i gotta build me one of those...
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline Mega

  • Full Member
  • ***
  • Posts: 88
  • Helpful? 0
    • MegaBot Blog
Re: Wii Nunchuck Controlled Robot
« Reply #6 on: December 16, 2007, 02:21:22 AM »
Very nice indeed!
If I spotted it correctly, your Charlie bot uses the AVRcam?
Do you have some more info on how you use the cam and how you connected it to the Arduino?
Visit my robotics blog at http://megabotblog.blogspot.com/

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #7 on: December 16, 2007, 11:40:09 AM »
It wasn't hard, but it's a pain in the ass to use.

I'll try and fish up some code, maybe even a library someday. But it's basically send your track command, then wait for a few packets, then end the tracking, and process the packets.

I'm also hoping to make my own image processor, but with a atmega128 instead of the atmega8
But the camera's datasheet is very very difficult to understand.

Offline HDL_CinC_Dragon

  • Supreme Robot
  • *****
  • Posts: 1,261
  • Helpful? 5
Re: Wii Nunchuck Controlled Robot
« Reply #8 on: December 16, 2007, 12:01:13 PM »
that is genius dude. Good freaking job! Seriously, that is cool as hell lol. That little bot has some serious application potential! :D
United States Marine Corps
Infantry
Returns to society: 2014JAN11

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #9 on: December 16, 2007, 09:42:31 PM »
This is weird, you guys see the wire antenna i used on the breadboarded transmitter? removing the antenna gives me a huge boost in signal quality... I need to make a project boxed version of the transmitter, and now i'm wondering about an antenna, what should I do? use an antenna or stick with what works?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Wii Nunchuck Controlled Robot
« Reply #10 on: December 17, 2007, 05:53:35 AM »
hmmm odd about the antenna . . .

is the antenna on your robot also vertical? antennas must be parallel for optimal transmission

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Wii Nunchuck Controlled Robot
« Reply #11 on: December 17, 2007, 11:59:16 AM »
Nice job, Frank!
Small request, can you post the code for the AVRcam processing sequence? I am struggling making mine work with a Arduino custom board...
Check out the uBotino robot controller!

Offline Mega

  • Full Member
  • ***
  • Posts: 88
  • Helpful? 0
    • MegaBot Blog
Re: Wii Nunchuck Controlled Robot
« Reply #12 on: December 17, 2007, 12:02:54 PM »
Quote
Small request, can you post the code for the AVRcam processing sequence?

Same request from me. Thanks in advance!
Visit my robotics blog at http://megabotblog.blogspot.com/

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Wii Nunchuck Controlled Robot
« Reply #13 on: December 17, 2007, 12:25:10 PM »
Quote
Quote
Small request, can you post the code for the AVRcam processing sequence?

Same request from me. Thanks in advance!
and me . . . I tried to do it yesterday actually with the CMUcam on my ATmega168 and so far no luck. The code is basically the same for both cams . . .

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #14 on: December 17, 2007, 02:53:36 PM »
Code: [Select]
// Cam Related Variables
// These needs to be written while reading buffer
byte objNum;
byte objColour[8]; // Refer to sensordef.h
// These are used by the robotic functions
boolean noObj;
byte objXCenter[8];
byte objYCenter[8];
byte objWidth[8];
byte objHeight[8];
byte objSize[8]; // Average between width and height used for ranging purposes
byte objShape[8]; // 0 for null, 1 for square, 2 for tall, 3 for wide
boolean objFound;
byte objAtt; // in view and right shape and colour
boolean objInterestFound;
byte objInterested; // not the right shape, but right colour on the edge of view
byte wantedColour = 1; // What colour you are looking for

boolean waitACK()
{
  boolean incomeValid = true;
  while(Serial.available() < 4);
  if(Serial.read() != 65)
  {
    incomeValid = false;
  }
  if(Serial.read() != 67)
  {
    incomeValid = false;
  }
  if(Serial.read() != 75)
  {
    incomeValid = false;
  }
  if(Serial.read() != 13)
  {
    incomeValid = false;
  }
  return incomeValid;
}

void getObj()
{
  byte objXMin[8];
  byte objXMax[8];
  byte objYMin[8];
  byte objYMax[8];
  byte waittimeout = 0; 
  byte temp;

  Serial.println("ET");

  while(waitAck() == false)
  {
    Serial.println("ET");
  }

  while((Serial.available() == 0) && (waittimeout != 10))
  {
    delay(1);
    waittimeout++;
  }
 
  if(Serial.available() == 0)
  {
    noObj = true;
    objNum = 0;
    Serial.println("DT");
    while(waitAck() == false)
    {
      Serial.flush();
      Serial.println("DT");
    }
  } else {
    temp = Serial.read(); // useless byte
    while(Serial.available() == 0);
    objNum = Serial.read();
    noObj = false;
  }

  waittimeout = 0;

  if(noObj == false)
  {
    for(temp = 0; temp < objNum; temp++)
    {
      while(Serial.available() == 0);
      objColour[temp] = Serial.read();
      while(Serial.available() == 0);
      objXMin[temp] = Serial.read();
      while(Serial.available() == 0);
      objYMin[temp] = Serial.read();
      while(Serial.available() == 0);
      objXMax[temp] = Serial.read();
      while(Serial.available() == 0);
      objYMax[temp] = Serial.read();
    }
  }
 
  Serial.println("DT");
  delay(100); // there might be some junk left over, wait for finish
  // for robots who need constant servo pulses, replace delay with
  // for loops that sends the pulses for a similar amount of time
  // 100 is only an estimate
  Serial.flush(); // clear buffer
 
  objFound = false;
  objInterestFound = false;
 
  if(noObj == false)
  {
    for(temp = 0; temp < objNum + 1; temp++)
    {
      objWidth[temp] = objXMax[temp] - objXMin[temp];
      objHeight[temp] = objYMax[temp] - objYMin[temp];
      objXCenter[temp] = objXMin[temp] + (objWidth[temp] / 2);
      objYCenter[temp] = objYMin[temp] + (objWidth[temp] / 2);
      objShape[temp] = 0;
      if(similarTo(objWidth[temp], objHeight[temp]))
      {
        objShape[temp] = 1;
      }
      if(objShape[temp] != 1)
      {
        objShape[temp] = 2;
        if(objWidth[temp] > objHeight[temp])
          objShape[temp] = 3;
      }
      objSize[temp] = averageWH(objWidth[temp], objHeight[temp]);
      if(objShape[temp] == 1)
      {
        if(objColour[temp] == wantedColour)
        {
          objAtt = temp;
          objFound = true;
        }
      }
      else {
        if(objColour[temp] == wantedColour)
        {
          objInterested = temp;
          objInterestFound = true;
        }
      }
    }
  }
}

I think that should do it, it doesn't configure the camera for you though
I am making various changes to the code, the current one might not work
I think you need these functions in another small library of mine

Code: [Select]
boolean similarTo(byte varAa, byte varBb) // used to compare length and width of objects to find shape
{
  float varA = varAa;
  float varB = varBb;
  boolean isSimilar = 0;
  if((varA < varB + (varA / 3)) && (varA > varB - (varA / 3)))
  {
    isSimilar = 1;
  }
  if((varB < varA + (varB / 3)) && (varB > varA - (varB / 3)))
  {
    isSimilar = 1;
  }
  return isSimilar;
}

boolean similarTo(int varAa, int varBb) // used to compare length and width of objects to find shape
{
  float varA = varAa;
  float varB = varBb;
  byte divider = 10;
  boolean isSimilar = 0;
  if((varA < varB + (varA / divider)) && (varA > varB - (varA / divider)))
  {
    isSimilar = 1;
  }
  if((varB < varA + (varB / divider)) && (varB > varA - (varB / divider)))
  {
    isSimilar = 1;
  }
  return isSimilar;
}

byte averageWH(byte varAa, byte varBb)
{
  float varA = varAa;
  float varB = varBb;
  byte avgSize;
  varA = (varA + varB) / 2;
  avgSize = varA;
  return avgSize;
}

A Processing program I made for the computer is attached to this post, it can only do frame dumps, nothing else
« Last Edit: December 17, 2007, 03:20:23 PM by frank26080115 »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Wii Nunchuck Controlled Robot
« Reply #15 on: December 17, 2007, 03:40:53 PM »
are the Serial.whatever() commands for Wiring? or perhaps require some other header?

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #16 on: December 17, 2007, 03:55:38 PM »
Serial.whatever works in Arduino without doing anything extra
But you have to initialize it with Serial.begin(115200); in initialization process.

Offline reSpawn

  • Full Member
  • ***
  • Posts: 56
  • Helpful? 0
Re: Wii Nunchuck Controlled Robot
« Reply #17 on: December 18, 2007, 09:59:13 AM »
Hi Frank! The Radio Module works "out of the box", I mean you don't need to configure anything? It works just like there would be a cable?

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #18 on: December 18, 2007, 10:08:01 AM »
it acts as an invisible wire, but only for digital signals (so only binary 0 and 1s, nothing in between), but it can't handle more than 2400 changes per second.

ALSO you must change the input to the transmitter every second or else the receiver starts to output junk, apparently this is not needed if you run the transmitter at 12V, but I didn't try that yet.

To use it for a serial connection, just connect the transmitter to the TX pin on your microcontroller, and the receiver to the RX pin on another microcontroller, and set the baud rate on both microcontrollers to 2400 baud.

The black and white answer is Yes, but with the above limitations you must look out for.
Dirt cheap compared to SparkFun, eh? Costs less than plain wire for that distance.
« Last Edit: December 18, 2007, 09:32:43 PM by frank26080115 »

Offline reSpawn

  • Full Member
  • ***
  • Posts: 56
  • Helpful? 0
Re: Wii Nunchuck Controlled Robot
« Reply #19 on: December 30, 2007, 11:29:31 AM »
it acts as an invisible wire, but only for digital signals (so only binary 0 and 1s, nothing in between), but it can't handle more than 2400 changes per second.

ALSO you must change the input to the transmitter every second or else the receiver starts to output junk, apparently this is not needed if you run the transmitter at 12V, but I didn't try that yet.

To use it for a serial connection, just connect the transmitter to the TX pin on your microcontroller, and the receiver to the RX pin on another microcontroller, and set the baud rate on both microcontrollers to 2400 baud.

The black and white answer is Yes, but with the above limitations you must look out for.
Dirt cheap compared to SparkFun, eh? Costs less than plain wire for that distance.
What do you mean by "change the input to the transmitter every second" ?

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #20 on: December 30, 2007, 11:33:00 AM »
oops i meant change the bit inputted to the transmitter, otherwise, the receiver goes nuts

Offline roschler

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Wii Nunchuck Controlled Robot
« Reply #21 on: January 02, 2008, 02:09:54 PM »
Great job Frank!  Nunchaku control and no host PC required!

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: Wii Nunchuck Controlled Robot
« Reply #22 on: January 10, 2008, 06:10:24 PM »
lol i told my friend and now he hates you for dishonouring the wii  ;D oh well freakin wiked tho
Howdy

Offline vidam

  • Supreme Robot
  • *****
  • Posts: 423
  • Helpful? 1
  • Robotronics.org
    • DC/MD/VA Robotics and Automation Team
Re: Wii Nunchuck Controlled Robot
« Reply #23 on: January 17, 2008, 02:56:01 PM »
I just read this post. Awesome!!! If you can only control the robot with WII to go to the fridge and get a beer.


Offline Nyuli

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Wii Nunchuck Controlled Robot
« Reply #24 on: January 20, 2008, 02:11:44 AM »
So if you are using the Arduino, you need to include "Wire.h" (i'm assuming that "stdio.h" and "string.h" are standard c libraries). say i wanted to do something similar, i.e: control servos and whatnot remotely using the Wii nunchuck and some cheap RF receivers/transmiters, but instead i have a homemade microcontroller similar to the $50 robot one (which will use the Atmega168). where would i find the required libraries, like "Wire.h" and any others that it may also include so that i can use the functions in your code? I could always just buy an Arduino, but im going to school for all this neato robotics jazz (Mechanical Engineering/Mechatronics) so i'd rather do EVERYTHING the hard way and make my own stuff. You learn more that way anyhow. thanks for any help.

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #25 on: January 20, 2008, 04:02:14 PM »
Wiring.h should be compatible with both ATMEGA8 and ATMEGA168

Offline Nyuli

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Wii Nunchuck Controlled Robot
« Reply #26 on: January 20, 2008, 07:53:54 PM »
No, basically what I'm saying is that i wanna do this without the Arduino. Where can I get "Wire.h"? doesnt that header file come with Arduino?

Offline frank26080115Topic starter

  • Supreme Robot
  • *****
  • Posts: 322
  • Helpful? 2
Re: Wii Nunchuck Controlled Robot
« Reply #27 on: January 20, 2008, 10:00:49 PM »
the "wire" library will work with AVR-GCC and with any AVR chips that has I2C

Offline Nyuli

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Wii Nunchuck Controlled Robot
« Reply #28 on: January 21, 2008, 11:29:52 AM »
Cool man. So any tips you can give me for the cheapo RF Receiver/Transmitter set, like hoe to make them talk to each other? got any code snippets for that part?

Offline E.Man.Lava

  • Full Member
  • ***
  • Posts: 55
  • Helpful? 0
Re: Wii Nunchuck Controlled Robot
« Reply #29 on: January 21, 2008, 05:38:31 PM »
dude that video is awesome.  i didnt know you could do that with the nunchuck!  ;D