: [1]
   
: Wiimote light follower with servo  ( 12536 )
0 and 1 Guest are viewing this topic.
*
Karma: +0/-0
: 11
Offline Offline
« : March 17, 2010, 12:49:41 AM »

Thought I'd post this project here. Used the wiimote IR camera (without removing it from the wiimote) to track and follow the 1st noticed light source using an arduino and a servo motor.


Best described here:
http://ohmwardbond.blogspot.com/2010/03/wiimote-light-follower-with-servo.html

[youtube]http://www.youtube.com/watch?v=Nj7UqjP-z6U[/youtube]
http://www.youtube.com/watch?v=Nj7UqjP-z6U

I'm going to work on the vertical axis as well ...

Code: [Select]
#include <Wire.h>
#include <PVision.h> // http://www.stephenhobley.com
#include <Servo.h>
 
Servo myservo;
PVision ircam;
byte result;

//Servo speeds
#define LEFT_SLOW 1510
#define LEFT_MEDIUM 1520
#define LEFT_FAST 1540
#define RIGHT_SLOW 1490
#define RIGHT_MEDIUM 1480
#define RIGHT_FAST 1460
#define STOP 1500

void setup()
{
  pinMode(13, OUTPUT);
  myservo.attach(9);
  ircam.init();
  digitalWrite(13, HIGH); //Turns Led on when ircam initiation is complete
  
}

void loop()
{
  result = ircam.read();
  
  if (result & BLOB1)
  {

 //If there is an object/blob, the servo is operated based on its position from the camera's 0 x-position
if (ircam.Blob1.X > 480 && ircam.Blob1.X < 520)
{
  myservo.write(STOP);
}
 
  else if (ircam.Blob1.X < 480)
{
    if (ircam.Blob1.X < 200)
    {
     move_servo(LEFT_FAST);
    }
   else if (ircam.Blob1.X < 400)
    {
     move_servo(LEFT_MEDIUM);
    }
    else
    {
     move_servo(LEFT_SLOW);
    }
}

else if (ircam.Blob1.X > 520)
{
    if (ircam.Blob1.X > 800)
    {
     move_servo(RIGHT_FAST);
    }
    else if (ircam.Blob1.X > 600)
    {
     move_servo(RIGHT_MEDIUM);
    }
    else
    {
     move_servo(RIGHT_SLOW);
    }
}

    
      
  }
  
   else
  {
    myservo.write(STOP);
  }
  
}


void move_servo(int val)
{
  myservo.write(val);                  

}
« : March 17, 2010, 01:00:00 AM johnnyonthespot »
*
Karma: +0/-0
: 11
Offline Offline
« #1 : April 25, 2010, 02:54:07 AM »

2 axis light follower:

http://ohmwardbond.blogspot.com/2010/04/light-follower-2-axis.html
: [1]
   
 
:  

Clicky Web Analytics