uavsim.graphics.instruments.attitudeindicator
Class AttitudeIndicator

java.lang.Object
  extended by uavsim.graphics.instruments.A_Instrument
      extended by uavsim.graphics.instruments.A_CircularInstrument<AttitudeRoll>
          extended by uavsim.graphics.instruments.attitudeindicator.AttitudeIndicator
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener, I_AngleMapper<AttitudeRoll>

public class AttitudeIndicator
extends A_CircularInstrument<AttitudeRoll>

Defines a standard attitude-indicator or artificial-horizon instrument to depict pitch and roll. The operable range is [-55,+55] degrees for pitch and [-180,+180] for roll. Pitch outside this range causes the instrument to show a tumble indicator as red crossbars. This limitation is consistent with the real-world instrument.

Author:
Dan Tappan [18.06.11]

Nested Class Summary
private static class AttitudeIndicator.AttitudeMapper
          Defines the mapper that converts a unit value (pitch or roll) into a corresponding angle on the display.
 
Field Summary
private  Attitude _attitude
          the attitude
private static AttitudeIndicator.AttitudeMapper _attitudeMapper
          the attitude mapper
private static NeedleDescriptor BEZEL_BUG
          the level-flight bug
private static java.awt.Color BEZEL_GROUND_COLOR
          the color of the ground element of the bezel
private static ScalerPair BEZEL_SCALER
          the size scale of the bezel inner and outer radii relative to the instrument size
private static java.awt.Color BEZEL_SKY_COLOR
          the color of the sky element of the bezel
private static java.awt.Color GROUND_COLOR
          the color of the ground
private static java.awt.Color GROUND_LINE_COLOR
          the color of the perspective lines overlain on the gorund
private static Scaler GROUND_LINE_SCALE
          the size scale of the ground lines relative to the instrument size
private static ScalerPair HORIZON_SCALER
          the size scale of the horizon inner and outer radii relative to the instrument size
private static java.awt.Color MINIATURE_AIRPLANE_COLOR
          the color of the miniature airplane
private static Scaler MINIATURE_AIRPLANE_DOT_SCALE
          the size scale of the airplane dot relative to the instrument size
private static Scaler MINIATURE_AIRPLANE_LINE_END_SCALE
          the position scale of the airplane wing line end relative to the instrument center
private static Scaler MINIATURE_AIRPLANE_LINE_SCALE
          the size scale of the airplane wing lines relative to the instrument size
private static Scaler MINIATURE_AIRPLANE_LINE_START_SCALE
          the position scale of the airplane wing line start relative to the instrument center
private static ScalerPair MINIATURE_AIRPLANE_LOOP_SCALE
          the size scale of the airplane loop inner and outer radii relative to the instrument size
private static Scaler PITCH_BAR_10_SCALE
          the position scale of the +/-10-degree pitch bar relative to the horizon midpoint
private static Scaler PITCH_BAR_20_SCALE
          the position scale of the +/-20-degree pitch bar relative to the horizon midpoint
private static Scaler PITCH_BAR_30_SCALE
          the position scale of the +/-30-degree pitch bar relative to the horizon midpoint
private static java.awt.Color PITCH_BAR_GROUND_COLOR
          the color of the pitch bars overlaying the ground
private static Scaler PITCH_BAR_SCALE
          the size scale of the pitch bars relative to the instrument size
private static java.awt.Color PITCH_BAR_SKY_COLOR
          the color of the pitch bars overlaying the sky
private static double PITCH_BAR_VERTICAL_SCALE
          the position scale of the pitch bars relative to the instrument size
private static java.awt.Color ROLL_TICK_COLOR
          the color of the rolls ticks
private static Scaler ROLL_TICK_MEDIUM_SCALE
          the size scale of the medium roll tick relative to the instrument size
private static Scaler ROLL_TICK_RADIUS_SCALE
          the position scale of the medium roll tick relative to the instrument center
private static Scaler ROLL_TICK_THICK_SCALE
          the size scale of the thick roll tick relative to the instrument size
private static Scaler ROLL_TICK_THIN_SCALE
          the size scale of the thin roll tick relative to the instrument size
private static java.awt.Color SKY_COLOR
          the color of the sky
private static java.awt.Color TUMBLE_COLOR
          the color of the tumble indicator X
private static Scaler TUMBLE_CROSSBAR_SCALE
          the size scale of the tumble crossbar relative to the instrument size
private static double VALID_PITCH_MAX
          the maximum valid pitch, beyond which the tumble crossbar appears
private static double VALID_PITCH_MIN
          the minimum valid pitch, beyond which the tumble crossbar appears
 
Fields inherited from class uavsim.graphics.instruments.A_CircularInstrument
_ringSize, DISK_COLOR, MOUNT_RING_COLOR, MOUNT_RING_INNER_SCALE
 
Fields inherited from class uavsim.graphics.instruments.A_Instrument
_canvasAnchor, _canvasSize, _graphics, _id
 
Constructor Summary
AttitudeIndicator(java.lang.String id, int canvasSize, CoordinateCartesianAbsolute canvasAnchor)
          Creates an attitude indicator.
 
Method Summary
private  Interval<AngleMathematical> calculateHorizonInterval(Attitude attitude)
          Calculates the angles where the sky portion of the horizon disk starts and ends based on the pitch and roll.
private  CoordinateCartesianAbsolute calculatePerspectiveLineIntercept(Attitude attitude, CoordinateCartesianAbsolute midpoint, AngleMathematical perspective)
          Calculates the pixel coordinates where a ground line originating at the horizon midpoint intersects the perimeter of the horizon ring
private  CoordinateCartesianAbsolute calculatePitchBarMidpoint(Attitude attitude, AttitudePitch pitchOffset)
          Calculates the midpoint of a pitch bar.
 Attitude getAttitude()
          Gets the attitude.
 AngleMathematical mapAngle_(AttitudeRoll roll)
          Returns the angle corresponding to the value of a unit.
 void render(java.awt.Graphics graphics)
          Renders the current state of the instrument.
private  void renderBezel(Attitude attitude)
          Renders the sky and ground portions on the bezel.
private  void renderBezel(Interval<AngleMathematical> horizon, java.awt.Color color)
          Renders the sky and ground portions of the bezel.
private  void renderBezelBug()
          Renders the "up" bug at the top of the bezel.
private  void renderGroundLine(Attitude attitude, CoordinateCartesianAbsolute midpoint, AngleMathematical perspective, Interval<AngleMathematical> horizon)
          Renders the horizon line or ground perspective line on the ground portion.
private  void renderGroundLines(Attitude attitude)
          Renders the horizon line and ground perspective lines on the ground portion.
private  void renderHorizon(Attitude attitude)
          Renders the sky and ground portions of the disk.
private  void renderHorizon(Interval<AngleMathematical> horizon, java.awt.Color color)
          Renders the sky or ground portion of the disk.
private  void renderMiniaturePlane()
          Renders the miniature airplane.
private  void renderPitchBar(Attitude attitude, AttitudePitch pitchOffset, Scaler lineWidthScaler, java.awt.Color color)
          Renders a pitch bar.
private  void renderPitchBars(Attitude attitude)
          Renders the pitch bars on the horizon.
private  void renderRollTick(AttitudeRoll roll, Scaler scale)
          Renders the roll ticks on the bezel.
private  void renderRollTicks(Attitude attitude)
          Renders the roll ticks on the bezel.
private  void renderTumbleIndicator()
          Renders the sky and ground portions.
 java.lang.String toString()
          
 void update(Attitude attitude)
          Updates the state of the instrument without rendering it.
 
Methods inherited from class uavsim.graphics.instruments.A_CircularInstrument
mapAngle, renderDisk, renderMountRing
 
Methods inherited from class uavsim.graphics.instruments.A_Instrument
getAnchor, getCanvasSize, getGraphics, getID, getParentComponent, handleControlCallback, hasControls, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, refresh, registerControl, setCanvasAnchor, setCanvasSize, setParentComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_attitude

private Attitude _attitude
the attitude


_attitudeMapper

private static final AttitudeIndicator.AttitudeMapper _attitudeMapper
the attitude mapper


BEZEL_BUG

private static final NeedleDescriptor BEZEL_BUG
the level-flight bug


BEZEL_GROUND_COLOR

private static final java.awt.Color BEZEL_GROUND_COLOR
the color of the ground element of the bezel


BEZEL_SCALER

private static final ScalerPair BEZEL_SCALER
the size scale of the bezel inner and outer radii relative to the instrument size


BEZEL_SKY_COLOR

private static final java.awt.Color BEZEL_SKY_COLOR
the color of the sky element of the bezel


GROUND_COLOR

private static final java.awt.Color GROUND_COLOR
the color of the ground


GROUND_LINE_COLOR

private static final java.awt.Color GROUND_LINE_COLOR
the color of the perspective lines overlain on the gorund


GROUND_LINE_SCALE

private static final Scaler GROUND_LINE_SCALE
the size scale of the ground lines relative to the instrument size


HORIZON_SCALER

private static final ScalerPair HORIZON_SCALER
the size scale of the horizon inner and outer radii relative to the instrument size


MINIATURE_AIRPLANE_COLOR

private static final java.awt.Color MINIATURE_AIRPLANE_COLOR
the color of the miniature airplane


MINIATURE_AIRPLANE_DOT_SCALE

private static final Scaler MINIATURE_AIRPLANE_DOT_SCALE
the size scale of the airplane dot relative to the instrument size


MINIATURE_AIRPLANE_LINE_END_SCALE

private static final Scaler MINIATURE_AIRPLANE_LINE_END_SCALE
the position scale of the airplane wing line end relative to the instrument center


MINIATURE_AIRPLANE_LINE_SCALE

private static final Scaler MINIATURE_AIRPLANE_LINE_SCALE
the size scale of the airplane wing lines relative to the instrument size


MINIATURE_AIRPLANE_LINE_START_SCALE

private static final Scaler MINIATURE_AIRPLANE_LINE_START_SCALE
the position scale of the airplane wing line start relative to the instrument center


MINIATURE_AIRPLANE_LOOP_SCALE

private static final ScalerPair MINIATURE_AIRPLANE_LOOP_SCALE
the size scale of the airplane loop inner and outer radii relative to the instrument size


PITCH_BAR_10_SCALE

private static final Scaler PITCH_BAR_10_SCALE
the position scale of the +/-10-degree pitch bar relative to the horizon midpoint


PITCH_BAR_20_SCALE

private static final Scaler PITCH_BAR_20_SCALE
the position scale of the +/-20-degree pitch bar relative to the horizon midpoint


PITCH_BAR_30_SCALE

private static final Scaler PITCH_BAR_30_SCALE
the position scale of the +/-30-degree pitch bar relative to the horizon midpoint


PITCH_BAR_GROUND_COLOR

private static final java.awt.Color PITCH_BAR_GROUND_COLOR
the color of the pitch bars overlaying the ground


PITCH_BAR_SCALE

private static final Scaler PITCH_BAR_SCALE
the size scale of the pitch bars relative to the instrument size


PITCH_BAR_SKY_COLOR

private static final java.awt.Color PITCH_BAR_SKY_COLOR
the color of the pitch bars overlaying the sky


PITCH_BAR_VERTICAL_SCALE

private static final double PITCH_BAR_VERTICAL_SCALE
the position scale of the pitch bars relative to the instrument size

See Also:
Constant Field Values

ROLL_TICK_COLOR

private static final java.awt.Color ROLL_TICK_COLOR
the color of the rolls ticks


ROLL_TICK_MEDIUM_SCALE

private static final Scaler ROLL_TICK_MEDIUM_SCALE
the size scale of the medium roll tick relative to the instrument size


ROLL_TICK_RADIUS_SCALE

private static final Scaler ROLL_TICK_RADIUS_SCALE
the position scale of the medium roll tick relative to the instrument center


ROLL_TICK_THICK_SCALE

private static final Scaler ROLL_TICK_THICK_SCALE
the size scale of the thick roll tick relative to the instrument size


ROLL_TICK_THIN_SCALE

private static final Scaler ROLL_TICK_THIN_SCALE
the size scale of the thin roll tick relative to the instrument size


SKY_COLOR

private static final java.awt.Color SKY_COLOR
the color of the sky


TUMBLE_COLOR

private static final java.awt.Color TUMBLE_COLOR
the color of the tumble indicator X


TUMBLE_CROSSBAR_SCALE

private static final Scaler TUMBLE_CROSSBAR_SCALE
the size scale of the tumble crossbar relative to the instrument size


VALID_PITCH_MAX

private static final double VALID_PITCH_MAX
the maximum valid pitch, beyond which the tumble crossbar appears

See Also:
Constant Field Values

VALID_PITCH_MIN

private static final double VALID_PITCH_MIN
the minimum valid pitch, beyond which the tumble crossbar appears

See Also:
Constant Field Values
Constructor Detail

AttitudeIndicator

public AttitudeIndicator(java.lang.String id,
                         int canvasSize,
                         CoordinateCartesianAbsolute canvasAnchor)
Creates an attitude indicator.

Parameters:
id - - the unique instrument identifier
canvasSize - - the square size of the instrument footprint in pixels
canvasAnchor - - the anchor position for the center of the canvas in pixels
Method Detail

calculateHorizonInterval

private Interval<AngleMathematical> calculateHorizonInterval(Attitude attitude)
Calculates the angles where the sky portion of the horizon disk starts and ends based on the pitch and roll.

Parameters:
attitude - - the attitude
Returns:
the angles

calculatePerspectiveLineIntercept

private CoordinateCartesianAbsolute calculatePerspectiveLineIntercept(Attitude attitude,
                                                                      CoordinateCartesianAbsolute midpoint,
                                                                      AngleMathematical perspective)
Calculates the pixel coordinates where a ground line originating at the horizon midpoint intersects the perimeter of the horizon ring

Parameters:
attitude - - the attitude
midpoint - - the horizon midpoint
perspective - - the angle from the midpoint
Returns:
the coordinates

calculatePitchBarMidpoint

private CoordinateCartesianAbsolute calculatePitchBarMidpoint(Attitude attitude,
                                                              AttitudePitch pitchOffset)
Calculates the midpoint of a pitch bar.

Parameters:
attitude - - the attitude
pitchOffset - - the offset from the horizon
Returns:
the midpoint of the pitch bar

getAttitude

public Attitude getAttitude()
Gets the attitude.

Returns:
the attitude

mapAngle_

public AngleMathematical mapAngle_(AttitudeRoll roll)
Returns the angle corresponding to the value of a unit.

Parameters:
roll - - the unit
Returns:
the angle

render

public void render(java.awt.Graphics graphics)
Renders the current state of the instrument.

Overrides:
render in class A_CircularInstrument<AttitudeRoll>
Parameters:
graphics - - the graphics context

renderBezel

private void renderBezel(Attitude attitude)
Renders the sky and ground portions on the bezel.

Parameters:
attitude - - the attitude

renderBezel

private void renderBezel(Interval<AngleMathematical> horizon,
                         java.awt.Color color)
Renders the sky and ground portions of the bezel.

Parameters:
horizon - - the angles defining the start and end of the horizon
color - - the color

renderBezelBug

private void renderBezelBug()
Renders the "up" bug at the top of the bezel.


renderGroundLine

private void renderGroundLine(Attitude attitude,
                              CoordinateCartesianAbsolute midpoint,
                              AngleMathematical perspective,
                              Interval<AngleMathematical> horizon)
Renders the horizon line or ground perspective line on the ground portion.

Parameters:
attitude - - the attitude
midpoint - - the horizon midpoint
perspective - - the angle from the midpoint
horizon - - the angles defining the start and end of the horizon

renderGroundLines

private void renderGroundLines(Attitude attitude)
Renders the horizon line and ground perspective lines on the ground portion.

Parameters:
attitude - - the start angle for the attitude of the horizon disk in mathematical degrees

renderHorizon

private void renderHorizon(Attitude attitude)
Renders the sky and ground portions of the disk.

Parameters:
attitude - - the attitude

renderHorizon

private void renderHorizon(Interval<AngleMathematical> horizon,
                           java.awt.Color color)
Renders the sky or ground portion of the disk.

Parameters:
horizon - - the angles defining the start and end of the horizon
color - - the portion color

renderMiniaturePlane

private void renderMiniaturePlane()
Renders the miniature airplane.


renderPitchBar

private final void renderPitchBar(Attitude attitude,
                                  AttitudePitch pitchOffset,
                                  Scaler lineWidthScaler,
                                  java.awt.Color color)
Renders a pitch bar.

Parameters:
attitude - - the attitude
pitchOffset - - the offset from the horizon
lineWidthScaler - - the bar width
color - - the bar color

renderPitchBars

private void renderPitchBars(Attitude attitude)
Renders the pitch bars on the horizon.

Parameters:
attitude - - the attitude

renderRollTick

private void renderRollTick(AttitudeRoll roll,
                            Scaler scale)
Renders the roll ticks on the bezel.

Parameters:
roll - - the roll
scale - - the tick scale

renderRollTicks

private void renderRollTicks(Attitude attitude)
Renders the roll ticks on the bezel.

Parameters:
attitude - - the roll

renderTumbleIndicator

private void renderTumbleIndicator()
Renders the sky and ground portions.


toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

update

public void update(Attitude attitude)
Updates the state of the instrument without rendering it.

Parameters:
attitude - - the attitude