Helo everyone,
I would like to help with Traffic Control in GUI. I'd like to program a basic crossroad, where cars are generated atuomatically at the beginning of the road. When a car comes to the traffic light, the object(car) decides whether it's green or red light. Object can move only straight, they doesn't have to turn. for a better understanding I attach a video of how it can work

6 commentaires

Rik
Rik le 15 Mar 2020
This is a project with many steps. Which step is causing you problems?
Miroslav Jiránek
Miroslav Jiránek le 15 Mar 2020
First of all, I have to create crossroad with autogenrated cars at the beginning of the roads. Cars should be monitored for location
Rik
Rik le 16 Mar 2020
That is still a high level description. How did you try to create the crossing? How are you implementing a car?
Miroslav Jiránek
Miroslav Jiránek le 17 Mar 2020
Modifié(e) : Miroslav Jiránek le 17 Mar 2020
I still don't know how to implement a car. I will definitely define it as a class with some properties, especially on which road the car is. I'll have 2 roads and 2 directions for both roads(something like this)
First of all, I have to program automatic random car generation on all four directions. For example: first car will be generated on road A-B, then the second car will be generated on road E-F and so on. Cars can go only straight(no turning right, left). when the car reaches the end point, it will disappears
Rik
Rik le 17 Mar 2020
Do things step by step. How are you going to draw this in Matlab? You can make it from scratch, but you could also simply load the image. I would suggest having a separate image for a car, which you could rotate to have a car for the other road. If you then add the image of the car to an axes with the image function you can change the Position property to simulate the movement.
Miroslav Jiránek
Miroslav Jiránek le 18 Mar 2020
Modifié(e) : Miroslav Jiránek le 19 Mar 2020
I continued a little further. Now I face some complications which I don't know how to continue. I've already loaded the background image of the crossaroad. I also load the image of the car(only one so far) which I have successfully managed to move.
And the next question is: My vision for this project is to randomly generate cars on all 4 roads. so together there can be a maximum of 16 cars (4 for each road). can you suggest any idea how to program this?
clc
clear
I=imread('C:\Users\Miroslav\Desktop\Crossroad\cross_matl.png');
hi = imagesc(I)
hold on
car=imread('C:\Users\Miroslav\Desktop\Crossroad\blue_car3.png');
Nt=10; % Number of time steps
xval=450;
ymin=900;
ymax=-75;
Nt=500; % Number of time steps
xval=450;
ymin=900;
ymax=-75;
y=linspace(ymin,ymax,Nt);
hCar = imagesc('CData',car,'XData',[450],'YData',[y(1)])
for it=1:Nt
set(hCar,'YData',[y(it)]);
pause(0.01);
end

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by