An optimised reward function for AWS DeepRacer that implements multiple racing strategies including racing line optimisation, dynamic speed adjustment, and safety controls. This implementation helps create more consistent and competitive autonomous racing models.
- Racing Line Optimisation: Rewards the agent for following an optimal racing path
- Dynamic Speed Control: Automatically adjusts target speed based on track curvature
- Safety Management: Implements lateral acceleration limits and track boundary awareness
- Predictive Steering: Looks ahead multiple waypoints to anticipate turns
- Lap Time Optimisation: Rewards efficient lap completion
- Comprehensive Error Handling: Robust validation of input parameters
MAX_SPEED = 4.0 # (m/s) Maximum speed on straight sections
TURN_SPEED = 2.0 # (m/s) Target speed during turnsMAX_STEERING_ANGLE = 30.0 # (degrees) Maximum steering angle
MAX_LATERAL_ACC = 3.0 # (m/s^2) Maximum lateral accelerationSAFETY_FACTOR = 0.8 # (0.0 to 1.0) Higher values = stay closer to center
CAR_LENGTH = 2.5 # (meters) Length of the car modelFUTURE_STEP = 5 # Number of waypoints to look ahead
TURN_THRESHOLD = 0.1 # Minimum curvature to identify as turnEXPECTED_STEPS = 300 # Baseline number of steps for optimal lap- Log in to your AWS DeepRacer console
- Navigate to the "Model" section
- Create a new model or select an existing one
- In the reward function section, copy and paste the contents of
reward_function.py - Adjust the parameters according to your track and racing style
The final reward is calculated by combining multiple factors:
- Distance Reward: Based on the car's proximity to the optimal racing line
- Lateral Acceleration Reward: Encourages smooth steering and stable cornering
- Speed Reward: Rewards maintaining appropriate speed for track conditions
- Safety Reward: Ensures the car stays within safe track boundaries
- Lap Time Reward: Bonus for completing laps efficiently
- Increase
MAX_SPEED - Decrease
SAFETY_FACTOR - Increase
TURN_SPEED - Adjust
TURN_THRESHOLD
- Decrease
MAX_LATERAL_ACC - Increase
SAFETY_FACTOR - Decrease
TURN_SPEED - Increase
FUTURE_STEP
- Lower speeds
- Higher
SAFETY_FACTOR - Increase
FUTURE_STEP
- Increase
MAX_SPEED - Lower
SAFETY_FACTOR - Decrease
FUTURE_STEP
- Start with conservative values and gradually increase them
- Test thoroughly after each parameter adjustment
- Monitor the completion rate alongside lap times
- Consider track width when setting safety parameters
- Adjust
EXPECTED_STEPSbased on your track length
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Note: This reward function is provided as-is and may require adjustments based on your specific track and racing conditions.