{"action":"created","comment":{"url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments/24717374","id":24717374,"diff_hunk":"@@ -0,0 +1,75 @@\n+classdef SimulationControlBlock < DrakeSystem\n+% This block provides an easy way to halt your running simulation gently (i.e. without ctrl+c).\n+% Pass the options gui_control_interface and/or lcm_control_interface into the simulate method to use it.\n+% This might be useful if, for example, you would like to see results plotted from a simulation\n+% without running it to completion.\n+  properties\n+    lc;\n+    monitor\n+    fig;\n+    halt_button\n+    halting\n+  end\n+\n+  methods\n+    function obj = SimulationControlBlock(show_gui, lcm_channel)\n+      % Construct a block to easily halt a running simulation. \n+      % @param show_gui whether to show a Matlab button labeled 'Halt Simulation'\n+      % @param lcm_channel channel on which to listen for\n+      % drake.lcmt_simulation_command messages\n+      if nargin < 2\n+        lcm_channel = '';\n+      end\n+      if nargin < 1\n+        show_gui = true;\n+      end\n+      obj = obj@DrakeSystem(0, 0, 0, 0, false, true);\n+      if ~isempty(lcm_channel)\n+        checkDependency('lcm');\n+        obj.lc = lcm.lcm.LCM.getSingleton();\n+        obj.monitor = drake.util.MessageMonitor(drake.lcmt_simulation_command(), 'timestamp');\n+        obj.lc.subscribe(lcm_channel, obj.monitor);\n+        fprintf(1,'Enabling LCM simultion control on channel %s\\n',lcm_channel);\n+      end\n+      if show_gui\n+        obj.fig = figure(142);\n+        set(obj.fig, 'Position', [600,100,350,100]);\n+        clf;\n+        % todo: add run, pause, stop etc buttons?\n+        obj.halt_button = uicontrol('Style', 'pushbutton', 'String', 'Halt Simulation', ...\n+          'Position', [5, 5, 340, 90],...\n+          'Callback', {@(s, e) set_param(bdroot(), 'SimulationCommand', 'Stop')},...\n+          'FontSize', 28,...\n+          'ForegroundColor', 'w',...\n+          'BackgroundColor', [.7,.2,.2]);\n+      end\n+    end\n+\n+    function y = output(obj, t, ~, ~)\n+      y=[];\n+      if ~isempty(obj.monitor)\n+        msg = obj.monitor.getNextMessage(0);\n+        if ~isempty(msg)\n+          msg = drake.lcmt_simulation_command(msg);\n+          \n+          % note: according to http://www.mathworks.com/help/simulink/ug/using-the-set-param-command.html\n+          % these will not work when matlab is run in -nodisplay mode\n+          % perhaps there is another way?\n+          % (e.g. http://www.mathworks.com/help/simulink/sfg/sssetstoprequested.html)\n+          % Despite the documentation, 'stop' seems to work even if the\n+          % simulation is started using the sim command.  but\n+          % 'start' and 'pause' seem to have no effect.\n+          % 'shutdown' seems easy, but you can't exit when a simulation is\n+          % running and force_close_system() didn't work.\n+          switch(msg.command_type)\n+            case msg.STOP\n+              disp('Received STOP LCM simulation command.');\n+              set_param(bdroot(), 'SimulationCommand', 'stop');","path":"util/SimulationControlBlock.m","position":67,"original_position":67,"commit_id":"adda9830474bf5cf507b60ae1203e598a005269c","original_commit_id":"adda9830474bf5cf507b60ae1203e598a005269c","user":{"login":"tkoolen","id":2585880,"avatar_url":"https://avatars.githubusercontent.com/u/2585880?v=3","gravatar_id":"","url":"https://api.github.com/users/tkoolen","html_url":"https://github.com/tkoolen","followers_url":"https://api.github.com/users/tkoolen/followers","following_url":"https://api.github.com/users/tkoolen/following{/other_user}","gists_url":"https://api.github.com/users/tkoolen/gists{/gist_id}","starred_url":"https://api.github.com/users/tkoolen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tkoolen/subscriptions","organizations_url":"https://api.github.com/users/tkoolen/orgs","repos_url":"https://api.github.com/users/tkoolen/repos","events_url":"https://api.github.com/users/tkoolen/events{/privacy}","received_events_url":"https://api.github.com/users/tkoolen/received_events","type":"User","site_admin":false},"body":"add default case and throw an error.","created_at":"2015-02-14T21:07:10Z","updated_at":"2015-02-14T21:07:10Z","html_url":"https://github.com/RobotLocomotion/drake/pull/757#discussion_r24717374","pull_request_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757","_links":{"self":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments/24717374"},"html":{"href":"https://github.com/RobotLocomotion/drake/pull/757#discussion_r24717374"},"pull_request":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757"}}},"pull_request":{"url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757","id":29133010,"html_url":"https://github.com/RobotLocomotion/drake/pull/757","diff_url":"https://github.com/RobotLocomotion/drake/pull/757.diff","patch_url":"https://github.com/RobotLocomotion/drake/pull/757.patch","issue_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/757","number":757,"state":"open","locked":false,"title":"(slightly) generalizes the HaltSimulationBlock logic from atlas to work ...","user":{"login":"RussTedrake","id":6442292,"avatar_url":"https://avatars.githubusercontent.com/u/6442292?v=3","gravatar_id":"","url":"https://api.github.com/users/RussTedrake","html_url":"https://github.com/RussTedrake","followers_url":"https://api.github.com/users/RussTedrake/followers","following_url":"https://api.github.com/users/RussTedrake/following{/other_user}","gists_url":"https://api.github.com/users/RussTedrake/gists{/gist_id}","starred_url":"https://api.github.com/users/RussTedrake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RussTedrake/subscriptions","organizations_url":"https://api.github.com/users/RussTedrake/orgs","repos_url":"https://api.github.com/users/RussTedrake/repos","events_url":"https://api.github.com/users/RussTedrake/events{/privacy}","received_events_url":"https://api.github.com/users/RussTedrake/received_events","type":"User","site_admin":false},"body":"...for any simulate.  removes minor drc lcmtype dependency\r\n","created_at":"2015-02-11T22:04:13Z","updated_at":"2015-02-14T21:07:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e2bd9c27e8439aef65bfb36f2b085efd0c8bf47","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757/commits","review_comments_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757/comments","review_comment_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments/{number}","comments_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/757/comments","statuses_url":"https://api.github.com/repos/RobotLocomotion/drake/statuses/adda9830474bf5cf507b60ae1203e598a005269c","head":{"label":"RussTedrake:lcm_sim_control","ref":"lcm_sim_control","sha":"adda9830474bf5cf507b60ae1203e598a005269c","user":{"login":"RussTedrake","id":6442292,"avatar_url":"https://avatars.githubusercontent.com/u/6442292?v=3","gravatar_id":"","url":"https://api.github.com/users/RussTedrake","html_url":"https://github.com/RussTedrake","followers_url":"https://api.github.com/users/RussTedrake/followers","following_url":"https://api.github.com/users/RussTedrake/following{/other_user}","gists_url":"https://api.github.com/users/RussTedrake/gists{/gist_id}","starred_url":"https://api.github.com/users/RussTedrake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RussTedrake/subscriptions","organizations_url":"https://api.github.com/users/RussTedrake/orgs","repos_url":"https://api.github.com/users/RussTedrake/repos","events_url":"https://api.github.com/users/RussTedrake/events{/privacy}","received_events_url":"https://api.github.com/users/RussTedrake/received_events","type":"User","site_admin":false},"repo":{"id":17115630,"name":"drake","full_name":"RussTedrake/drake","owner":{"login":"RussTedrake","id":6442292,"avatar_url":"https://avatars.githubusercontent.com/u/6442292?v=3","gravatar_id":"","url":"https://api.github.com/users/RussTedrake","html_url":"https://github.com/RussTedrake","followers_url":"https://api.github.com/users/RussTedrake/followers","following_url":"https://api.github.com/users/RussTedrake/following{/other_user}","gists_url":"https://api.github.com/users/RussTedrake/gists{/gist_id}","starred_url":"https://api.github.com/users/RussTedrake/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RussTedrake/subscriptions","organizations_url":"https://api.github.com/users/RussTedrake/orgs","repos_url":"https://api.github.com/users/RussTedrake/repos","events_url":"https://api.github.com/users/RussTedrake/events{/privacy}","received_events_url":"https://api.github.com/users/RussTedrake/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RussTedrake/drake","description":"A planning, control, and analysis toolbox for nonlinear dynamical systems.  Please see the WIKI for documentation.","fork":true,"url":"https://api.github.com/repos/RussTedrake/drake","forks_url":"https://api.github.com/repos/RussTedrake/drake/forks","keys_url":"https://api.github.com/repos/RussTedrake/drake/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RussTedrake/drake/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RussTedrake/drake/teams","hooks_url":"https://api.github.com/repos/RussTedrake/drake/hooks","issue_events_url":"https://api.github.com/repos/RussTedrake/drake/issues/events{/number}","events_url":"https://api.github.com/repos/RussTedrake/drake/events","assignees_url":"https://api.github.com/repos/RussTedrake/drake/assignees{/user}","branches_url":"https://api.github.com/repos/RussTedrake/drake/branches{/branch}","tags_url":"https://api.github.com/repos/RussTedrake/drake/tags","blobs_url":"https://api.github.com/repos/RussTedrake/drake/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RussTedrake/drake/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RussTedrake/drake/git/refs{/sha}","trees_url":"https://api.github.com/repos/RussTedrake/drake/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RussTedrake/drake/statuses/{sha}","languages_url":"https://api.github.com/repos/RussTedrake/drake/languages","stargazers_url":"https://api.github.com/repos/RussTedrake/drake/stargazers","contributors_url":"https://api.github.com/repos/RussTedrake/drake/contributors","subscribers_url":"https://api.github.com/repos/RussTedrake/drake/subscribers","subscription_url":"https://api.github.com/repos/RussTedrake/drake/subscription","commits_url":"https://api.github.com/repos/RussTedrake/drake/commits{/sha}","git_commits_url":"https://api.github.com/repos/RussTedrake/drake/git/commits{/sha}","comments_url":"https://api.github.com/repos/RussTedrake/drake/comments{/number}","issue_comment_url":"https://api.github.com/repos/RussTedrake/drake/issues/comments/{number}","contents_url":"https://api.github.com/repos/RussTedrake/drake/contents/{+path}","compare_url":"https://api.github.com/repos/RussTedrake/drake/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RussTedrake/drake/merges","archive_url":"https://api.github.com/repos/RussTedrake/drake/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RussTedrake/drake/downloads","issues_url":"https://api.github.com/repos/RussTedrake/drake/issues{/number}","pulls_url":"https://api.github.com/repos/RussTedrake/drake/pulls{/number}","milestones_url":"https://api.github.com/repos/RussTedrake/drake/milestones{/number}","notifications_url":"https://api.github.com/repos/RussTedrake/drake/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RussTedrake/drake/labels{/name}","releases_url":"https://api.github.com/repos/RussTedrake/drake/releases{/id}","created_at":"2014-02-23T19:55:24Z","updated_at":"2014-07-22T11:55:16Z","pushed_at":"2015-02-13T21:51:55Z","git_url":"git://github.com/RussTedrake/drake.git","ssh_url":"git@github.com:RussTedrake/drake.git","clone_url":"https://github.com/RussTedrake/drake.git","svn_url":"https://github.com/RussTedrake/drake","homepage":"https://github.com/RobotLocomotion/drake/wiki","size":150722,"stargazers_count":0,"watchers_count":0,"language":"Matlab","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"RobotLocomotion:master","ref":"master","sha":"a9444c76357f4dec3216e53df538fff83102ed6f","user":{"login":"RobotLocomotion","id":6496345,"avatar_url":"https://avatars.githubusercontent.com/u/6496345?v=3","gravatar_id":"","url":"https://api.github.com/users/RobotLocomotion","html_url":"https://github.com/RobotLocomotion","followers_url":"https://api.github.com/users/RobotLocomotion/followers","following_url":"https://api.github.com/users/RobotLocomotion/following{/other_user}","gists_url":"https://api.github.com/users/RobotLocomotion/gists{/gist_id}","starred_url":"https://api.github.com/users/RobotLocomotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobotLocomotion/subscriptions","organizations_url":"https://api.github.com/users/RobotLocomotion/orgs","repos_url":"https://api.github.com/users/RobotLocomotion/repos","events_url":"https://api.github.com/users/RobotLocomotion/events{/privacy}","received_events_url":"https://api.github.com/users/RobotLocomotion/received_events","type":"Organization","site_admin":false},"repo":{"id":16256144,"name":"drake","full_name":"RobotLocomotion/drake","owner":{"login":"RobotLocomotion","id":6496345,"avatar_url":"https://avatars.githubusercontent.com/u/6496345?v=3","gravatar_id":"","url":"https://api.github.com/users/RobotLocomotion","html_url":"https://github.com/RobotLocomotion","followers_url":"https://api.github.com/users/RobotLocomotion/followers","following_url":"https://api.github.com/users/RobotLocomotion/following{/other_user}","gists_url":"https://api.github.com/users/RobotLocomotion/gists{/gist_id}","starred_url":"https://api.github.com/users/RobotLocomotion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobotLocomotion/subscriptions","organizations_url":"https://api.github.com/users/RobotLocomotion/orgs","repos_url":"https://api.github.com/users/RobotLocomotion/repos","events_url":"https://api.github.com/users/RobotLocomotion/events{/privacy}","received_events_url":"https://api.github.com/users/RobotLocomotion/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RobotLocomotion/drake","description":"A planning, control, and analysis toolbox for nonlinear dynamical systems.  Please see the WIKI for documentation.","fork":false,"url":"https://api.github.com/repos/RobotLocomotion/drake","forks_url":"https://api.github.com/repos/RobotLocomotion/drake/forks","keys_url":"https://api.github.com/repos/RobotLocomotion/drake/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RobotLocomotion/drake/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RobotLocomotion/drake/teams","hooks_url":"https://api.github.com/repos/RobotLocomotion/drake/hooks","issue_events_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/events{/number}","events_url":"https://api.github.com/repos/RobotLocomotion/drake/events","assignees_url":"https://api.github.com/repos/RobotLocomotion/drake/assignees{/user}","branches_url":"https://api.github.com/repos/RobotLocomotion/drake/branches{/branch}","tags_url":"https://api.github.com/repos/RobotLocomotion/drake/tags","blobs_url":"https://api.github.com/repos/RobotLocomotion/drake/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RobotLocomotion/drake/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RobotLocomotion/drake/git/refs{/sha}","trees_url":"https://api.github.com/repos/RobotLocomotion/drake/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RobotLocomotion/drake/statuses/{sha}","languages_url":"https://api.github.com/repos/RobotLocomotion/drake/languages","stargazers_url":"https://api.github.com/repos/RobotLocomotion/drake/stargazers","contributors_url":"https://api.github.com/repos/RobotLocomotion/drake/contributors","subscribers_url":"https://api.github.com/repos/RobotLocomotion/drake/subscribers","subscription_url":"https://api.github.com/repos/RobotLocomotion/drake/subscription","commits_url":"https://api.github.com/repos/RobotLocomotion/drake/commits{/sha}","git_commits_url":"https://api.github.com/repos/RobotLocomotion/drake/git/commits{/sha}","comments_url":"https://api.github.com/repos/RobotLocomotion/drake/comments{/number}","issue_comment_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/comments/{number}","contents_url":"https://api.github.com/repos/RobotLocomotion/drake/contents/{+path}","compare_url":"https://api.github.com/repos/RobotLocomotion/drake/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RobotLocomotion/drake/merges","archive_url":"https://api.github.com/repos/RobotLocomotion/drake/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RobotLocomotion/drake/downloads","issues_url":"https://api.github.com/repos/RobotLocomotion/drake/issues{/number}","pulls_url":"https://api.github.com/repos/RobotLocomotion/drake/pulls{/number}","milestones_url":"https://api.github.com/repos/RobotLocomotion/drake/milestones{/number}","notifications_url":"https://api.github.com/repos/RobotLocomotion/drake/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RobotLocomotion/drake/labels{/name}","releases_url":"https://api.github.com/repos/RobotLocomotion/drake/releases{/id}","created_at":"2014-01-26T16:11:05Z","updated_at":"2015-02-13T21:51:52Z","pushed_at":"2015-02-13T21:51:52Z","git_url":"git://github.com/RobotLocomotion/drake.git","ssh_url":"git@github.com:RobotLocomotion/drake.git","clone_url":"https://github.com/RobotLocomotion/drake.git","svn_url":"https://github.com/RobotLocomotion/drake","homepage":"https://github.com/RobotLocomotion/drake/wiki","size":168992,"stargazers_count":85,"watchers_count":85,"language":"Matlab","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":83,"mirror_url":null,"open_issues_count":84,"forks":83,"open_issues":84,"watchers":85,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757"},"html":{"href":"https://github.com/RobotLocomotion/drake/pull/757"},"issue":{"href":"https://api.github.com/repos/RobotLocomotion/drake/issues/757"},"comments":{"href":"https://api.github.com/repos/RobotLocomotion/drake/issues/757/comments"},"review_comments":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757/comments"},"review_comment":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/RobotLocomotion/drake/pulls/757/commits"},"statuses":{"href":"https://api.github.com/repos/RobotLocomotion/drake/statuses/adda9830474bf5cf507b60ae1203e598a005269c"}}}}