Guest User

Untitled

a guest
Nov 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import rospkg
  5. import rospy
  6. import threading
  7.  
  8. from qt_gui.plugin import Plugin
  9. from python_qt_binding import loadUi
  10. from python_qt_binding.QtWidgets import QWidget
  11.  
  12. from std_msgs.msg import String
  13. from topic_tools.srv import *
  14.  
  15. class MyPlugin(Plugin):
  16.  
  17. def _pb1_clicked(self, checked):
  18. if self.found_service:
  19. self.mux(self.channels[0])
  20.  
  21. def _pb2_clicked(self, checked):
  22. if self.found_service:
  23. self.mux(self.channels[1])
  24.  
  25.  
  26. def _pb3_clicked(self, checked):
  27. if self.found_service:
  28. self.mux(self.channels[2])
  29.  
  30.  
  31. def _pb4_clicked(self, checked):
  32. if self.found_service:
  33. self.mux(self.channels[3])
  34.  
  35.  
  36.  
  37. def __init__(self, context):
  38. super(MyPlugin, self).__init__(context)
  39. print('testing')
  40. #return
  41. # Give QObjects reasonable names
  42. self.setObjectName('MyPlugin')
  43. rp = rospkg.RosPack()
  44.  
  45. # Process standalone plugin command-line arguments
  46. from argparse import ArgumentParser
  47. parser = ArgumentParser()
  48. # Add argument(s) to the parser.
  49. parser.add_argument("-q", "--quiet", action="store_true",
  50. dest="quiet",
  51. help="Put plugin in silent mode")
  52. args, unknowns = parser.parse_known_args(context.argv())
  53. if not args.quiet:
  54. print 'arguments: ', args
  55. print 'unknowns: ', unknowns
  56.  
  57. # Create QWidget
  58. self._widget = QWidget()
  59. # Get path to UI file which is a sibling of this file
  60. # in this example the .ui and .py file are in the same folder
  61. #ui_file = os.path.join(rp.get_path('rover_ui_plugins'), 'resource', 'CameraSelection.ui')
  62. ui_file = os.path.join(rp.get_path('rover_ui_plugins'), 'resource', 'CameraSelectionSimple.ui')
  63. # Extend the widget with all attributes and children from UI file
  64. loadUi(ui_file, self._widget, {})
  65. # Give QObjects reasonable names
  66. self._widget.setObjectName('CameraSelection')
  67. # Show _widget.windowTitle on left-top of each plugin (when
  68. # it's set in _widget). This is useful when you open multiple
  69. # plugins at once. Also if you open multiple instances of your
  70. # plugin at once, these lines add number to make it easy to
  71. # tell from pane to pane.
  72. if context.serial_number() > 1:
  73. self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
  74. # Add widget to the user interface
  75. context.add_widget(self._widget)
  76.  
  77. #self.pub = rospy.Publisher('image_mux/sel_image', String, queue_size=1)
  78.  
  79.  
  80. self.sub_num = 0
  81. self.channels = ['cam1', 'cam2', 'cam3', 'cam4']
  82.  
  83. self._widget.pb1.clicked[bool].connect(self._pb1_clicked)
  84. self._widget.pb2.clicked[bool].connect(self._pb2_clicked)
  85. self._widget.pb3.clicked[bool].connect(self._pb3_clicked)
  86. self._widget.pb4.clicked[bool].connect(self._pb4_clicked)
  87.  
  88. print(vars(self._widget))
  89. print("I am here")
  90.  
  91.  
  92. rate = rospy.Rate(10)
  93. self.running = True
  94. self.found_service = False
  95. def run():
  96. while (self.running):
  97. try:
  98. rospy.wait_for_service('video_mux/select', 1)
  99. except:
  100. pass
  101.  
  102.  
  103. self.found_service = True
  104. self.running = True
  105. print('Found mux service')
  106. self.mux = rospy.ServiceProxy('video_mux/select', MuxSelect)
  107. while not self.running:
  108. #self.pub.publish(self.channels[self.sub_num])
  109. rate.sleep()
  110. #print(self.sub_num)
  111.  
  112. self.run_thread = threading.Thread(target=run)
  113. self.run_thread.start()
  114.  
  115.  
  116. def shutdown_plugin(self):
  117. # TODO unregister all publishers here
  118. self.running = False
  119. self.found_service = True
  120. #self.pub.unregister()
  121.  
  122. #def save_settings(self, plugin_settings, instance_settings):
  123. # # TODO save intrinsic configuration, usually using:
  124. # # instance_settings.set_value(k, v)
  125. # pass
  126.  
  127. #def restore_settings(self, plugin_settings, instance_settings):
  128. # # TODO restore intrinsic configuration, usually using:
  129. # # v = instance_settings.value(k)
  130. # pass
  131.  
  132. #def trigger_configuration(self):
  133. # Comment in to signal that the plugin has a way to configure
  134. # This will enable a setting button (gear icon) in each dock widget title bar
  135. # Usually used to open a modal configuration dialog
Add Comment
Please, Sign In to add comment