{"action":"created","issue":{"url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/3269","repository_url":"https://api.github.com/repos/MarlinFirmware/Marlin","labels_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/3269/labels{/name}","comments_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/3269/comments","events_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/3269/events","html_url":"https://github.com/MarlinFirmware/Marlin/issues/3269","id":143998811,"number":3269,"title":"Use Lidar to Trigger Endstop","user":{"login":"chevellebro1","id":16858114,"avatar_url":"https://avatars.githubusercontent.com/u/16858114?v=3","gravatar_id":"","url":"https://api.github.com/users/chevellebro1","html_url":"https://github.com/chevellebro1","followers_url":"https://api.github.com/users/chevellebro1/followers","following_url":"https://api.github.com/users/chevellebro1/following{/other_user}","gists_url":"https://api.github.com/users/chevellebro1/gists{/gist_id}","starred_url":"https://api.github.com/users/chevellebro1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chevellebro1/subscriptions","organizations_url":"https://api.github.com/users/chevellebro1/orgs","repos_url":"https://api.github.com/users/chevellebro1/repos","events_url":"https://api.github.com/users/chevellebro1/events{/privacy}","received_events_url":"https://api.github.com/users/chevellebro1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":33,"created_at":"2016-03-28T15:09:51Z","updated_at":"2016-04-01T17:25:52Z","closed_at":null,"body":"I would like to use a Lidar sensor as an edge finder for a CNC mill. Is it possible to set the Lidar to trigger the endstop pin if the distance changes so that the machine ZERO is at the edge of the material?"},"comment":{"url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/comments/204478774","html_url":"https://github.com/MarlinFirmware/Marlin/issues/3269#issuecomment-204478774","issue_url":"https://api.github.com/repos/MarlinFirmware/Marlin/issues/3269","id":204478774,"user":{"login":"Roxy-3DPrintBoard","id":8404322,"avatar_url":"https://avatars.githubusercontent.com/u/8404322?v=3","gravatar_id":"","url":"https://api.github.com/users/Roxy-3DPrintBoard","html_url":"https://github.com/Roxy-3DPrintBoard","followers_url":"https://api.github.com/users/Roxy-3DPrintBoard/followers","following_url":"https://api.github.com/users/Roxy-3DPrintBoard/following{/other_user}","gists_url":"https://api.github.com/users/Roxy-3DPrintBoard/gists{/gist_id}","starred_url":"https://api.github.com/users/Roxy-3DPrintBoard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Roxy-3DPrintBoard/subscriptions","organizations_url":"https://api.github.com/users/Roxy-3DPrintBoard/orgs","repos_url":"https://api.github.com/users/Roxy-3DPrintBoard/repos","events_url":"https://api.github.com/users/Roxy-3DPrintBoard/events{/privacy}","received_events_url":"https://api.github.com/users/Roxy-3DPrintBoard/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T17:25:52Z","updated_at":"2016-04-01T17:25:52Z","body":"I think relative positioning has a lot of merit here.  But I've never used it so I'm kind of thinking about your problem from a different perspective.   Isn't it appropriate for the CNC machine to position the corner of the material at (0,0) ?   And you would just make sure your GCode has the generated part at the origin also?     \r\n\r\nBut all that aside...    Your code up above does not ask the Lidar sensor where it is.  This code sets the current position (for the axis being homed) to 0.0 and goes towards the endstop until it bumps into the switch.  \r\n~~~~\r\n    current_position[axis] = 0;\r\n    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\r\n    destination[axis] = -home_retract_mm(axis) * axis_home_dir;\r\n    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);\r\n    st_synchronize();\r\n~~~~\r\nThen it retracts a little bit...   And it should bump at a slower speed, but you have the 1st and 2nd bump happening at the same speed (which doesn't seem right).\r\n~~~~\r\n    destination[axis] = 2*home_retract_mm(X_AXIS) * axis_home_dir;\r\n    feedrate = 500;\r\n    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);\r\n    st_synchronize();\r\n~~~~\r\nAnd then this next code just sets the position based on the current location of the bump.   But you never reference the Lidar sensor.      (Unless you buried that way down into the stepper code that watches for endstops being triggered.)\r\n~~~~\r\n    axis_is_at_home(axis);\r\n    destination[axis] = current_position[axis];\r\n    feedrate = 0.0;\r\n    endstops_hit_on_purpose();\r\n    axis_known_position[axis] = true;\r\n~~~~\r\n"}}