Commit 9a5fedf7 authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

updated test models

parent 8803420c
Pipeline #61292 failed with stage
in 1 minute and 44 seconds
package de.monticore.lang.monticar.generator.testing;
/**
* @author Sascha Schneiders
*/
public class BasicStreamTestValue<T> implements StreamTestValue {
T value;
public BasicStreamTestValue(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
@Override
public String getStringRepresentation() {
return value.toString();
}
}
package de.monticore.lang.monticar.generator.testing;
/**
* @author Sascha Schneiders
*/
public class StreamGenerator {
}
package de.monticore.lang.monticar.generator.testing;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sascha Schneiders
*/
public class StreamTest {
List<StreamTestPort> ports = new ArrayList<>();
}
package de.monticore.lang.monticar.generator.testing;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sascha Schneiders
*/
public class StreamTestPort {
protected String name;
protected List<StreamTestValue> values = new ArrayList<>();
public StreamTestPort() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<StreamTestValue> getValues() {
return values;
}
public void setValues(List<StreamTestValue> values) {
this.values = values;
}
}
package de.monticore.lang.monticar.generator.testing;
/**
* @author Sascha Schneiders
*/
public interface StreamTestValue {
String getStringRepresentation();//Maybe replace by using regular toString?
}
package ${streamTest.packageName};
stream ${streamTest.testName} for ${streamTest.componentName}{
<#list streamTest.ports as p>
${p.name}:<#list p.values as v> ${v.getStringRepresentation()} <#if v_has_next> tick </#if>></#list>;
</#list>
};
#endif
......@@ -4,7 +4,6 @@
#include "catch.hpp"
#include "../${viewModel.componentName}.h"
<#list viewModel.streams as stream>
TEST_CASE("${stream.name}", "[${viewModel.componentName}]") {
${viewModel.componentName} component;
......
<#include "/Common.ftl">
#ifndef ${viewModel.fileNameWithoutExtension?upper_case}
#define ${viewModel.fileNameWithoutExtension?upper_case}
#include "catch.hpp"
#include "../${viewModel.componentName}.h"
#include <iostream>
<#list viewModel.streams as stream>
TEST_CASE("${stream.name}", "[${viewModel.componentName}]") {
${viewModel.componentName} component;
component.init();
<#list stream.checks as check>
<#list check.inputPortName2Value?keys as portName>
component.${portName} = ${check.inputPortName2Value[portName]};
</#list>
component.execute();
<#list check.outputPortName2Check?keys as outputPortName>
<@renderPortCheck outputPortName=outputPortName check=check.outputPortName2Check[outputPortName] />
</#list>
</#list>
std::cout << "${stream.name}: success\n";
}
</#list>
#endif
<#macro renderPortCheck outputPortName check>
<#assign portValue="component.${outputPortName}">
<#if helper.isBooleanOutputPortCheck(check)>
<#if helper.isTrueExpectedCheck(check)>
REQUIRE( ${portValue} );
<#else>
REQUIRE_FALSE( ${portValue} );
</#if>
<#elseif helper.isRangeOutputPortCheck(check)>
REQUIRE( ${portValue} >= ${check.lowerBound} );
REQUIRE( ${portValue} <= ${check.upperBound} );
</#if>
<#else>
std::cout << (${portValue}) << "\n";
</#if>
</#macro>
package de.rwth.armin.modeling.autopilot;
import de.rwth.armin.modeling.autopilot.common.*;
import de.rwth.armin.modeling.autopilot.behavior.*;
import de.rwth.armin.modeling.autopilot.motion.*;
component Autopilot {
port
// length of simulation time frame
// e.g. when simulation frequency is 200 Hz
// this value will be equal to 5ms
in Q (0.0 s : 0.001 s : 1.0 s) timeIncrement,
// current velocity
in Q (0.0 m/s : 0.01 m/s : oo m/s) currentVelocity,
// current vehicle's position
in Q (-oo m : 0.01 m : oo m) x,
in Q (-oo m : 0.01 m : oo m) y,
// orientation angle (also sometimes called yaw angle) in radians
// it is measured from from the positive Y axis direction
// to the actual vehicle's direction counter-clockwise
// Example 1: vehicle has direction (-1.0; -1.0)
// compass = 0.25 * PI (positive)
// Example 2: vehicle has direction (1.0; 0.0) i.e. it is directed along the X axis
// compass = -0.5 * PI (negative)
in Q (-oo : 0.001 : oo) compass,
// current engine actuation
in Q (0.0 : 0.001 : 2.5) currentEngine,
// current steering actuation
// negative value: left turn
// positive value: right turn
in Q (-0.785 : 0.001 : 0.785) currentSteering,
// current brakes actuation
in Q (0.0 : 0.001 : 3.0) currentBrakes,
// planned trajectory (with look ahead 100-200m)
// represented by two arrays trajectory_x[] and trajectory_y[]
// which both have length trajectory_length
in Z (0 : 100) trajectory_length,
in Q (-oo m : 0.01 m : oo m) ^ {1,100} trajectory_x,
in Q (-oo m : 0.01 m : oo m) ^ {1,100} trajectory_y,
// output actuation commands
out Q (0.0 : 0.001 : 2.5) engine,
out Q (-0.785 : 0.001 : 0.785) steering,
out Q (0.0 : 0.001 : 3.0) brakes;
instance Compass2CurrentDirection c2cd;
instance BehaviorGeneration behaviorGeneration;
instance MotionPlanning motionPlanning;
connect compass -> c2cd.compass;
connect x -> behaviorGeneration.currentPositionX;
connect y -> behaviorGeneration.currentPositionY;
connect trajectory_length -> behaviorGeneration.plannedTrajectoryLength;
connect trajectory_x -> behaviorGeneration.plannedTrajectoryX;
connect trajectory_y -> behaviorGeneration.plannedTrajectoryY;
connect c2cd.currentDirectionX -> behaviorGeneration.currentDirectionX;
connect c2cd.currentDirectionY -> behaviorGeneration.currentDirectionY;
connect currentVelocity -> motionPlanning.currentVelocity;
connect c2cd.currentDirectionX -> motionPlanning.currentDirectionX;
connect c2cd.currentDirectionY -> motionPlanning.currentDirectionY;
connect behaviorGeneration.desiredDirectionX -> motionPlanning.desiredDirectionX;
connect behaviorGeneration.desiredDirectionY -> motionPlanning.desiredDirectionY;
connect behaviorGeneration.signedDistanceToTrajectory -> motionPlanning.signedDistanceToTrajectory;
connect behaviorGeneration.desiredVelocity -> motionPlanning.desiredVelocity;
connect motionPlanning.engine -> engine;
connect motionPlanning.steering -> steering;
connect motionPlanning.brakes -> brakes;
}
package de.rwth.armin.modeling.autopilot;
view Autopilot {
component Autopilot{
ports in ? currentVelocity,
in ? compass,
in ? currentPosX,
in ? currentPosY,
in ? trajectory_length,
in ? trajectory_x,
in ? trajectory_y,
out ? Engine,
out ? Brakes,
out ? Steering;
component Compass2CurrentDirection{
ports in ? ?,
out ? ?,
out ? ?;
}
instance Compass2CurrentDirection comp;
component BehaviorGeneration{
ports in ? ?,
in ? ?,
in ? ?,
in ? ?,
in ? ?,
in ? ?,
in ? ?,
out ? ?;
}
instance BehaviorGeneration behavior;
component CalculateMotionCommands{
ports in ? ?,
in ? ?,
in ? ?,
in ? ?,
in ? ?,
out ? ?;
}
instance CalculateMotionCommands calcMotion;
component TrimPath{
ports in ? ?,
in ? ?,
in ? ?,
in ? ?,
in ? ?,
out ? ?;
}
instance TrimPath trim;
component MotionPlanning{
ports in ? ?,
in ? ?,
out ? ?;
}
instance MotionPlanning motion;
component CalculateEngineAndBrakes{
ports in ? ?,
in ? ?,
out ? ?;
}
instance CalculateEngineAndBrakes calcEngine;
component KeepDirection{
ports in ? ?,
out ? ?;
}
instance KeepDirection keep;
component SteeringAngleCorrection{
ports in ? ?,
out ? ?;
}
instance SteeringAngleCorrection steer;
component EnsureBounds{
ports in ? ?,
out ? ?;
}
instance EnsureBounds ensure;
connect currentVelocity -> motion;
connect compass -> comp;
connect currentPosX -> behavior;
connect currentPosY -> behavior;
connect trajectory_length -> behavior;
connect trajectory_x -> behavior;
connect trajectory_y -> behavior;
connect comp -> behavior;
connect comp -> behavior;
connect behavior -> calcMotion;
connect behavior -> calcMotion;
connect behavior -> calcMotion;
connect behavior -> calcMotion;
connect behavior -> trim;
connect behavior -> trim;
connect behavior -> trim;
connect behavior -> trim;
connect behavior -> trim;
connect trim -> calcMotion;
connect calcMotion -> behavior;
connect behavior -> motion;
connect motion -> calcEngine;
connect motion -> calcEngine;
connect calcEngine -> keep;
connect keep -> steer;
connect steer -> ensure;
connect ensure -> motion;
connect motion -> Engine;
connect motion -> Brakes;
connect motion -> Steering;
}
}
\ No newline at end of file
package de.rwth.armin.modeling.autopilot;
component Tests {
port in B in1, out B out1;
instance de.rwth.armin.modeling.autopilot.common.Tests t1;
instance de.rwth.armin.modeling.autopilot.motion.Tests t2;
instance de.rwth.armin.modeling.autopilot.behavior.Tests t3;
}
package de.rwth.armin.modeling.autopilot.basicComp;
component PID{
port
in Q desiredVel,
in Q currentVel,
in Q timeInc,
out Q engineVal,
out Q breakesVal;
implementation Math {
Q diff = desiredVel - currentVel;
static Q totalTime = 0.0;
totalTime = totalTime + timeInc;
if totalTime > 100
engineVal = 0.0;
breakesVal = 2.5;
elseif diff > 0
engineVal = 2.5;
breakesVal = 0.0;
else
engineVal = 0.0;
breakesVal = 2.5;
end
}
}
package de.rwth.armin.modeling.autopilot.basicComp;
view PID {
component PID{
ports in ? currentSpeed,
in ? desiredSpeed,
out ? Engine,
out ? Brakes;
}
}
\ No newline at end of file
package de.rwth.armin.modeling.autopilot.basicComp;
stream PID1 for PID {
desiredVel: 5 tick 5 tick 5 tick 5;
currentVel: 0 tick 4 tick 5 tick 10;
timeInc : 0.001 tick 0.0001 tick 0.0001 tick 0.0001;
engineVal: 2.5 tick 2.5 tick - tick 0.0;
breakesVal: 0 tick 0 tick - tick 2.5;
}
package de.rwth.armin.modeling.autopilot.behavior;
component BehaviorGeneration {
port
in Q (-oo m : 0.01 m : oo m) currentPositionX,
in Q (-oo m : 0.01 m : oo m) currentPositionY,
in Q (-oo m : 0.01 m : oo m) currentDirectionX,
in Q (-oo m : 0.01 m : oo m) currentDirectionY,
in Z (0 : 100) plannedTrajectoryLength,
in Q (-oo m : 0.01 m : oo m) ^ {1,100} plannedTrajectoryX,
in Q (-oo m : 0.01 m : oo m) ^ {1,100} plannedTrajectoryY,
out Q (-oo m : 0.01 m : oo m) desiredDirectionX,
out Q (-oo m : 0.01 m : oo m) desiredDirectionY,
out Q (-oo m : 0.01 m : oo m) signedDistanceToTrajectory,
out Q (0.0 m/s : 0.01 m/s : 13.0 m/s) desiredVelocity;
instance TrimPath trimPath;
instance CalculateMotionCommands calcMotionCmds;
connect currentPositionX -> trimPath.currentPositionX;
connect currentPositionY -> trimPath.currentPositionY;
connect plannedTrajectoryLength -> trimPath.plannedTrajectoryLength;
connect plannedTrajectoryX -> trimPath.plannedTrajectoryX;
connect plannedTrajectoryY -> trimPath.plannedTrajectoryY;
connect currentPositionX -> calcMotionCmds.currentPositionX;
connect currentPositionY -> calcMotionCmds.currentPositionY;
connect currentDirectionX -> calcMotionCmds.currentDirectionX;
connect currentDirectionY -> calcMotionCmds.currentDirectionY;
connect trimPath.trimmedTrajectoryLength -> calcMotionCmds.trimmedTrajectoryLength;
connect trimPath.trimmedTrajectoryX -> calcMotionCmds.trimmedTrajectoryX;
connect trimPath.trimmedTrajectoryY -> calcMotionCmds.trimmedTrajectoryY;
connect calcMotionCmds.desiredDirectionX -> desiredDirectionX;
connect calcMotionCmds.desiredDirectionY -> desiredDirectionY;
connect calcMotionCmds.signedDistanceToTrajectory -> signedDistanceToTrajectory;
connect calcMotionCmds.desiredVelocity -> desiredVelocity;
}
package de.rwth.armin.modeling.autopilot.behavior;
component CalculateMotionCommands {
port
in Q (-oo m : 0.01 m : oo m) currentPositionX,
in Q (-oo m : 0.01 m : oo m) currentPositionY,
in Q (-oo m : 0.01 m : oo m) currentDirectionX,
in Q (-oo m : 0.01 m : oo m) currentDirectionY,
in Z (0 : 100) trimmedTrajectoryLength,
in Q (-oo m : 0.01 m : oo m) ^ {1,100} trimmedTrajectoryX,
in Q (-oo m : 0.01 m : oo m) ^ {1,100} trimmedTrajectoryY,
out Q (-oo m : 0.01 m : oo m) desiredDirectionX,
out Q (-oo m : 0.01 m : oo m) desiredDirectionY,
out Q (-oo m : 0.01 m : oo m) signedDistanceToTrajectory,
out Q (0.0 m/s : 0.01 m/s : 13.0 m/s) desiredVelocity;
instance IsDriveToFirstPosition isDriveToFirstPosition;
instance DriveToFirstPosition driveToFirstPosition;
instance Distance2Velocity d2v1;
instance FollowTrajectory followTrajectory;
instance Distance2Velocity d2v2;
instance Selector selector;
connect currentPositionX -> isDriveToFirstPosition.currentPositionX;
connect currentPositionY -> isDriveToFirstPosition.currentPositionY;
connect trimmedTrajectoryLength -> isDriveToFirstPosition.trimmedTrajectoryLength;
connect trimmedTrajectoryX -> isDriveToFirstPosition.trimmedTrajectoryX;
connect trimmedTrajectoryY -> isDriveToFirstPosition.trimmedTrajectoryY;
connect isDriveToFirstPosition.result -> driveToFirstPosition.isDriveToFirstPosition;
connect currentPositionX -> driveToFirstPosition.currentPositionX;
connect currentPositionY -> driveToFirstPosition.currentPositionY;
connect trimmedTrajectoryLength -> driveToFirstPosition.trimmedTrajectoryLength;
connect trimmedTrajectoryX -> driveToFirstPosition.trimmedTrajectoryX;
connect trimmedTrajectoryY -> driveToFirstPosition.trimmedTrajectoryY;
connect driveToFirstPosition.distance -> d2v1.distance;
connect driveToFirstPosition.minVelocity -> d2v1.minVelocity;
connect driveToFirstPosition.maxVelocity -> d2v1.maxVelocity;
connect isDriveToFirstPosition.result -> followTrajectory.isDriveToFirstPosition;
connect currentPositionX -> followTrajectory.currentPositionX;
connect currentPositionY -> followTrajectory.currentPositionY;
connect trimmedTrajectoryLength -> followTrajectory.trimmedTrajectoryLength;
connect trimmedTrajectoryX -> followTrajectory.trimmedTrajectoryX;
connect trimmedTrajectoryY -> followTrajectory.trimmedTrajectoryY;
connect followTrajectory.distance -> d2v2.distance;
connect followTrajectory.minVelocity -> d2v2.minVelocity;
connect followTrajectory.maxVelocity -> d2v2.maxVelocity;
connect isDriveToFirstPosition.result -> selector.isDriveToFirstPosition;
connect driveToFirstPosition.desiredDirectionX -> selector.desiredDirectionX1;
connect driveToFirstPosition.desiredDirectionY -> selector.desiredDirectionY1;
connect driveToFirstPosition.signedDistanceToTrajectory -> selector.signedDistanceToTrajectory1;
connect d2v1.velocity -> selector.desiredVelocity1;
connect followTrajectory.desiredDirectionX -> selector.desiredDirectionX2;
connect followTrajectory.desiredDirectionY -> selector.desiredDirectionY2;
connect followTrajectory.signedDistanceToTrajectory -> selector.signedDistanceToTrajectory2;
connect d2v2.velocity -> selector.desiredVelocity2;
connect selector.desiredDirectionX -> desiredDirectionX;
connect selector.desiredDirectionY -> desiredDirectionY;
connect selector.signedDistanceToTrajectory -> signedDistanceToTrajectory;
connect selector.desiredVelocity -> desiredVelocity;
}
package de.rwth.armin.modeling.autopilot.behavior;
import de.rwth.armin.modeling.autopilot.common.*;
component Distance2Velocity {
port
in Q (0.0 m : 0.01 m : oo m) distance,
in Q (0.0 m/s : 0.01 m/s : 13.0 m/s) minVelocity,
in Q (0.0 m/s : 0.01 m/s : 13.0 m/s) maxVelocity,