In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit 43e41dcc authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

implement TraCI commands for artery use

parent 46dcfdea
Pipeline #307279 passed with stages
in 127 minutes and 20 seconds
......@@ -456,12 +456,32 @@ public class TestClient extends org.vadere.manager.client.AbstractTestClient imp
}
@Override
public void simulationapi_getDepartedPedestrianId(String[] args) throws IOException {
}
@Override
public void simulationapi_getArrivedPedestrianIds(String[] args) throws IOException {
}
@Override
public void simulationapi_getPositionConversion(String[] args) throws IOException {
}
@Override
public void simulationapi_getTime(String[] args) throws IOException {
TraCIResponse res = simulationapi.getTime();
System.out.println(res.toString());
}
@Override
public void simulationapi_getSimSte(String[] args) throws IOException {
}
@Override
public void simulationapi_setSimConfig(String[] args) throws IOException {
System.out.println("not implemented");
......@@ -599,6 +619,11 @@ public class TestClient extends org.vadere.manager.client.AbstractTestClient imp
System.out.println(res.toString());
}
@Override
public void simulationapi_getNetworkBound(String[] args) throws IOException {
}
// vadere api
@Override
......
......@@ -30,9 +30,9 @@ public class CommandExecutor {
cmdMap.put(TraCICmd.SEND_FILE.id, ControlCommandHandler.instance::process_load_file);
cmdMap.put(TraCICmd.GET_PERSON_VALUE.id, PersonCommandHandler.instance::processGet);
cmdMap.put(TraCICmd.SET_PERSON_STATE.id, PersonCommandHandler.instance::processSet);
cmdMap.put(TraCICmd.SUB_PERSON_VARIABLE.id, PersonCommandHandler.instance::processValueSub);
cmdMap.put(TraCICmd.GET_VADERE_VALUE.id, VadereCommandHandler.instance::processGet);
cmdMap.put(TraCICmd.SET_VADERE_STATE.id, VadereCommandHandler.instance::processSet);
cmdMap.put(TraCICmd.SUB_PERSON_VARIABLE.id, PersonCommandHandler.instance::processValueSub);
cmdMap.put(TraCICmd.GET_SIMULATION_VALUE.id, SimulationCommandHandler.instance::processGet);
cmdMap.put(TraCICmd.SET_SIMULATION_STATE.id, SimulationCommandHandler.instance::processSet);
cmdMap.put(TraCICmd.SUB_SIMULATION_VALUE.id, SimulationCommandHandler.instance::processValueSub);
......@@ -67,6 +67,7 @@ public class CommandExecutor {
return TraCIPacket.createErr(cmd.getTraCICmd().id, e.getMessageForClient());
}
logger.tracef("return response for: %s", cmd.getTraCICmd().logShort());
return response;
}
}
......@@ -116,8 +116,11 @@ public abstract class CommandHandler<VAR extends Enum> {
}
public TraCICommand processValueSub(TraCICommand rawCmd, RemoteManager remoteManager,
TraCICmdHandler traCICmdHandler, TraCICmd getCommand, TraCICmd apiCmdResponse) {
public TraCICommand processValueSub(TraCICommand rawCmd,
RemoteManager remoteManager,
TraCICmdHandler traCICmdHandler,
TraCICmd getCommand,
TraCICmd apiCmdResponse) {
TraCIValueSubscriptionCommand cmd = (TraCIValueSubscriptionCommand) rawCmd;
List<TraCIGetCommand> getCommands = new ArrayList<>();
......
......@@ -84,7 +84,9 @@ public class ControlCommandHandler extends CommandHandler<ControlVar> {
logger.debugf("%s: execute %d subscriptions",
TraCICmd.SIM_STEP.name(),
remoteManager.getSubscriptions().size());
remoteManager.getSubscriptions().forEach(sub -> sub.executeSubscription(remoteManager));
remoteManager.getSubscriptions().forEach(sub -> {
sub.executeSubscription(remoteManager);
});
// remove subscriptions no longer valid
remoteManager.getSubscriptions().removeIf(Subscription::isMarkedForRemoval);
......
......@@ -210,8 +210,10 @@ public class PersonCommandHandler extends CommandHandler<PersonVar> {
remoteManager.accessState((manager, state) -> {
Pedestrian ped = state.getTopography().getPedestrianDynamicElements()
.getElement(Integer.parseInt(cmd.getElementIdentifier()));
if (checkIfPedestrianExists(ped, cmd))
cmd.setResponse(responseOK(PersonVar.SPEED.type, ped.getFreeFlowSpeed()));
if (checkIfPedestrianExists(ped, cmd)){
double speed = ped.getFootstepHistory().getAverageSpeedInMeterPerSecond();
cmd.setResponse(responseOK(PersonVar.SPEED.type, Double.isNaN(speed) ? 0.0 : speed));
}
});
return cmd;
}
......@@ -366,7 +368,15 @@ public class PersonCommandHandler extends CommandHandler<PersonVar> {
@PersonHandler(cmd = TraCICmd.GET_PERSON_VALUE, var = PersonVar.ANGLE, name = "getAngle")
public TraCICommand process_getAngle(TraCIGetCommand cmd, RemoteManager remoteManager) {
// return dummy value
cmd.setResponse(responseOK(PersonVar.ANGLE.type, 0.0));
remoteManager.accessState((manager, state) -> {
Pedestrian ped = state.getTopography().getPedestrianDynamicElements()
.getElement(Integer.parseInt(cmd.getElementIdentifier()));
if (checkIfPedestrianExists(ped, cmd)){
double angle = ped.getFootstepHistory().getNorthBoundHeadingAngleDeg();
cmd.setResponse(responseOK(PersonVar.ANGLE.type, angle));
}
});
return cmd;
}
......
......@@ -2,14 +2,19 @@ package org.vadere.manager.traci.commandHandler.variables;
import org.vadere.manager.TraCIException;
import org.vadere.manager.traci.TraCIDataType;
import org.vadere.manager.traci.commands.TraCICommand;
public enum SimulationVar {
CURR_SIM_TIME(0x66, TraCIDataType.DOUBLE),
VAR_DELTA_T(0x7b, TraCIDataType.DOUBLE), //step length
NUM_LOADED_VEHICLES(0x71, TraCIDataType.INTEGER),
LOADED_VEHICLES_IDS(0x72, TraCIDataType.STRING_LIST),
NUM_DEPARTED_VEHICLES(0x73, TraCIDataType.INTEGER),
DEPARTED_VEHICLES_IDS(0x74, TraCIDataType.STRING_LIST),
NUM_DEPARTED_PEDESTRIAN(0x73, TraCIDataType.INTEGER), // alias NUM_DEPARTED_VEHICLES
DEPARTED_PEDESTRIAN_IDS(0x74, TraCIDataType.STRING_LIST), // alias DEPARTED_VEHICLES_IDS
NUM_ARRIVED_PEDESTRIAN(0x79, TraCIDataType.INTEGER), // alias VAR_ARRIVED_VEHICLES_NUMBER
ARRIVED_PEDESTRIAN_PEDESTRIAN_IDS(0x7a, TraCIDataType.STRING_LIST), // alias VAR_ARRIVED_VEHICLES_IDS
POSITION_CONVERSION(0x82, TraCIDataType.COMPOUND_OBJECT),
NUM_VEHICLES_START_TELEPORT(0x75, TraCIDataType.INTEGER),
VEHICLES_START_TELEPORT_IDS(0x76, TraCIDataType.STRING_LIST),
NUM_VEHICLES_END_TELEPORT(0x77, TraCIDataType.INTEGER),
......
package org.vadere.manager.traci.reader;
import org.vadere.manager.traci.TraCICmd;
import org.vadere.manager.traci.commandHandler.CommandExecutor;
import org.vadere.manager.traci.commands.TraCICommand;
import org.vadere.manager.traci.response.StatusResponse;
import org.vadere.manager.traci.response.TraCIResponse;
import org.vadere.util.logging.Logger;
import java.nio.ByteBuffer;
......@@ -16,6 +18,8 @@ import java.nio.ByteBuffer;
*/
public class TraCIPacketBuffer extends TraCIByteBuffer {
private static Logger logger = Logger.getLogger(TraCIPacketBuffer.class);
protected TraCIPacketBuffer(byte[] buf) {
super(buf);
}
......@@ -41,7 +45,7 @@ public class TraCIPacketBuffer extends TraCIByteBuffer {
return null;
int cmdLen = getCommandDataLen();
logger.tracef("read next command with length %d", cmdLen);
return TraCICommand.create(readByteBuffer(cmdLen));
}
......
......@@ -93,7 +93,7 @@ public class SimulationCommandHandlerTest extends CommandHandlerTest {
when(simState.getSimTimeInSec()).thenReturn(retVal);
}
};
TraCICommand ret = simCmdHandler.process_getSimTime(cmd, rm, var);
TraCICommand ret = simCmdHandler.process_getSimTime(cmd, rm);
checkGET_OK(ret);
testGetValue(ret, varID, varType, elementID, retVal);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment