Skip to content

Commit

Permalink
Merge branch 'dev' into throwBenchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
klausdorer committed Jul 1, 2024
2 parents 5c9339c + 3150c8b commit 1da9ff2
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 91 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 3.2 (to be relesaed)
---------------------
- added Throw In Challenge for RoboCup 2024

Version 3.1 (RoboCup 2023)
---------------------
- Rolling Ball Challenge: add rule to prevent player from moving too far
Expand Down
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>magmaoffenburg</groupId>
<artifactId>magmachallenge</artifactId>
<packaging>jar</packaging>
<version>3.1</version>
<version>3.2-beta1</version>
<name>magmaChallenge</name>
<url>https://github.com/magmaOffenburg/magmaChallenge</url>

Expand Down Expand Up @@ -35,11 +35,6 @@
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
</dependency>
</dependencies>

<build>
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/magma/tools/benchmark/ChallengeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import magma.tools.benchmark.view.bench.runchallenge.RunBenchmarkTableView;
import magma.tools.benchmark.view.bench.throwinchallenge.ThrowInBenchmarkTableView;

public enum ChallengeType {
public enum ChallengeType
{
RUN("Run", server -> new RunBenchmark(server, false), RunBenchmarkTableView::getInstance),

KICK("Kick", KickBenchmark::new, KickBenchmarkTableView::getInstance),
Expand All @@ -32,9 +33,9 @@ public enum ChallengeType {
GOALIE("Goalie", GoalieBenchmark::new, GoalieBenchmarkTableView::getInstance),

ROLLING_BALL("Rolling Ball", RollingBallBenchmark::new, RollingBallBenchmarkTableView::getInstance),

THROW_IN("Throw In", ThrowInBenchmark::new, ThrowInBenchmarkTableView::getInstance);

public static final ChallengeType DEFAULT = THROW_IN;

public final String name;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/magma/tools/benchmark/UserInterface.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package magma.tools.benchmark;

public enum UserInterface { GUI, CLI }
public enum UserInterface
{
GUI,
CLI
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public static void run(String[] args, UserInterface userInterface)
StringArgument defaultPathArgument =
new StringArgument("defaultPath", "examples", "the initial path to use for file dialogs");

IntegerArgument defaultRandomSeed = new IntegerArgument("randomSeed", (int) BenchmarkConfiguration.DEFAULT_RANDOM_SEED, 0, "the random seed to use");

IntegerArgument defaultRandomSeed = new IntegerArgument(
"randomSeed", (int) BenchmarkConfiguration.DEFAULT_RANDOM_SEED, 0, "the random seed to use");

new HelpArgument(challengeArgument, startScriptFolderArgument, roboVizServerArgument, defaultPathArgument)
.parse(args);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/magma/tools/benchmark/model/IModelReadOnly.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
*
* @author kdorer
*/
public interface IModelReadOnly {
public interface IModelReadOnly
{
/**
* @return the results per team
*/
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/magma/tools/benchmark/model/IModelReadWrite.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
*
* @author kdorer
*/
public interface IModelReadWrite extends IModelReadOnly {
public interface IModelReadWrite extends IModelReadOnly
{
void resetModel();

void start(BenchmarkConfiguration config, List<TeamConfiguration> teamConfig);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/magma/tools/benchmark/model/ISingleResult.java
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package magma.tools.benchmark.model;

public interface ISingleResult {
public interface ISingleResult
{
boolean isFallen();

/**
Expand All @@ -11,7 +12,6 @@ public interface ISingleResult {
boolean isValid();

String getStatusText();

double getScore();

double getScore();
}
2 changes: 1 addition & 1 deletion src/main/java/magma/tools/benchmark/model/ITeamResult.java
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package magma.tools.benchmark.model;

public interface ITeamResult extends ISingleResult
public interface ITeamResult extends ISingleResult
{
void addResult(ISingleResult result);

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/magma/tools/benchmark/model/bench/BenchmarkMain.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,16 @@ protected boolean performAverageOutRuns(TeamConfiguration currentTeamConfig, Run
if (runsInIDE()) {
serverStartScript = "scripts/startServer.sh";
}
Runtime.getRuntime().exec(serverStartScript + " " + config.getServerPort() +
" " + config.getTrainerPort() + " " + scriptPath);
Runtime.getRuntime().exec(serverStartScript + " " + config.getServerPort() + " " +
config.getTrainerPort() + " " + scriptPath);
}

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

boolean success = startTrainer(config, currentTeamConfig, runInfo, roboVizServer);
if (success) {
collectResults(currentRunResult);
Expand All @@ -427,7 +427,8 @@ protected boolean performAverageOutRuns(TeamConfiguration currentTeamConfig, Run
}
}
String marker = "---------------------------";
System.out.println(marker + "\nAverage " + avgRuns + " Score: " + currentRunResult.getScore() + "\n" + marker);
System.out.println(
marker + "\nAverage " + avgRuns + " Score: " + currentRunResult.getScore() + "\n" + marker);
return stopped;
}

Expand All @@ -442,7 +443,8 @@ public void stopTeam()
}
}

private boolean runsInIDE() {
private boolean runsInIDE()
{
String absPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
String libPath = absPath.substring(0, absPath.lastIndexOf(File.separator));
return libPath.substring(libPath.lastIndexOf(File.separator)).equals(File.separator + "classes");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/magma/tools/benchmark/model/bench/RunInformation.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public RunInformation(int runID, double ballX, double ballY, double ballVelX, do
this(runID, 0, 0, ballX, ballY, ballVelX, ballVelY, ballVelZ);
}

public RunInformation(int runID, double beamX, double beamY, double ballX, double ballY, double ballVelX, double ballVelY, double ballVelZ)
public RunInformation(int runID, double beamX, double beamY, double ballX, double ballY, double ballVelX,
double ballVelY, double ballVelZ)
{
super();
this.runID = runID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

import hso.autonomy.util.file.StreamBufferer;
import hso.autonomy.util.misc.CommandUtil;

import java.io.File;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SinglePlayerLauncher
{
Expand Down Expand Up @@ -112,8 +112,9 @@ private void runScript(String scriptName, Object[] arguments)
return;
}

Object[] commands = ArrayUtils.addAll(new Object[] {"bash", fullPath.getPath()}, arguments);
String command = StringUtils.join(commands, " ");
String command =
Stream.concat(Stream.of("bash", fullPath.getPath()), Arrays.stream(arguments).map(Object::toString))
.collect(Collectors.joining(" "));
System.out.println(command);

Process ps = CommandUtil.launch(command, null, workingDir);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/magma/tools/benchmark/model/bench/SingleResult.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class SingleResult implements ISingleResult
{
private final double score;

private final boolean fallen;

private final boolean penalty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public class PassingBenchmarkReferee extends BenchmarkRefereeBase

private AgentState agentStates[] = new AgentState[PassingBenchmark.PLAYERS];

private enum AgentState { NEUTRAL, TOUCHED, PASSED }
private enum AgentState
{
NEUTRAL,
TOUCHED,
PASSED
}

private boolean goal;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public double getScore()
for (ISingleResult result : results) {
scores.add(result.getScore());
}

Collections.sort(scores);

int end = PassingBenchmark.AVG_OUT_OF_BEST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

package magma.tools.benchmark.model.bench.rollingballchallenge;

import java.util.Random;

import hso.autonomy.util.geometry.Angle;
import hso.autonomy.util.geometry.Pose2D;
import java.util.Random;
import magma.monitor.general.impl.MonitorComponentFactory;
import magma.monitor.referee.IReferee.RefereeState;
import magma.tools.benchmark.model.BenchmarkConfiguration;
Expand Down Expand Up @@ -105,16 +104,17 @@ protected RunInformation createRunInformation(Random rand, int runID)
double beamX = -12;
double beamY = 0;
Pose2D beamPose = new Pose2D(beamX, beamY);

Vector2D direction = angle.applyTo(new Vector2D(1, 0));
Vector2D destinationBallPosition = beamPose.getPosition().add(new Vector2D(0.15 + noise(rand, 0.05), 0 + noise(rand, 0.05)));
Vector2D destinationBallPosition =
beamPose.getPosition().add(new Vector2D(0.15 + noise(rand, 0.05), 0 + noise(rand, 0.05)));
Vector2D ballStart = destinationBallPosition.add(direction.scalarMultiply(radius));
double ballX = ballStart.getX();
double ballY = ballStart.getY();

double speedX = -direction.getX() * speedFactor;
double speedY = -direction.getY() * speedFactor;

return new RunInformation(runID, beamX, beamY, ballX, ballY, speedX, speedY, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public RollingBallBenchmarkMonitorComponentFactory(
public IReferee createReferee(IMonitorWorldModel worldModel, IServerCommander serverCommander)
{
BenchmarkFactoryParameters params = (BenchmarkFactoryParameters) this.params;
SinglePlayerLauncher launcher = new SinglePlayerLauncher(params.getServerIP(), params.getAgentPort(),
params.getTeamPath(), params.getStartScriptName(), ChallengeType.ROLLING_BALL.startScriptArgument, false);
SinglePlayerLauncher launcher =
new SinglePlayerLauncher(params.getServerIP(), params.getAgentPort(), params.getTeamPath(),
params.getStartScriptName(), ChallengeType.ROLLING_BALL.startScriptArgument, false);
return new RollingBallBenchmarkReferee(worldModel, serverCommander, params.getServerPid(), launcher,
params.getDropHeight(), runInfo, roboVizServer);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package magma.tools.benchmark.model.bench.rollingballchallenge;

import hso.autonomy.util.geometry.Angle;
import java.awt.Color;
import magma.common.spark.PlayMode;
import magma.monitor.command.IServerCommander;
import magma.monitor.worldmodel.IMonitorWorldModel;
Expand All @@ -8,14 +10,9 @@
import magma.tools.benchmark.model.bench.SinglePlayerLauncher;
import magma.util.roboviz.RoboVizDraw;
import magma.util.roboviz.RoboVizParameters;

import java.awt.Color;

import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;

import hso.autonomy.util.geometry.Angle;

public class RollingBallBenchmarkReferee extends BenchmarkRefereeBase
{
/**
Expand Down Expand Up @@ -44,8 +41,9 @@ public class RollingBallBenchmarkReferee extends BenchmarkRefereeBase

private int ballNotMoving;

public RollingBallBenchmarkReferee(IMonitorWorldModel mWorldModel, IServerCommander serverCommander, String serverPid,
SinglePlayerLauncher launcher, float dropHeight, RunInformation runInfo, String roboVizServer)
public RollingBallBenchmarkReferee(IMonitorWorldModel mWorldModel, IServerCommander serverCommander,
String serverPid, SinglePlayerLauncher launcher, float dropHeight, RunInformation runInfo,
String roboVizServer)
{
// ignoring passed runtime since the check should anyhow not fire
super(mWorldModel, serverCommander, serverPid, launcher, 20, runInfo, false);
Expand Down Expand Up @@ -77,7 +75,7 @@ protected boolean onStartBenchmark()
serverCommander.beamBall((float) runInfo.getBallX(), (float) runInfo.getBallY());

roboVizDraw.drawMeterMarkers(false, Color.BLACK, (int) runInfo.getBeamX(), Angle.ZERO, 20);

return true;
}

Expand All @@ -95,7 +93,7 @@ protected boolean onDuringBenchmark()
if (hasFallen()) {
hasFallen = true;
}

if (currentTime > runTime) {
// finished this run
runTime = currentTime;
Expand All @@ -117,7 +115,7 @@ protected boolean onDuringBenchmark()
oldBallPos = ballNow;
return false;
}

if (!ballRolling) {
serverCommander.beamBall((float) runInfo.getBallX(), (float) runInfo.getBallY(), 0.0f,
(float) runInfo.getBallVelX(), (float) runInfo.getBallVelY(), (float) runInfo.getBallVelZ());
Expand All @@ -136,12 +134,12 @@ protected boolean onDuringBenchmark()
ballNotMoving = 0;
}
}

// stop if player is moving too much
if (posPlayer.getX() > playerInitial.getX() + 1.5) {
return true;
}

// stop if playmode changes (e.g. because someone scored an own goal)
if (worldModel.getPlayMode() != PlayMode.PLAY_ON) {
return true;
Expand All @@ -157,7 +155,7 @@ protected void onStopBenchmark()
{
// evaluation function
Vector2D start = new Vector2D(runInfo.getBeamX(), runInfo.getBeamY());

distance = 0;
if (oldBallPos.getX() > start.getX()) {
// only count forward movement of ball
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class RollingBallBenchmarkSingleResult extends SingleResult
private final double distance;
private final double deltaY;

public RollingBallBenchmarkSingleResult(boolean valid, boolean fallen, boolean penalty, String statusText,
double distance, double deltaY)
public RollingBallBenchmarkSingleResult(
boolean valid, boolean fallen, boolean penalty, String statusText, double distance, double deltaY)
{
super(calculateScore(distance, deltaY, fallen), valid, fallen, penalty, statusText);
this.distance = distance;
Expand All @@ -42,7 +42,7 @@ public RollingBallBenchmarkSingleResult(boolean valid, boolean fallen, boolean p

private static double calculateScore(double distance, double deltaY, boolean fallen)
{
return distance - deltaY - 3 * ((fallen) ?1 :0);
return distance - deltaY - 3 * ((fallen) ? 1 : 0);
}

public double getDistance()
Expand Down
Loading

0 comments on commit 1da9ff2

Please sign in to comment.