Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TU avec le simulateur #95

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -44,6 +45,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 @@ -98,6 +110,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 @@ -152,10 +167,12 @@ public final void run() {

initLidar();

step = OrdonanceurStep.WAIT_AU;
waitAu();

waitPower();

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

initPathfinder();
Expand All @@ -167,10 +184,12 @@ public final void run() {
startLidar();

addDeadZones();


step = OrdonanceurStep.READY_TO_PLAY;
beforeMatch(ecranService.config().isSkipCalageBordure()); // impl

ecranService.displayMessage("!!! ... ATTENTE DEPART TIRETTE ... !!!");
step = OrdonanceurStep.WAIT_START_MATCH;
robotStatus.waitTirette(true);
while (waitTirette()) {
ThreadUtils.sleep(1);
Expand Down Expand Up @@ -202,6 +221,7 @@ public final void run() {
io.disableAlimServos();
io.disableAlimMoteurs();
}
step = OrdonanceurStep.END;
}

/**
Expand Down Expand Up @@ -437,10 +457,12 @@ private void cycleFin() {
robotStatus.calculerPoints())
);

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

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

Expand Down