Skip to content

Commit 819221e

Browse files
authored
Add Custom Configurations (#24)
* feat: add new Configurator singleton class to configure default launch options * chore: bump gradle version * fix: remove old comments, add return to try catch * docs: split development and user instructions in readme * chore: add logging to Configurator * ci: add config.toml to release * fix: add config.toml to git
1 parent 870a6c7 commit 819221e

File tree

7 files changed

+216
-39
lines changed

7 files changed

+216
-39
lines changed

.github/workflows/release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ jobs:
5454
- name: Create GitHub Release (attaches JAR)
5555
uses: softprops/action-gh-release@v2
5656
with:
57-
tag_name: ${{ steps.version.outputs.version }}
58-
name: Release ${{ steps.version.outputs.version }}
59-
files: build/libs/*-all.jar
57+
tag_name: ${{ steps.version.outputs.version }}
58+
name: Release ${{ steps.version.outputs.version }}
59+
files: |
60+
build/libs/*-all.jar
61+
config.toml
6062
env:
6163
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6264

README.md

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,50 @@
22

33
OpenRocket, and our code for running monte carlo simulations in OpenRocket.
44

5-
## Dependencies
6-
- Java 17 (JDK 17, Required for OpenRocket)
7-
- IntelliJ IDEA (Recommended for development)
8-
- OpenRocket 24.12.RC.01 (Included as a submodule)
5+
## Requirements
96

10-
## Release Process
7+
- Java 17
118

12-
Follow these steps to release a new version of the Monte-Carlo OR plugin:
9+
## Running the Simulator
1310

14-
### 1. Update the Version Number
15-
Edit the [build.gradle](build.gradle) file to reflect the new version:
11+
Download the latest release from
12+
the [releases page](https://github.com/waterloo-rocketry/or-monte-carlo/releases/latest)
1613

17-
```gradle
18-
group 'com.waterloorocketry'
19-
version 'X.Y.Z' // Format: Major.Minor.Hotfix
20-
```
14+
In the downloaded directory run `java -jar WaterlooRocketry-OpenRocket-{version}-all.jar`
2115

22-
Example: Change `version '1.0.0'` to `version '1.1.0'` for a minor update.
16+
## Configuration
2317

24-
### 2. Verify CI Build
25-
Ensure the following CI workflow is successful on the `main` branch:
18+
Create a file named `config.toml` in the same directory as the jar with the structure as follows:
2619

27-
- CI – Build Monte-Carlo or-plugin
20+
```toml
21+
[simulation]
2822

29-
You can check this in your CI/CD platform (e.g., GitHub Actions, Jenkins, etc.).
23+
[simulation.executor]
24+
batch_size = 30
3025

31-
### 3. Trigger the Release
32-
Initiate the release by running the following workflow on the `main` branch:
26+
[simulation.options]
27+
launch_latitude = 47.965378
28+
launch_longitude = -81.873536
29+
launch_altitude = 420.0144
30+
launch_rod_length = 9.144
31+
launch_into_wind = false
32+
launch_rod_angle = 0.0872665
33+
launch_rod_direction = 4.71239
34+
max_simulation_time = 2400
35+
```
3336

34-
- Manual Release – Monte-Carlo or-plugin
37+
The above is the default configuration if no configuration file is provided.
38+
All measurements are in SI units.
3539

36-
This step will publish the current build based on the version specified in `build.gradle`.
40+
## Development
41+
42+
### Setup
3743

44+
#### Dependencies
3845

39-
## Setup
46+
- Java 17 (JDK 17, Required for OpenRocket)
47+
- IntelliJ IDEA (Recommended for development)
48+
- OpenRocket 24.12.RC.01 (Included as a submodule)
4049

4150
Start by cloning this repository:
4251

@@ -47,18 +56,51 @@ git clone --recurse-submodules https://github.com/waterloo-rocketry/openrocket
4756
(If you did not use `--recurse-submodules`, run `git submodule update --init --recursive`. See
4857
https://git-scm.com/book/en/v2/Git-Tools-Submodules for details.)
4958

50-
### IntelliJ
59+
#### IntelliJ
5160

5261
We will continue using [IntelliJ IDEA](https://www.jetbrains.com/idea/) IDE. Open the project.
5362
You do not need to install a JDK or Ant separately.
5463

55-
You will need to configure your project JDK in File > Project Structure > Project. We will use Java 17.
64+
You will need to configure your project JDK in File > Project Structure > Project. We will use Java 17.
5665
Intellij should recognize and download this automatically.
5766

5867
In the top-right of the project, you will see a few gradle tasks. Here are the three important ones:
68+
5969
- `./gradlew buildOpenRocket`: This builds OpenRocket. **Run this first before running the plugin**!
6070
- `./gradlew runOpenRocket`: This is used to run OpenRocket by itself.
6171
- `./gradlew run`: This is used to run the Monte-Carlo plugin
62-
- `./gradlew buildExtensions`: This will build all extensions in the extensions directory. Run this first if you want extensions
72+
- `./gradlew buildExtensions`: This will build all extensions in the extensions directory. Run this first if you want
73+
extensions
6374

64-
To get debug logging from OpenRocket and the extension, add `-Dlog-level='DEBUG'` to the run command.
75+
To get debug logging from OpenRocket and the extension, add `-Dlog-level='DEBUG'` to the run command.
76+
77+
### Release Process
78+
79+
Follow these steps to release a new version of the Monte-Carlo OR plugin:
80+
81+
#### 1. Update the Version Number
82+
83+
Edit the [build.gradle](build.gradle) file to reflect the new version:
84+
85+
```gradle
86+
group 'com.waterloorocketry'
87+
version 'X.Y.Z' // Format: Major.Minor.Hotfix
88+
```
89+
90+
Example: Change `version '1.0.0'` to `version '1.1.0'` for a minor update.
91+
92+
#### 2. Verify CI Build
93+
94+
Ensure the following CI workflow is successful on the `main` branch:
95+
96+
- CI – Build Monte-Carlo or-plugin
97+
98+
You can check this in your CI/CD platform (e.g., GitHub Actions, Jenkins, etc.).
99+
100+
#### 3. Trigger the Release
101+
102+
Initiate the release by running the following workflow on the `main` branch:
103+
104+
- Manual Release – Monte-Carlo or-plugin
105+
106+
This step will publish the current build based on the version specified in `build.gradle`.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'com.waterloorocketry'
8-
version '1.1.1'
8+
version '1.2.0'
99

1010
ext {
1111
openRocketVersion = '24.12'

config.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[simulation]
2+
3+
[simulation.executor]
4+
batch_size = 30
5+
6+
[simulation.options]
7+
launch_latitude = 47.965378
8+
launch_longitude = -81.873536
9+
launch_altitude = 420.0144
10+
launch_rod_length = 9.144
11+
launch_into_wind = false
12+
launch_rod_angle = 0.0872665
13+
launch_rod_direction = 4.71239
14+
max_simulation_time = 2400
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.waterloorocketry.openrocket_monte_carlo;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.io.FileNotFoundException;
7+
import java.io.IOException;
8+
9+
public class Configurator {
10+
private final static Logger log = LoggerFactory.getLogger(Configurator.class);
11+
private final static String CONFIG_FILE_PATH = "config.toml";
12+
private static Configurator instance;
13+
private int batchSize = 30;
14+
private double launchLatitude = 47.965378;
15+
private double launchLongitude = -81.873536;
16+
private double launchAltitude = 420.0144;
17+
private double launchRodLength = 9.144;
18+
private boolean launchIntoWind = false;
19+
private double launchRodAngle = 0.0872665;
20+
private double launchRodDirection = 4.71239;
21+
private int maxSimulationTime = 2400;
22+
23+
private Configurator() {
24+
try {
25+
java.util.Properties props = new java.util.Properties();
26+
java.io.FileInputStream fis = new java.io.FileInputStream(CONFIG_FILE_PATH);
27+
props.load(fis);
28+
29+
batchSize = Integer.parseInt(props.getProperty("batch_size", String.valueOf(batchSize)));
30+
launchLatitude = Double.parseDouble(props.getProperty("launch_latitude", String.valueOf(launchLatitude)));
31+
launchLongitude = Double.parseDouble(props.getProperty("launch_longitude", String.valueOf(launchLongitude)));
32+
launchAltitude = Double.parseDouble(props.getProperty("launch_altitude", String.valueOf(launchAltitude)));
33+
launchRodLength = Double.parseDouble(props.getProperty("launch_rod_length", String.valueOf(launchRodLength)));
34+
launchIntoWind = Boolean.parseBoolean(props.getProperty("launch_into_wind", String.valueOf(launchIntoWind)));
35+
launchRodAngle = Double.parseDouble(props.getProperty("launch_rod_angle", String.valueOf(launchRodAngle)));
36+
launchRodDirection = Double.parseDouble(props.getProperty("launch_rod_direction", String.valueOf(launchRodDirection)));
37+
maxSimulationTime = Integer.parseInt(props.getProperty("max_simulation_time", String.valueOf(maxSimulationTime)));
38+
39+
fis.close();
40+
} catch (FileNotFoundException ex) {
41+
log.info("No user configuration file found, using defaults.");
42+
log.debug(ex.getMessage());
43+
return;
44+
} catch (IOException ex) {
45+
log.warn("Error reading configuration file: " + CONFIG_FILE_PATH);
46+
log.debug(ex.getMessage());
47+
System.exit(-1); // exit since we don't want to run with partial config
48+
}
49+
log.info("User configuration loaded.");
50+
log.info(this.toString());
51+
}
52+
53+
54+
public static Configurator getInstance() {
55+
if (instance == null) {
56+
instance = new Configurator();
57+
}
58+
return instance;
59+
}
60+
61+
@Override
62+
public String toString() {
63+
return "Configuration: \n" +
64+
"batchSize=" + batchSize + "\n" +
65+
"launchLatitude=" + launchLatitude + "\n" +
66+
"launchLongitude=" + launchLongitude + "\n" +
67+
"launchAltitude=" + launchAltitude + "\n" +
68+
"launchRodLength=" + launchRodLength + "\n" +
69+
"launchIntoWind=" + launchIntoWind + "\n" +
70+
"launchRodAngle=" + launchRodAngle + "\n" +
71+
"launchRodDirection=" + launchRodDirection + "\n" +
72+
"maxSimulationTime=" + maxSimulationTime;
73+
}
74+
75+
public int getBatchSize() {
76+
return batchSize;
77+
}
78+
79+
public double getLaunchLatitude() {
80+
return launchLatitude;
81+
}
82+
83+
public double getLaunchLongitude() {
84+
return launchLongitude;
85+
}
86+
87+
public double getLaunchAltitude() {
88+
return launchAltitude;
89+
}
90+
91+
public double getLaunchRodLength() {
92+
return launchRodLength;
93+
}
94+
95+
public boolean isLaunchIntoWind() {
96+
return launchIntoWind;
97+
}
98+
99+
public double getLaunchRodAngle() {
100+
return launchRodAngle;
101+
}
102+
103+
public double getLaunchRodDirection() {
104+
return launchRodDirection;
105+
}
106+
107+
public int getMaxSimulationTime() {
108+
return maxSimulationTime;
109+
}
110+
}

or-monte-carlo/src/com/waterloorocketry/openrocket_monte_carlo/SimulationEngine.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class SimulationEngine {
4242
private final static int CSV_SIMULATION_COLUMN_COUNT = 2; // skip the date column
4343
private final static int CSV_WIND_LEVEL_COLUMN_COUNT = 3;
4444

45+
private final Configurator config = Configurator.getInstance();
46+
4547
private final OpenRocketDocument document;
4648
/**
4749
* How many simulations we should run
@@ -289,21 +291,27 @@ private void configureMonteCarloSimulationOptions(SimulationOptions opts) {
289291
log.debug("Cond: Pressure: {}Pa", pressure);
290292
}
291293

294+
/**
295+
* Generates a reference simulation with default values. Use createMonteCarloSimulations to create
296+
* Monte-Carlo simulations based on this reference simulation.
297+
* @return Reference simulation with default values
298+
* @see SimulationEngine#createMonteCarloSimulations(Simulation)
299+
*/
292300
public Simulation generateDefaultSimulation() {
293301
Simulation defaultSimulation = new Simulation(document, document.getRocket());
294302
defaultSimulation.setName("Monte-Carlo Simulation");
295303
SimulationOptions opts = defaultSimulation.getOptions();
296304

297-
opts.setLaunchLatitude(47.58);
298-
opts.setLaunchLongitude(-81.87);
299-
opts.setLaunchAltitude(420.0144); // 1378ft
305+
opts.setLaunchLatitude(config.getLaunchLatitude());
306+
opts.setLaunchLongitude(config.getLaunchLongitude());
307+
opts.setLaunchAltitude(config.getLaunchAltitude());
300308

301-
opts.setLaunchRodLength(11.2776); // 444in
302-
opts.setLaunchIntoWind(false);
303-
opts.setLaunchRodAngle(0.0872665);
304-
opts.setLaunchRodDirection(1.62316);
309+
opts.setLaunchRodLength(config.getLaunchRodLength());
310+
opts.setLaunchIntoWind(config.isLaunchIntoWind());
311+
opts.setLaunchRodAngle(config.getLaunchRodAngle());
312+
opts.setLaunchRodDirection(config.getLaunchRodDirection());
305313

306-
opts.setMaxSimulationTime(2400); // double sim time
314+
opts.setMaxSimulationTime(config.getMaxSimulationTime());
307315

308316
return defaultSimulation;
309317
}

or-monte-carlo/src/com/waterloorocketry/openrocket_monte_carlo/SimulationOptionsFrame.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public class SimulationOptionsFrame extends JFrame {
5757
SIMULATIONS_PROCESSED_EVENT = "simulationProcessed", // fires whenever a batch is processed (updates table)
5858
SIMULATIONS_DONE_EVENT = "simulationDone"; // fires when all simulations are done (begin export)
5959

60-
private final int BATCH_RUN_SIZE = 30;
60+
private final Configurator config = Configurator.getInstance();
61+
private final int BATCH_RUN_SIZE = config.getBatchSize();
6162

6263
private OpenRocketDocument document;
6364

0 commit comments

Comments
 (0)