{"action":"created","comment":{"url":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/comments/229752466","pull_request_review_id":170325957,"id":229752466,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyOTc1MjQ2Ng==","diff_hunk":"@@ -0,0 +1,283 @@\n+#include \"backend_output/grsim/motion_controller.h\"\n+\n+#include <chrono>\n+#include <iostream>\n+#include <utility>\n+\n+#include \"ai/world/robot.h\"\n+#include \"geom/angle.h\"\n+#include \"geom/point.h\"\n+#include \"shared/constants.h\"\n+\n+\n+/**\n+ * .cpp file for the grSim motion controller.\n+ *\n+ * In the current state it is a bang-bang controller.\n+ *\n+ * It assumed the robot max acceleration is constant.\n+ *\n+ * Uses constant acceleration kinematics equations to\n+ * calculate changes in speed.\n+ *\n+ * See https://en.wikipedia.org/wiki/Bang%E2%80%93bang_control for more info\n+ */\n+MotionController::Velocity MotionController::bangBangVelocityController(\n+    const Robot robot, const Point dest, const double desired_final_speed,\n+    const Angle desired_final_orientation, const double delta_time)\n+{\n+    MotionController::Velocity robot_velocities;\n+\n+    // if the change is time is somehow negative or zero, just return the current robot\n+    // velocity\n+    if (delta_time <= 0)\n+    {\n+        robot_velocities.linear_velocity  = robot.velocity();\n+        robot_velocities.angular_velocity = robot.angularVelocity();\n+    }\n+    else\n+    {\n+        robot_velocities.linear_velocity = MotionController::determineLinearVelocity(\n+            robot, dest, desired_final_speed, delta_time);\n+        robot_velocities.angular_velocity = MotionController::determineAngularVelocity(\n+            robot, desired_final_orientation, delta_time);\n+    }\n+\n+    return robot_velocities;\n+}\n+\n+AngularVelocity MotionController::determineAngularVelocity(\n+    const Robot robot, const Angle desired_final_orientation, const double delta_time)\n+{\n+    // boolean value if the robot can reach it's destination at target speed based on\n+    // angular MAX acceleration\n+    bool can_stop_rotate_in_time;\n+    bool rotating_towards_dest;\n+\n+    // check the direction of rotation of the robot\n+    bool angular_velocity_is_positive = robot.angularVelocity().toRadians() > 0;\n+    AngularVelocity robot_angular_velocity;\n+\n+    // rotation used for constant angular acceleration calculations\n+    const Angle angle_to_dest = (desired_final_orientation - robot.orientation());\n+    // integer that will be -1 or 1 giving the rotation direction to reach the destination\n+    const int direction_to_dest =\n+        angle_to_dest.toRadians() / angle_to_dest.abs().toRadians();\n+\n+    AngularVelocity delta_angular_speed;\n+\n+    // check if the robot is nearly in it's final orientation with close to no angular\n+    // velocity\n+    if ((robot.orientation() - desired_final_orientation).abs().toRadians() <=\n+            POSITION_STOP_TOLERANCE &&\n+        robot.angularVelocity().toRadians() <= VELOCITY_STOP_TOLERANCE)\n+    {\n+        return AngularVelocity::ofRadians(0);\n+    }\n+\n+    // check if the robot is rotating in the same direction as it's target angle\n+    if ((desired_final_orientation - robot.orientation()).abs().toRadians() > 0 &&","path":"src/thunderbots/software/backend_output/grsim/motion_controller.cpp","position":79,"original_position":79,"commit_id":"6e52b95fe592b8fe1b3b2f25ee282ddc5f300611","original_commit_id":"6e52b95fe592b8fe1b3b2f25ee282ddc5f300611","user":{"login":"EvanMorcom","id":25271038,"node_id":"MDQ6VXNlcjI1MjcxMDM4","avatar_url":"https://avatars0.githubusercontent.com/u/25271038?v=4","gravatar_id":"","url":"https://api.github.com/users/EvanMorcom","html_url":"https://github.com/EvanMorcom","followers_url":"https://api.github.com/users/EvanMorcom/followers","following_url":"https://api.github.com/users/EvanMorcom/following{/other_user}","gists_url":"https://api.github.com/users/EvanMorcom/gists{/gist_id}","starred_url":"https://api.github.com/users/EvanMorcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EvanMorcom/subscriptions","organizations_url":"https://api.github.com/users/EvanMorcom/orgs","repos_url":"https://api.github.com/users/EvanMorcom/repos","events_url":"https://api.github.com/users/EvanMorcom/events{/privacy}","received_events_url":"https://api.github.com/users/EvanMorcom/received_events","type":"User","site_admin":false},"body":"Double check this math","created_at":"2018-10-31T15:44:56Z","updated_at":"2018-10-31T15:44:57Z","html_url":"https://github.com/UBC-Thunderbots/Software/pull/100#discussion_r229752466","pull_request_url":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/comments/229752466"},"html":{"href":"https://github.com/UBC-Thunderbots/Software/pull/100#discussion_r229752466"},"pull_request":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100"}}},"pull_request":{"url":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100","id":223449724,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIzNDQ5NzI0","html_url":"https://github.com/UBC-Thunderbots/Software/pull/100","diff_url":"https://github.com/UBC-Thunderbots/Software/pull/100.diff","patch_url":"https://github.com/UBC-Thunderbots/Software/pull/100.patch","issue_url":"https://api.github.com/repos/UBC-Thunderbots/Software/issues/100","number":100,"state":"open","locked":false,"title":"GrSim Bang-bang Motion Controller","user":{"login":"EvanMorcom","id":25271038,"node_id":"MDQ6VXNlcjI1MjcxMDM4","avatar_url":"https://avatars0.githubusercontent.com/u/25271038?v=4","gravatar_id":"","url":"https://api.github.com/users/EvanMorcom","html_url":"https://github.com/EvanMorcom","followers_url":"https://api.github.com/users/EvanMorcom/followers","following_url":"https://api.github.com/users/EvanMorcom/following{/other_user}","gists_url":"https://api.github.com/users/EvanMorcom/gists{/gist_id}","starred_url":"https://api.github.com/users/EvanMorcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EvanMorcom/subscriptions","organizations_url":"https://api.github.com/users/EvanMorcom/orgs","repos_url":"https://api.github.com/users/EvanMorcom/repos","events_url":"https://api.github.com/users/EvanMorcom/events{/privacy}","received_events_url":"https://api.github.com/users/EvanMorcom/received_events","type":"User","site_admin":false},"body":"<!---\r\nThis file outlines a list of common things that should be addressed when opening a PR. It's built from previous issues we've seen in a lot of pull requests. If you notice something that's being noted in a lot of PR's, it should probably be added here to help save people time in the future.\r\n-->\r\n\r\n## GrSim Motion Controller\r\n\r\n### Description\r\nWe're looking to improve the \"realism\" of our robot control in grSim, so I've put together a simple bang-bang motion controller. This is similar to the controller on the real robot. \r\nA bang-bang controller should in theory be much more accurate than the previous one. The old motion controller for grsim has no time dependence and robot velocities can change instantaneously.\r\n\r\n### Testing Done\r\n- 23 Unit tests checking that the controller gives an appropriate velocity for each directional case. Additionally, there are 6 iterative time-step based unit tests to make sure that the robot reaches it's target destination with the target velocity for the 4 linear direction cases and the 2 angular direction cases.\r\nNo actual grSim testing was done as we don't really have the capability right now.\r\n\r\n### Resolved Issues\r\nresolved #9 \r\n\r\n### Review Checklist\r\n***It is the reviewers responsibility to also make sure every item here has been covered***\r\n- [X] **Start of document comments**: each `.cpp` and `.h` file should have a comment at the start of it. See files in the `thunderbots/software/geom` folder for examples.\r\n- [X] **Function comments**: All function definitions (usually in the `.h` file) should have a javadoc style comment at the start of them. For examples, see the classes defined in `thunderbots/software/geom` \r\n- [X] **Remove all commented out code**\r\n- [X] **Remove extra print statements**: for example, those just used for testing\r\n- [X] **Resolve all TODO's**: All `TODO` (or similar) statements should either be completed or associated with a github issue\r\n\r\n\r\n","created_at":"2018-10-17T02:25:37Z","updated_at":"2018-10-31T15:44:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8308ae26454fe9e09cc078bc103dfbed0b97c1f2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100/commits","review_comments_url":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100/comments","review_comment_url":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/comments{/number}","comments_url":"https://api.github.com/repos/UBC-Thunderbots/Software/issues/100/comments","statuses_url":"https://api.github.com/repos/UBC-Thunderbots/Software/statuses/6e52b95fe592b8fe1b3b2f25ee282ddc5f300611","head":{"label":"EvanMorcom:MotionControllerGrsim","ref":"MotionControllerGrsim","sha":"6e52b95fe592b8fe1b3b2f25ee282ddc5f300611","user":{"login":"EvanMorcom","id":25271038,"node_id":"MDQ6VXNlcjI1MjcxMDM4","avatar_url":"https://avatars0.githubusercontent.com/u/25271038?v=4","gravatar_id":"","url":"https://api.github.com/users/EvanMorcom","html_url":"https://github.com/EvanMorcom","followers_url":"https://api.github.com/users/EvanMorcom/followers","following_url":"https://api.github.com/users/EvanMorcom/following{/other_user}","gists_url":"https://api.github.com/users/EvanMorcom/gists{/gist_id}","starred_url":"https://api.github.com/users/EvanMorcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EvanMorcom/subscriptions","organizations_url":"https://api.github.com/users/EvanMorcom/orgs","repos_url":"https://api.github.com/users/EvanMorcom/repos","events_url":"https://api.github.com/users/EvanMorcom/events{/privacy}","received_events_url":"https://api.github.com/users/EvanMorcom/received_events","type":"User","site_admin":false},"repo":{"id":142702380,"node_id":"MDEwOlJlcG9zaXRvcnkxNDI3MDIzODA=","name":"Software","full_name":"EvanMorcom/Software","private":false,"owner":{"login":"EvanMorcom","id":25271038,"node_id":"MDQ6VXNlcjI1MjcxMDM4","avatar_url":"https://avatars0.githubusercontent.com/u/25271038?v=4","gravatar_id":"","url":"https://api.github.com/users/EvanMorcom","html_url":"https://github.com/EvanMorcom","followers_url":"https://api.github.com/users/EvanMorcom/followers","following_url":"https://api.github.com/users/EvanMorcom/following{/other_user}","gists_url":"https://api.github.com/users/EvanMorcom/gists{/gist_id}","starred_url":"https://api.github.com/users/EvanMorcom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EvanMorcom/subscriptions","organizations_url":"https://api.github.com/users/EvanMorcom/orgs","repos_url":"https://api.github.com/users/EvanMorcom/repos","events_url":"https://api.github.com/users/EvanMorcom/events{/privacy}","received_events_url":"https://api.github.com/users/EvanMorcom/received_events","type":"User","site_admin":false},"html_url":"https://github.com/EvanMorcom/Software","description":null,"fork":true,"url":"https://api.github.com/repos/EvanMorcom/Software","forks_url":"https://api.github.com/repos/EvanMorcom/Software/forks","keys_url":"https://api.github.com/repos/EvanMorcom/Software/keys{/key_id}","collaborators_url":"https://api.github.com/repos/EvanMorcom/Software/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/EvanMorcom/Software/teams","hooks_url":"https://api.github.com/repos/EvanMorcom/Software/hooks","issue_events_url":"https://api.github.com/repos/EvanMorcom/Software/issues/events{/number}","events_url":"https://api.github.com/repos/EvanMorcom/Software/events","assignees_url":"https://api.github.com/repos/EvanMorcom/Software/assignees{/user}","branches_url":"https://api.github.com/repos/EvanMorcom/Software/branches{/branch}","tags_url":"https://api.github.com/repos/EvanMorcom/Software/tags","blobs_url":"https://api.github.com/repos/EvanMorcom/Software/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/EvanMorcom/Software/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/EvanMorcom/Software/git/refs{/sha}","trees_url":"https://api.github.com/repos/EvanMorcom/Software/git/trees{/sha}","statuses_url":"https://api.github.com/repos/EvanMorcom/Software/statuses/{sha}","languages_url":"https://api.github.com/repos/EvanMorcom/Software/languages","stargazers_url":"https://api.github.com/repos/EvanMorcom/Software/stargazers","contributors_url":"https://api.github.com/repos/EvanMorcom/Software/contributors","subscribers_url":"https://api.github.com/repos/EvanMorcom/Software/subscribers","subscription_url":"https://api.github.com/repos/EvanMorcom/Software/subscription","commits_url":"https://api.github.com/repos/EvanMorcom/Software/commits{/sha}","git_commits_url":"https://api.github.com/repos/EvanMorcom/Software/git/commits{/sha}","comments_url":"https://api.github.com/repos/EvanMorcom/Software/comments{/number}","issue_comment_url":"https://api.github.com/repos/EvanMorcom/Software/issues/comments{/number}","contents_url":"https://api.github.com/repos/EvanMorcom/Software/contents/{+path}","compare_url":"https://api.github.com/repos/EvanMorcom/Software/compare/{base}...{head}","merges_url":"https://api.github.com/repos/EvanMorcom/Software/merges","archive_url":"https://api.github.com/repos/EvanMorcom/Software/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/EvanMorcom/Software/downloads","issues_url":"https://api.github.com/repos/EvanMorcom/Software/issues{/number}","pulls_url":"https://api.github.com/repos/EvanMorcom/Software/pulls{/number}","milestones_url":"https://api.github.com/repos/EvanMorcom/Software/milestones{/number}","notifications_url":"https://api.github.com/repos/EvanMorcom/Software/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/EvanMorcom/Software/labels{/name}","releases_url":"https://api.github.com/repos/EvanMorcom/Software/releases{/id}","deployments_url":"https://api.github.com/repos/EvanMorcom/Software/deployments","created_at":"2018-07-28T18:53:53Z","updated_at":"2018-10-14T01:11:26Z","pushed_at":"2018-10-27T22:42:06Z","git_url":"git://github.com/EvanMorcom/Software.git","ssh_url":"git@github.com:EvanMorcom/Software.git","clone_url":"https://github.com/EvanMorcom/Software.git","svn_url":"https://github.com/EvanMorcom/Software","homepage":null,"size":1889,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"UBC-Thunderbots:master","ref":"master","sha":"095e3cd3faa6527109969ffaba78fc0ac4427841","user":{"login":"UBC-Thunderbots","id":27097762,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3MDk3NzYy","avatar_url":"https://avatars1.githubusercontent.com/u/27097762?v=4","gravatar_id":"","url":"https://api.github.com/users/UBC-Thunderbots","html_url":"https://github.com/UBC-Thunderbots","followers_url":"https://api.github.com/users/UBC-Thunderbots/followers","following_url":"https://api.github.com/users/UBC-Thunderbots/following{/other_user}","gists_url":"https://api.github.com/users/UBC-Thunderbots/gists{/gist_id}","starred_url":"https://api.github.com/users/UBC-Thunderbots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UBC-Thunderbots/subscriptions","organizations_url":"https://api.github.com/users/UBC-Thunderbots/orgs","repos_url":"https://api.github.com/users/UBC-Thunderbots/repos","events_url":"https://api.github.com/users/UBC-Thunderbots/events{/privacy}","received_events_url":"https://api.github.com/users/UBC-Thunderbots/received_events","type":"Organization","site_admin":false},"repo":{"id":141040516,"node_id":"MDEwOlJlcG9zaXRvcnkxNDEwNDA1MTY=","name":"Software","full_name":"UBC-Thunderbots/Software","private":false,"owner":{"login":"UBC-Thunderbots","id":27097762,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI3MDk3NzYy","avatar_url":"https://avatars1.githubusercontent.com/u/27097762?v=4","gravatar_id":"","url":"https://api.github.com/users/UBC-Thunderbots","html_url":"https://github.com/UBC-Thunderbots","followers_url":"https://api.github.com/users/UBC-Thunderbots/followers","following_url":"https://api.github.com/users/UBC-Thunderbots/following{/other_user}","gists_url":"https://api.github.com/users/UBC-Thunderbots/gists{/gist_id}","starred_url":"https://api.github.com/users/UBC-Thunderbots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UBC-Thunderbots/subscriptions","organizations_url":"https://api.github.com/users/UBC-Thunderbots/orgs","repos_url":"https://api.github.com/users/UBC-Thunderbots/repos","events_url":"https://api.github.com/users/UBC-Thunderbots/events{/privacy}","received_events_url":"https://api.github.com/users/UBC-Thunderbots/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/UBC-Thunderbots/Software","description":"we do things","fork":false,"url":"https://api.github.com/repos/UBC-Thunderbots/Software","forks_url":"https://api.github.com/repos/UBC-Thunderbots/Software/forks","keys_url":"https://api.github.com/repos/UBC-Thunderbots/Software/keys{/key_id}","collaborators_url":"https://api.github.com/repos/UBC-Thunderbots/Software/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/UBC-Thunderbots/Software/teams","hooks_url":"https://api.github.com/repos/UBC-Thunderbots/Software/hooks","issue_events_url":"https://api.github.com/repos/UBC-Thunderbots/Software/issues/events{/number}","events_url":"https://api.github.com/repos/UBC-Thunderbots/Software/events","assignees_url":"https://api.github.com/repos/UBC-Thunderbots/Software/assignees{/user}","branches_url":"https://api.github.com/repos/UBC-Thunderbots/Software/branches{/branch}","tags_url":"https://api.github.com/repos/UBC-Thunderbots/Software/tags","blobs_url":"https://api.github.com/repos/UBC-Thunderbots/Software/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/UBC-Thunderbots/Software/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/UBC-Thunderbots/Software/git/refs{/sha}","trees_url":"https://api.github.com/repos/UBC-Thunderbots/Software/git/trees{/sha}","statuses_url":"https://api.github.com/repos/UBC-Thunderbots/Software/statuses/{sha}","languages_url":"https://api.github.com/repos/UBC-Thunderbots/Software/languages","stargazers_url":"https://api.github.com/repos/UBC-Thunderbots/Software/stargazers","contributors_url":"https://api.github.com/repos/UBC-Thunderbots/Software/contributors","subscribers_url":"https://api.github.com/repos/UBC-Thunderbots/Software/subscribers","subscription_url":"https://api.github.com/repos/UBC-Thunderbots/Software/subscription","commits_url":"https://api.github.com/repos/UBC-Thunderbots/Software/commits{/sha}","git_commits_url":"https://api.github.com/repos/UBC-Thunderbots/Software/git/commits{/sha}","comments_url":"https://api.github.com/repos/UBC-Thunderbots/Software/comments{/number}","issue_comment_url":"https://api.github.com/repos/UBC-Thunderbots/Software/issues/comments{/number}","contents_url":"https://api.github.com/repos/UBC-Thunderbots/Software/contents/{+path}","compare_url":"https://api.github.com/repos/UBC-Thunderbots/Software/compare/{base}...{head}","merges_url":"https://api.github.com/repos/UBC-Thunderbots/Software/merges","archive_url":"https://api.github.com/repos/UBC-Thunderbots/Software/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/UBC-Thunderbots/Software/downloads","issues_url":"https://api.github.com/repos/UBC-Thunderbots/Software/issues{/number}","pulls_url":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls{/number}","milestones_url":"https://api.github.com/repos/UBC-Thunderbots/Software/milestones{/number}","notifications_url":"https://api.github.com/repos/UBC-Thunderbots/Software/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/UBC-Thunderbots/Software/labels{/name}","releases_url":"https://api.github.com/repos/UBC-Thunderbots/Software/releases{/id}","deployments_url":"https://api.github.com/repos/UBC-Thunderbots/Software/deployments","created_at":"2018-07-15T16:06:15Z","updated_at":"2018-10-30T16:51:55Z","pushed_at":"2018-10-31T14:15:36Z","git_url":"git://github.com/UBC-Thunderbots/Software.git","ssh_url":"git@github.com:UBC-Thunderbots/Software.git","clone_url":"https://github.com/UBC-Thunderbots/Software.git","svn_url":"https://github.com/UBC-Thunderbots/Software","homepage":"http://www.ubcthunderbots.ca","size":1824,"stargazers_count":6,"watchers_count":6,"language":"C++","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":23,"mirror_url":null,"archived":false,"open_issues_count":49,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":23,"open_issues":49,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100"},"html":{"href":"https://github.com/UBC-Thunderbots/Software/pull/100"},"issue":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/issues/100"},"comments":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/issues/100/comments"},"review_comments":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100/comments"},"review_comment":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/pulls/100/commits"},"statuses":{"href":"https://api.github.com/repos/UBC-Thunderbots/Software/statuses/6e52b95fe592b8fe1b3b2f25ee282ddc5f300611"}},"author_association":"NONE"}}
{"actor":{"display_login":"EvanMorcom"}}