Using contstrain() to limit servo values

After fiddling around with my dysfunctional, bloated Servo limit function, I decided to scrap it entirely and go with something else that was more intuitive. I knew that there must be something that would serve my purposes without using a bunch of if statements and switch statements. As it turns out—that function was constrain(). It’s really easy to use if you have specific functions to adjust their respective servos. Here’s how I did it:

void Plane::Aileron(byte desiredDir, int increase) {
  int deg;
  switch(desiredDir) {     
  case RIGHT:  
      deg = aileronServo.read()-increase;
      deg = constrain(deg, minAileronServoLimit, maxAileronServoLimit);
      aileronServo.write(deg);
    break;

  case LEFT:
...

In this case, I calculate the original servo command, constrain it to my 2 global variables, minAileronServoLimit and maxAileronServoLimit, and then Servo.write() the resulting integer.

Advertisements

Test Board Almost Completed

Over the last week we built a flight system test board. The board will be used to test and debug the UAV (Unmanned Aerial Vehicle) programs. There is still one PCB that needs to be mounted in the middle of the test board (The Mongoose).

IMG_3806

The over view shows the board with most of the main components.

IMG_3809

Since this is a four channel airplane we have four readouts one for each channel.

IMG_3810

The roll indicator is mounted on the end of the test board so that when the board is tilted to simulate plane roll, the aileron gauge will be relevant to the position of the board and therefore more easily read.

The Airplane

We are using a Banana Hobby foam airplane for the UAV airframe. The airplane flies very nice and should work well as a UAV for the time being.

IMG_3799

The airplane’s wingspan is about 55″ wingtip to wingtip.

IMG_3800

We upgraded to a six channel radio so that we could use channel five as the switch between autonomous and manual flight modes. The Hobby King radio set has worked quite well.