jaron.pde
Class Servo

java.lang.Object
  extended by jaron.components.Signal
      extended by jaron.pde.Servo
All Implemented Interfaces:
SignalListener, java.util.EventListener

public class Servo
extends Signal

The Servo class provides a virtual servo for the Processing Development Environment (PDE).
By extending the Signal class it can hook into the EventListener mechanism and thus receive and send numeric values.
Reversing the servo's direction is done by swapping the high and the low signal values.

This is a Processing Development Development application that demonstrates the usage of the Servo.

import jaron.gui.*;
import jaron.pde.*;

// PDE GUI defaults
static final String kWindowTitle = "UAV Playground - Servos";
static final int kWindowWidth = 360;
static final int kWindowHeight = 325;
static final int kFrameRate = 30;

// These are all the components that are used for this application
Joystick stickRight;
Joystick stickLeft;
Servo servoRudder;
Servo servoThrottle;
Servo servoElevator;
Servo servoAileron;

// The PDE setup method
void setup() {
  // Setup the PDE display panel
  size(kWindowWidth, kWindowHeight);
  background(Colors.kColorGrayWindow);
  if (frame != null) frame.setTitle(kWindowTitle);

  // Setup the PDE graphics options
  frameRate(kFrameRate);
  smooth();

  // Setup the left stick (throttle and rudder)
  stickLeft = new Joystick(this, "Rudder", "Throttle", 15, 160);
  // Set bandwidth for throttle (FG uses 0-1)
  stickLeft.setBandwidthY(0, 1);
  // The throttle has no spring
  stickLeft.setSpringY(false);
  // Setup the right stick (elevator and aileron)
  stickRight = new Joystick(this, "Aileron", "Elevator", 195, 160);

  // Setup the servos
  servoRudder = new Servo(this, "Rudder", 15, 15);
  servoThrottle = new Servo(this, "Throttle", 110, 15);
  servoThrottle.setBandwidth(0, 1);
  servoAileron = new Servo(this, "Aileron", 195, 15);
  servoElevator = new Servo(this, "Elevator", 290, 15);

  // The servos are listening to the sticks
  stickLeft.addListenerX(servoRudder);
  stickLeft.addListenerY(servoThrottle);
  stickRight.addListenerX(servoAileron);
  stickRight.addListenerY(servoElevator);
}

// The PDE draw method
void draw() {
  stickRight.draw();
  stickLeft.draw();
  servoRudder.draw();
  servoThrottle.draw();
  servoElevator.draw();
  servoAileron.draw();
}

// The PDE mouseDragged method
void mouseDragged() {
  stickRight.mouseDragged(mouseX, mouseY);
  stickLeft.mouseDragged(mouseX, mouseY);
}

// The PDE mousePressed method
void mousePressed() {
  stickRight.mousePressed(mouseX, mouseY);
  stickLeft.mousePressed(mouseX, mouseY);
}

// The PDE mouseReleased method
void mouseReleased() {
  stickRight.mouseReleased(mouseX, mouseY);
  stickLeft.mouseReleased(mouseX, mouseY);
}

// The PDE mouseMoved method
void mouseMoved() {
  stickRight.mouseMoved(mouseX, mouseY);
  stickLeft.mouseMoved(mouseX, mouseY);
} * 

Since:
1.0
Version:
1.2
Author:
jarontec gmail com

Constructor Summary
Servo(processing.core.PApplet applet, int left, int top)
          Creates a new Servo object for the Processing Development Environment (PDE).
Servo(processing.core.PApplet applet, int left, int top, int width, int height)
          Creates a new Servo object for the Processing Development Environment (PDE).
Servo(processing.core.PApplet applet, java.lang.String label, int left, int top)
          Creates a new Servo object for the Processing Development Environment (PDE).
Servo(processing.core.PApplet applet, java.lang.String label, int left, int top, int width, int height)
          Creates a new Servo object for the Processing Development Environment (PDE).
 
Method Summary
 void draw()
          Draws the servo to the screen.
 void setLabel(java.lang.String label)
          Sets the servos's label that is displayed at the bottom the servo.
 void setMaxDeflection(int maxDeflection)
          Sets the maximum deflection of the servo in degrees.
 
Methods inherited from class jaron.components.Signal
addSignalListener, getBandwidth, getHigh, getLow, getValue, removeSignalListener, setBandwidth, setHigh, setLow, setValue, signalChanged
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Servo

public Servo(processing.core.PApplet applet,
             java.lang.String label,
             int left,
             int top,
             int width,
             int height)
Creates a new Servo object for the Processing Development Environment (PDE).

Parameters:
applet - a reference to the PDE applet that provides the drawing environment
label - the label that is displayed at the bottom
left - the component's position from the left
top - the component's position from top
height - the component's height
width - the component's width

Servo

public Servo(processing.core.PApplet applet,
             int left,
             int top,
             int width,
             int height)
Creates a new Servo object for the Processing Development Environment (PDE).

Parameters:
applet - a reference to the PDE applet that provides the drawing environment
left - the component's position from the left
top - the component's position from top
height - the component's height
width - the component's width

Servo

public Servo(processing.core.PApplet applet,
             java.lang.String label,
             int left,
             int top)
Creates a new Servo object for the Processing Development Environment (PDE).

Parameters:
applet - a reference to the PDE applet that provides the drawing environment
label - the label that is displayed at the bottom
left - the component's position from the left
top - the component's position from top

Servo

public Servo(processing.core.PApplet applet,
             int left,
             int top)
Creates a new Servo object for the Processing Development Environment (PDE).

Parameters:
applet - a reference to the PDE applet that provides the drawing environment
left - the component's position from the left
top - the component's position from top
Method Detail

draw

public void draw()
Draws the servo to the screen. This method should usually be called from the draw method of the Processing Development Environment. This ensures that the servo is updated periodically.


setLabel

public void setLabel(java.lang.String label)
Sets the servos's label that is displayed at the bottom the servo.

Parameters:
label - a String describing the servos's functionality in short

setMaxDeflection

public void setMaxDeflection(int maxDeflection)
Sets the maximum deflection of the servo in degrees. The default value is 120 degrees for full left to full right deflection.

Parameters:
maxDeflection - maximum deflection in degrees