You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
7.8 KiB

#### Smart Road
### Objectives
Do you remember the [`road_intersection`](https://public.01-edu.org/subjects/road_intersection/) raid done in the Rust Piscine? Well, you
4 years ago
will have to create another traffic control strategy and its simulation. However, this time it will have to be done without traffic lights and with a smart intersection management strategy.
4 years ago
Most of the time overused intersections might lead to serious traffic jams on multiple roads, which wastes drivers'time and money, and also causes unnecessary air pollution. Additionally, according to a study from the National Highway Traffic Safety administration in the U.S., it is reported that about 96% of the intersection-related crashes had critical reasons to be the drivers fault, such as inadequate surveillance, false assumption of other actions, and turns with obstructed view.
4 years ago
[Autonomous vehicles](https://en.wikipedia.org/wiki/Self-driving_car) (AVs) are a promising solution to traffic accidents. An optimistic prediction is that AVs will be publicly available in the next decade, and thus traffic issues related to autonomous vehicles are also being extensively investigated.
Current intersection management strategies, such as the traditional traffic light and other more advanced methods are designed exclusively
for human drivers. With the rapid development of AVs, new traffic strategies must be taken into account.\
4 years ago
This is where you come in. You will have to create this new traffic strategy algorithm, so that AVs can pass an intersection without any
collisions and with a minimum of traffic congestion.
### Instructions
#### **Intersection**
There are various shapes of intersections, we will focus on the widely seen cross intersection, where each lane has a different route:
- `r`, turning right
- `s`, straight ahead
- `l`, turning left
```console
| | | | | | |
| | | | | | |
| | | | | | |
|r | s | l | | | |
_______________| ← | ↓ | → | | | |________________
| ↑ r
_______________ | ________________
| ← s
_______________ | ________________
| ↓ l
___________________________|____________________________
l ↑ |
_______________ | ________________
s → |
_______________ | ________________
r ↓ |
_______________ | ________________
| | | | ← | ↑ | → |
| | | | l | s | r |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
```
The simplicity of this intersection is that each lane has only one outgoing direction, that is, the route of the vehicle in the
4 years ago
intersection area can only be represented by the corresponding lane.
---
#### **Vehicles**
```console
______
/|_||_\`.__
=`-(_)--(_)-'
```
4 years ago
As stated above you will be considering that all vehicles are autonomous (AVs), also known as self-driving cars.
4 years ago
You will have to implement the physics for this type of vehicles by taking into account the following rules :
1. AVs driving on a lane with a **given route** must follow the direction of
4 years ago
that route, it is not possible for the AVs to change lanes or route.
4 years ago
2. AVs must have at least 3 different velocities, therefore the **smart intersection system** can control the velocity of the vehicle.\
4 years ago
This will be the way of controlling the current velocity/time/distance (depending on the algorithm you implement) of the AVs.
4 years ago
3. Each AV must respect a safety distance from other AVs.\
4 years ago
If it is driving with a high velocity and encounters another vehicle, it must detect that vehicle and keep a safe distance from it. It should not collide!
You are free to decide what is the safety distance but it must a strictly positive value.
4. Other vehicles such as emergency vehicles are not considered in this project.
5. You must implement physics for the vehicle, such as `velocity = distance / time`. Each vehicle must have a :
4 years ago
- `time`, this will be the time that the AV takes to leave the intersection
- `distance`, this will be the distance that the AV takes to leave the intersection
- `velocity`, this will be the speed of the AV at current time
---
#### **Animation**
Animation is required for this project, you will have to find some assets for the vehicles and roads. Here are some assets for this:
- [limezu](https://limezu.itch.io/)
- [finalbossblue](http://finalbossblues.com/timefantasy/free-graphics/).
- [mobilegamegraphics](https://mobilegamegraphics.com/product-category/all_products/freestuff/).
- [spriters-resource](https://www.spriters-resource.com/).
Animation is not just rendering an image into the canvas. By using assets you get to decide your "world coordinate system"
4 years ago
for the rendered image and therefore you create your own animation. But this is not enough, basically you must animate while moving.
A simple example of movement animation is imagining a vehicle with a route of `r`. This means that the vehicle arrives at the
intersection and turns right. If we render just an image of the vehicle facing down and it arrives to the point of turning, the rendered image
will continue to be facing down and not right, like it should be.
Concluding, you must animate the vehicle while moving. This way manipulating the image so that it appears that the vehicle is turning.
---
#### **Commands**
You will have to implement several commands so that the simulation can be well tested. The commands to be implemented are the following :
1. The generating of vehicles must be done using the keyboard events. It must be able to randomly generate vehicles with different routes. The keys to be used are the following :
- `Arrow Up`, generate vehicles from south to north.
- `Arrow Down`, generate vehicles from north to south.
- `Arrow Right`, generate vehicles from west to east.
- `Arrow Left`, generate vehicles from east to west.
4 years ago
2. It must also be possible to use the key `R` to continually generate random vehicles (using the game loop).
3. The `Esc` key must finish the simulation and generate a window with all statistics (you can see more about the statistics on its section).
4. When spamming the same key the vehicles should not be generated all at the same time, in other words, the vehicles should not be created on top of each other.
---
#### **Statistics**
4 years ago
Your program must be able to generate statistics, as stated above, this must be displayed in a window right after the user tries to exit the simulation.
The statistics must include:
- Max number of vehicles that passed the intersection
- Collisions if there was any
4 years ago
- Max velocity of all vehicles (Display the fastest speed achieved)
- Min velocity of all vehicles (Dislay the slowest speed reached)
4 years ago
- Max time that the vehicles took to pass the intersection (for all vehicles, display the one that took more time)
4 years ago
- The time starts to count whenever the vehicle is detected by the **smart intersection algorithm** until the end of the intersection, which is when the vehicle is removed from the canvas.
4 years ago
- Min time that the vehicles took to pass the intersection (for all vehicles, display the one that took less time)
4 years ago
- Close calls, this is when both vehicles pass each other with a violation of the safe distance.
---
### Example
4 years ago
You can see an example [here](https://youtu.be/_z8WDX_YS9k).
---
### Bonus
You can implement the following optional features:
- Create your own assets for the animation of the vehicles
- Add more statistics
This project will help you learn about:
- Rust programming language
- [sdl2](https://docs.rs/sdl2/0.34.3/sdl2/)
- Animation
- Algorithm
- Mathematics
- Events