Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev ekshita #19

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Dev ekshita #19

wants to merge 6 commits into from

Conversation

ekshishetty
Copy link
Contributor

No description provided.

ekshishetty and others added 6 commits November 29, 2023 13:31
CLEANUP 1  Exchanged underscore attributes like _max_speed with config.max_speed.
pedastrians/ sudden obstacle
sudden stop/ change in road
Copy link
Owner

@Daraan Daraan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, Please resolve the conflicts so it can be merged without breaking things.
It will be easier if you merge main into your branch beforehand.


Secondly, I think some parts make no sense or need further explenation to make sense to me. See below.

Comment on lines +144 to +246

def main():
global spawner, vehicles

# Initialise the class for vehicle spawning
spawner = VehicleSpawner('VehicleSpawning/config/vehicle_spawn.yaml')
spawner.initialize_carla_service()
world, world_map = spawner.setup_world()
ego_bp, car_bp, driver1, spawn_points, rule_interpreter = spawner.prepare_vehicles(world)

# Spawn vehicles and assign drivers
ego = spawner.spawn_vehicles(world, ego_bp, spawn_points)
ego_vehicle = spawner.assign_drivers(ego, driver1)

# Spawn traffic
vehicles, tm = spawner.spawn_traffic(world, car_bp, spawn_points, driver1, ego.vehicle)

# Initialize loop variables
world.tick()
road_lane_ids = get_all_road_lane_ids(world_map=world.get_map())
t_end = time.time() + 10000

# Create a thread for the camera functionality
camera_thread = threading.Thread(target=camera_function, args=(ego_vehicle, world))
camera_thread.start()

# Initialize matrix thread
data_matrix = DataMatrix(ego_vehicle, world, world_map, road_lane_ids)

while time.time() < t_end:
try:
pass
# Retrieve the latest matrix from the matrix thread
matrix = data_matrix.getMatrix()

if matrix is None:
continue

(i_car, j_car) = get_car_coords(matrix)
results = rule_interpreter.execute_all_functions(driver1, matrix, i_car, j_car, tm)

overtake_direction = 0
# Random lane change
overtake_choice = random.randint(1, 100)
if overtake_choice <= driver1.risky_overtake_chance:
if matrix[i_car + 1][j_car + 1] == 3 and matrix[i_car - 1][j_car + 1] == 3:
continue
elif matrix[i_car + 1][j_car + 1] == 3:
tm.force_overtake(100, -1)
elif matrix[i_car - 1][j_car + 1] == 3:
tm.force_overtake(100, 1)
else:
overtake_direction = random.choice([-1, 1])
tm.force_overtake(100, overtake_direction)
print("Random lane change")
continue

if matrix[i_car + 1][j_car + 1] == 0:
# print("can overtake on right")
overtake_direction = 1
if matrix[i_car - 1][j_car + 1] == 0:
# print("can overtake on left")
overtake_direction = -1

# Overtake logic
if matrix[i_car][j_car + 1] == 2 or matrix[i_car][j_car + 2] == 2:
overtake_choice = random.randint(1, 100)
if overtake_choice >= driver1.overtake_mistake_chance:
tm.force_overtake(100, overtake_direction)
print("overtake!")
continue
else:
print("overtake averted by chance")

# Brake logic
if matrix[i_car][j_car + 1] == 2:
# Check distance to obstacle
distance_to_obstacle = j_car + 1
if distance_to_obstacle < MIN_DISTANCE_TO_BRAKE:
# Apply emergency braking
driver1.vehicle.setBrake(1) # Adjust brake intensity as needed
print("Emergency braking activated!")

except Exception as e:
print(e.__str__())

input("press any key to end...")
data_matrix.stop()
camera_thread.join()


if __name__ == '__main__':
try:
main()
finally:
try:
if spawner and spawner.client:
spawner.client.apply_batch([carla.command.DestroyActor(x.actor) for x in vehicles])
except NameError:
pass
Copy link
Owner

@Daraan Daraan Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block is duplicated code is this wanted?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle conflicts.

lunatic_agent.py Outdated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an old file. Please do not reintroduce.

Comment on lines +14 to +30
spawner = None
vehicles = []
import random
import threading
import time
from asyncio import Queue

import carla

from DataGathering.informationUtils import get_all_road_lane_ids
from DataGathering.matrix_wrap import get_car_coords
from DataGathering.run_matrix import DataMatrix
from utils.Camera import camera_function
from VehicleSpawning.vehicle_spawner import VehicleSpawner

spawner = None
vehicles = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated code

print("overtake averted by chance")

# Brake logic
if matrix[i_car][j_car + 1] == 2:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could conflict with above code

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if it is not in the top-level of the repository. Please move to examples (maybe change name).

print("overtake averted by chance")

# Brake logic for sudden stop of vehicle ahead or sudden change in road conditions
if matrix[i_car][j_car + 1] == 4 or matrix[i_car][j_car + 1] == 5:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the ==4 and ==5 represent?

To my knowledge these values do not exist.

Comment on lines +97 to +98
distance_to_obstacle = j_car + 1
if distance_to_obstacle < MIN_DISTANCE_TO_BRAKE:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other review about this line. Makes no sense in my opinion.

if distance_to_obstacle < MIN_DISTANCE_TO_BRAKE:
# Apply emergency braking
driver1.vehicle.setBrake(1) # Adjust brake intensity as needed
if matrix[i_car][j_car + 1] == 4:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other review about entry 4 and 5

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its okay to overwrite this file how you wish but make sure that it still works after merge, i.e. that the imports align with main.

NOTE: I have not updated this to the final version of Bogdan which introduces more changes.

@Daraan Daraan added the invalid This doesn't seem right label Apr 11, 2024
@Daraan Daraan force-pushed the main branch 6 times, most recently from c42e61a to 2bffb48 Compare July 15, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants