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

Pedestrian events #127

Draft
wants to merge 2 commits into
base: develop
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
2 changes: 1 addition & 1 deletion jpo-conflictmonitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>usdot.jpo.ode</groupId>
<artifactId>jpo-conflictmonitor</artifactId>
<version>1.5.0-SNAPSHOT</version>
<version>1.6.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jpo-conflictmonitor</name>
<url>http://maven.apache.org</url>
Expand Down
562 changes: 562 additions & 0 deletions jpo-conflictmonitor/scripts/IntegrationTestScripts/pedestrian.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
import lombok.Data;
import lombok.Generated;
import us.dot.its.jpo.conflictmonitor.monitor.models.IntersectionRegion;
import us.dot.its.jpo.conflictmonitor.monitor.models.concurrent_permissive.ConnectedLanes;
import us.dot.its.jpo.conflictmonitor.monitor.models.concurrent_permissive.ConnectedLanesPair;
import us.dot.its.jpo.conflictmonitor.monitor.models.concurrent_permissive.ConnectedLanesPairList;
import us.dot.its.jpo.conflictmonitor.monitor.models.config.ConfigData;
import us.dot.its.jpo.conflictmonitor.monitor.models.config.ConfigDataClass;
import us.dot.its.jpo.conflictmonitor.monitor.models.config.ConfigMap;

import java.util.List;

import static us.dot.its.jpo.conflictmonitor.monitor.algorithms.config.ConfigUtil.getIntersectionValue;
import static us.dot.its.jpo.conflictmonitor.monitor.models.config.UpdateType.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public void updateStartLines(){
}
}



public LaneConnection getLaneConnection(Lane ingressLane, Lane egressLane){
if (ingressLane == null || egressLane == null) {
return null;
Expand Down Expand Up @@ -196,6 +198,22 @@ public ArrayList<LaneConnection> getLaneConnectionBySignalGroup(int signalGroup)
return connections;
}

public ArrayList<Lane> getPedestrianLanes(){
ArrayList<Lane> pedLanes = new ArrayList<>();
for(Lane lane: this.ingressLanes){
if(lane.isPedestrian()){
pedLanes.add(lane);
}
}

for(Lane lane: this.egressLanes){
if(lane.isPedestrian()){
pedLanes.add(lane);
}
}
return pedLanes;
}



public void setIngressLanes(ArrayList<Lane> ingressLanes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import us.dot.its.jpo.geojsonconverter.pojos.geojson.map.MapFeature;
import us.dot.its.jpo.geojsonconverter.pojos.geojson.map.MapNode;
import us.dot.its.jpo.geojsonconverter.pojos.geojson.map.MapProperties;
import us.dot.its.jpo.ode.plugin.j2735.J2735LaneTypeAttributes;



Expand All @@ -28,6 +29,8 @@ public class Lane {
private int laneWidthCm;
private int region;

private J2735LaneTypeAttributes type;

public static Lane fromGeoJsonFeature(MapFeature<us.dot.its.jpo.geojsonconverter.pojos.geojson.LineString> feature, Coordinate referencePoint, int laneWidthCm){

Lane lane = new Lane();
Expand Down Expand Up @@ -63,6 +66,7 @@ public static Lane fromGeoJsonFeature(MapFeature<us.dot.its.jpo.geojsonconverter
lanePoints = lanePoints.reverse();
}

lane.type = feature.getProperties().getLaneType();


lane.setPoints(lanePoints);
Expand Down Expand Up @@ -90,6 +94,52 @@ public ArrayList<LaneSegment> getLaneSegmentPolygons(){
return laneSegments;
}

public boolean isPedestrian(){
return getLaneTypeString().equals("pedestrian");
}

public String getLaneTypeString(){
if(type == null){
return "Unknown";
}

if(type.getVehicle() != null){
return "roadway";
}else if(type.getCrosswalk() != null){
return "pedestrian";
}else if(type.getBikeLane() != null){
return "roadway";
}else if(type.getSidewalk() != null){
return "pedestrian";
}else if(type.getMedian() != null){
return "roadway";
}else if(type.getStriping() != null){
return "roadway";
}else if(type.getTrackedVehicle() != null){
return "roadway";
}else if(type.getParking() != null){
return "roadway";
}
return "Unknown";
}

public Point getOriginPoint(){
if(this.ingress){
return this.getPoints().getPointN(0);
}else{
LineString points = this.getPoints();
return points.getPointN(points.getNumPoints() -1);
}
}

public Point getDestinationPoint(){
if(!this.ingress){
return this.getPoints().getPointN(0);
}else{
LineString points = this.getPoints();
return points.getPointN(points.getNumPoints() -1);
}
}

public int getId() {
return id;
Expand Down Expand Up @@ -139,6 +189,14 @@ public void setRegion(int region) {
this.region = region;
}

public J2735LaneTypeAttributes getLaneType() {
return type;
}

public void setLaneType(J2735LaneTypeAttributes type) {
this.type = type;
}

public String getLaneAsWkt() {
WKTWriter writer = new WKTWriter(2);
String wktOut = "wkt\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public LaneConnection(Lane ingressLane, Lane egressLane, int connectionId, int s
public LineString calculateConnectingLineString(int numIntermediatePoints){

int egressPointCount = egressLane.getPoints().getNumPoints();
Point startPoint = ingressLane.getPoints().getPointN(0);
Point startPoint = ingressLane.getOriginPoint();
// Point startPoint = ingressLane.getPoints().getPointN(0);
Point leadInPoint = ingressLane.getPoints().getPointN(1);

Point endPoint = egressLane.getPoints().getPointN(egressPointCount-1);
Point endPoint = egressLane.getDestinationPoint();
// Point endPoint = egressLane.getPoints().getPointN(egressPointCount-1);
Point leadOutPoint = egressLane.getPoints().getPointN(egressPointCount-2);


Expand Down Expand Up @@ -95,6 +97,14 @@ public LineString calculateConnectingLineString(int numIntermediatePoints){
return new LineString(sequence, this.ingressLane.getGeometryFactory());
}

public boolean isPedestrianConnection(){
return this.ingressLane.isPedestrian();
}

public boolean crosses(Lane otherLane){
return this.connectingLineString.crosses(otherLane.getPoints());
}

public boolean crosses(LaneConnection otherConnection){
return this.connectingLineString.crosses(otherConnection.getConnectingLineString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ public class SignalStateConflictEvent extends Event{
private int secondConflictingSignalGroup;
private J2735MovementPhaseState secondConflictingSignalState;
private String source;
private int firstIngressLane;
private String firstIngressLaneType;
private int firstEgressLane;
private String firstEgressLaneType;
private int secondIngressLane;
private String secondIngressLaneType;
private int secondEgressLane;
private String secondEgressLaneType;



public SignalStateConflictEvent(){
super("SignalStateConflict");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import us.dot.its.jpo.conflictmonitor.monitor.algorithms.map_spat_message_assessment.MapSpatMessageAssessmentParameters;
import us.dot.its.jpo.conflictmonitor.monitor.algorithms.map_spat_message_assessment.MapSpatMessageAssessmentStreamsAlgorithm;
import us.dot.its.jpo.conflictmonitor.monitor.models.Intersection.Intersection;
import us.dot.its.jpo.conflictmonitor.monitor.models.Intersection.Lane;
import us.dot.its.jpo.conflictmonitor.monitor.models.Intersection.LaneConnection;
import us.dot.its.jpo.conflictmonitor.monitor.models.RegulatorIntersectionId;
import us.dot.its.jpo.conflictmonitor.monitor.models.SpatMap;
Expand All @@ -42,6 +43,7 @@
import us.dot.its.jpo.geojsonconverter.pojos.spat.MovementEvent;
import us.dot.its.jpo.geojsonconverter.pojos.spat.MovementState;
import us.dot.its.jpo.geojsonconverter.pojos.spat.ProcessedSpat;
import us.dot.its.jpo.ode.plugin.j2735.J2735LaneTypeAttributes;
import us.dot.its.jpo.ode.plugin.j2735.J2735MovementPhaseState;

import java.util.*;
Expand Down Expand Up @@ -71,6 +73,11 @@ private J2735MovementPhaseState getSpatEventStateBySignalGroup(ProcessedSpat spa
}
}
}

if(signalGroup == 255){
return J2735MovementPhaseState.PROTECTED_MOVEMENT_ALLOWED;
}

return null;
}

Expand All @@ -92,6 +99,55 @@ private boolean doStatesConflict(J2735MovementPhaseState a, J2735MovementPhaseSt
&& !a.equals(J2735MovementPhaseState.STOP_AND_REMAIN);
}

private boolean isPedestrian(LaneConnection connection){
return mapLaneType(connection.getIngressLane().getLaneType()).equals("pedestrian") || mapLaneType(connection.getEgressLane().getLaneType()).equals("pedestrian");
}

private boolean isPermissiveState(J2735MovementPhaseState state){
return state == J2735MovementPhaseState.PERMISSIVE_MOVEMENT_ALLOWED || state == J2735MovementPhaseState.PERMISSIVE_CLEARANCE;
}

private boolean isProtectedState(J2735MovementPhaseState state){
return state == J2735MovementPhaseState.PROTECTED_MOVEMENT_ALLOWED || state == J2735MovementPhaseState.PROTECTED_CLEARANCE;
}

private boolean isActiveState(J2735MovementPhaseState state){
return state == J2735MovementPhaseState.PERMISSIVE_CLEARANCE || state == J2735MovementPhaseState.PERMISSIVE_MOVEMENT_ALLOWED || state == J2735MovementPhaseState.PROTECTED_CLEARANCE || state == J2735MovementPhaseState.PROTECTED_MOVEMENT_ALLOWED;
}

private boolean doesLaneLaneConnectionConflict(Lane lane, int laneSignalGroup, LaneConnection connection, ProcessedSpat spat){
J2735MovementPhaseState laneState = getSpatEventStateBySignalGroup(spat, laneSignalGroup);
J2735MovementPhaseState connectionState = getSpatEventStateBySignalGroup(spat, connection.getSignalGroup());

if(isActiveState(laneState) && !isPedestrian(connection) && isActiveState(connectionState)){ // Should only apply for designed near side movements
return true;
}

return false;
}

public String mapLaneType(J2735LaneTypeAttributes attributes){
if(attributes.getVehicle() != null){
return "roadway";
}else if(attributes.getCrosswalk() != null){
return "pedestrian";
}else if(attributes.getBikeLane() != null){
return "roadway";
}else if(attributes.getSidewalk() != null){
return "pedestrian";
}else if(attributes.getMedian() != null){
return "roadway";
}else if(attributes.getStriping() != null){
return "roadway";
}else if(attributes.getTrackedVehicle() != null){
return "roadway";
}else if(attributes.getParking() != null){
return "roadway";
}
return "Unknown";
}


public Topology buildTopology() {

// Populate concurrent permissive allowed from intersection-level config
Expand All @@ -118,8 +174,6 @@ public Topology buildTopology() {
us.dot.its.jpo.geojsonconverter.serialization.JsonSerdes.ProcessedMapGeoJson()));




// For intersection reference alignment, re-key to RSU-only key to test if intersection ID and region match between
// MAP and SPaTs from the same RSU
KTable<String, ProcessedMap<LineString>> mapKTableRsuKey =
Expand Down Expand Up @@ -341,12 +395,14 @@ public Topology buildTopology() {

Intersection intersection = Intersection.fromProcessedMap(map);
ArrayList<LaneConnection> connections = intersection.getLaneConnections();

ArrayList<Lane> pedestrianLanes = intersection.getPedestrianLanes();



for (int i = 0; i < connections.size(); i++) {
LaneConnection firstConnection = connections.get(i);

// Compare Lane Connections with one another
for (int j = i + 1; j < connections.size(); j++) {
LaneConnection secondConnection = connections.get(j);

Expand All @@ -361,7 +417,8 @@ public Topology buildTopology() {
continue;
}

if (firstConnection.crosses(secondConnection) && firstConnection.getIngressLane() != secondConnection.getIngressLane()) {
// Compare between multiple lane connections
if (!firstConnection.isPedestrianConnection() && !secondConnection.isPedestrianConnection() && firstConnection.crosses(secondConnection) && firstConnection.getIngressLane() != secondConnection.getIngressLane()) {

J2735MovementPhaseState firstState = getSpatEventStateBySignalGroup(spat,
firstConnection.getSignalGroup());
Expand All @@ -384,6 +441,16 @@ public Topology buildTopology() {
event.setSecondConflictingSignalState(secondState);
event.setSource(key.toString());

event.setFirstIngressLane(firstConnection.getIngressLane().getId());
event.setFirstEgressLane(firstConnection.getEgressLane().getId());
event.setFirstIngressLaneType(firstConnection.getIngressLane().getLaneTypeString());
event.setFirstEgressLaneType(firstConnection.getEgressLane().getLaneTypeString());

event.setSecondIngressLane(secondConnection.getIngressLane().getId());
event.setSecondEgressLane(secondConnection.getEgressLane().getId());
event.setSecondIngressLaneType(secondConnection.getIngressLane().getLaneTypeString());
event.setSecondEgressLaneType(secondConnection.getEgressLane().getLaneTypeString());

if (firstState.equals(J2735MovementPhaseState.PROTECTED_MOVEMENT_ALLOWED)
|| firstState.equals(J2735MovementPhaseState.PROTECTED_CLEARANCE)) {
event.setConflictType(secondState);
Expand All @@ -398,6 +465,52 @@ public Topology buildTopology() {
}
}

// Compare Lane Connections to Pedestrian Lanes
for (Lane pedLane : pedestrianLanes) {
Set<Integer> pedLaneSignalGroups = intersection.getSignalGroupsForIngressLane(pedLane);
if(pedLaneSignalGroups.size() > 0){
for(LaneConnection connection : connections){
if(connection.crosses(pedLane)){
for(Integer pedLaneSignalGroup : pedLaneSignalGroups){
if(doesLaneLaneConnectionConflict(pedLane, pedLaneSignalGroup, connection, spat)){
J2735MovementPhaseState laneState = getSpatEventStateBySignalGroup(spat, pedLaneSignalGroup);
J2735MovementPhaseState connectionState = getSpatEventStateBySignalGroup(spat, connection.getSignalGroup());

SignalStateConflictEvent event = new SignalStateConflictEvent();
event.setTimestamp(SpatTimestampExtractor.getSpatTimestamp(spat));
event.setRoadRegulatorID(intersection.getRoadRegulatorId());
event.setIntersectionID(intersection.getIntersectionId());
event.setFirstConflictingSignalGroup(pedLaneSignalGroup);
event.setSecondConflictingSignalGroup(connection.getSignalGroup());
event.setFirstConflictingSignalState(laneState);
event.setSecondConflictingSignalState(connectionState);
event.setSource(key.toString());

event.setFirstIngressLane(pedLane.getId());
event.setFirstEgressLane(pedLane.getId());
event.setFirstIngressLaneType(mapLaneType(pedLane.getLaneType()));
event.setFirstEgressLaneType(mapLaneType(pedLane.getLaneType()));

event.setSecondIngressLane(connection.getIngressLane().getId());
event.setSecondEgressLane(connection.getEgressLane().getId());
event.setSecondIngressLaneType(mapLaneType(connection.getIngressLane().getLaneType()));
event.setSecondEgressLaneType(mapLaneType(connection.getEgressLane().getLaneType()));

if (isProtectedState(laneState)) {
event.setConflictType(connectionState);
} else {
event.setConflictType(laneState);
}

System.out.println("Generating Event" + event);
events.add(new KeyValue<String, SignalStateConflictEvent>(key.toString(), event));
}
}
}
}
}
}

return events;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import us.dot.its.jpo.conflictmonitor.monitor.serialization.JsonSerdes;
import us.dot.its.jpo.conflictmonitor.monitor.topologies.MapSpatMessageAssessmentTopology;
import us.dot.its.jpo.conflictmonitor.monitor.algorithms.map_spat_message_assessment.MapSpatMessageAssessmentParameters;
import us.dot.its.jpo.geojsonconverter.partitioner.RsuIdKey;
import us.dot.its.jpo.geojsonconverter.partitioner.RsuIntersectionKey;

import static org.junit.Assert.assertTrue;
Expand Down
Loading
Loading