Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
F33RNI authored May 11, 2021
1 parent c7863f3 commit bf07167
Show file tree
Hide file tree
Showing 20 changed files with 2,075 additions and 750 deletions.
36 changes: 24 additions & 12 deletions src/com/liberty_amls/BlackboxHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class BlackboxHandler implements Runnable {
private final PositionContainer positionContainer;
private final PlatformContainer platformContainer;
private final String blackboxDirectory;
private boolean handlerRunning;
private boolean fileStarted = false;
private long timeStart;
private BufferedWriter bufferedWriter;
private FileOutputStream fileOutputStream;
private OutputStreamWriter outputStreamWriter;
volatile public boolean blackboxEnabled, stabilizationEnabled = false;
volatile public boolean newPositionFlag = false;
private boolean blackboxEnabled = false;
private boolean newEntryFlag = false;
private volatile boolean handlerRunning;

/**
* This class writes the current state of the drone to log files
Expand All @@ -49,7 +49,6 @@ public class BlackboxHandler implements Runnable {
this.positionContainer = positionContainer;
this.platformContainer = platformContainer;
this.blackboxDirectory = blackboxDirectory;
this.blackboxEnabled = Main.settings.get("blackbox_enabled_by_default").getAsBoolean();
}

/**
Expand All @@ -62,6 +61,20 @@ public void run() {
proceedLogs();
}

/**
* Set to true if there is new data to log
*/
public void setNewEntryFlag(boolean newEntryFlag) {
this.newEntryFlag = newEntryFlag;
}

/**
* Enables or disables blackbox logs
*/
public void setBlackboxEnabled(boolean blackboxEnabled) {
this.blackboxEnabled = blackboxEnabled;
}

/**
* Close file stream and end the loop
*/
Expand All @@ -74,22 +87,21 @@ public void stop() {
* Checks current state and opens/closes file or pushes new data
*/
private void proceedLogs() {
if (fileStarted && (!blackboxEnabled || !stabilizationEnabled || positionContainer.status == 5)) {
// Blackbox disabled or stabilization disabled or status == DONE
if (fileStarted && !blackboxEnabled) {
// Blackbox disabled
// Close file
closeFile();
}
if (!fileStarted && blackboxEnabled && stabilizationEnabled
&& (positionContainer.status == 1 || positionContainer.status == 2)) {
// Blackbox enabled and stabilization enabled and status == STAB or LAND
if (!fileStarted && blackboxEnabled) {
// Blackbox enabled and stabilization enabled
// Open new file
startNewFile();
}
if (fileStarted && blackboxEnabled && stabilizationEnabled && newPositionFlag) {
if (fileStarted && blackboxEnabled && newEntryFlag) {
// Continue pushing data
// If there is new position, push it and uncheck the flag
// If there is new entry, push it and uncheck the flag
pushPosition();
newPositionFlag = false;
newEntryFlag = false;
}
}

Expand Down
22 changes: 2 additions & 20 deletions src/com/liberty_amls/FileWorkers.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.liberty_amls;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.opencv.core.CvType;
Expand Down Expand Up @@ -72,8 +71,7 @@ public static Mat loadImageAsMat(String file) {
* Loads camera matrix from json (the file is specified in the settings)
* @return 3x3 Mat filled with float (32FC1)
*/
public static Mat loadCameraMatrix() {
String file = Main.settings.get("camera_matrix_file").getAsString();
public static Mat loadCameraMatrix(String file) {
Main.logger.info("Loading " + file);
Gson gson = new Gson();
try (Reader reader = new FileReader(file)) {
Expand All @@ -97,8 +95,7 @@ public static Mat loadCameraMatrix() {
* Loads camera distortions from json (the file is specified in the settings)
* @return 1x3 Mat filled with float (32FC1)
*/
public static Mat loadCameraDistortions() {
String file = Main.settings.get("camera_distortions_file").getAsString();
public static Mat loadCameraDistortions(String file) {
Main.logger.info("Loading " + file);
Gson gson = new Gson();
try (Reader reader = new FileReader(file)) {
Expand Down Expand Up @@ -134,21 +131,6 @@ public static JsonObject loadJsonObject(String file) {
return pids;
}

/**
* Saves JsonObject as .json file
* @param jsonObject input data
* @param file path to the file (.json)
*/
public static void saveJsonObject(JsonObject jsonObject, String file) {
Main.logger.info("Saving " + file);
try (Writer writer = new FileWriter(file)) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
gson.toJson(jsonObject, writer);
} catch (Exception e) {
Main.logger.error("Error saving " + file, e);
}
}

/**
* Creates parent directories and opens blackbox .csv file with timestamp name
* @param blackboxDirectory folder with logs
Expand Down
20 changes: 11 additions & 9 deletions src/com/liberty_amls/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

package com.liberty_amls;

import com.google.gson.JsonObject;
import org.apache.commons.cli.*;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Main {
private static final String version = "beta_1.1.5";
private static final String version = "beta_3.0.0";
public static final Logger logger = Logger.getLogger(Main.class.getSimpleName());
public static JsonObject settings;

public static void main(String[] args) {
// Set the lowest priority for Main and WebServer classes
Expand Down Expand Up @@ -66,8 +64,12 @@ public static void main(String[] args) {
// Print app version
logger.info("Liberty-Way AMLS Landing Controller. Version: " + version);

// Parse app settings
settings = FileWorkers.loadJsonObject("settings.json");
// Create settings container and parse app settings
SettingsContainer settingsContainer = new SettingsContainer();
SettingsHandler settingsHandler = new SettingsHandler(settingsContainer,
FileWorkers.loadJsonObject("settings.json"));
settingsHandler.parseSettings();


// Use colorful logs properties if 'c' argument specified
if (cmd.hasOption("c")) {
Expand All @@ -78,28 +80,28 @@ public static void main(String[] args) {
}

// Custom server IP (Default is specified in the settings.json)
String serverIP = settings.get("default_server_host").getAsString();
String serverIP = settingsContainer.defaultServerHost;
if (cmd.hasOption("i")) {
serverIP = cmd.getOptionValue("i");
logger.info("Server IP argument provided. IP " + serverIP + " will be used");
}

// Custom server port (Default is specified in the settings.json)
int serverPort = settings.get("default_server_port").getAsInt();
int serverPort = settingsContainer.defaultServerPort;
if (cmd.hasOption("sp")) {
serverPort = Integer.parseInt(cmd.getOptionValue("sp"));
logger.info("Server Port argument provided. Port " + serverPort + " will be used");
}

// Custom server IP (Default is specified in the settings.json)
int videoPort = settings.get("default_video_port").getAsInt();
int videoPort = settingsContainer.defaultVideoPort;
if (cmd.hasOption("vp")) {
videoPort = Integer.parseInt(cmd.getOptionValue("vp"));
logger.info("Video stream port argument provided. Port " + videoPort + " will be used");
}

// Start the server with given IP and Port
WebServer webServer = new WebServer(serverIP, serverPort, videoPort);
WebServer webServer = new WebServer(serverIP, serverPort, videoPort, settingsContainer);
webServer.start();
} catch (ParseException | NumberFormatException e) {
logger.error("Error parsing command-line arguments!", e);
Expand Down
Loading

0 comments on commit bf07167

Please sign in to comment.