-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python interface #17
Open
Chamango90
wants to merge
4
commits into
rosin-project:master
Choose a base branch
from
Chamango90:snp_py
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Python interface #17
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(snp_py) | ||
|
||
find_package(catkin REQUIRED) | ||
catkin_package() | ||
catkin_python_setup() | ||
|
||
catkin_install_python(PROGRAMS scripts/snp_auto_run | ||
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0"?> | ||
<package format="2"> | ||
<name>snp_py</name> | ||
<version>0.0.0</version> | ||
<description>Scan and plan Python interface</description> | ||
<maintainer email="[email protected]">Jonathan Hechtbauer</maintainer> | ||
<author email="[email protected]">Jonathan Hechtbauer</author> | ||
|
||
<license>Apache License 2.0</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
|
||
<exec_depend>actionlib</exec_depend> | ||
<exec_depend>godel_msgs</exec_depend> | ||
<exec_depend>moveit_commander</exec_depend> | ||
<exec_depend>rospy</exec_depend> | ||
<!-- <exec_depend>snp_prbt_bringup</exec_depend> Removed since bringup_pkg as arg | ||
<exec_depend>snp_prbt_support</exec_depend> --> | ||
<exec_depend>std_srvs</exec_depend> | ||
|
||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
|
||
import rospy | ||
from moveit_commander import MoveItCommanderException | ||
from snp_py.snp_interface import SNPCommander | ||
|
||
if __name__ == "__main__": | ||
rospy.init_node("snp_test") | ||
move_group = rospy.get_param("/godel_process_planning/blend_group") | ||
SNP = SNPCommander(move_group, planner="PTP") | ||
try: | ||
SNP.move_home() | ||
SNP.surface_detection() | ||
SNP.select_surface() | ||
SNP.plan() | ||
SNP.get_available_motion_plan() | ||
SNP.select_motion_plan(simulate=True) | ||
SNP.select_motion_plan(simulate=False) | ||
|
||
except (MoveItCommanderException, rospy.ROSException, rospy.ServiceException) as e: | ||
rospy.logerr("SNP failed due to %s" % e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python | ||
from distutils.core import setup | ||
from catkin_pkg.python_setup import generate_distutils_setup | ||
|
||
d = generate_distutils_setup(packages=["snp_py"], package_dir={"": "src"}) | ||
setup(**d) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import rospy | ||
import time | ||
import moveit_commander | ||
import actionlib | ||
from moveit_msgs.msg import MoveGroupAction | ||
from std_srvs.srv import Empty, EmptyRequest | ||
|
||
|
||
def unpause_gazebo(delay): | ||
# Give Gazebo enough time. Sim_time not running yet | ||
time.sleep(delay) | ||
|
||
# Pause is required to span model with defined joint_values | ||
unpause = init_srv("/gazebo/unpause_physics", Empty) | ||
unpause(EmptyRequest()) | ||
|
||
|
||
def init_move_group(group_name): | ||
# This is to make sure that MoveIt! has been started up. | ||
init_action("/move_group", MoveGroupAction, timeout=60) | ||
|
||
moveit_commander.roscpp_initialize(sys.argv) | ||
robot = moveit_commander.RobotCommander() | ||
return moveit_commander.MoveGroupCommander(group_name) | ||
|
||
|
||
def init_srv(srv_ns, srv_type): | ||
rospy.loginfo("Wait for service '%s' ..." % srv_ns) | ||
rospy.wait_for_service(srv_ns) | ||
return rospy.ServiceProxy(srv_ns, srv_type) | ||
|
||
|
||
def init_action(act_ns, act_type, timeout=30): | ||
client = actionlib.SimpleActionClient(act_ns, act_type) | ||
rospy.loginfo("Wait for action '%s' ..." % act_ns) | ||
server_up = client.wait_for_server(timeout=rospy.Duration(timeout)) | ||
if not server_up: | ||
raise rospy.ROSInterruptException("Action timed out.") | ||
return client | ||
|
||
|
||
def call_action(client, request, timeout): | ||
client.send_goal(request) | ||
action_returned = client.wait_for_result(timeout=rospy.Duration(timeout)) | ||
if not action_returned: | ||
raise rospy.ROSInterruptException("Action timed out.") | ||
return client.get_result() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python | ||
|
||
import rospy | ||
import godel_msgs.srv as _s | ||
import godel_msgs.msg as _a | ||
from snp_py.snp_helper import ( | ||
init_move_group, | ||
init_srv, | ||
init_action, | ||
call_action, | ||
unpause_gazebo, | ||
) | ||
|
||
|
||
class SNPCommander: | ||
def __init__(self, move_group, planner, delay_unpause_gazebo=0): | ||
if not rospy.get_param("/sim_robot"): | ||
raise rospy.ROSException("SNPCommander is only allowed for simulation.") | ||
|
||
# Pause is required to span model with defined joint_values | ||
unpause_gazebo(delay_unpause_gazebo) | ||
|
||
self._group = init_move_group(move_group) | ||
self._group.set_planner_id(planner) | ||
|
||
self._surfaceDetection = init_srv("surface_detection", _s.SurfaceDetection) | ||
self._selectSurface = init_srv("select_surface", _s.SelectSurface) | ||
self._getAvailableMotionPlan = init_srv( | ||
"get_available_motion_plans", _s.GetAvailableMotionPlans | ||
) | ||
self._plan = init_action("process_planning_as", _a.ProcessPlanningAction) | ||
self._selectMotionPlan = init_action( | ||
"select_motion_plan_as", _a.SelectMotionPlanAction | ||
) | ||
self._plans = [] | ||
|
||
def move_home(self): | ||
self._group.set_named_target("home") | ||
return self._group.go(wait=True) is not None | ||
|
||
def surface_detection(self): | ||
return self._surfaceDetection( | ||
_s.SurfaceDetectionRequest( | ||
action=_s.SurfaceDetectionRequest.SCAN_AND_FIND_ONLY, | ||
use_default_parameters=True, | ||
) | ||
).surfaces_found | ||
|
||
def select_surface(self): | ||
return self._selectSurface( | ||
_s.SelectSurfaceRequest(action=_s.SelectSurfaceRequest.SELECT_ALL) | ||
).succeeded | ||
|
||
def plan(self, timeout=120): | ||
return call_action( | ||
self._plan, | ||
_a.ProcessPlanningGoal( | ||
action=_a.ProcessPlanningGoal.GENERATE_MOTION_PLAN_AND_PREVIEW, | ||
use_default_parameters=True, | ||
), | ||
timeout, | ||
).succeeded | ||
|
||
def get_available_motion_plan(self): | ||
self._plans = self._getAvailableMotionPlan( | ||
_s.GetAvailableMotionPlansRequest() | ||
).names | ||
return self._plans != [] | ||
|
||
def select_motion_plan(self, simulate, timeout=120): | ||
for p in self._plans: | ||
result = call_action( | ||
self._selectMotionPlan, | ||
_a.SelectMotionPlanGoal( | ||
simulate=simulate, wait_for_execution=True, name=p | ||
), | ||
timeout, | ||
) | ||
if result.code != _a.SelectMotionPlanResult.SUCCESS: | ||
return False | ||
return True | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we delete this completely maybe? We will always be launching the camera separately