{"action":"opened","issue":{"url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1498","labels_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1498/labels{/name}","comments_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1498/comments","events_url":"https://api.github.com/repos/RobotLocomotion/drake/issues/1498/events","html_url":"https://github.com/RobotLocomotion/drake/issues/1498","id":120591364,"number":1498,"title":"HybridTrajectoryOptimization addJumpConstraints Indexing Bug","user":{"login":"bronadav","id":4855927,"avatar_url":"https://avatars.githubusercontent.com/u/4855927?v=3","gravatar_id":"","url":"https://api.github.com/users/bronadav","html_url":"https://github.com/bronadav","followers_url":"https://api.github.com/users/bronadav/followers","following_url":"https://api.github.com/users/bronadav/following{/other_user}","gists_url":"https://api.github.com/users/bronadav/gists{/gist_id}","starred_url":"https://api.github.com/users/bronadav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bronadav/subscriptions","organizations_url":"https://api.github.com/users/bronadav/orgs","repos_url":"https://api.github.com/users/bronadav/repos","events_url":"https://api.github.com/users/bronadav/events{/privacy}","received_events_url":"https://api.github.com/users/bronadav/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-05T22:07:12Z","updated_at":"2015-12-05T22:07:12Z","closed_at":null,"body":"Hi there!\r\nThere appears to be a bug with HybridTrajectoryOptimization lines 254 and 262.\r\nOriginal code:\r\n```\r\n % add guard constraints, 0 = guard(xm,u) for the transition and\r\n        % 0 >= guard(xm,u) for everything else\r\n        for j=1:length(obj.plant.guard{i}),\r\n...\r\n            guard_fun = @(x,u) guard_constraint_fun(obj.plant,obj.plant.guard{i}{j},x,u);\r\n```\r\nThis results in an index out of bounds error, because the guard is being indexed not by the type of mode, but by which number mode this is in the sequence of modes. So, for example, if there is a 3-mode sequence {1, 2, 1}, then for the 3rd mode it should be indexed as `obj.plant.guard{1}`, but instead it's being indexed as `obj.plant.guard{3}`, resulting in an out-of-bounds error for a 2-mode system.\r\n\r\nThe correct lines of code are:\r\n```\r\nfor j=1:length(obj.plant.guard{obj.mode_sequence(i)}),\r\n...\r\nguard_fun = @(x,u) guard_constraint_fun(obj.plant,obj.plant.guard{obj.mode_sequence(i)}{j},x,u);\r\n```\r\nAt least, they worked for me."}}