{"action":"created","comment":{"url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/comments/86261884","pull_request_review_id":6928471,"id":86261884,"diff_hunk":"@@ -0,0 +1,207 @@\n+#include \"movement/maestro_thruster_controller.hpp\"\n+namespace rs\n+{\n+    /**\n+     * Constructor.\n+     *\n+     */\n+    MaestroThrusterController::MaestroThrusterController()\n+    {\n+        _is_initialized = false;\n+\n+\n+    }\n+\n+\n+    /**\n+     * Deconstructor.\n+     *\n+     */\n+    MaestroThrusterController::~MaestroThrusterController()\n+    {\n+    }\n+\n+    /**\n+     * initializes the thruster controller. Must be called before using any\n+     * other functions\n+     *\n+     * @param thrusters The number of thrusters controlled by the controller.\n+     * @param max_speed The maximum normalized speed in the forward and reverse\n+     *        directions that should be allowed by the controller.\n+     * @param delay_ms Delay specified in milliseconds to continue sending\n+     *        zeroing signal to continue thruster operation.\n+     * @param port The serial port to be used for communicating with the\n+     *        thrusters. This port may be changed during runtime.\n+     */\n+    int MaestroThrusterController::init( const double max_speed,\n+                                           Serial *port,\n+                                           const double delay_ms)\n+    {\n+        if(setPort(port) != 0)\n+        {\n+            return -1;\n+        }\n+\n+        _post_reset_delay_ms == delay_ms;\n+\n+        //initialze thruster settings\n+        //loop over all possible channels (0-11)\n+        ros::Time now = ros::Time::now();\n+        for(uint8_t i = 0; i < _max_thrusters; ++i)\n+        {\n+            //initialze reset time\n+            _next_reset[i] = now;\n+\n+            //set max speed for thruster\n+            _max_speed[i] = max_speed;\n+        }\n+\n+        if (delay_ms < 185.00)\n+        {\n+            ROS_ERROR(\"Thruster millisecond delay is too low.\");\n+            return -1;\n+        }\n+\n+        _is_initialized = true;\n+        return 0;\n+    }\n+\n+    /**\n+     * Sets the serial port used to communicate with the thrusters.\n+     *\n+     * @param port A pointer to a configured and initialized serial port to be\n+     *        used for communicating with the Maestro.\n+     *\n+     * @return Zero upon success and -1 upon failure.\n+     */\n+    int MaestroThrusterController::setPort(Serial *port)\n+    {\n+        _port = port;\n+        if (_port != nullptr)\n+        {\n+            uint8_t detect_byte = 0xAA;\n+            if (port->Write(&detect_byte, 1) != 1)\n+            {\n+                ROS_ERROR(\"Serial port failed to write baud-detection bit.\");\n+                return -1;\n+            }\n+            return 0;\n+        }\n+        ROS_ERROR(\"Serial port pointer supplied is not a valid pointer.\");\n+        return -1;\n+    }\n+\n+    /**\n+     * Sets the speed of a thruster.\n+     *\n+     * @param speeds The normalized speed to set the thruster to.\n+     *\n+     * @return 0 on success and -1 on failure.\n+     */\n+    int MaestroThrusterController::set(double speed, const uint8_t &channel)\n+    {\n+        if(_is_initialized != true)\n+        {\n+            ROS_ERROR(\"motor controller used before being initialized\");\n+            return -1;\n+        }\n+\n+\n+        /*\n+         * Create an array of bytes. A thruster command requires 4 bytes\n+         */\n+        uint8_t command[4];\n+\n+        command[0] = static_cast<uint8_t>(MaestroCommands::SetTarget);\n+        command[1] = channel;\n+\n+        /*\n+         * Check to see if it's currently time to send a reset signal.\n+         * Send the reset signal first if necessary\n+         */\n+        ros::Time now = ros::Time::now();\n+        if (now > _next_reset[channel])\n+        {\n+            ROS_DEBUG_STREAM(\"Sending thruster reset signal.\");\n+            if (parseNormalized(0, command[3], command[2]))\n+            {\n+                ROS_ERROR( \"Parse Normalized encountered abnormal thruster speed.\");\n+                return -1;\n+            }\n+\n+            if (_port->Write(command, sizeof(command)) != sizeof(command))\n+            {\n+                ROS_ERROR(\"Serial port failed to write entire command.\");\n+                return -1;\n+            }\n+\n+            _next_reset[channel] = ros::Time::now() + ros::Duration(reset_delay);\n+\n+            /*\n+             * Sleep to ensure that the zero pulse has propogated to the ESC.\n+             * Any value less than 185ms may result in the ESC not receiving\n+             * the zero pulse, which will cause it to malfunction\n+             */\n+            ros::Duration(float(_post_reset_delay_ms)/1000).sleep();\n+        }\n+\n+        /*\n+         * Send thruster command down the to the Maestro.\n+         */\n+        if (speed < -1 || speed > 1)\n+        {\n+            ROS_ERROR(\"Thruster speed out of range.\");\n+            return -1;\n+        }\n+\n+        if (speed > _max_speed[channel])","path":"src/movement/maestro_thruster_controller.cpp","position":157,"original_position":157,"commit_id":"b14cd9ccf98d8a62cbb461e8a2feb51c78e51f5c","original_commit_id":"b50eaa5928fbfc8a0db8d5063754a78e16267aad","user":{"login":"irwineffect","id":3589531,"avatar_url":"https://avatars.githubusercontent.com/u/3589531?v=3","gravatar_id":"","url":"https://api.github.com/users/irwineffect","html_url":"https://github.com/irwineffect","followers_url":"https://api.github.com/users/irwineffect/followers","following_url":"https://api.github.com/users/irwineffect/following{/other_user}","gists_url":"https://api.github.com/users/irwineffect/gists{/gist_id}","starred_url":"https://api.github.com/users/irwineffect/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/irwineffect/subscriptions","organizations_url":"https://api.github.com/users/irwineffect/orgs","repos_url":"https://api.github.com/users/irwineffect/repos","events_url":"https://api.github.com/users/irwineffect/events{/privacy}","received_events_url":"https://api.github.com/users/irwineffect/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-11-02T23:04:17Z","updated_at":"2016-11-02T23:04:17Z","html_url":"https://github.com/PalouseRobosub/robosub/pull/56#discussion_r86261884","pull_request_url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56","_links":{"self":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/comments/86261884"},"html":{"href":"https://github.com/PalouseRobosub/robosub/pull/56#discussion_r86261884"},"pull_request":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56"}}},"pull_request":{"url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56","id":91322910,"html_url":"https://github.com/PalouseRobosub/robosub/pull/56","diff_url":"https://github.com/PalouseRobosub/robosub/pull/56.diff","patch_url":"https://github.com/PalouseRobosub/robosub/pull/56.patch","issue_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues/56","number":56,"state":"open","locked":false,"title":"ThrusterController Class Review","user":{"login":"ryan-summers","id":8771450,"avatar_url":"https://avatars.githubusercontent.com/u/8771450?v=3","gravatar_id":"","url":"https://api.github.com/users/ryan-summers","html_url":"https://github.com/ryan-summers","followers_url":"https://api.github.com/users/ryan-summers/followers","following_url":"https://api.github.com/users/ryan-summers/following{/other_user}","gists_url":"https://api.github.com/users/ryan-summers/gists{/gist_id}","starred_url":"https://api.github.com/users/ryan-summers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryan-summers/subscriptions","organizations_url":"https://api.github.com/users/ryan-summers/orgs","repos_url":"https://api.github.com/users/ryan-summers/repos","events_url":"https://api.github.com/users/ryan-summers/events{/privacy}","received_events_url":"https://api.github.com/users/ryan-summers/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-28T05:05:44Z","updated_at":"2016-11-02T23:04:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"da010057a5315b57fef37d2cfcf88775205b0bf8","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56/commits","review_comments_url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56/comments","review_comment_url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues/56/comments","statuses_url":"https://api.github.com/repos/PalouseRobosub/robosub/statuses/b14cd9ccf98d8a62cbb461e8a2feb51c78e51f5c","head":{"label":"PalouseRobosub:rsummers/thruster","ref":"rsummers/thruster","sha":"b14cd9ccf98d8a62cbb461e8a2feb51c78e51f5c","user":{"login":"PalouseRobosub","id":5367721,"avatar_url":"https://avatars.githubusercontent.com/u/5367721?v=3","gravatar_id":"","url":"https://api.github.com/users/PalouseRobosub","html_url":"https://github.com/PalouseRobosub","followers_url":"https://api.github.com/users/PalouseRobosub/followers","following_url":"https://api.github.com/users/PalouseRobosub/following{/other_user}","gists_url":"https://api.github.com/users/PalouseRobosub/gists{/gist_id}","starred_url":"https://api.github.com/users/PalouseRobosub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PalouseRobosub/subscriptions","organizations_url":"https://api.github.com/users/PalouseRobosub/orgs","repos_url":"https://api.github.com/users/PalouseRobosub/repos","events_url":"https://api.github.com/users/PalouseRobosub/events{/privacy}","received_events_url":"https://api.github.com/users/PalouseRobosub/received_events","type":"Organization","site_admin":false},"repo":{"id":67822722,"name":"robosub","full_name":"PalouseRobosub/robosub","owner":{"login":"PalouseRobosub","id":5367721,"avatar_url":"https://avatars.githubusercontent.com/u/5367721?v=3","gravatar_id":"","url":"https://api.github.com/users/PalouseRobosub","html_url":"https://github.com/PalouseRobosub","followers_url":"https://api.github.com/users/PalouseRobosub/followers","following_url":"https://api.github.com/users/PalouseRobosub/following{/other_user}","gists_url":"https://api.github.com/users/PalouseRobosub/gists{/gist_id}","starred_url":"https://api.github.com/users/PalouseRobosub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PalouseRobosub/subscriptions","organizations_url":"https://api.github.com/users/PalouseRobosub/orgs","repos_url":"https://api.github.com/users/PalouseRobosub/repos","events_url":"https://api.github.com/users/PalouseRobosub/events{/privacy}","received_events_url":"https://api.github.com/users/PalouseRobosub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PalouseRobosub/robosub","description":"Code for the computer on the sub","fork":false,"url":"https://api.github.com/repos/PalouseRobosub/robosub","forks_url":"https://api.github.com/repos/PalouseRobosub/robosub/forks","keys_url":"https://api.github.com/repos/PalouseRobosub/robosub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PalouseRobosub/robosub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PalouseRobosub/robosub/teams","hooks_url":"https://api.github.com/repos/PalouseRobosub/robosub/hooks","issue_events_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues/events{/number}","events_url":"https://api.github.com/repos/PalouseRobosub/robosub/events","assignees_url":"https://api.github.com/repos/PalouseRobosub/robosub/assignees{/user}","branches_url":"https://api.github.com/repos/PalouseRobosub/robosub/branches{/branch}","tags_url":"https://api.github.com/repos/PalouseRobosub/robosub/tags","blobs_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/refs{/sha}","trees_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PalouseRobosub/robosub/statuses/{sha}","languages_url":"https://api.github.com/repos/PalouseRobosub/robosub/languages","stargazers_url":"https://api.github.com/repos/PalouseRobosub/robosub/stargazers","contributors_url":"https://api.github.com/repos/PalouseRobosub/robosub/contributors","subscribers_url":"https://api.github.com/repos/PalouseRobosub/robosub/subscribers","subscription_url":"https://api.github.com/repos/PalouseRobosub/robosub/subscription","commits_url":"https://api.github.com/repos/PalouseRobosub/robosub/commits{/sha}","git_commits_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/commits{/sha}","comments_url":"https://api.github.com/repos/PalouseRobosub/robosub/comments{/number}","issue_comment_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues/comments{/number}","contents_url":"https://api.github.com/repos/PalouseRobosub/robosub/contents/{+path}","compare_url":"https://api.github.com/repos/PalouseRobosub/robosub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PalouseRobosub/robosub/merges","archive_url":"https://api.github.com/repos/PalouseRobosub/robosub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PalouseRobosub/robosub/downloads","issues_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues{/number}","pulls_url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls{/number}","milestones_url":"https://api.github.com/repos/PalouseRobosub/robosub/milestones{/number}","notifications_url":"https://api.github.com/repos/PalouseRobosub/robosub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PalouseRobosub/robosub/labels{/name}","releases_url":"https://api.github.com/repos/PalouseRobosub/robosub/releases{/id}","deployments_url":"https://api.github.com/repos/PalouseRobosub/robosub/deployments","created_at":"2016-09-09T18:28:47Z","updated_at":"2016-10-22T20:44:57Z","pushed_at":"2016-11-02T22:52:00Z","git_url":"git://github.com/PalouseRobosub/robosub.git","ssh_url":"git@github.com:PalouseRobosub/robosub.git","clone_url":"https://github.com/PalouseRobosub/robosub.git","svn_url":"https://github.com/PalouseRobosub/robosub","homepage":"","size":211,"stargazers_count":3,"watchers_count":3,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":15,"forks":0,"open_issues":15,"watchers":3,"default_branch":"dev"}},"base":{"label":"PalouseRobosub:dev","ref":"dev","sha":"ca9c91a1a15eb4ca2bd0cb39986dd745d3381688","user":{"login":"PalouseRobosub","id":5367721,"avatar_url":"https://avatars.githubusercontent.com/u/5367721?v=3","gravatar_id":"","url":"https://api.github.com/users/PalouseRobosub","html_url":"https://github.com/PalouseRobosub","followers_url":"https://api.github.com/users/PalouseRobosub/followers","following_url":"https://api.github.com/users/PalouseRobosub/following{/other_user}","gists_url":"https://api.github.com/users/PalouseRobosub/gists{/gist_id}","starred_url":"https://api.github.com/users/PalouseRobosub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PalouseRobosub/subscriptions","organizations_url":"https://api.github.com/users/PalouseRobosub/orgs","repos_url":"https://api.github.com/users/PalouseRobosub/repos","events_url":"https://api.github.com/users/PalouseRobosub/events{/privacy}","received_events_url":"https://api.github.com/users/PalouseRobosub/received_events","type":"Organization","site_admin":false},"repo":{"id":67822722,"name":"robosub","full_name":"PalouseRobosub/robosub","owner":{"login":"PalouseRobosub","id":5367721,"avatar_url":"https://avatars.githubusercontent.com/u/5367721?v=3","gravatar_id":"","url":"https://api.github.com/users/PalouseRobosub","html_url":"https://github.com/PalouseRobosub","followers_url":"https://api.github.com/users/PalouseRobosub/followers","following_url":"https://api.github.com/users/PalouseRobosub/following{/other_user}","gists_url":"https://api.github.com/users/PalouseRobosub/gists{/gist_id}","starred_url":"https://api.github.com/users/PalouseRobosub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PalouseRobosub/subscriptions","organizations_url":"https://api.github.com/users/PalouseRobosub/orgs","repos_url":"https://api.github.com/users/PalouseRobosub/repos","events_url":"https://api.github.com/users/PalouseRobosub/events{/privacy}","received_events_url":"https://api.github.com/users/PalouseRobosub/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PalouseRobosub/robosub","description":"Code for the computer on the sub","fork":false,"url":"https://api.github.com/repos/PalouseRobosub/robosub","forks_url":"https://api.github.com/repos/PalouseRobosub/robosub/forks","keys_url":"https://api.github.com/repos/PalouseRobosub/robosub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PalouseRobosub/robosub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PalouseRobosub/robosub/teams","hooks_url":"https://api.github.com/repos/PalouseRobosub/robosub/hooks","issue_events_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues/events{/number}","events_url":"https://api.github.com/repos/PalouseRobosub/robosub/events","assignees_url":"https://api.github.com/repos/PalouseRobosub/robosub/assignees{/user}","branches_url":"https://api.github.com/repos/PalouseRobosub/robosub/branches{/branch}","tags_url":"https://api.github.com/repos/PalouseRobosub/robosub/tags","blobs_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/refs{/sha}","trees_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PalouseRobosub/robosub/statuses/{sha}","languages_url":"https://api.github.com/repos/PalouseRobosub/robosub/languages","stargazers_url":"https://api.github.com/repos/PalouseRobosub/robosub/stargazers","contributors_url":"https://api.github.com/repos/PalouseRobosub/robosub/contributors","subscribers_url":"https://api.github.com/repos/PalouseRobosub/robosub/subscribers","subscription_url":"https://api.github.com/repos/PalouseRobosub/robosub/subscription","commits_url":"https://api.github.com/repos/PalouseRobosub/robosub/commits{/sha}","git_commits_url":"https://api.github.com/repos/PalouseRobosub/robosub/git/commits{/sha}","comments_url":"https://api.github.com/repos/PalouseRobosub/robosub/comments{/number}","issue_comment_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues/comments{/number}","contents_url":"https://api.github.com/repos/PalouseRobosub/robosub/contents/{+path}","compare_url":"https://api.github.com/repos/PalouseRobosub/robosub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PalouseRobosub/robosub/merges","archive_url":"https://api.github.com/repos/PalouseRobosub/robosub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PalouseRobosub/robosub/downloads","issues_url":"https://api.github.com/repos/PalouseRobosub/robosub/issues{/number}","pulls_url":"https://api.github.com/repos/PalouseRobosub/robosub/pulls{/number}","milestones_url":"https://api.github.com/repos/PalouseRobosub/robosub/milestones{/number}","notifications_url":"https://api.github.com/repos/PalouseRobosub/robosub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PalouseRobosub/robosub/labels{/name}","releases_url":"https://api.github.com/repos/PalouseRobosub/robosub/releases{/id}","deployments_url":"https://api.github.com/repos/PalouseRobosub/robosub/deployments","created_at":"2016-09-09T18:28:47Z","updated_at":"2016-10-22T20:44:57Z","pushed_at":"2016-11-02T22:52:00Z","git_url":"git://github.com/PalouseRobosub/robosub.git","ssh_url":"git@github.com:PalouseRobosub/robosub.git","clone_url":"https://github.com/PalouseRobosub/robosub.git","svn_url":"https://github.com/PalouseRobosub/robosub","homepage":"","size":211,"stargazers_count":3,"watchers_count":3,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":15,"forks":0,"open_issues":15,"watchers":3,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56"},"html":{"href":"https://github.com/PalouseRobosub/robosub/pull/56"},"issue":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/issues/56"},"comments":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/issues/56/comments"},"review_comments":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56/comments"},"review_comment":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/pulls/56/commits"},"statuses":{"href":"https://api.github.com/repos/PalouseRobosub/robosub/statuses/b14cd9ccf98d8a62cbb461e8a2feb51c78e51f5c"}}}}
{"actor":{"display_login":"irwineffect"}}