├── .github ├── ISSUE_TEMPLATE │ └── feature_request.md └── PULL_REQUEST_TEMPLATE ├── .gitignore ├── 00_Void └── .gitkeep ├── 01_Single ├── single_aws-samples_v0.py └── single_mtmoncur_v1.py ├── 02_Double └── double_aws-samples_1_v1.py ├── 03_Triple ├── triple_aws-samples_2_v1.py └── triple_aws-samples_3_v1.py ├── 04_Quadruple ├── quadruple_cnunezre_v0.py ├── quadruple_michelangelopagliarini_v0.py └── quadruple_pelirrojo_3_v1.py ├── 05_Quintuple └── quintuple_pelirrojo_1_v1.py ├── 06_Sextuple ├── sextuple_siutsin_1_v1.py └── sextuple_tiboonn_v1.py ├── 07_Septuple ├── septuple_pelirrojo_2_v1.py └── septuple_siutsin_2_v1.py ├── 08_Octuple └── octuple_tgjohnst_3_v0.py ├── 09_Nonuple ├── nonuple_elmic11111_v0.py ├── nonuple_tgjohnst_1_v0.py └── nonuple_tgjohnst_2_v0.py ├── 10_Decuple └── .gitkeep ├── 11_Undecuple └── .gitkeep ├── 12_Duodecuple └── .gitkeep ├── 13_Tredecuple └── .gitkeep ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md └── base.py /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. 4 | List any dependencies that are required for this change. 5 | 6 | Fixes # (issue) 7 | 8 | ## Type of change 9 | 10 | Please delete options that are not relevant. 11 | 12 | - [ ] Bug fix (non-breaking change which fixes an issue) 13 | - [ ] New feature (non-breaking change which adds functionality) 14 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 15 | - [ ] This change requires a documentation update 16 | 17 | # How Has This Been Tested? 18 | 19 | Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration 20 | 21 | - [ ] By adding automated tests 22 | - [ ] Manually deploying at cloud 23 | - [ ] Not tested 24 | 25 | # Checklist: 26 | 27 | - [ ] My code follows the style guidelines of this project 28 | - [ ] I have performed a self-review of my own code 29 | - [ ] I have commented my code, particularly in hard-to-understand areas 30 | - [ ] I have made corresponding changes to the documentation 31 | - [ ] My changes generate no new warnings 32 | - [ ] I have added tests that prove my fix is effective or that my feature works 33 | - [ ] New and existing unit tests pass locally with my changes 34 | - [ ] Any dependent changes have been merged and published in downstream modules 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea 3 | temp.py 4 | 5 | # Created by https://www.gitignore.io/api/python,jetbrains+all,jupyternotebook,jupyternotebooks 6 | # Edit at https://www.gitignore.io/?templates=python,jetbrains+all,jupyternotebook,jupyternotebooks 7 | 8 | ### JetBrains+all ### 9 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 10 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 11 | 12 | # User-specific stuff 13 | .idea/**/workspace.xml 14 | .idea/**/tasks.xml 15 | .idea/**/usage.statistics.xml 16 | .idea/**/dictionaries 17 | .idea/**/shelf 18 | 19 | # Generated files 20 | .idea/**/contentModel.xml 21 | 22 | # Sensitive or high-churn files 23 | .idea/**/dataSources/ 24 | .idea/**/dataSources.ids 25 | .idea/**/dataSources.local.xml 26 | .idea/**/sqlDataSources.xml 27 | .idea/**/dynamic.xml 28 | .idea/**/uiDesigner.xml 29 | .idea/**/dbnavigator.xml 30 | 31 | # Gradle 32 | .idea/**/gradle.xml 33 | .idea/**/libraries 34 | 35 | # Gradle and Maven with auto-import 36 | # When using Gradle or Maven with auto-import, you should exclude module files, 37 | # since they will be recreated, and may cause churn. Uncomment if using 38 | # auto-import. 39 | # .idea/modules.xml 40 | # .idea/*.iml 41 | # .idea/modules 42 | 43 | # CMake 44 | cmake-build-*/ 45 | 46 | # Mongo Explorer plugin 47 | .idea/**/mongoSettings.xml 48 | 49 | # File-based project format 50 | *.iws 51 | 52 | # IntelliJ 53 | out/ 54 | 55 | # mpeltonen/sbt-idea plugin 56 | .idea_modules/ 57 | 58 | # JIRA plugin 59 | atlassian-ide-plugin.xml 60 | 61 | # Cursive Clojure plugin 62 | .idea/replstate.xml 63 | 64 | # Crashlytics plugin (for Android Studio and IntelliJ) 65 | com_crashlytics_export_strings.xml 66 | crashlytics.properties 67 | crashlytics-build.properties 68 | fabric.properties 69 | 70 | # Editor-based Rest Client 71 | .idea/httpRequests 72 | 73 | # Android studio 3.1+ serialized cache file 74 | .idea/caches/build_file_checksums.ser 75 | 76 | # JetBrains templates 77 | **___jb_tmp___ 78 | 79 | ### JetBrains+all Patch ### 80 | # Ignores the whole .idea folder and all .iml files 81 | # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 82 | 83 | .idea/ 84 | 85 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 86 | 87 | *.iml 88 | modules.xml 89 | .idea/misc.xml 90 | *.ipr 91 | 92 | # Sonarlint plugin 93 | .idea/sonarlint 94 | 95 | ### JupyterNotebook ### 96 | .ipynb_checkpoints 97 | */.ipynb_checkpoints/* 98 | 99 | # Remove previous ipynb_checkpoints 100 | # git rm -r .ipynb_checkpoints/ 101 | # 102 | 103 | ### JupyterNotebooks ### 104 | # gitignore template for Jupyter Notebooks 105 | # website: http://jupyter.org/ 106 | 107 | 108 | # Remove previous ipynb_checkpoints 109 | # git rm -r .ipynb_checkpoints/ 110 | 111 | ### Python ### 112 | # Byte-compiled / optimized / DLL files 113 | __pycache__/ 114 | *.py[cod] 115 | *$py.class 116 | 117 | # C extensions 118 | *.so 119 | 120 | # Distribution / packaging 121 | .Python 122 | build/ 123 | develop-eggs/ 124 | dist/ 125 | downloads/ 126 | eggs/ 127 | .eggs/ 128 | lib/ 129 | lib64/ 130 | parts/ 131 | sdist/ 132 | var/ 133 | wheels/ 134 | pip-wheel-metadata/ 135 | share/python-wheels/ 136 | *.egg-info/ 137 | .installed.cfg 138 | *.egg 139 | MANIFEST 140 | 141 | # PyInstaller 142 | # Usually these files are written by a python script from a template 143 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 144 | *.manifest 145 | *.spec 146 | 147 | # Installer logs 148 | pip-log.txt 149 | pip-delete-this-directory.txt 150 | 151 | # Unit test / coverage reports 152 | htmlcov/ 153 | .tox/ 154 | .nox/ 155 | .coverage 156 | .coverage.* 157 | .cache 158 | nosetests.xml 159 | coverage.xml 160 | *.cover 161 | .hypothesis/ 162 | .pytest_cache/ 163 | 164 | # Translations 165 | *.mo 166 | *.pot 167 | 168 | # Django stuff: 169 | *.log 170 | local_settings.py 171 | db.sqlite3 172 | 173 | # Flask stuff: 174 | instance/ 175 | .webassets-cache 176 | 177 | # Scrapy stuff: 178 | .scrapy 179 | 180 | # Sphinx documentation 181 | docs/_build/ 182 | 183 | # PyBuilder 184 | target/ 185 | 186 | # Jupyter Notebook 187 | 188 | # IPython 189 | profile_default/ 190 | ipython_config.py 191 | 192 | # pyenv 193 | .python-version 194 | 195 | # pipenv 196 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 197 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 198 | # having no cross-platform support, pipenv may install dependencies that don’t work, or not 199 | # install all needed dependencies. 200 | #Pipfile.lock 201 | 202 | # celery beat schedule file 203 | celerybeat-schedule 204 | 205 | # SageMath parsed files 206 | *.sage.py 207 | 208 | # Environments 209 | .env 210 | .venv 211 | env/ 212 | venv/ 213 | ENV/ 214 | env.bak/ 215 | venv.bak/ 216 | 217 | # Spyder project settings 218 | .spyderproject 219 | .spyproject 220 | 221 | # Rope project settings 222 | .ropeproject 223 | 224 | # mkdocs documentation 225 | /site 226 | 227 | # mypy 228 | .mypy_cache/ 229 | .dmypy.json 230 | dmypy.json 231 | 232 | # Pyre type checker 233 | .pyre/ 234 | 235 | # End of https://www.gitignore.io/api/python,jetbrains+all,jupyternotebook,jupyternotebooks -------------------------------------------------------------------------------- /00_Void/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Machine-Learning-Labs/DeepRacerRewardFunctionsCollection/f6addf4654de90f9d1669fd5de67331add93ab2f/00_Void/.gitkeep -------------------------------------------------------------------------------- /01_Single/single_aws-samples_v0.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: AWS Samples 3 | @Link: https://github.com/aws-samples/aws-deepracer-workshops 4 | @License: Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | ''' 6 | 7 | 8 | def reward_function(self, on_track, x, y, distance_from_center, car_orientation, progress, steps, 9 | throttle, steering, track_width, waypoints, closest_waypoints): 10 | if distance_from_center >= 0.0 and distance_from_center <= 0.02: 11 | return 1.0 12 | elif distance_from_center >= 0.02 and distance_from_center <= 0.03: 13 | return 0.3 14 | elif distance_from_center >= 0.03 and distance_from_center <= 0.05: 15 | return 0.1 16 | return 1e-3 # like crashed 17 | -------------------------------------------------------------------------------- /01_Single/single_mtmoncur_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: mtmoncur 3 | @Link: https://github.com/mtmoncur/deepracer_env 4 | @License: MIT 5 | ''' 6 | 7 | 8 | def reward_function(params): 9 | """ 10 | Available option: 11 | all_wheels_on_track (bool) 12 | True if car is on track, False otherwise 13 | x (float) 14 | x coordinate in meters 15 | y (float) 16 | y coordinate in meters 17 | distance_from_center (float) 18 | distance from car center to track center in meters 19 | is_left_of_center (bool) 20 | True if car is left of track cener, False otherwise 21 | heading (float) 22 | range of [0,360), this is the angle in degrees between 23 | the car's direction and the x-axis 24 | progress (float) 25 | range of [0,100], this is the percentage of the track completed 26 | steps (int) 27 | number of steps taken in the environment. This resets every time 28 | a new episode begins, and currently the maximum episode length is 200 29 | speed (float) 30 | current speed of car in meters per second 31 | steering_angle (float) 32 | range of about [-30,30], this is the angle at which the wheels are 33 | turning 34 | track_width (float) 35 | the track width in meters 36 | """ 37 | if params['all_wheels_on_track']: 38 | return 1.0 39 | else: 40 | return 0.0 41 | -------------------------------------------------------------------------------- /02_Double/double_aws-samples_1_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: AWS Samples 3 | @Link: https://docs.aws.amazon.com/deepracer/latest/developerguide/what-is-deepracer.html 4 | @License: Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | ''' 6 | 7 | def reward_function(params): 8 | ''' 9 | Example of rewarding the agent to follow the track center line 10 | ''' 11 | 12 | # Read input parameters 13 | track_width = params['track_width'] 14 | distance_from_center = abs(params['distance_from_center']) 15 | 16 | # Calculate 3 marks that are farther and father away from the center line 17 | marker_1 = 0.1 * track_width 18 | marker_2 = 0.25 * track_width 19 | marker_3 = 0.5 * track_width 20 | 21 | # Give higher reward if the car is closer to center line and vice versa 22 | if distance_from_center <= marker_1: 23 | reward = 1 24 | elif distance_from_center <= marker_2: 25 | reward = 0.5 26 | elif distance_from_center <= marker_3: 27 | reward = 0.1 28 | else: 29 | reward = 1e-3 # likely crashed/close to off-track 30 | 31 | return reward 32 | -------------------------------------------------------------------------------- /03_Triple/triple_aws-samples_2_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: AWS Samples 3 | @Link: https://docs.aws.amazon.com/deepracer/latest/developerguide/what-is-deepracer.html 4 | @License: Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | ''' 6 | 7 | 8 | def reward_function(params): 9 | ''' 10 | Example of rewarding the agent to stay inside the two track borders 11 | ''' 12 | 13 | # Read input parameters 14 | all_wheels_on_track = params['all_wheels_on_track'] 15 | distance_from_center = abs(params['distance_from_center']) 16 | track_width = params['track_width'] 17 | 18 | # Give a very low reward by default 19 | reward = 1e-3 20 | 21 | # Give a high reward if no wheels go off the track and 22 | # the vehicle is somewhere in between the track borders 23 | if all_wheels_on_track and (0.5 * track_width - distance_from_center) >= 0.05: 24 | reward = 1.0 25 | 26 | # Always return a float value 27 | return reward 28 | -------------------------------------------------------------------------------- /03_Triple/triple_aws-samples_3_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: AWS Samples 3 | @Link: https://docs.aws.amazon.com/deepracer/latest/developerguide/what-is-deepracer.html 4 | @License: Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 | ''' 6 | 7 | 8 | def reward_function(params): 9 | ''' 10 | Example of penalize steering, which helps mitigate zig-zag behaviors 11 | ''' 12 | 13 | # Read input parameters 14 | distance_from_center = params['distance_from_center'] 15 | track_width = params['track_width'] 16 | steering = abs(params['steering_angle']) # Only need the absolute steering angle 17 | 18 | # Calculate 3 marks that are farther and father away from the center line 19 | marker_1 = 0.1 * track_width 20 | marker_2 = 0.25 * track_width 21 | marker_3 = 0.5 * track_width 22 | 23 | # Give higher reward if the car is closer to center line and vice versa 24 | if distance_from_center <= marker_1: 25 | reward = 1 26 | elif distance_from_center <= marker_2: 27 | reward = 0.5 28 | elif distance_from_center <= marker_3: 29 | reward = 0.1 30 | else: 31 | reward = 1e-3 # likely crashed/ close to off track 32 | 33 | # Steering penality threshold, change the number based on your action space setting 34 | ABS_STEERING_THRESHOLD = 15 35 | 36 | # Penalize reward if the car is steering too much 37 | if steering > ABS_STEERING_THRESHOLD: 38 | reward *= 0.8 39 | 40 | return float(reward) 41 | -------------------------------------------------------------------------------- /04_Quadruple/quadruple_cnunezre_v0.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: cnunezre 3 | @Link: https://github.com/cnunezre/deepRacerReinvent 4 | @License: N/D 5 | ''' 6 | 7 | def reward_function (on_track, x, y, distance_from_center, car_orientation, progress, steps, throttle, steering, track_width, waypoints, closest_waypoint): 8 | 9 | reward = 1e-3 10 | 11 | if distance_from_center >= 0.0 and distance_from_center <= track_width/3: 12 | reward = 1.0 13 | 14 | # add steering penalty 15 | if abs(steering) > 0.5: 16 | reward *= 0.80 17 | 18 | # add throttle penalty 19 | if throttle < 0.5: 20 | reward *= 0.80 21 | 22 | return reward 23 | -------------------------------------------------------------------------------- /04_Quadruple/quadruple_michelangelopagliarini_v0.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: MichelangeloPagliarini 3 | @Link: https://github.com/MichelangeloPagliarini/DeepRacer 4 | @License: N/D 5 | ''' 6 | 7 | def reward_function(on_track, x, y, distance_from_center, car_orientation, progress, steps, throttle, steering, 8 | track_width, waypoints, closest_waypoint): 9 | import math 10 | 11 | marker_1 = 0.25 * track_width 12 | marker_2 = 0.3 * track_width 13 | marker_3 = 0.5 * track_width 14 | 15 | reward = 1e-3 16 | if distance_from_center >= 0.0 and distance_from_center <= marker_1: 17 | reward = 1 18 | elif distance_from_center <= marker_2: 19 | reward = 0.2 20 | elif distance_from_center <= marker_3: 21 | reward = 0.1 22 | else: 23 | reward = 1e-3 24 | 25 | # add steering penalty 26 | if abs(steering) > 0.3: 27 | reward *= 0.8 28 | elif abs(steering) > 0.5: 29 | reward *= 0.6 30 | 31 | # add throttle penalty 32 | if throttle < 0.5: 33 | reward *= 0.7 34 | 35 | return float(reward) 36 | -------------------------------------------------------------------------------- /04_Quadruple/quadruple_pelirrojo_3_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Manuel Eusebio de Paz Carmona // Pelirrojo 3 | @Link: https://github.com/Pelirrojo/DeepRacerRewardFunctionsCollection 4 | @License: MIT 5 | 6 | Inspired on AWS Samples 3 7 | ''' 8 | 9 | 10 | def reward_function(params): 11 | ''' 12 | Example of penalize steering, which helps mitigate zig-zag behaviors 13 | ''' 14 | 15 | # Read input parameters 16 | distance_from_center = params['distance_from_center'] 17 | track_width = params['track_width'] 18 | steering = abs(params['steering_angle']) # Only need the absolute steering angle 19 | progress = params["progress"] 20 | 21 | # Constants¡ 22 | ABS_STEERING_THRESHOLD = 15 # Steering penality threshold, change the number based on your action space setting 23 | REWARD_MAX = 1e5 24 | REWARD_MIN = -1e5 25 | 26 | # Calculate 3 marks that are farther and father away from the center line 27 | marker_1 = 0.1 * track_width 28 | marker_2 = 0.25 * track_width 29 | marker_3 = 0.5 * track_width 30 | 31 | # Give higher reward if the car is closer to center line and vice versa 32 | if distance_from_center <= marker_1: 33 | reward = 1 34 | elif distance_from_center <= marker_2: 35 | reward = 0.5 36 | elif distance_from_center <= marker_3: 37 | reward = 0.1 38 | else: 39 | reward = 1e-3 # likely crashed/ close to off track 40 | 41 | # Penalize reward if the car is steering too much 42 | if steering > ABS_STEERING_THRESHOLD: 43 | reward *= 0.8 44 | 45 | # We want the vehicle to continue making progress 46 | if progress >= 99: 47 | return float(REWARD_MAX) 48 | elif progress >= 1: 49 | reward *= REWARD_MAX * (progress / 100) 50 | 51 | # make sure reward value returned is within the prescribed value range. 52 | reward = max(reward, REWARD_MIN) 53 | reward = min(reward, REWARD_MAX) 54 | 55 | return float(reward) 56 | -------------------------------------------------------------------------------- /05_Quintuple/quintuple_pelirrojo_1_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Manuel Eusebio de Paz Carmona // Pelirrojo 3 | @Link: https://github.com/Pelirrojo/DeepRacerRewardFunctionsCollection 4 | @License: MIT 5 | ''' 6 | 7 | 8 | def reward_function(params): 9 | 10 | # Read input parameters ############################## 11 | 12 | all_wheels_on_track = params["all_wheels_on_track"] 13 | distance_from_center = abs(params['distance_from_center']) 14 | track_width = params['track_width'] 15 | progress = params["progress"] 16 | speed = params["speed"] 17 | 18 | # Constants ######################################### 19 | 20 | REWARD_MIN = -1e5 21 | REWARD_MAX = 1e5 22 | 23 | # Logic ######################################### 24 | 25 | # Give a very low reward by default 26 | reward = 1e-3 27 | 28 | try: 29 | 30 | # Give a high reward if no wheels go off the track and 31 | # the vehicle is somewhere in between the track borders 32 | if all_wheels_on_track and (0.5 * track_width - distance_from_center) >= 0.05: 33 | reward = 1.0 34 | 35 | # we want the vehicle to continue making progress 36 | if progress >= 99: 37 | return float(REWARD_MAX) 38 | elif progress >= 75: 39 | reward = (REWARD_MAX / 2) * (progress / 100) 40 | elif progress >= 50: 41 | reward = (REWARD_MAX / 4) * (progress / 100) 42 | elif progress >= 25: 43 | reward = (REWARD_MAX / 8) * (progress / 100) 44 | elif progress >= 10: 45 | reward = (REWARD_MAX / 16) * (progress / 100) 46 | else: 47 | reward *= (speed / 5) 48 | 49 | # we want the vehicle stay inside the track 50 | if not all_wheels_on_track: 51 | return float(REWARD_MIN) 52 | 53 | except: 54 | reward = 1e-3 55 | 56 | return float(reward) 57 | -------------------------------------------------------------------------------- /06_Sextuple/sextuple_siutsin_1_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Simon Li // siutsin 3 | @Link: https://github.com/siutsin/DeepRacer 4 | @License: MIT 5 | ''' 6 | 7 | def reward_function(params): 8 | # Read input parameters 9 | all_wheels_on_track = params['all_wheels_on_track'] 10 | distance_from_center = params['distance_from_center'] 11 | track_width = params['track_width'] 12 | # Only need the absolute steering angle 13 | steering = abs(params['steering_angle']) 14 | 15 | # Calculate 3 marks that are farther and father away from the center line 16 | marker_1 = 0.1 * track_width 17 | marker_2 = 0.25 * track_width 18 | marker_3 = 0.5 * track_width 19 | 20 | # Give higher reward if the car is closer to center line and vice versa 21 | if distance_from_center <= marker_1: 22 | reward = 1 23 | elif distance_from_center <= marker_2: 24 | reward = 0.5 25 | elif distance_from_center <= marker_3: 26 | reward = 0.1 27 | else: 28 | return float(1e-3) # likely crashed/ close to off track 29 | 30 | if params['is_reversed'] == True or all_wheels_on_track == False: 31 | return float(1e-3) # likely crashed/ close to off track 32 | 33 | # Steering penality threshold, change the number based on your action space setting 34 | ABS_STEERING_THRESHOLD = 30 35 | 36 | # Penalize reward if the car is steering too much 37 | if steering > ABS_STEERING_THRESHOLD: # Only need the absolute steering angle 38 | reward *= 0.5 39 | 40 | # penalize reward for the car taking slow actions 41 | # speed is in m/s 42 | # the below assumes your action space has a maximum speed of 5 m/s and speed granularity of 3 43 | # we penalize any speed less than 2m/s 44 | SPEED_THRESHOLD = 4.5 45 | if params['speed'] < SPEED_THRESHOLD: 46 | reward *= 0.5 47 | 48 | return float(reward) 49 | -------------------------------------------------------------------------------- /06_Sextuple/sextuple_tiboonn_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Tibor Hercz // Tiboonn 3 | @Link: https://github.com/Tiboonn/AWS-DeepRacer 4 | @License: N/D 5 | ''' 6 | 7 | def reward_function(params): 8 | ''' 9 | Example of rewarding the agent to follow center line 10 | ''' 11 | 12 | # Read input parameters 13 | track_width = params['track_width'] 14 | distance_from_center = params['distance_from_center'] 15 | all_wheels_on_track = params['all_wheels_on_track'] 16 | steering = abs(params['steering_angle']) 17 | speed = params['speed'] 18 | is_left_of_center = params['is_left_of_center'] 19 | 20 | # Calculate 3 markers that are at varying distances away from the center line 21 | marker_1 = 0.1 * track_width 22 | marker_2 = 0.15 * track_width 23 | marker_3 = 0.25 * track_width 24 | marker_4 = 0.5 * track_width 25 | 26 | # Give higher reward if the car is closer to center line and vice versa 27 | if not all_wheels_on_track: 28 | reward = 1e-3 29 | return reward 30 | elif distance_from_center <= marker_1: 31 | reward = 1.0 * speed 32 | if is_left_of_center: 33 | reward = reward + 0.1 34 | elif distance_from_center <= marker_2: 35 | reward = 0.8 * speed 36 | if is_left_of_center: 37 | reward = reward + 0.1 38 | elif distance_from_center <= marker_3: 39 | reward = 0.3 * speed 40 | if is_left_of_center: 41 | reward = reward + 0.1 42 | elif distance_from_center <= marker_4: 43 | reward = 0.1 * speed 44 | if is_left_of_center: 45 | reward = reward + 0.1 46 | else: 47 | reward = 1e-3 # likely crashed/ close to off track 48 | 49 | ABS_STEERING_THRESHOLD = 15 50 | 51 | if steering > ABS_STEERING_THRESHOLD: 52 | reward *= 0.8 53 | 54 | return float(reward) 55 | -------------------------------------------------------------------------------- /07_Septuple/septuple_pelirrojo_2_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Manuel Eusebio de Paz Carmona // Pelirrojo 3 | @Link: https://github.com/Pelirrojo/DeepRacerRewardFunctionsCollection 4 | @License: MIT 5 | 6 | Inspired on sextuple_tiboonn_v1.py 7 | ''' 8 | 9 | 10 | def reward_function(params): 11 | 12 | # Read input parameters ############################## 13 | speed = params['speed'] 14 | progress = params['progress'] 15 | track_width = params['track_width'] 16 | distance_from_center = params['distance_from_center'] 17 | all_wheels_on_track = params['all_wheels_on_track'] 18 | steering = abs(params['steering_angle']) 19 | is_left_of_center = params['is_left_of_center'] 20 | 21 | # Constants ######################################### 22 | 23 | ABS_STEERING_THRESHOLD = 15 24 | 25 | # Min / Max Reward 26 | REWARD_MIN = -100000.0 27 | REWARD_MAX = 100000.0 28 | 29 | # Calculate markers that are at varying distances away from the center line 30 | marker_1 = 0.1 * track_width 31 | marker_2 = 0.15 * track_width 32 | marker_3 = 0.25 * track_width 33 | marker_4 = 0.5 * track_width 34 | 35 | # Set Base Reward 36 | reward = 1 37 | 38 | # we want the vehicle to continue making progress 39 | if not all_wheels_on_track: # Fail them if off Track 40 | return float(REWARD_MIN) 41 | elif progress >= 99: 42 | return float(REWARD_MAX) 43 | elif progress >= 75: 44 | reward = (REWARD_MAX/2) * (progress/100) 45 | elif progress >= 50: 46 | reward = (REWARD_MAX/4) * (progress/100) 47 | elif progress >= 25: 48 | reward = (REWARD_MAX/8) * (progress / 100) 49 | elif progress >= 1: 50 | reward = (REWARD_MAX/10) * (progress / 100) 51 | 52 | # Give higher reward if the car is closer to center line and vice versa 53 | if distance_from_center <= marker_1: 54 | reward *= 1.0 * speed 55 | if is_left_of_center: 56 | reward *= reward * 0.1 57 | elif distance_from_center <= marker_2: 58 | reward *= 0.8 * speed 59 | if is_left_of_center: 60 | reward *= reward + 0.1 61 | elif distance_from_center <= marker_3: 62 | reward *= 0.3 * speed 63 | if is_left_of_center: 64 | reward *= reward + 0.1 65 | elif distance_from_center <= marker_4: 66 | reward *= 0.1 * speed 67 | if is_left_of_center: 68 | reward = reward + 0.1 69 | else: 70 | return float(REWARD_MIN) # likely crashed/ close to off track 71 | 72 | # penalize reward if the car is steering way too much 73 | if steering > ABS_STEERING_THRESHOLD: 74 | reward *= 0.8 75 | 76 | # make sure reward value returned is within the prescribed value range. 77 | reward = max(reward, REWARD_MIN) 78 | reward = min(reward, REWARD_MAX) 79 | 80 | return float(reward) 81 | -------------------------------------------------------------------------------- /07_Septuple/septuple_siutsin_2_v1.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Simon Li // siutsin 3 | @Link: https://github.com/siutsin/DeepRacer 4 | @License: MIT 5 | ''' 6 | 7 | 8 | def reward_function(params): 9 | # Read input parameters 10 | # all_wheels_on_track = params['all_wheels_on_track'] 11 | distance_from_center = params['distance_from_center'] 12 | track_width = params['track_width'] 13 | # Only need the absolute steering angle 14 | steering = abs(params['steering_angle']) 15 | 16 | # Calculate 3 marks that are farther and father away from the center line 17 | marker_1 = 0.1 * track_width 18 | marker_2 = 0.25 * track_width 19 | marker_3 = 0.5 * track_width 20 | 21 | # Give higher reward if the car is closer to center line and vice versa 22 | if distance_from_center <= marker_1: 23 | reward = 1 24 | elif distance_from_center <= marker_2: 25 | reward = 0.5 26 | elif distance_from_center <= marker_3: 27 | reward = 0.1 28 | else: 29 | return float(1e-3) # likely crashed/ close to off track 30 | 31 | if params['is_reversed'] == True: 32 | return float(1e-3) # likely crashed/ close to off track 33 | 34 | # first corner - left turn 35 | if params['closest_waypoints'][0] == 8 and params['closest_waypoints'][1] == 9 and params[ 36 | 'is_left_of_center'] == False: 37 | reward = 5 38 | if params['closest_waypoints'][0] == 17 and params['closest_waypoints'][1] == 18 and params[ 39 | 'is_left_of_center'] == True: 40 | reward = 5 41 | if params['closest_waypoints'][0] == 26 and params['closest_waypoints'][ 42 | 1] == 27 and distance_from_center == marker_2: 43 | reward = 5 44 | # second corner - right turn 45 | if params['closest_waypoints'][0] == 33 and params['closest_waypoints'][1] == 34 and params[ 46 | 'is_left_of_center'] == False: 47 | reward = 5 48 | # third corner - left turn 49 | if params['closest_waypoints'][0] == 36 and params['closest_waypoints'][1] == 37 and params[ 50 | 'is_left_of_center'] == False: 51 | reward = 5 52 | if params['closest_waypoints'][0] == 40 and params['closest_waypoints'][1] == 41 and params[ 53 | 'is_left_of_center'] == True: 54 | reward = 5 55 | if params['closest_waypoints'][0] == 49 and params['closest_waypoints'][ 56 | 1] == 50 and distance_from_center == marker_2: 57 | reward = 5 58 | # third corner - left turn 59 | if params['closest_waypoints'][0] == 36 and params['closest_waypoints'][1] == 37 and params[ 60 | 'is_left_of_center'] == False: 61 | reward = 5 62 | if params['closest_waypoints'][0] == 40 and params['closest_waypoints'][1] == 41 and params[ 63 | 'is_left_of_center'] == True: 64 | reward = 5 65 | if params['closest_waypoints'][0] == 49 and params['closest_waypoints'][ 66 | 1] == 50 and distance_from_center == marker_2: 67 | reward = 5 68 | # fourth corner - left turn 69 | if params['closest_waypoints'][0] == 51 and params['closest_waypoints'][1] == 52 and params[ 70 | 'is_left_of_center'] == True: 71 | reward = 5 72 | if params['closest_waypoints'][0] == 54 and params['closest_waypoints'][ 73 | 1] == 55 and distance_from_center == marker_2: 74 | reward = 5 75 | # fifth corner - left turn 76 | if params['closest_waypoints'][0] == 59 and params['closest_waypoints'][1] == 60 and params[ 77 | 'is_left_of_center'] == False: 78 | reward = 5 79 | if params['closest_waypoints'][0] == 64 and params['closest_waypoints'][1] == 65 and params[ 80 | 'is_left_of_center'] == True: 81 | reward = 5 82 | if params['closest_waypoints'][0] == 68 and params['closest_waypoints'][ 83 | 1] == 69 and distance_from_center == marker_2: 84 | reward = 5 85 | 86 | # Steering penality threshold, change the number based on your action space setting 87 | ABS_STEERING_THRESHOLD = 30 88 | 89 | # Penalize reward if the car is steering too much 90 | if steering > ABS_STEERING_THRESHOLD: # Only need the absolute steering angle 91 | reward *= 0.5 92 | 93 | # penalize reward for the car taking slow actions 94 | # speed is in m/s 95 | # the below assumes your action space has a maximum speed of 5 m/s and speed granularity of 3 96 | # we penalize any speed less than 2m/s 97 | SPEED_THRESHOLD = 4 98 | if params['speed'] < SPEED_THRESHOLD: 99 | reward *= 0.5 100 | 101 | return float(reward) 102 | -------------------------------------------------------------------------------- /08_Octuple/octuple_tgjohnst_3_v0.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Timothy Johnstone // tgjohnst 3 | @Link: https://github.com/tgjohnst/DeepestRacer 4 | @License: N/D 5 | ''' 6 | 7 | def reward_function(on_track, x, y, distance_from_center, car_orientation, progress, steps, throttle, steering, 8 | track_width, waypoints, closest_waypoint): 9 | ''' 10 | ''' 11 | 12 | import math 13 | from statistics import mean 14 | 15 | ###################### 16 | ##### Constants ###### 17 | ###################### 18 | 19 | GLOBAL_MIN = -1e5 20 | GLOBAL_MAX = 1e5 21 | 22 | ###################### 23 | ##### Helper fns ##### 24 | ###################### 25 | 26 | ###################### 27 | ##### Centering ###### 28 | ###################### 29 | 30 | # negative exponential penalty for distance from center 31 | reward = math.exp(-6 * distance_from_center) 32 | 33 | # giant penalty if vehicle is exiting track 34 | if not on_track: 35 | reward = GLOBAL_MIN 36 | elif progress == 1: 37 | reward = GLOBAL_MAX 38 | else: # we want the vehicle to continue making progress 39 | reward = reward * progress 40 | 41 | ###################### 42 | ###### Steering ###### 43 | ###################### 44 | 45 | # penalize reward if orientation of the vehicle deviates way too much when compared to ideal orientation 46 | next_waypoint_yaw = waypoints[min(closest_waypoint + 1, len(waypoints) - 1)][-1] 47 | if abs(car_orientation - next_waypoint_yaw) >= math.radians(10): 48 | reward *= 0.25 49 | 50 | # penalize reward if the car is steering too much 51 | ABS_STEERING_THRESHOLD = 0.85 52 | if abs(steering) > ABS_STEERING_THRESHOLD: 53 | reward *= 0.75 54 | 55 | ###################### 56 | ###### Throttle ###### 57 | ###################### 58 | 59 | # Gotta go fast 60 | # if throttle < 0.35: 61 | reward *= 0.5 + throttle 62 | 63 | # decrease throttle while steering to some extent 64 | if throttle > 1 - (0.4 * abs(steering)): 65 | reward *= 0.8 66 | 67 | # make sure reward value returned is within the prescribed value range. 68 | reward = max(reward, GLOBAL_MIN) 69 | reward = min(reward, GLOBAL_MAX) 70 | 71 | return float(reward) 72 | -------------------------------------------------------------------------------- /09_Nonuple/nonuple_elmic11111_v0.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: David Hofmann // elmic11111 3 | @Link: https://github.com/elmic11111/DeepRacer 4 | @License: MIT 5 | ''' 6 | 7 | def reward_function(on_track, x, y, distance_from_center, car_orientation, progress, steps, throttle, steering, track_width, waypoints, closest_waypoint): 8 | 9 | ''' 10 | @on_track (boolean) :: The vehicle is off-track if the front of the vehicle is outside of the white 11 | lines 12 | 13 | @x (float range: [0, 1]) :: Fraction of where the car is along the x-axis. 1 indicates 14 | max 'x' value in the coordinate system. 15 | 16 | @y (float range: [0, 1]) :: Fraction of where the car is along the y-axis. 1 indicates 17 | max 'y' value in the coordinate system. 18 | 19 | @distance_from_center (float [0, track_width/2]) :: Displacement from the center line of the track 20 | as defined by way points 21 | 22 | @car_orientation (float: [-3.14, 3.14]) :: yaw of the car with respect to the car's x-axis in 23 | radians (-180 degrees, 180 degrees) 24 | 25 | @progress (float: [0,1]) :: % of track complete 26 | 27 | @steps (int) :: numbers of steps completed. One step is one move by the car 28 | 29 | @throttle :: (float) 0 to 1 (0 indicates stop, 1 max throttle) 30 | 31 | @steering :: (float) -1 to 1 (-1 is right, 1 is left) 32 | 33 | @track_width (float) :: width of the track (> 0) 34 | 35 | @waypoints (ordered list) :: list of waypoint in order; each waypoint is a set of coordinates 36 | (x,y,yaw) that define a turning point. Defines center. 37 | 38 | @closest_waypoint (int) :: index of the closest waypoint (0-indexed) given the car's x,y 39 | position as measured by the eucliedean distance 40 | 41 | @@output: @reward (float [-1e5, 1e5]) 42 | ''' 43 | 44 | import math 45 | from statistics import mean 46 | 47 | ########## 48 | # Settings 49 | ########## 50 | # Min / Max Reward 51 | REWARD_MIN = -1e5 52 | REWARD_MAX = 1e5 53 | # Define the Area each side of the center that the card can use. 54 | # Later version might consider adjust this so that it can hug corners 55 | CENTER_LANE = track_width * .25 56 | HALF_TRACK = track_width / 2 57 | 58 | ABS_STEERING_THRESHOLD = .85 59 | 60 | #################### 61 | # Locations on track 62 | #################### 63 | 64 | # Set Base Reward 65 | if not on_track: # Fail them if off Track 66 | reward = REWARD_MIN 67 | return reward 68 | elif progress == 1: 69 | reward = REWARD_MAX 70 | return reward 71 | else: # we want the vehicle to continue making progress 72 | reward = REWARD_MAX * progress 73 | 74 | # If outside track center than penalize 75 | if distance_from_center > 0.0 and distance_from_center > CENTER_LANE: 76 | reward *= 1 - (distance_from_center / HALF_TRACK) 77 | 78 | ########## 79 | # Steering 80 | ########## 81 | 82 | # Add penalty for wrong direction 83 | next_waypoint_yaw = waypoints[min(closest_waypoint+1, len(waypoints)-1)][-1] 84 | if abs(car_orientation - next_waypoint_yaw) >= math.radians(10): 85 | reward *= 1 - (abs(car_orientation - next_waypoint_yaw) / 180) 86 | elif abs(car_orientation - next_waypoint_yaw) < math.radians(10) and abs(steering) > ABS_STEERING_THRESHOLD: # penalize if stearing to much 87 | reward *= ABS_STEERING_THRESHOLD / abs(steering) 88 | else: 89 | reward *= 1 + (10 - (abs(car_orientation - next_waypoint_yaw) / 10)) 90 | 91 | # Add penalty if throttle exsides the steering else add reward 92 | if abs(steering) > .5 and abs(steering > throttle): 93 | reward *= 1 - (steering - throttle) 94 | else: 95 | reward *= 1 + throttle 96 | 97 | # make sure reward value returned is within the prescribed value range. 98 | reward = max(reward, REWARD_MIN) 99 | reward = min(reward, REWARD_MAX) 100 | 101 | return float(reward) 102 | -------------------------------------------------------------------------------- /09_Nonuple/nonuple_tgjohnst_1_v0.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Timothy Johnstone // tgjohnst 3 | @Link: https://github.com/tgjohnst/DeepestRacer 4 | @License: N/D 5 | ''' 6 | 7 | # This model was my first and was able to complete a lap, but not consistently. it implements a few kinds of penalties 8 | 9 | def reward_function(on_track, x, y, distance_from_center, car_orientation, progress, steps, throttle, steering, 10 | track_width, waypoints, closest_waypoint): 11 | ''' 12 | ''' 13 | 14 | import math 15 | 16 | marker_1 = 0.1 * track_width 17 | marker_2 = 0.25 * track_width 18 | marker_3 = 0.5 * track_width 19 | 20 | ###################### 21 | ##### Centering ###### 22 | ###################### 23 | 24 | # negative exponential penalty for distance from center 25 | reward = math.exp(-1 * distance_from_center) 26 | 27 | # giant penalty if vehicle is exiting track 28 | if not on_track: 29 | reward = -1 30 | elif progress == 1: 31 | reward = 1e3 32 | else: # we want the vehicle to continue making progress 33 | reward = reward * progress 34 | 35 | ###################### 36 | ###### Steering ###### 37 | ###################### 38 | 39 | # penalize reward if orientation of the vehicle deviates way too much when compared to ideal orientation 40 | waypoint_yaw = waypoints[closest_waypoint][-1] 41 | if abs(car_orientation - waypoint_yaw) >= math.radians(5): 42 | reward *= 0.5 43 | 44 | # penalize reward if the car is steering too much 45 | ABS_STEERING_THRESHOLD = 0.7 46 | if abs(steering) > ABS_STEERING_THRESHOLD: 47 | reward *= 0.75 48 | 49 | ###################### 50 | ###### Throttle ###### 51 | ###################### 52 | 53 | # Gotta go fast 54 | if throttle < 0.35: 55 | reward *= 1 - (0.5 * throttle) 56 | 57 | # decrease throttle while steering to some extent 58 | if throttle > 1 - (0.4 * abs(steering)): 59 | reward *= 0.8 60 | 61 | # make sure reward value returned is within the prescribed value range. 62 | reward = max(reward, 1e-5) 63 | reward = min(reward, 1e5) 64 | 65 | return float(reward) 66 | -------------------------------------------------------------------------------- /09_Nonuple/nonuple_tgjohnst_2_v0.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: Timothy Johnstone // tgjohnst 3 | @Link: https://github.com/tgjohnst/DeepestRacer 4 | @License: N/D 5 | ''' 6 | 7 | 8 | # this is after iterating a bit on the first model. not sure performance improved, but code organization did :) 9 | 10 | def reward_function(on_track, x, y, distance_from_center, car_orientation, progress, steps, throttle, steering, 11 | track_width, waypoints, closest_waypoint): 12 | ''' 13 | ''' 14 | 15 | import math 16 | 17 | ###################### 18 | ##### Constants ###### 19 | ###################### 20 | 21 | GLOBAL_MIN = -1e5 22 | GLOBAL_MAX = 1e5 23 | 24 | marker_1 = 0.1 * track_width 25 | marker_2 = 0.25 * track_width 26 | marker_3 = 0.5 * track_width 27 | 28 | ###################### 29 | ##### Centering ###### 30 | ###################### 31 | 32 | # negative exponential penalty for distance from center 33 | reward = math.exp(-6 * distance_from_center) 34 | 35 | # giant penalty if vehicle is exiting track 36 | if not on_track: 37 | reward = GLOBAL_MIN 38 | elif progress == 1: 39 | reward = GLOBAL_MAX 40 | else: # we want the vehicle to continue making progress 41 | reward = reward * progress 42 | 43 | ###################### 44 | ###### Steering ###### 45 | ###################### 46 | 47 | # penalize reward if orientation of the vehicle deviates way too much when compared to ideal orientation 48 | waypoint_yaw = waypoints[closest_waypoint][-1] 49 | if abs(car_orientation - waypoint_yaw) >= math.radians(10): 50 | reward *= 0.25 51 | 52 | # penalize reward if the car is steering too much 53 | ABS_STEERING_THRESHOLD = 0.85 54 | if abs(steering) > ABS_STEERING_THRESHOLD: 55 | reward *= 0.75 56 | 57 | ###################### 58 | ###### Throttle ###### 59 | ###################### 60 | 61 | # Gotta go fast 62 | # if throttle < 0.35: 63 | reward *= 0.5 + throttle 64 | 65 | # decrease throttle while steering to some extent 66 | if throttle > 1 - (0.4 * abs(steering)): 67 | reward *= 0.8 68 | 69 | # make sure reward value returned is within the prescribed value range. 70 | reward = max(reward, GLOBAL_MIN) 71 | reward = min(reward, GLOBAL_MAX) 72 | 73 | return float(reward) 74 | -------------------------------------------------------------------------------- /10_Decuple/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Machine-Learning-Labs/DeepRacerRewardFunctionsCollection/f6addf4654de90f9d1669fd5de67331add93ab2f/10_Decuple/.gitkeep -------------------------------------------------------------------------------- /11_Undecuple/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Machine-Learning-Labs/DeepRacerRewardFunctionsCollection/f6addf4654de90f9d1669fd5de67331add93ab2f/11_Undecuple/.gitkeep -------------------------------------------------------------------------------- /12_Duodecuple/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Machine-Learning-Labs/DeepRacerRewardFunctionsCollection/f6addf4654de90f9d1669fd5de67331add93ab2f/12_Duodecuple/.gitkeep -------------------------------------------------------------------------------- /13_Tredecuple/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Machine-Learning-Labs/DeepRacerRewardFunctionsCollection/f6addf4654de90f9d1669fd5de67331add93ab2f/13_Tredecuple/.gitkeep -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at Pelirrojo@users.noreply.github.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Transcriptase 2 | 3 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 4 | 5 | - Reporting a bug 6 | - Discussing the current state of the code 7 | - Submitting a fix 8 | - Proposing new features 9 | - Becoming a maintainer 10 | 11 | ## We Develop with Github 12 | We use github to host code, to track issues and feature requests, as well as accept pull requests. 13 | 14 | ## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests 15 | Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests: 16 | 17 | 1. Fork the repo and create your branch from `master`. 18 | 2. If you've added code that should be tested, add tests. 19 | 3. If you've changed APIs, update the documentation. 20 | 4. Ensure the test suite passes. 21 | 5. Make sure your code lints. 22 | 6. Issue that pull request! 23 | 24 | ## Any contributions you make will be under the MIT Software License 25 | In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern. 26 | 27 | ## Report bugs using Github's [issues](https://github.com/briandk/transcriptase-atom/issues) 28 | We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy! 29 | 30 | ## Write bug reports with detail, background, and sample code 31 | [This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report I wrote, and I think it's not a bad model. Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408), an app developer whom I greatly respect. 32 | 33 | **Great Bug Reports** tend to have: 34 | 35 | - A quick summary and/or background 36 | - Steps to reproduce 37 | - Be specific! 38 | - Give sample code if you can. [My stackoverflow question](http://stackoverflow.com/q/12488905/180626) includes sample code that *anyone* with a base R setup can run to reproduce what I was seeing 39 | - What you expected would happen 40 | - What actually happens 41 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 42 | 43 | People *love* thorough bug reports. I'm not even kidding. 44 | 45 | ## Use a Consistent Coding Style 46 | I'm again borrowing these from [Facebook's Guidelines](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md) 47 | 48 | * 2 spaces for indentation rather than tabs 49 | * You can try running `npm run lint` for style unification 50 | 51 | ## License 52 | By contributing, you agree that your contributions will be licensed under its MIT License. 53 | 54 | ## References 55 | This document was adapted from the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md) 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright © 2019 Manuel Eusebio de Paz Carmona 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the “Software”), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS Deep Racer Reward Functions Compilation 2 | 3 | This repository includes a compilation of reward functions for the AWS Deep Racer service. 4 | They have been collected from many other authors with the interest of conducting a comparative study. 5 | 6 | All the files include a initial description with: 7 | 8 | ```python 9 | 10 | ''' 11 | @author: // 12 | @Link: https://github.com// 13 | @License: 14 | ''' 15 | 16 | ``` 17 | 18 | ## Taxonomy 19 | 20 | The classification system is based solely on the input variables used in the function. 21 | 22 | * Void: None of input params 23 | * Single: One input var i.e. all_wheels_on_track 24 | * Double: Two ... 25 | * Tredecuple: All the input 26 | 27 | ## Input Parameters 28 | 29 | The ```params``` dictionary object contains the following key-value pairs: 30 | 31 | ```python 32 | params = { 33 | "all_wheels_on_track": Boolean, # flag to indicate if the vehicle is on the track 34 | "x": float, # vehicle's x-coordinate in meters 35 | "y": float, # vehicle's y-coordinate in meters 36 | "distance_from_center": float, # distance in meters from the track center 37 | "is_left_of_center": Boolean, # Flag to indicate if the vehicle is on the left side to the track center or not. 38 | "heading": float, # vehicle's yaw in degrees 39 | "progress": float, # percentage of track completed 40 | "steps": int, # number steps completed 41 | "speed": float, # vehicle's speed in meters per second (m/s) 42 | "steering_angle": float, # vehicle's steering angle in degrees 43 | "track_width": float, # width of the track 44 | "waypoints": [[float, float], ... ], # list of [x,y] as milestones along the track center 45 | "closest_waypoints": [int, int] # indices of the two nearest waypoints. 46 | } 47 | 48 | ``` 49 | 50 | ## FAQ 51 | 52 | * __What means v0 & v1?__ v0 It's about the Deep Racer SDK, some examples uses a ```reward_function(param1, param2,...)``` version with params 53 | in a verbose way, but last version (v1) uses the dictionary defined before: ```reward_function(params)```. 54 | * __Which license are you using?__ Each file includes its licence if available, rest of own work is under MIT license. 55 | 56 | ## References 57 | 58 | * https://aws.amazon.com/deepracer/ 59 | * https://docs.aws.amazon.com/deepracer/latest/developerguide/ 60 | -------------------------------------------------------------------------------- /base.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @author: // 3 | @Link: https://github.com// 4 | @License: 5 | ''' 6 | 7 | def reward_function(params): 8 | 9 | # Read input parameters ############################## 10 | 11 | all_wheels_on_track = params["all_wheels_on_track"] 12 | x = params["x"] 13 | y = params["y"] 14 | distance_from_center = params["distance_from_center"] 15 | is_left_of_center = params["is_left_of_center"] 16 | heading = params["heading"] 17 | progress = params["progress"] 18 | steps = params["steps"] 19 | speed = params["speed"] 20 | streering_angle = params["streering_angle"] 21 | track_width = params["track_width"] 22 | waypoints = params["waypoints"] 23 | closest_waypoints = params["closest_waypoints"] 24 | 25 | # Constants ######################################### 26 | 27 | REWARD_MIN = -1e5 28 | REWARD_MAX = 1e5 29 | 30 | # Logic ######################################### 31 | 32 | reward = 0 33 | 34 | return float(reward) 35 | --------------------------------------------------------------------------------