Bùi Dũng
Bùi Dũng

Reputation: 79

how to see the color identification signal lights?

layout intersections with traffic lights. I want the car to stop when the red lights and the lights go xanh.thi what I should use for car algorithm can recognize the color of the lightsenter image description here

I have used light layout algorithm as follows

to draw-stop-light

  ifelse stop-light = "north"
  [ 

      ask patch -7 12 [set pcolor green ]
      ask patch 10 10 [ set pcolor red ]
      ask patch -10 -10 [ set pcolor red ]
    ]
    [ 
      ask patch -7 12 [ set pcolor red ]
      ask patch 10 10 [ set pcolor green ]
      ask patch -10 -10 [ set pcolor green ]
    ]
end

Upvotes: 0

Views: 139

Answers (2)

Seth Tisue
Seth Tisue

Reputation: 30453

patch-right-and-ahead (http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch-lr-and-ahead) could be useful here. Perhaps something like:

if [pcolor] of patch-right-and-ahead 90 1 = red
  [ set speed 0 ]

Upvotes: 1

JenB
JenB

Reputation: 17678

This is really a question better suited to the NetLogo users group here than Stack Overflow since you are asking how to program a poorly defined specification. For example, the users group may be able to point you to a similar model. Stack Overflow is really about fixing specific problems with your code. However, here's something to get you started until the question gets deleted.

Break down what you want to happen into very small steps and then code each step. The steps will be something like:

  1. When the car gets near the intersection, check to see what colour the traffic light is
  2. If the light is red, remember to stop at the intersection
  3. Stop at the intersection if required
  4. If at the intersection, wait until the light turns green then go

Do NOT try to write the whole thing. Instead, write one bit at a time and test is to see if it works. Here is some approximate code for the first bit:

ask cars
[ ifelse heading = 180 and ycor > 20 and ycor < 25 and not stop-flag
  [ if [ pcolor of patch -7 12 ] = red [ set stop-flag true ] ]
  [ ... (cars from other directions)
]
ask cars
[ forward speed
  if stop-flag and ... (on intersection patches)
  [ ... (move backwards to be outside the intersection)
    set stop-flag false
  ]
]

Upvotes: 1

Related Questions