# Crossroads Navigating
## Authors
* Tianjian Song (r0815584)
* Zhongxi Li (r0866180)
## Context
We are trying to simulate the scenario that the robot is at a crossroad.
## Domain Knowledge
The knowledges involved in our reason are traffic rules, human ethics and environment.
## Map Information
### Map
Below is the simulation map where the robot runs into a crossroad. 
## Situation
1. If the traffic lights are present, which traffic light is the right one for the upcoming robot? What is its state?
There could be multiple traffic lights visible to the robot in a crossroads, but we know that robot should only focus on one of the right lights. Detecting the traffic light and checking its __state__ (yellow, red, green) can be done by the computer vision algorithms. In addition, the robot should also decide __which__ one to follow and explain why does it make such a decision?
2. Priority Rules from Traffic Rule
Though __traffic rules__ are not perceivable, but they can be already stored in the robot meaning that it can be the arguments linked to the robot's decision making software. There are certainly various of priority rules, for example, if the traffic lights are not present, robot needs to comply with the Priority to the right.
## Situation Reasoning
We consider the robot entering the crossroad is our main robot, representing a car.
First thing our main robot enter the crossroad is checking the traffic light presence and its target type. Because there could be lights control the pedestrians and no lights for the car. Once our robot knows that there are no traffic lights for cars, robot knows that the current crossroad is under Priority to the Right.
It will slow down for safety reason and it starts putting more computation power analyzing the situation on the right incoming road.
If another robot come from the right side and current crossroad follows the rule: Priority to the Right, the robot will detect its location, speed and its intention. The intention of the robot can be represented by its turing_light_system. And there are two situations requires robot to stop:
1. *Stop Situation 1*: If CV algorithm detects that the first right incoming robot turns on its __left turn light or does not turn on any light__. Meaning that our main robot A must stop early before disturbing their way. The exact constraint is that robot cannot pass the __leftmost boundary__ of the right road whose direction is towards crossroad.
2. *Stop Situation 2*: If CV algorithm detects that the first right incoming robot turns on its __right turn light__. It means that it is trying to join the road of our main robot. Then the main robot can slow down and stop later. Just leaving the right robots space to do a right turn is enough and our main robot can go over the left boundary. The exact stopping plot should minimally disturb the other robots/cars and give the right turning robot enough space. The exact spot can be found based on the landmarks.
Also robot needs to know when to start its engine again.
1. *Restart Situation 1*: Generally speaking we say that as long as there is no right incoming robot that is approaching to the crossroad within certain distance, then our main robot can continue. The distance threshold can be set as a hyperparameter, like 50m.
2. *Restart Situation 2*: After one robot from the right side finishes its left turn, there is another robot tries to turn right. Of course it is driving on the right side of the right road. In this case, our robot should move forward a bit to the spot indicated in *stop situation 2*.
Robot higly rely on its CV algorithm system to differeentiate situations and decide the stop spot.
## Entities
**Robot:**
* Property:
* ID: robots are represented by their specific id.
* Role_in_traffic: car
```json
{
"@type": "https://example.org/robot",
"@id": "robot_A",
"role_in_traffic": "car"
}
```
```json
{
"@type": "https://example.org/robot",
"@id": "robot_B",
"role_in_traffic": "car"
}
```
**Traffic_Light:**
* Property:
* ID
* Type: For cars, for pedestrians, or for bicycles.
```json
{
"@type": "https://example.org/traffic_light",
"@id": "traffic_light_A",
"Target_of_Traffic_Light": "car"
}
```
**Traffic_Rule:**
* Property:
* ID: indicate which rules it is. Can be divided into more details.
```json
{
"@type": "https://example.org/traffic_rule",
"@id": "Priority_to_Right"
}
```
```json
{
"@type": "https://example.org/traffic_rule",
"@id": "Traffic_Light_Control"
}
```
**Crossroad:**
* Property:
* ID
```json
{
"@type": "https://example.org/crossroad",
"@id": "Crossroad_A"
}
```
## Relations
**Robot_In_Crossroad**
* Argument:
* Robot
* Road
* Crossroad
* Description: The robot can enter/exit the crossroad from one of the roads.
```json
{
"@type": "https://example.org/In_Crossroad",
"@id": "in_crossroad_A",
"motion": "enter",
"arguments": {
"robot": {"@id": "robot_A"},
"crossroad": {"@id": "crossroad_A"}
}
}
```
**On_The_Right**
* Argument:
* Crossroad
* Robots
* Description: The geometric relation of different roads in a crossroad.
```json
{
"@type": "https://example.org/on_the_right",
"@id": "on_the_right_A",
"arguments": {
"crossroad": {"@id": "crossroad_A"},
"set_of_robots": {
"robots": [
{"@id": "robot_A"},
{"@id": "robot_B"}
]}
}
}
```
**Traffic_Light_Presence_Control:**
* Argument:
* Traffic_Light
* Crossroad
* Description: This relation can be obtained by human inputs or algorithms that take into account the geometric information (e.g. orientations, positions) of the traffic lights and the crossroad.
```json
{
"@type": "https://example.org/traffic_light_Presence",
"@id": "traffic_light_Presence_A",
"State": "Presence_And_HasControl",
"arguments": {
"traffic_light": {"@id": "traffic_light_A"},
"crossroad": {"@id": "crossroad_A"}
}
}
```
**Crossroad_Traffic_Rule**:
* Arguments:
* Crossroad
* Traffic_Rule
* Traffic_Light_Presence
* Description: This relation represents which traffic rule is applied to a cross road. For example, for crossroad without traffic lights, vehicles need to comply the Priority of the right. And for those with the traffic lights, vehicles comply with the signal of the lights.
```json
{
"@type": "https://example.org/crossroad_traffic_rule",
"@id": "crossroad_traffic_rule_A",
"arguments": {
"crossroad": {"@id": "crossroad_A"},
"traffic_light_presence":
{"@id": "traffic_light_Presence_A"},
"traffic_rule": {"@id": "Priority_to_Right"}
}
}
```
**Robot_Motion_on_Crossroad**:
* Arguments:
* Robot
* Robot Perception
* Properties:
* robot_motion (continue_navigation, stop)
```json
{
"@type": "https://example.org/Robot_Motion",
"@id": "Robot_Motion",
"Motion": "Stop",
"arguments": {
"Robot": {"@id": "Robot_A"}
"Robot_Perception": {"@id": "Robot_Perception"}
}
}
```
**Robot_Perception**:
* Arguments:
* Robot
* Car_Detection
* Blinker_Detection
* Traffic_Light_Detection
* Stop_Lines_Detection
```json
{
"@type": "https://example.org/Robot_Perception",
"@id": "Robot_Perception",
"arguments": {
"Robot": {"@id": "Robot_A"},
"Car_Detection": {"@id": "Car_Perception_A"},
"Blinker_Detection": {"@id": "Blinker_Perception"}
}
}
```
**Car_Detection**:
* Arguments:
* Robot_In_Crossroad
* On_The_Right
* Properties:
* Position of the car on the right
Detection of cars on the right.
```json
{
"@type": "https://example.org/Car_Perception",
"@id": "Car_Perception_A",
"Position_of_Cars": ["Position1"],
"arguments": {
"robot_in_crossroad": {"@id": "robot_in_crossroad_A"},
"on_the_right": {"@id": "on_the_right_A"}
}
}
```
**Blinker_Detection**:
* Arguments:
* Car_Detection
* Properties:
* Intension of the car on the right
Do inference on the intension (turn left, turn right, go straight) of the car on the right based on detection of its blinkers.
```json
{
"@type": "https://example.org/Blinker_Perception",
"@id": "Blinker_Perception",
"intension_of_cars": ["turn_left"],
"arguments": {
"car_perception": {"@id": "Car_Perception_A"}
}
}
```
**Crossroad_Strategy**:
* Arguments:
* Robot_In_Crossroad
* Crossroad_Traffic_Rule
* Robot_Motion
* Robot_Perception
* Description: This relation represents the strategy robot needs to take based on the current situation.
```json
{
"@type": "https://example.org/adjustment",
"@id": "crossroad_traffic_rule_A",
"arguments": {
"robot_in_crossroad":
{"@id": "in_crossroad_A"},
"crossroad_traffic_rule":
{"@id": "crossroad_traffic_rule_A"},
"robot_motion":
{"@id": "on_the_right_A"},
"robot_perception":
{"@id": "robot_perception_A"}
}
}
```
## Constraints
**Stop_Before_Stop_Line**
* Arguments:
* Robot_In_Crossroad
* Crossroad_Connection
* Robot_Motion
* Robot_Perception
**Stop_Before_Obstructing_Road_On_The_Right**
* Arguments:
* Robot_In_Crossroad
* Crossroad_Connection
* Robot_Motion
* Robot_Perception
* Properties:
* Safe_Distance
**Restart_For_Traffic_Light_Permission**
* Arguments:
* Robot_In_Crossroad
* Crossroad_Connection
* Robot_Motion
* Robot_Perception
**Restart_For_No_Incoming_Cars_On_The_Right**
* Arguments:
* Robot_In_Crossroad
* Crossroad_Connection
* Robot_Motion
* Robot_Perception
## Reference
[Traffic_rules.html](https://rijbewijs-online.be/en/belgium/traffic-rules/priority-rules)
Different rules are applied to crossroad with and without traffic lights.
[Priority to the right](https://en.wikipedia.org/wiki/Priority_to_the_right)