Skip to content

Commit

Permalink
PID plots added. Motor gauges on seperate tab
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddheshRane committed Jan 27, 2017
1 parent 09e6c8f commit eeef9a0
Show file tree
Hide file tree
Showing 17 changed files with 876 additions and 281 deletions.
Binary file added lib/Lombok/lombok.jar
Binary file not shown.
Binary file added lib/Medusa-7.3.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions lib/nblibraries.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ libs.CopyLibs.classpath=\
${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
libs.CopyLibs.prop-version=2.0
libs.Lombok.classpath=\
${base}/Lombok/lombok.jar
14 changes: 13 additions & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.jssc-2.8.0.jar=lib/jssc-2.8.0.jar
file.reference.Medusa-7.3.jar=lib/Medusa-7.3.jar
includes=**
# Non-JavaFX jar file creation is deactivated in JavaFX 2.0+ projects
jar.archive.disabled=true
jar.compress=false
javac.classpath=\
${javafx.classpath.extension}:\
${file.reference.jssc-2.8.0.jar}:\
${libs.controlsfx.classpath}
${libs.controlsfx.classpath}:\
${libs.Lombok.classpath}:\
${file.reference.Medusa-7.3.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down Expand Up @@ -69,11 +72,16 @@ javafx.classpath.extension=\
${java.home}/lib/javaws.jar:\
${java.home}/lib/deploy.jar:\
${java.home}/lib/plugin.jar
javafx.deploy.adddesktopshortcut=false
javafx.deploy.addstartmenushortcut=false
javafx.deploy.allowoffline=true
# If true, application update mode is set to 'background', if false, update mode is set to 'eager'
javafx.deploy.backgroundupdate=false
javafx.deploy.disable.proxy=false
javafx.deploy.embedJNLP=true
javafx.deploy.includeDT=true
javafx.deploy.installpermanently=false
javafx.deploy.permissionselevated=false
# Set true to prevent creation of temporary copy of deployment artifacts before each run (disables concurrent runs)
javafx.disable.concurrent.runs=false
# Set true to enable multiple concurrent runs of the same WebStart or Run-in-Browser project
Expand All @@ -94,6 +102,9 @@ javafx.preloader.type=none
javafx.rebase.libs=false
javafx.run.height=600
javafx.run.width=800
javafx.signing.blob=false
javafx.signing.enabled=false
javafx.signing.type=notsigned
# Pre-JavaFX 2.0 WebStart is deactivated in JavaFX 2.0+ projects
jnlp.enabled=false
# Main class for Java launcher
Expand All @@ -105,6 +116,7 @@ manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
native.bundling.enabled=true
platform.active=default_platform
run.classpath=\
${dist.jar}:\
Expand Down
52 changes: 51 additions & 1 deletion src/ground/station/Experiments.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.Animation;
import javafx.animation.AnimationTimer;
import javafx.animation.FillTransition;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.RotateTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Point3D;
import javafx.geometry.Pos;
import javafx.scene.Camera;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
Expand All @@ -22,8 +33,12 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
Expand All @@ -42,10 +57,10 @@ public void start(Stage primaryStage) {
// noiseSimulatorTest(primaryStage);
// arduinoSerialConnectorTest(primaryStage);
// serialMonitorTest(primaryStage);
// serialConnectionTest(primaryStage);
// groundSationApp(primaryStage);
// animationTimerTest(primaryStage);
//orientationTest(primaryStage);
test3D(primaryStage);
}

void animationTimerTest(Stage primaryStage) {
Expand Down Expand Up @@ -198,6 +213,41 @@ void orientationTest(Stage primaryStage) {
primaryStage.show();
}

void test3D(Stage primaryStage) {
Box box = new Box(200, 100, 50);
final PhongMaterial material = new PhongMaterial(Color.BLUEVIOLET);
Timeline t = new Timeline(new KeyFrame(Duration.seconds(4), new KeyValue(material.diffuseColorProperty(), Color.SPRINGGREEN)));
t.setCycleCount(Animation.INDEFINITE);
t.setAutoReverse(true);
t.play();
box.setMaterial(material);
box.setLayoutX(100);
box.setLayoutY(100);
RotateTransition rotateTransition = new RotateTransition(Duration.seconds(6), box);
rotateTransition.setAxis(new Point3D(0, 1, 0.5));
rotateTransition.setByAngle(360);
rotateTransition.setCycleCount(Animation.INDEFINITE);
rotateTransition.setInterpolator(Interpolator.LINEAR);
rotateTransition.playFromStart();

Camera c = new PerspectiveCamera();
StackPane group = new StackPane(box);
Scene scene = new Scene(group);
scene.setOnMouseMoved(me->{
// c.setLayoutX(me.getSceneX());
// c.setLayoutY(me.getSceneY());
});

scene.setCamera(c);
primaryStage.setScene(scene);
primaryStage.setTitle("3D Test");
primaryStage.show();
}

void medusaTest(Stage primaryStage){

}

/**
* @param args the command line arguments
*/
Expand Down
8 changes: 3 additions & 5 deletions src/ground/station/GroundStation.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
<tabs>
<Tab fx:id="connectTab" closable="false" text="Connect" />
<Tab fx:id="plotsTab" closable="false" text="Plots" />
<Tab fx:id="consoleTab" text="Console">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
<Tab fx:id="pidTab" text="PID" />
<Tab fx:id="motorTab" closable="false" text="Motors" />
<Tab fx:id="consoleTab" text="Console" />
</tabs>
</TabPane>
</children>
Expand Down
75 changes: 57 additions & 18 deletions src/ground/station/GroundStation.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package ground.station;

import ground.station.SerialDevice.SensorData;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.MapChangeListener;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
Expand All @@ -29,14 +34,40 @@ public class GroundStation extends Application implements Initializable {
@FXML
private Tab plotsTab;
@FXML
private Tab motorTab;
@FXML
private Tab consoleTab;
@FXML
private Tab pidTab;

private final ConnectController connect;
private SensorPlotter plotter;
private PIDController pidController;
private MotorController motorController;
private SerialConsole console;
private SerialDevice serialDevice;

private final AnimationTimer serialDataFetcher = new AnimationTimer() {
@Override
public void handle(long now) {
if (serialDevice == null || !serialDevice.getSerialPort().isOpened()) {
return;
}
ConcurrentLinkedQueue<SensorData> q = serialDevice.q;
for (int i = 0; i < 15; i++) {
if (q.isEmpty()) {
break;
}
final SensorData data = q.poll();
plotter.processSensorData(data);
pidController.processSensorData(data);
motorController.processSensorData(data);
}
}
};

@Override
public void start(Stage primaryStage) {

FXMLLoader loader = new FXMLLoader(GroundStation.class.getResource("GroundStation.fxml"));
loader.setController(this);
Parent root = new Label("Could not load fxml file");
Expand All @@ -54,11 +85,9 @@ public void start(Stage primaryStage) {

@Override
public void stop() throws Exception {
if (plotter != null && plotter.getSerialDevice() != null) {
if (serialDevice != null && serialDevice.getSerialPort().isOpened()) {
try {
if (plotter.getSerialDevice().getSerialPort().isOpened()) {
plotter.getSerialDevice().getSerialPort().closePort();
}
serialDevice.getSerialPort().closePort();
} catch (SerialPortException ex) {
Logger.getLogger(GroundStation.class.getName()).log(Level.SEVERE, null, ex);
}
Expand All @@ -68,36 +97,46 @@ public void stop() throws Exception {

public GroundStation() {
connect = new ConnectController();
connect.OPEN_PORTS.addListener(new MapChangeListener<String, SerialPort>() {
@Override
public void onChanged(MapChangeListener.Change<? extends String, ? extends SerialPort> change) {
if (change.wasAdded()) {
SerialPort deviceAdded = change.getValueAdded();
connectDevice(new SerialDevice(deviceAdded));
}
connect.OPEN_PORTS.addListener((MapChangeListener.Change<? extends String, ? extends SerialPort> change) -> {
if (change.wasAdded()) {
SerialPort deviceAdded = change.getValueAdded();
connectDevice(new SerialDevice(deviceAdded));
}
});
}

public void connectDevice(SerialDevice device) {
if (plotter != null && plotter.getSerialDevice() != null) {
if (serialDevice != null && serialDevice.getSerialPort().isOpened()) {
try {
if (plotter.getSerialDevice().getSerialPort().isOpened()) {
plotter.getSerialDevice().getSerialPort().closePort();
}
serialDevice.getSerialPort().closePort();
serialDataFetcher.stop();
} catch (SerialPortException ex) {
Logger.getLogger(GroundStation.class.getName()).log(Level.SEVERE, null, ex);
}
}
plotter = new SensorPlotter(device);
SerialConsole console = new SerialConsole(device);
serialDevice = device;
plotter = new SensorPlotter();
pidController = new PIDController();
motorController = new MotorController();
console = new SerialConsole(device);
plotsTab.setContent(plotter);
pidTab.setContent(pidController);
motorTab.setContent(motorController);
consoleTab.setContent(console);
serialDataFetcher.start();
}

@Override
public void initialize(URL location, ResourceBundle resources) {
connectTab.setContent(connect);
consoleTab.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean selected) {
if (selected && consoleTab.getContent() != null) {
consoleTab.getContent().requestFocus();
}
}
});
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/ground/station/Motor.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import eu.hansolo.medusa.Gauge?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<fx:root alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="10.0" type="HBox" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<Gauge fx:id="flMotor" maxHeight="1.7976931348623157E308" maxValue="1000.0" maxWidth="1.7976931348623157E308" minMeasuredValue="0.0" prefHeight="130.0" prefWidth="120.0" skinType="FLAT" title="Front Left" value="200.0" VBox.vgrow="ALWAYS" />
<Gauge fx:id="rlMotor" maxHeight="1.7976931348623157E308" maxValue="1000.0" maxWidth="1.7976931348623157E308" minMeasuredValue="0.0" prefHeight="130.0" prefWidth="120.0" skinType="FLAT" title="Rear Left" value="200.0" VBox.vgrow="ALWAYS" />
</children>
</VBox>
<Gauge fx:id="throttle" animated="true" interactive="true" maxHeight="1.7976931348623157E308" maxValue="2000.0" maxWidth="1.7976931348623157E308" minMeasuredValue="1000.0" minValue="1000.0" skinType="MODERN" subTitle="OFF" title="Throttle" value="1200.0" HBox.hgrow="ALWAYS" />
<VBox alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" spacing="10.0" HBox.hgrow="ALWAYS">
<children>
<Gauge fx:id="frMotor" averageVisible="true" averagingEnabled="true" maxHeight="1.7976931348623157E308" maxValue="1000.0" maxWidth="1.7976931348623157E308" minMeasuredValue="0.0" prefHeight="130.0" prefWidth="120.0" skinType="FLAT" startAngle="0.0" title="Front Right" value="200.0" VBox.vgrow="ALWAYS" />
<Gauge fx:id="rrMotor" maxHeight="1.7976931348623157E308" maxValue="1000.0" maxWidth="1.7976931348623157E308" minMeasuredValue="0.0" prefHeight="130.0" prefWidth="120.0" skinType="FLAT" title="Rear Right" value="200.0" VBox.vgrow="ALWAYS" />
</children>
</VBox>
</children>
</fx:root>
62 changes: 62 additions & 0 deletions src/ground/station/MotorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ground.station;

import eu.hansolo.medusa.Gauge;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.HBox;

/**
* FXML Controller class
*
* @author Siddhesh Rane
*/
public class MotorController extends HBox implements Initializable {

@FXML
private Gauge flMotor;
@FXML
private Gauge rlMotor;
@FXML
private Gauge throttle;
@FXML
private Gauge frMotor;
@FXML
private Gauge rrMotor;

public MotorController() {
FXMLLoader loader = new FXMLLoader(SensorPlotter.class.getResource("Motor.fxml"));
loader.setRoot(this);
loader.setController(this);
try {
loader.load();
} catch (IOException ex) {
Logger.getLogger(SensorPlotter.class.getName()).log(Level.SEVERE, null, ex);
}
}

/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
ComboBox<Gauge.SkinType> skinType = new ComboBox<>(FXCollections.observableArrayList(Gauge.SkinType.values()));
skinType.setOnAction(ae->{throttle.setSkinType(skinType.getValue());});
}

public void processSensorData(SerialDevice.SensorData sensorData) {
flMotor.setValue(sensorData.motorFL - 1000);
frMotor.setValue(sensorData.motorFR - 1000);
rrMotor.setValue(sensorData.motorRR - 1000);
rlMotor.setValue(sensorData.motorRL - 1000);
throttle.setValue(sensorData.rcThrottle);
throttle.setSubTitle(sensorData.rcMode < 1500 ? "OFF" : "ON");
}
}
Loading

0 comments on commit eeef9a0

Please sign in to comment.