Thursday, December 13, 2007

Wii Nunchuck Control

Here's a video of my little project last night. I used a Wii nunchuck to control the rotation of two servos to set up a dinky little two-axis gimbal control system. The servos are all duct taped together so it's not very pretty, but duct tape holds the world together. Hopefully I'll get a chance to write up a detailed description of how it works along with source code (here's the source code temporarily while I try to find time to detail this post). For now I just have the video and a few links for you.





http://www.windmeadow.com/node/42
http://www.wiili.org/
http://www.mcmanis.com/chuck/Robotics/projects/servo.html

Friday, December 7, 2007

MAE 154S and news/thoughts

Mechanical and Aerospace Engineering 154S is a class I'm currently finishing up (poorly) for Fall quarter at UCLA. It's titled "Flight Mechanics, Stability, and Control of Aircraft" and will prove pretty important to what we're trying to do here. We're doing a fairly rough run through of aircraft stability and control, exactly what needs to be studied to get a plane to fly. The great thing is that our professor, Damien Toohey, has done exactly what we're trying to do now, but as a graduate student. He's expressed a lot of interest in the project and will probably be a valuable source of experience.

Anyway, I just wanted to jot down some thoughts on the team while I'm at it. The team itself hasn't been set up yet actually. I'm planning on setting up a kick off meeting early second week of Winter quarter and having the team down by third week. Hopefully we'll be picking up a lot of the DBF (Design/Build/Fly) members as well as finding some specialized electronics, software, and stability people.

I'm starting to realize that the stability and controls side of things is probably the most important part. The controls dictates what the programmers have to program while both stability and controls dictates what sensors and electronics we need. It's then up to the electronics to get the proper information. Controls doesn't care whether or not we get attitude using GPS or IMUs (Inertial Measurement Unit), they just want to know it. Same goes for software, controls doesn't want to know how to tell a servo to deflect a certain angle, they just know that the rudder needs to be deflected so much to maintain stability. With this in mind, I'm hoping to take some time to set up the team structure into "modules," much like black boxes. The encapsulation should help with each module concentrating on obtaining high quality results. Of course interaction between modules to maintain proper direction is both necessary and wanted. Classic client-contractor setup.

In terms of hardware, that's still kind of a blur. I am playing with the Arduino right now and it looks fairly capable of what we want to do. However, a single unit wouldn't do it so we'd probably have to get multiple microcontrollers to work together. However, that involves interfacing directly with the microcontroller, which is what the Arduino was designed to do. Looks fun but might be more complication than it's worth. With that in mind we're looking towards using Gumstix as a single powerful unit. There are also more powerful microcontrollers we can try. I feel inclined to keep this fairly low level but that's mostly out of personal preference at the moment. Keeping things low-level does have its advantages however: more knowledge for future use, more capabilities, a more customized solution, etc.

For stability and controls, I'm hoping to get a good simulation up and running that's easy to interface to. Damien Toohey has written one and I've been thinking about taking it and modifying it to our project. When first going into the project I felt that it would simply "be nice" to have an active simulator, but I'm starting to realize that it might be an integral part of the project. By having a simulator that we can both fly manually and through our program; we can get a feel for how to control the plane as well as dry-test our algorithms. Personally I would like to have my own programmed or derived off of Toohey's, but whether the time investment would be worth it is a concern for me. I've been looking into other flight sims like FlightGear but I'm not liking what I see so far. I'll probably know what I want to do once I get my hands on Toohey's flight simulator.

Forgot to mention: getting started

So I forgot to make a post on how to get started with the Arduino stuff. All I really wanted to post was a link to a tutorial that will get you all the fundamentals you need to get started. It takes you step by step from taking out your Arduino board to installing drivers, getting the IDE, and programming some simple stuff. Even better is that it tells you what you need for the tutorials. So where is it? Check it out at,

http://www.ladyada.net/learn/arduino/index.html

Motors, servos, and back EMF, oh my!

I had a chance to play with my Arduino board some more. My first task was getting proper speed control of a DC motor using pulse-width modulation. I wrote a little program to vary the width (in time) of the HIGH pulse in set total pulse period. You can find the idea behind it here. The code for my manual PWM speed control is right below:


int highPulseWidth = 10000;
int totalPulseWidth = highPulseWidth;
int dir = 0;
int threshold = 3;

void setup()
{
  pinMode(11, OUTPUT);
}

void loop()
{
  digitalWrite(11, HIGH);
  delayMicroseconds(highPulseWidth);
  if( totalPulseWidth-highPulseWidth > threshold )
  {
    digitalWrite(11, LOW);
    delayMicroseconds(totalPulseWidth-highPulseWidth);
  }
  if( dir == 0 )
  {
    highPulseWidth = highPulseWidth-10;
    if( highPulseWidth < threshold )
    {
      highPulseWidth = threshold;
      dir = 1;
    }
  }
  else
  {
    highPulseWidth = highPulseWidth+10;
    if( highPulseWidth > totalPulseWidth )
    {
      highPulseWidth = totalPulseWidth;
      dir = 0;
    }
  }
}


The dir variable tracks what direction we're changing the pulse width (1 for increase, 0 for decrease). Something definitely worth noting, since it caused me some confusion early on, is where the delayMicroseconds() function is accurate. It's noted in the Arduino reference here; the function is only accurate in the range from 3 microseconds to 16383 (2^14-1) microseconds. This caused me problems because at first I was trying to delay for a second using the delayMicroseconds() function which means passing in one million, definitely over 16383. This also explains why I have that threshold variable there. So this program will decrease the HIGH pulse width from the total pulse width (full speed) to zero. When it reaches zero (well, reaches threshold) it changes directions and increases the HIGH pulse width until it reaches the total pulse width size. The idea is that the period of the pulse cycle remains constant (totalPulseWidth) so the delay on HIGH and delay on LOW added together stay that period.

Well, that's all nice and dandy but how does this interface with the motor itself? Well, that's where transistors come to the rescue. I just grabbed some random transistor (the TIP31 apparently) with a high voltage rating at Radio Shack.



This web page proved to be extremely useful. A transistor is just a gate. You'll notice that it has three pins: base, collector, and emitter. The idea is that if something is flowing through the base then the collector opens up. If nothing is flowing through the base then the collector is closed. What makes this useful is you can control a larger voltage source using a relatively small one. The voltage on the HIGH and LOW signals outputted by the Arduino board are only 3.3V or 5V, I forget which. This means you can't really drive a 9V motor with the digital signal alone. Instead you want to connect the motor to a 9V power source and use the transistor to control the motor's connection to the 9V power source. That's pretty much it.

So I used a regular ole' 9V batter as my power source.



So the first thing in setting up the circuit was to get the battery and the Arduino board to share the same ground so that the currents will flow where we want them to flow. So I just connected the battery's negative to the Arduino's ground.



Next I get the motor ready to be connected to the collector pin of the transistor. I also connect where the base of the transistor will be to my output pin, 11 (no reason I picked 11, could be any of them). Finally I have a wire going from where the emitter pin of the transistor will be to the ground. All of this is based on the diagram from here.





With the above the transistor is ready to be put in. My Arduino board is already loaded with the program I posted above.



After that the motor starts spinning. I'd get video of it up if I had it, maybe later.

Anyway, I still need to write on how to control a servo and how I used the back EMF from my motor to control the servo's rotation speed. That's for later I guess!

Monday, December 3, 2007

UCLA AIAA AUAV

So what the heck does that mean? The University of California, Los Angeles (UCLA) American Institute of Aeronautics and Astronautics (AIAA) Autonomous Unmanned Aerial Vehicle (AUAV). My name is Viet Nguyen (most people call me Jonathan or Jon). I'm a senior (4th year) as an aerospace engineering major at UCLA. Currently I'm a member of the UCLA branch of AIAA. Recently we decided to embark on attempting the AUVSI AUAV competition. I've been voted as project manager so it's my responsibility to research the feasibility of joining the competition on a bit of a short notice and, if feasible, assemble the team and ensure the project is successful.

Anyway, as a student branch we've competed in plane building competitions before. Making a plane isn't what worries us. Instead we're worried about the electronics and software side of things. I'm a programmer myself so I'm not incredibly worried about the programming part. Instead how we'll pull off the electronics side is where it gets fun. I recently bought myself an Arduino Diecimila board from SparkFun to learn some basic electronics and hardware-to-software interfacing. This is all brand new to me (seriously, you'll see what I mean when I talk about the mistakes I've made) so I'm going to go through a lot of learning pains in the process. I created this blog to sort of keep track of my progress and to act as a reference/learning source for anyone else trying to achieve the same results. I'm hoping that this will work as a learning source as well as a history that I can reference for future reports.

Just tonight I managed to pulse-width modulate the speed on a simple DC motor using a NPN transistor. At first I tried it with a 1.5-3V DC motor on the 5V power source on the Arduino board ("seemed like a good idea at the time"). I ran into some problems where my HIGH digital signal wasn't lasting the one second I programmed it to. Instead it would pulse and simply stop. The off delay was lasting the one second it was programmed for. After switching to the bigger motor and a 9V battery source this seemed to work. I'll post more details and pictures about it later. I'm still trying to figure out what's going on with it.

Also, a big thing I plan on accomplishing soon is getting away from the included Arduino IDE for programming and getting this stuff to work with Microsoft Visual Studio. The included IDE simply appends some stuff to your source code to turn it into proper C code anyway. I'm a big C++ fan (it's what I use, it's what I'm fluent in) but it seems like I'll have to program in C (I miss my encapsulated classes already) to conserve program size because the ATmega168 micro controller used on the Arduino board only has 16kB of space for the program. It looks like I'll have to set up the compiler to use a makefile. There's a makefile on the Arduino website so it should be pretty straight forward, I just haven't gotten around to doing it yet.

Anyway, that's enough for tonight. Hopefully I'll have more to post about this stuff later.