Monday, January 18, 2010

IT LIVESSSSS!

After many hours of toiling away (and by many hours, I really mean about one or so), I wrote the necessary Arduino code needed to run the servos. It looks like this (I wish this blog site had actual code quoting):
#include

Servo pan, tilt;

void setup()
{
  Serial.begin(9600);
  pan.attach(3, 1000, 2000);
  tilt.attach(10, 1000, 2000);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  delay(15);
  pan.write(100);
  tilt.write(100);
}

void loop()
{
  digitalWrite(2, HIGH);
  digitalWrite(4, LOW);
  while(Serial.available() > 2)
  {
    int command = Serial.read();
    if(command == 255)
    {
      int command = Serial.read();
      int value = Serial.read();

      switch (command)
      {
      case 0:
        pan.write(value);
        break;

      case 1:
        tilt.write(value);
        break;
      }
    }
  }
}

All the code does is set up the servos and the on board serial port using the nice included libraries. It then instructs the Arduino to sit around and wait for serial data. When it gets something on its serial port, it checks first for a start byte (255), then for a servo ID (either 0 or 1), then a value to move the servo. This value should range from 0 to 180 and it (theoretically) corresponds to the degree the servo rotates to.

Here's a quick video of it moving:

There are still a number of issues to be worked out, mainly, it seems that sometimes when I issue a command to control one of the motors, it inadvertently moves the other motor as well. I am not completely sure what causes this, but I think I may try rewriting a large portion of the Arduino code to better deal with the serial communication.

Although I can (mostly) control the pan-tilt rig via a computer, there is still one last hardware issue that needs to be addressed before I can start distracting kittens and that is I need to create a method by which the computer can actually turn the laser pointer on and off. This shouldn't be too difficult of a challenge seeing as it should only consist of a few resistors and a transistor. I'll post that update sometime in the future.

Saturday, January 9, 2010

The pan-tilt rig

As I mentioned before, the pan-tilt rig takes relatively little time to construct

You can see from the picture the rig is built using wooden blocks I cut out of scraps of 2x4. The servos are connected to an Arduino via a servo shield I constructed last year for a robotic platypus. The battery in the background supplies power to the servos and while it probably is not necessary when only two servos are involved (a single USB port should supply enough current), the way the shield was constructed necessitates and external power source.

I will eventually construct a nice little enclosure for the rig, the Arduino, and the camera, but I'm more excited about getting something that actually points up and running.

The next step is to write code for the Arduino that allows a computer to actually control the servos.

Finally, as a note to those that know me, I plan to make this rig fully compatible with a wiimote for a more futuristic pointing experience.


Thursday, January 7, 2010

Game Plan



The first step any sane person would conduct in creating a device is to have a plan, and this is it.

The actual pointing will be done by a green laser pointer I purchased off Amazon for about $30 some time ago. It will be mounted on a pan-tilt rig constructed from two servo motors and some random scraps of wood. The servos will interface to the computer via an Arduino micro-controller and a webcam will provide the video feed of what to point at.

That's my plan, the rest is winging it. The hardware aspect of this project is rather simple and should hopefully be completed in a few days, but there is a lot of leeway with the software side of things, so completion of that will take a long time.


Introduction

This is a blog about pointing at things. Why would someone ever write a blog about pointing at things, you may ask. Well, the answer to that is that it isn't so much about the direct action of pointing, but rather about building a mean, green laser pointing machine. This will serve as a build log for a small project I am doing in my free time.

Why am I documenting this project? Because a particular physics genius told me I should do so. He also enlisted the help of a number of individuals to scream "raserbrog" resulting in the title of this log.