Reputation: 25
I am trying to simulate an overtaking scenario by editing the existing highway_overtaking.wbt in Webots to observe the indicator lights turn on/off before switching lanes. How do I use the Driver library to do so?
In the modified scenario I currently have just 3 cars in the middle lane, with the grey Lincoln car in between the other 2 cars. I used the setIndicator() function to set the Indicator lights (as shown in code snippet below) But I do not observe any change when the Lincoln car is overtaking the car in front.
Following is the modified snippet of code from the highway_overtaking.py file
if (is_vehicle_on_side("left") and
(not safeOvertake or sensors["rear left"].getValue() > 0.8 * sensors["rear left"].getMaxValue()) and
sensors["left"].getValue() > 0.8 * sensors["left"].getMaxValue() and
currentLane < 2):
driver.setIndicator(1)
currentLane += 1
overtakingSide = 'right'
lane_change = True
elif (is_vehicle_on_side("right") and
(not safeOvertake or sensors["rear right"].getValue() > 0.8 * sensors["rear right"].getMaxValue()) and
sensors["right"].getValue() > 0.8 * sensors["right"].getMaxValue() and
currentLane > 0):
driver.setIndicator(2)
currentLane -= 1
overtakingSide = 'left'
lane_change = True
I read the value of the indicator using getIndicator() function and observed that the Indicator value was changed from 0 to 1 when I set it to 1. But I do not observe the Indicator lights changing color on the window. Please help!
Upvotes: 1
Views: 103
Reputation: 1733
This is due to the auto-disabling behavior of the indicators (when you turn the steering wheel in the opposite direction of the indicator, the indicator switches off automatically). This is causing issues in this simulation because the commands send to the steering wheels are quite noisy.
One simple solution to fix it is to disable this auto-disabling mechanism with the 'enableIndicatorAutoDisabling' function (https://www.cyberbotics.com/doc/automobile/car-library?tab=python#wbu_car_enable_indicator_auto_disabling).
However, in order to use this function, you should use the Car class instead of the Driver one (the Car class inherits from the Driver class). This requires to add the corresponding import:
from vehicle import Car
And call the Car constructor instead of the Driver one:
driver = Car()
One other minor detail, you should not use integer value with the 'setIndicator' but instead one of the pre-defined value such as:
driver.setIndicator(Driver.INDICATOR_OFF)
driver.setIndicator(Driver.INDICATOR_RIGHT)
driver.setIndicator(Driver.INDICATOR_LEFT)
Upvotes: 1