driver = Driver()

# get the time step of the current world.
timestep = int(driver.getBasicTimeStep())

Max_hizi = 80

ileri_hizi = 20
fren = 0
sayici = 0
plot = 10

camera = driver.getCamera("camera")
Camera.enable(camera, timestep)

lms291 = driver.getLidar("Sick LMS 291")
Lidar.enable(lms291, timestep)

lms291_yatay = Lidar.getHorizontalResolution(lms291)

fig = plt.figure(figsize=(3, 3))

# Main loop:
# - perform simulation steps until Webots is stopping the controller
while driver.step() != -1:

    Camera.getImage(camera)
    Camera.saveImage(camera, "camera.png", 1)
    frame = cv2.imread("camera.png")
    #cv2.imshow("Camera",frame)
    #cv2.waitKey(1)
from controller import Camera
from vehicle import Driver
import warnings

warnings.filterwarnings("ignore")
import numpy as np

DEBUG_FLAG = True
DEBUG_FLAG_OBJ = False

driver = Driver()

timestep = int(driver.getBasicTimeStep())

lidar = driver.getLidar('Sick LMS 291')
lidar.enable(10)

accelerometer = driver.getAccelerometer("accelerometer")
accelerometer.enable(timestep)

# accelerometer = driver.getAccelerometer("gyro")
# accelerometer.enable(timestep)
# print(type(accelerometer))

front_camera = driver.getCamera("front_camera")
front_camera.enable(10)
#front_camera.recognitionEnable(10)

back_camera = driver.getCamera("rear_camera")
#  from controller import Robot, Motor, DistanceSensor
from controller import Robot, Camera, Motor, DistanceSensor
import numpy as np
import cv2 as cv
import math
import matplotlib.pyplot as plt
from vehicle import Driver

MAKEPLOT = False
 
# create the Robot instance.
#robot = Robot()
robot = Driver()
front_camera = robot.getCamera("front_camera")
rear_camera = robot.getCamera("rear_camera")
lidar = robot.getLidar("Sick LMS 291")

#for att in dir(robot):
#    print(att,getattr(robot,att))
# get the time step of the current world.
timestep = int(robot.getBasicTimeStep())
print(timestep)
#print(dir(robot))

# You should insert a getDevice-like function in order to get the
#instance of a device of the robot. Something like:
 # motor = robot.getMotor('motorname')
 # ds = robot.getDistanceSensor('dsname')
 # ds.enable(timestep)

import math

TIME_STEP = 64  # ms
MAX_SPEED = 100  # km/h

driver = Driver()

speedFoward = 0.1 * MAX_SPEED  # km/h
speedBrake = 0  # km/h
cont = 0
plot = 10

cameraRGB = driver.getCamera('camera')
Camera.enable(cameraRGB, TIME_STEP)

lms291 = driver.getLidar('Sick LMS 291')
print(lms291)
Lidar.enable(lms291, TIME_STEP)
lms291_width = Lidar.getHorizontalResolution(lms291)
print(lms291_width)

fig = plt.figure(figsize=(3, 3))

while driver.step() != -1:

    if cont < 1000:
        driver.setDippedBeams(True)  # farol ligado
        driver.setIndicator(0)  # 0 -> OFF  1 -> Right   2 -> Left
        driver.setCruisingSpeed(speedFoward)  # acelerador (velocidade)
        driver.setSteeringAngle(0.0)  # volante (giro)
    elif cont > 1000 and cont < 1500: