-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Dev ekshita #19
Conversation
CLEANUP 1 Exchanged underscore attributes like _max_speed with config.max_speed.
pedastrians/ sudden obstacle
sudden stop/ change in road
There was a problem hiding this 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.
|
||
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 |
There was a problem hiding this comment.
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?
agents/lunatic_agent.py
Outdated
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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 = [] |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
distance_to_obstacle = j_car + 1 | ||
if distance_to_obstacle < MIN_DISTANCE_TO_BRAKE: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
c42e61a
to
2bffb48
Compare
No description provided.