From 5909b1e02279c93208d4d5cb113a53efc59c515f Mon Sep 17 00:00:00 2001 From: Brendan Date: Tue, 3 Mar 2015 23:47:55 -0700 Subject: [PATCH] improvements to Groundstation. Makes sent data have fixed length values --- GroundStation/v2/ConnectionPanel.java | 10 ++-- GroundStation/v2/Display3d.java | 4 +- GroundStation/v2/DisplayController.java | 64 +++++++++++++++++++++++-- GroundStation/v2/GroundStation.java | 10 +++- 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/GroundStation/v2/ConnectionPanel.java b/GroundStation/v2/ConnectionPanel.java index b5c643b..bd42011 100644 --- a/GroundStation/v2/ConnectionPanel.java +++ b/GroundStation/v2/ConnectionPanel.java @@ -108,6 +108,7 @@ class ConnectionPanel extends JPanel implements ActionListener { */ public void disconnectTcp( boolean reconnect ) { out.print( "DISCONNECT" ); + out.print( "D" ); if( reconnect ) out.print( "_R" ); out.println(); @@ -131,16 +132,19 @@ class ConnectionPanel extends JPanel implements ActionListener { if( contentOut.getMotorsEnabled() ) out.print( "E " ); // enable motors if( contentOut.motorTesting ) { for( int i = 0; i < contentOut.motorValues.length; i++ ) - out.print( "M" + i + "_" + contentOut.motorValues[i] + " " ); + out.printf( "M%2d_%4d ", i, contentOut.motorValues[i] ); } + if( contentOut.getMotorsEnabled() ) out.print( "E " ); // enable motors (redundant) if( contentOut.controls ) { for( int i = 0; i < contentOut.controlValues.length; i++ ) - out.print( "C" + i + "_" + contentOut.controlValues[i] + " " ); + out.printf( "C%2d_%4d ", i, contentOut.controlValues[i] ); } + if( contentOut.getMotorsEnabled() ) out.print( "E " ); // enable motors (redundant) if( contentOut.orientation ) { for( int i = 0; i < contentOut.orientValues.length; i++ ) out.print( "O" + i + "_" + contentOut.orientValues[i] + " " ); } + if( contentOut.getMotorsEnabled() ) out.print( "E " ); // enable motors (redundant) out.println(); } @@ -227,7 +231,7 @@ class ConnectionPanel extends JPanel implements ActionListener { connectTcp( hostAddr.getText(), Integer.parseInt( hostPort.getText() ) ); } } - else { + else if( connectButton.getText().equals("disconnect") ){ sendTCP(); readTCP(); } diff --git a/GroundStation/v2/Display3d.java b/GroundStation/v2/Display3d.java index 8104dd3..be66f35 100644 --- a/GroundStation/v2/Display3d.java +++ b/GroundStation/v2/Display3d.java @@ -33,8 +33,8 @@ class Display3d extends JPanel implements ActionListener, ChangeListener { setLayout( new BorderLayout() ); slider = new JSlider(); slider.setOrientation( JSlider.VERTICAL ); - slider.addChangeListener( this ); - add( slider, BorderLayout.EAST ); + //slider.addChangeListener( this ); + //add( slider, BorderLayout.EAST ); } /** diff --git a/GroundStation/v2/DisplayController.java b/GroundStation/v2/DisplayController.java index a22d088..8f35f6e 100644 --- a/GroundStation/v2/DisplayController.java +++ b/GroundStation/v2/DisplayController.java @@ -1,26 +1,82 @@ import javax.swing.*; +import java.awt.*; import java.awt.event.*; -class DisplayController.java extends JPanel implements ActionListener { +class DisplayController extends JPanel implements ActionListener { private MessageContent source = new MessageContent(); + private Font normalFont = new Font( "Normal", Font.BOLD, 15 ); + + private int chanMax; + private int chanMin; public DisplayController() { setBackground( Color.DARK_GRAY ); - setPerferredSize( new Dimension( 0, 100 ) ); + setPreferredSize( new Dimension( 0, 100 ) ); + } + + public DisplayController( MessageContent content ) { + this(); + source = content; + } + + /** + * + */ + private int scaleChan( int chan, int range ) { + return (int)(range * ( ( (double)(chan - chanMin) / (chanMax - chanMin) ) - 0.5 )); } public void paintComponent( Graphics g ) { super.paintComponent( g ); - g.setColor( Color.LIGHT_GRAY ); + int centerX = getWidth() / 2; + int centerY = getHeight() / 2; + int boxSide = getWidth() / 3; + int circleDiam = boxSide / 10; + int circleRad = circleDiam / 2; + + g.setColor( Color.LIGHT_GRAY ); + g.fillRect( boxSide / 4, boxSide / 4, boxSide , boxSide ); + g.fillRect( boxSide * 7/4 , boxSide / 4, boxSide , boxSide ); + g.setColor( Color.BLACK ); + g.drawRect( boxSide / 4, boxSide / 4, boxSide , boxSide ); + g.drawRect( boxSide * 7/4 , boxSide / 4, boxSide , boxSide ); + + g.setColor( Color.RED ); + // left stick + g.fillOval( + scaleChan( source.controlValues[ 3 ], boxSide ) - circleRad + boxSide * 3/4, + scaleChan( source.controlValues[ 0 ], boxSide ) - circleRad + boxSide * 3/4, + circleDiam, + circleDiam ); + // right stick + g.fillOval( + scaleChan( source.controlValues[ 1 ], boxSide ) - circleRad + boxSide * 9/4, + scaleChan( source.controlValues[ 2 ], boxSide ) - circleRad + boxSide * 3/4, + circleDiam, + circleDiam ); + + g.setColor( Color.LIGHT_GRAY ); + for( int i = 0; i < source.controlValues.length; i++ ) { + //g.drawString( "Channel " + i + ": " + source.controlValues[0], 15, boxSide * 3/2 + i * 15 ); + if( i %3 == 0 ) { + g.drawString( "Channel " + i + ": " + source.controlValues[0], 15, boxSide * 3/2 + i/3 * 15 ); + } + else if( i %3 == 1) { + g.drawString( "Channel " + i + ": " + source.controlValues[0], 150 + 15, boxSide * 3/2 + i/3 * 15 ); + } + else { + g.drawString( "Channel " + i + ": " + source.controlValues[0], 300 + 15, boxSide * 3/2 + i/3 * 15 ); + } + } } /** * */ public void actionPerformed( ActionEvent evt ) { - redraw(); + repaint(); } } \ No newline at end of file diff --git a/GroundStation/v2/GroundStation.java b/GroundStation/v2/GroundStation.java index 5447c60..3a62507 100644 --- a/GroundStation/v2/GroundStation.java +++ b/GroundStation/v2/GroundStation.java @@ -20,8 +20,11 @@ class GroundStation implements ActionListener { private JTabbedPane tabbedPane; /** motor testing panel */ private MotorTestPanel motorTestPanel; - /** */ + /** displays visual representation of copter orientation */ private Display3d orientationPanel; + /** displays visual representation of control positions */ + private DisplayController controllerPanel; + /** outgoing message content options */ public MessageContent sendContent = new MessageContent(); /** incoming message content */ @@ -29,7 +32,7 @@ class GroundStation implements ActionListener { public GroundStation() { mainWindow = new JFrame( "PiCopter Ground Station" ); - mainWindow.setResizable( true ); + mainWindow.setResizable( false ); mainWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); mainWindow.getContentPane().setLayout( new BoxLayout( mainWindow.getContentPane(), BoxLayout.PAGE_AXIS ) ); @@ -40,6 +43,9 @@ class GroundStation implements ActionListener { tabbedPane = new JTabbedPane(); mainWindow.getContentPane().add( tabbedPane ); + controllerPanel = new DisplayController( receiveContent ); + tabbedPane.add( controllerPanel, "Controller" ); + orientationPanel = new Display3d( receiveContent ); tabbedPane.add( orientationPanel, "Orientation" );