improvements to Groundstation. Makes sent data have fixed length values

This commit is contained in:
Brendan Haines 2015-03-03 23:47:55 -07:00
parent 4405f009b4
commit 5909b1e022
4 changed files with 77 additions and 11 deletions

View File

@ -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();
}

View File

@ -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 );
}
/**

View File

@ -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();
}
}

View File

@ -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" );