You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use below code to test my RL test but if i used RoadsSensor then freeze about 1000 iterations but I remove then no problem but I need RoadSensor. Btw normally it runs 30it/s but enable RoadsSensor decresed to 20it/s. I used latest beamngpy and beamng.tech.
self.road_sensor=RoadsSensor("rs1", self.bng, self.vehicle,physics_update_time=1)
def_compute_reward(self, speed, current_location, camera_image):
reward=0.0# Poll the road sensor for datars1=self.road_sensor.poll()
iflen(rs1) !=0: # Ensure the sensor data is available# 1. Lane Keeping Rewarddist_to_center=rs1[0.0].get("dist2CL", None)
ifdist_to_centerisnotNone:
reward+=max(
0, 1-abs(dist_to_center)
) # Closer to centerline gets higher reward# 2. Staying on Road Penaltydist_to_left=rs1[0.0].get("dist2Left", None)
dist_to_right=rs1[0.0].get("dist2Right", None)
half_width=rs1[0.0].get("halfWidth", None)
if (
dist_to_leftisnotNoneanddist_to_rightisnotNoneandhalf_widthisnotNone
):
ifdist_to_left<0ordist_to_right<0: # Vehicle is off the roadreward-=10elifabs(dist_to_left-dist_to_right) >half_width: # Veering too muchreward-=5# 4. Curvature and Heading Alignment Rewardroad_radius=rs1[0.0].get("roadRadius", None)
heading_angle=rs1[0.0].get("headingAngle", None)
ifheading_angleisnotNone:
heading_angle=heading_angle*180/np.pi# Convert to degreesifroad_radiusisnotNoneandnotnp.isnan(road_radius):
reward+=1/ (
1+abs(heading_angle)
) # Smaller heading angle gets higher reward# 6. Alignment with Centerlinex_closest=rs1[0.0].get("xP0onCL", None)
y_closest=rs1[0.0].get("yP0onCL", None)
ifx_closestisnotNoneandy_closestisnotNone:
vehicle_x, vehicle_y=current_location[:2]
distance_to_closest=np.sqrt(
(vehicle_x-x_closest) **2+ (vehicle_y-y_closest) **2
)
reward+=max(
0, 1-distance_to_closest
) # Higher reward for staying close to centerline# Damage Penaltyifself.damage_sensor["damage"] >0:
self.obstacles_hit+=1reward-=50.0# Large penalty for damageself.last_location=current_locationreturnreward
The text was updated successfully, but these errors were encountered:
I use below code to test my RL test but if i used
RoadsSensor
then freeze about 1000 iterations but I remove then no problem but I need RoadSensor. Btw normally it runs 30it/s but enableRoadsSensor
decresed to 20it/s. I used latest beamngpy and beamng.tech.The text was updated successfully, but these errors were encountered: