本文整理汇总了Python中rospy.on_shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python rospy.on_shutdown方法的具体用法?Python rospy.on_shutdown怎么用?Python rospy.on_shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rospy
的用法示例。
在下文中一共展示了rospy.on_shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def __init__(self, argv):
self.node_name = "ObjectMeasurer"
rospy.init_node(self.node_name)
# What we do during shutdown
rospy.on_shutdown(self.cleanup)
# Create the cv_bridge object
self.bridge = CvBridge()
# Subscribe to the camera image topics and set
# the appropriate callbacks
self.image_sub = rospy.Subscriber(argv[1], Image, self.image_callback)
self.image_pub = rospy.Publisher(
"%s/ObjectMeasurer" % (argv[1]), Image, queue_size=10)
rospy.loginfo("Waiting for image topics...")
# Initialization of the 'pixels per metric variable'
self.pixelsPerMetric = None
示例2: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def __init__(self, args):
self.node_name = "MaskPlantTray"
rospy.init_node(self.node_name)
# What we do during shutdown
rospy.on_shutdown(self.cleanup)
# Create the cv_bridge object
self.bridge = CvBridge()
# Subscribe to the camera image topics and set
# the appropriate callbacks
self.image_sub = rospy.Subscriber(args[1], Image, self.image_callback)
self.image_pub = rospy.Publisher(
"%s/MaskPlantTray" % (args[1]), Image, queue_size=10)
rospy.loginfo("Waiting for image topics...")
示例3: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def __init__(self, args):
self.node_name = "ImgMerger"
rospy.init_node(self.node_name)
# What we do during shutdown
rospy.on_shutdown(self.cleanup)
# Create the cv_bridge object
self.bridge = CvBridge()
self.frame_img1 = np.zeros((1280, 1024), np.uint8)
self.frame_img2 = np.zeros((1280, 1024), np.uint8)
# Subscribe to the camera image topics and set
# the appropriate callbacks
self.image_sub_first_image = rospy.Subscriber(
args[1], Image, self.image_callback_img1)
self.image_sub_second_image = rospy.Subscriber(
args[2], Image, self.image_callback_img2)
self.image_pub = rospy.Publisher(args[3], Image, queue_size=10)
rospy.loginfo("Waiting for image topics...")
示例4: main
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def main():
"""RSDK Head Example: Wobbler
Nods the head and pans side-to-side towards random angles.
Demonstrates the use of the intera_interface.Head class.
"""
arg_fmt = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=arg_fmt,
description=main.__doc__)
parser.parse_args(rospy.myargv()[1:])
print("Initializing node... ")
rospy.init_node("rsdk_head_wobbler")
wobbler = Wobbler()
rospy.on_shutdown(wobbler.clean_shutdown)
print("Wobbling... ")
wobbler.wobble()
print("Done.")
示例5: main
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def main():
"""Intera RSDK Joint Velocity Example: Wobbler
Commands joint velocities of randomly parameterized cosine waves
to each joint. Demonstrates Joint Velocity Control Mode.
"""
arg_fmt = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=arg_fmt,
description=main.__doc__)
parser.parse_args(rospy.myargv()[1:])
print("Initializing node... ")
rospy.init_node("rsdk_joint_velocity_wobbler")
wobbler = Wobbler()
rospy.on_shutdown(wobbler.clean_shutdown)
wobbler.wobble()
print("Done.")
示例6: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def __init__(self):
self.process_list = []
self.process_config = rospy.get_param("~processes")
self.create_processes()
rospy.on_shutdown(self.clean_ros_processes)
self.process_state_publish_rate = rospy.get_param("~process_state_publish_rate")
self.process_state_publisher = rospy.Publisher(
'/niryo_one/rpi/process_state', ProcessState, queue_size=1)
rospy.Timer(rospy.Duration(1.0 / self.process_state_publish_rate), self.publish_process_state)
self.manage_process_server = rospy.Service(
'/niryo_one/rpi/manage_process', ManageProcess, self.callback_manage_process)
self.start_init_processes()
# self.start_all_processes()
示例7: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def __init__(self):
self.node_name = "cv_bridge_demo"
rospy.init_node(self.node_name)
# What we do during shutdown
rospy.on_shutdown(self.cleanup)
# Create the OpenCV display window for the RGB image
self.cv_window_name = self.node_name
# Create the cv_bridge object
self.bridge = CvBridge()
# Subscribe to the camera image and depth topics and set
# the appropriate callbacks
rospy.Subscriber("/camera/rgb/image_raw", Image, self.image_callback)
rospy.Subscriber("/camera/depth/image_raw", Image, self.depth_callback)
rospy.Timer(rospy.Duration(0.03), self.show_img_cb)
rospy.loginfo("Waiting for image topics...")
开发者ID:PacktPublishing,项目名称:Learning-Robotics-using-Python-Second-Edition,代码行数:24,代码来源:cv_bridge_demo.py
示例8: move_gripper
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def move_gripper(limb, action):
# initialize interfaces
print("Getting robot state...")
rs = intera_interface.RobotEnable(CHECK_VERSION)
init_state = rs.state()
gripper = None
original_deadzone = None
def clean_shutdown():
if gripper and original_deadzone:
gripper.set_dead_zone(original_deadzone)
print("Finished.")
try:
gripper = intera_interface.Gripper(limb + '_gripper')
except (ValueError, OSError) as e:
rospy.logerr("Could not detect an electric gripper attached to the robot.")
clean_shutdown()
return
rospy.on_shutdown(clean_shutdown)
original_deadzone = gripper.get_dead_zone()
# WARNING: setting the deadzone below this can cause oscillations in
# the gripper position. However, setting the deadzone to this
# value is required to achieve the incremental commands in this example
gripper.set_dead_zone(0.001)
rospy.loginfo("Gripper deadzone set to {}".format(gripper.get_dead_zone()))
rospy.loginfo("Enabling robot...")
rs.enable()
print("Controlling grippers.")
if (action == "open"):
gripper.open()
rospy.sleep(1.0)
print("Opened grippers")
elif (action == "close"):
gripper.close()
rospy.sleep(1.0)
print("Closed grippers")
# force shutdown call if caught by key handler
rospy.signal_shutdown("Example finished.")
示例9: start_server
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def start_server(limb, rate, mode, valid_limbs):
rospy.loginfo("Initializing node... ")
rospy.init_node("sdk_{0}_joint_trajectory_action_server{1}".format(
mode, "" if limb == 'all_limbs' else "_" + limb,))
rospy.wait_for_service("/ExternalTools/right/PositionKinematicsNode/IKService")
rospy.loginfo("Initializing joint trajectory action server...")
robot_name = intera_interface.RobotParams().get_robot_name().lower().capitalize()
config_module = "intera_interface.cfg"
if mode == 'velocity':
config_name = ''.join([robot_name,"VelocityJointTrajectoryActionServerConfig"])
elif mode == 'position':
config_name = ''.join([robot_name,"PositionJointTrajectoryActionServerConfig"])
else:
config_name = ''.join([robot_name,"PositionFFJointTrajectoryActionServerConfig"])
cfg = importlib.import_module('.'.join([config_module,config_name]))
dyn_cfg_srv = Server(cfg, lambda config, level: config)
jtas = []
if limb == 'all_limbs':
for current_limb in valid_limbs:
jtas.append(JointTrajectoryActionServer(current_limb, dyn_cfg_srv,
rate, mode))
else:
jtas.append(JointTrajectoryActionServer(limb, dyn_cfg_srv, rate, mode))
def cleanup():
for j in jtas:
j.clean_shutdown()
rospy.on_shutdown(cleanup)
rospy.loginfo("Joint Trajectory Action Server Running. Ctrl-c to quit")
rospy.spin()
示例10: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def __init__(self):
# set up openrave
self.env = rave.Environment()
self.env.StopSimulation()
self.env.Load("robots/pr2-beta-static.zae") # todo: use up-to-date urdf
self.robot = self.env.GetRobots()[0]
self.joint_listener = TopicListener("/joint_states", sm.JointState)
# rave to ros conversions
joint_msg = self.get_last_joint_message()
ros_names = joint_msg.name
inds_ros2rave = np.array([self.robot.GetJointIndex(name) for name in ros_names])
self.good_ros_inds = np.flatnonzero(inds_ros2rave != -1) # ros joints inds with matching rave joint
self.rave_inds = inds_ros2rave[self.good_ros_inds] # openrave indices corresponding to those joints
self.update_rave()
self.larm = Arm(self, "l")
self.rarm = Arm(self, "r")
self.lgrip = Gripper(self, "l")
self.rgrip = Gripper(self, "r")
self.head = Head(self)
self.torso = Torso(self)
self.base = Base(self)
rospy.on_shutdown(self.stop_all)
示例11: main
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def main():
"""Save / Load EndEffector Config utility
Read current config off of ClickSmart and save to file.
Or load config from file and reconfigure and save it to ClickSmart device.
"""
arg_fmt = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=arg_fmt,
description=main.__doc__)
parser.add_argument(
'-s', '--save', metavar='PATH',
help='save current EE config to given file'
)
parser.add_argument(
'-l', '--load', metavar='PATH',
help='load config from given file onto EE'
)
args = parser.parse_args(rospy.myargv()[1:])
print("Initializing node... ")
rospy.init_node('ee_config_editor', anonymous=True)
ee = intera_interface.get_current_gripper_interface()
if not ee:
rospy.logerr("Could not detect an attached EndEffector!")
return
if args.save:
rospy.loginfo("Saving EE config to {}".format(args.save))
save_config(ee, args.save)
if args.load:
rospy.loginfo("Loading config and writing config to ClickSmart from {}".format(args.load))
load_config(ee, args.load)
def clean_shutdown():
print("\nExiting example...")
rospy.on_shutdown(clean_shutdown)
示例12: start_server
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def start_server(limb, rate, mode, valid_limbs):
rospy.loginfo("Initializing node... ")
rospy.init_node("sdk_{0}_joint_trajectory_action_server{1}".format(
mode, "" if limb == 'all_limbs' else "_" + limb,))
rospy.loginfo("Initializing joint trajectory action server...")
robot_name = intera_interface.RobotParams().get_robot_name().lower().capitalize()
config_module = "intera_interface.cfg"
if mode == 'velocity':
config_name = ''.join([robot_name,"VelocityJointTrajectoryActionServerConfig"])
elif mode == 'position':
config_name = ''.join([robot_name,"PositionJointTrajectoryActionServerConfig"])
else:
config_name = ''.join([robot_name,"PositionFFJointTrajectoryActionServerConfig"])
cfg = importlib.import_module('.'.join([config_module,config_name]))
dyn_cfg_srv = Server(cfg, lambda config, level: config)
jtas = []
if limb == 'all_limbs':
for current_limb in valid_limbs:
jtas.append(JointTrajectoryActionServer(current_limb, dyn_cfg_srv,
rate, mode))
else:
jtas.append(JointTrajectoryActionServer(limb, dyn_cfg_srv, rate, mode))
def cleanup():
for j in jtas:
j.clean_shutdown()
rospy.on_shutdown(cleanup)
rospy.loginfo("Joint Trajectory Action Server Running. Ctrl-c to quit")
rospy.spin()
示例13: main
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def main():
"""SDK Joint Position Waypoints Example
Records joint positions each time the navigator 'OK/wheel'
button is pressed.
Upon pressing the navigator 'Rethink' button, the recorded joint positions
will begin playing back in a loop.
"""
arg_fmt = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=arg_fmt,
description=main.__doc__)
parser.add_argument(
'-s', '--speed', default=0.3, type=float,
help='joint position motion speed ratio [0.0-1.0] (default:= 0.3)'
)
parser.add_argument(
'-a', '--accuracy',
default=intera_interface.settings.JOINT_ANGLE_TOLERANCE, type=float,
help='joint position accuracy (rad) at which waypoints must achieve'
)
args = parser.parse_args(rospy.myargv()[1:])
print("Initializing node... ")
rospy.init_node("sdk_joint_position_waypoints", anonymous=True)
waypoints = Waypoints(args.speed, args.accuracy)
# Register clean shutdown
rospy.on_shutdown(waypoints.clean_shutdown)
# Begin example program
waypoints.record()
waypoints.playback()
示例14: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def __init__(self):
rospy.init_node('sound_server', anonymous=False)
rospy.on_shutdown(self._shutdown)
while (rospy.get_rostime() == 0.0):
pass
rospy.Subscriber("/sound_server/speech_synth", String, self.cb_speech_synth)
rospy.Subscriber("/sound_server/play_sound_file", String, self.cb_play_sound_file)
self.pub_status = rospy.Publisher("/sound_server/status", String)
self.s = mirage_sound_out(festival_cache_path="/home/ubuntu/Music/mirage_engrams/festival_cache/", sound_effects_path="/home/ubuntu/Music/mirage_engrams/sound_effects/")
rospy.sleep(2.0) # Startup time.
rospy.loginfo("mirage_sound_out ready")
rospy.spin()
示例15: get_python_code_from_xml
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import on_shutdown [as 别名]
def get_python_code_from_xml(self, xml):
return self.blockly_generator.get_generated_python_code(xml)
# !! Need to call this with rospy.on_shutdown !!