Skip to content

Commit

Permalink
Exécution du simulateur en TU
Browse files Browse the repository at this point in the history
  • Loading branch information
gdepuille committed May 17, 2021
1 parent 9819877 commit 26aefa6
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.arig.robot;

import lombok.SneakyThrows;
import org.arig.robot.AbstractOrdonanceur.OrdonanceurStep;
import org.arig.robot.config.spring.NerellSimulator;
import org.arig.robot.config.spring.NerellSimulatorTestContext;
import org.arig.robot.constants.IConstantesConfig;
import org.arig.robot.model.ETeam;
import org.arig.robot.model.NerellRobotStatus;
import org.arig.robot.services.NerellIOServiceBouchon;
import org.arig.robot.system.capteurs.IEcran;
import org.arig.robot.system.capteurs.NerellTestEcran;
import org.arig.robot.utils.ThreadUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {NerellSimulator.class, NerellSimulatorTestContext.class})
public class NerellSimulatorTest {

@Autowired
private NerellRobotStatus rs;

@Autowired
private NerellOrdonanceur ordonanceur;

@Autowired
private NerellIOServiceBouchon ioService;

@Autowired
private IEcran ecran;

@BeforeClass
public static void before() {
// Définition d'un ID unique pour le nommage des fichiers
final String execId = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
System.setProperty(IConstantesConfig.keyExecutionId, execId);
System.setProperty(IConstantesConfig.disableEcran, "true");

// Surcharge de bean
System.setProperty("spring.main.allow-bean-definition-overriding", "true");
}

@SneakyThrows
@Test(timeout = 300000)
public void runSimulateurTest() {
rs.simulateur(true);

ExecutorService exec = Executors.newSingleThreadExecutor();
exec.submit(() -> ordonanceur.run());

waitStep(OrdonanceurStep.WAIT_AU);
ioService.au(true);

// Selection de la couleur de l'équipe
waitStep(OrdonanceurStep.AFTER_INIT);
while(rs.team() != ETeam.JAUNE) {
((NerellTestEcran) ecran).getConfigInfos().setTeam(1); // 1 Jaune, 2 Bleu
ThreadUtils.sleep(2000);
}
((NerellTestEcran) ecran).getConfigInfos().setStartCalibration(true);

// Mise tirette
waitStep(OrdonanceurStep.READY_TO_PLAY);
ioService.tirette(true);

// Start match
waitStep(OrdonanceurStep.WAIT_START_MATCH);
ioService.tirette(false);

// Remise tirette fin match
waitStep(OrdonanceurStep.EJECTION);
ioService.tirette(true);

waitStep(OrdonanceurStep.READY_TO_STORE);
ioService.tirette(false);

// Check all are terminated
waitStep(OrdonanceurStep.END);
}

private void waitStep(OrdonanceurStep step) {
while(ordonanceur.getStep() != step) {
ThreadUtils.sleep(2000);
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.arig.robot.config.spring;

import org.arig.robot.system.capteurs.IEcran;
import org.arig.robot.system.capteurs.NerellTestEcran;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class NerellSimulatorTestContext extends NerellSimulatorContext {

@Override
@Bean
@DependsOn("ecranProcess")
public IEcran ecran() throws Exception {
return new NerellTestEcran();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.arig.robot.system.capteurs;

import lombok.Getter;
import org.arig.robot.model.ecran.GetConfigInfos;
import org.arig.robot.model.ecran.UpdateMatchInfos;
import org.arig.robot.model.ecran.UpdatePhotoInfos;
import org.arig.robot.model.ecran.UpdateStateInfos;

public class NerellTestEcran implements IEcran {

@Getter
private final GetConfigInfos configInfos;

public NerellTestEcran() {
configInfos = new GetConfigInfos();
configInfos.setTeam(-1);
}

@Override
public GetConfigInfos configInfos() {
return configInfos;
}

@Override
public void end() {
}

@Override
public void updateState(final UpdateStateInfos data) {
}

@Override
public void updateMatch(final UpdateMatchInfos data) {
}

@Override
public void updatePhoto(final UpdatePhotoInfos photo) {
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.arig.robot;

import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -42,6 +43,17 @@
@Slf4j
public abstract class AbstractOrdonanceur {

public enum OrdonanceurStep {
INIT,
WAIT_AU,
AFTER_INIT,
READY_TO_PLAY,
WAIT_START_MATCH,
EJECTION,
READY_TO_STORE,
END
}

@Autowired
protected RobotConfig robotConfig;

Expand Down Expand Up @@ -90,6 +102,9 @@ public abstract class AbstractOrdonanceur {

protected String launchExecId;

@Getter
protected OrdonanceurStep step = OrdonanceurStep.INIT;

/**
* Construit le chemin de la map du pathfinder dans le classpath
*/
Expand Down Expand Up @@ -134,10 +149,12 @@ public final void run() {

initLidar();

step = OrdonanceurStep.WAIT_AU;
waitAu();

waitPower();

step = OrdonanceurStep.AFTER_INIT;
afterInit(); // impl

initPathfinder();
Expand All @@ -148,8 +165,10 @@ public final void run() {

startLidar();

step = OrdonanceurStep.READY_TO_PLAY;
beforeMatch(); // impl

step = OrdonanceurStep.WAIT_START_MATCH;
waitTirette();

match();
Expand All @@ -170,6 +189,7 @@ public final void run() {
ioService.disableAlim5VPuissance();
ioService.disableAlim12VPuissance();
}
step = OrdonanceurStep.END;
}

/**
Expand Down Expand Up @@ -369,12 +389,14 @@ private void cycleFin() {
robotStatus.calculerPoints())
);

step = OrdonanceurStep.EJECTION;
while (!ioService.tirette() || !ioService.auOk()) {
ThreadUtils.sleep(1000);
}

ioService.enableAlim5VPuissance();

step = OrdonanceurStep.READY_TO_STORE;
beforePowerOff(); // impl

ioService.disableAlim5VPuissance();
Expand Down

0 comments on commit 26aefa6

Please sign in to comment.