|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjaron.components.Signal
jaron.pde.Servo
public class Servo
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); } *
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 |
---|
public Servo(processing.core.PApplet applet, java.lang.String label, int left, int top, int width, int height)
Servo
object for the Processing Development
Environment (PDE).
applet
- a reference to the PDE applet that provides the drawing environmentlabel
- the label that is displayed at the bottomleft
- the component's position from the lefttop
- the component's position from topheight
- the component's heightwidth
- the component's widthpublic Servo(processing.core.PApplet applet, int left, int top, int width, int height)
Servo
object for the Processing Development
Environment (PDE).
applet
- a reference to the PDE applet that provides the drawing environmentleft
- the component's position from the lefttop
- the component's position from topheight
- the component's heightwidth
- the component's widthpublic Servo(processing.core.PApplet applet, java.lang.String label, int left, int top)
Servo
object for the Processing Development
Environment (PDE).
applet
- a reference to the PDE applet that provides the drawing environmentlabel
- the label that is displayed at the bottomleft
- the component's position from the lefttop
- the component's position from toppublic Servo(processing.core.PApplet applet, int left, int top)
Servo
object for the Processing Development
Environment (PDE).
applet
- a reference to the PDE applet that provides the drawing environmentleft
- the component's position from the lefttop
- the component's position from topMethod Detail |
---|
public void draw()
draw
method of the Processing Development Environment. This
ensures that the servo is updated periodically.
public void setLabel(java.lang.String label)
label
- a String
describing the servos's functionality in shortpublic void setMaxDeflection(int maxDeflection)
maxDeflection
- maximum deflection in degrees
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |