Python std_msgs.msg.String() Examples

The following are 30 code examples of std_msgs.msg.String(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module std_msgs.msg , or try the search function .
Example #1
Source File: google_client.py    From dialogflow_ros with MIT License 9 votes vote down vote up
def __init__(self):
        # Audio stream input setup
        FORMAT = pyaudio.paInt16
        CHANNELS = 1
        RATE = 16000
        self.CHUNK = 4096
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(format=FORMAT, channels=CHANNELS,
                                      rate=RATE, input=True,
                                      frames_per_buffer=self.CHUNK,
                                      stream_callback=self.get_data)
        self._buff = Queue.Queue()  # Buffer to hold audio data
        self.closed = False

        # ROS Text Publisher
        self.text_pub = rospy.Publisher('/google_client/text', String, queue_size=10)

        # Context clues in yaml file
        rospack = rospkg.RosPack()
        yamlFileDir = rospack.get_path('dialogflow_ros') + '/config/context.yaml'
        with open(yamlFileDir, 'r') as f:
            self.context = yaml.load(f) 
Example #2
Source File: lidarEvasion.py    From Cherry-Autonomous-Racecar with MIT License 6 votes vote down vote up
def __init__(self):
        self.evadeSet = False
        self.controller = XBox360()
        self.bridge = CvBridge()
        self.throttle = 0
        self.grid_img = None
        ##self.throttleLock = Lock()
        print "evasion"
        rospy.Subscriber("/lidargrid", Image, self.gridCB, queue_size=1)
        rospy.Subscriber("/cmd_vel", TwistStamped , self.twistCB , queue_size = 1)
        rospy.Subscriber("/joy", Joy, self.joyCB, queue_size=5)
        self.pub_img = rospy.Publisher("/steering_img", Image)
        self.pub_twist = rospy.Publisher("/lidar_twist", TwistStamped, queue_size=1)
        self.sound = rospy.Publisher("/sound_server/speech_synth", String, queue_size=1)        
        rospy.init_node ('lidar_cmd',anonymous=True)
        rospy.spin() 
Example #3
Source File: dataRecorder.py    From Cherry-Autonomous-Racecar with MIT License 6 votes vote down vote up
def __init__(self):
        print "dataRecorder"
        self.record = False
        self.twist = None
        self.twistLock = Lock()
        self.bridge = CvBridge()
        self.globaltime = None
        self.controller = XBox360()
        ##rospy.Subscriber("/camera/depth/points" , PointCloud2, self.ptcloudCB)
        rospy.Subscriber("/camera/depth/image_rect_raw_drop", Image, self.depthCB)
        rospy.Subscriber("/camera/rgb/image_rect_color_drop", Image, self.streamCB)
        #rospy.Subscriber("/camera/rgb/image_rect_mono_drop", Image, self.streamCB)  ##for black and white images see run.launch and look at the drop fps nodes near the bottom
        rospy.Subscriber("/lidargrid", Image, self.lidargridCB)
        rospy.Subscriber("/cmd_vel", TwistStamped, self.cmd_velCB)
        rospy.Subscriber("/joy", Joy ,self.joyCB)
        self.sound = rospy.Publisher("/sound_server/speech_synth", String, queue_size=1)
        rospy.init_node('dataRecorder',anonymous=True)
        rospy.spin() 
Example #4
Source File: runModel.py    From Cherry-Autonomous-Racecar with MIT License 6 votes vote down vote up
def __init__(self):
        rospy.loginfo("runner.__init__")
        # ----------------------------
        self.sess = tf.InteractiveSession()
        self.model = cnn_cccccfffff()
        saver = tf.train.Saver()
        saver.restore(self.sess, "/home/ubuntu/catkin_ws/src/car/scripts/model.ckpt")
        rospy.loginfo("runner.__init__: model restored")
        # ----------------------------
        self.bridge = CvBridge()
        self.netEnable = False
        self.controller = XBox360()
        rospy.Subscriber("/camera/rgb/image_rect_color", Image, self.runCB)
        rospy.Subscriber("/joy", Joy ,self.joyCB)
        self.pub_twist = rospy.Publisher("/neural_twist", TwistStamped, queue_size=1)
        self.sound = rospy.Publisher("/sound_server/speech_synth", String, queue_size=1)
        rospy.init_node('neural_cmd',anonymous=True)
        rospy.spin() 
Example #5
Source File: publisher_old_school.py    From examples with Apache License 2.0 6 votes vote down vote up
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('minimal_publisher')

    publisher = node.create_publisher(String, 'topic', 10)

    msg = String()

    i = 0
    while rclpy.ok():
        msg.data = 'Hello World: %d' % i
        i += 1
        node.get_logger().info('Publishing: "%s"' % msg.data)
        publisher.publish(msg)
        sleep(0.5)  # seconds

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    node.destroy_node()
    rclpy.shutdown() 
Example #6
Source File: mic_client.py    From dialogflow_ros with MIT License 6 votes vote down vote up
def __init__(self):
        # Audio stream input setup
        FORMAT = pyaudio.paInt16
        CHANNELS = 1
        RATE = 16000
        self.CHUNK = 4096
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(format=FORMAT, channels=CHANNELS,
                                      rate=RATE, input=True,
                                      frames_per_buffer=self.CHUNK,
                                      stream_callback=self._get_data)
        self._buff = Queue.Queue()  # Buffer to hold audio data
        self.closed = False

        # ROS Text Publisher
        text_topic = rospy.get_param('/text_topic', '/dialogflow_text')
        self.text_pub = rospy.Publisher(text_topic, String, queue_size=10) 
Example #7
Source File: publisher_member_function.py    From examples with Apache License 2.0 5 votes vote down vote up
def timer_callback(self):
        msg = String()
        msg.data = 'Hello World: %d' % self.i
        self.publisher_.publish(msg)
        self.get_logger().info('Publishing: "%s"' % msg.data)
        self.i += 1 
Example #8
Source File: gripper.py    From pyrobot with MIT License 5 votes vote down vote up
def set_primitive(self, primitive, wait=True):
        if primitive not in self.primitives:
            ValueError(
                "Invalid primitive. Only the following are available: {}".format(
                    self.primitives
                )
            )
        msg = str_msg()
        msg.data = primitive
        self.primitive_pub.publish(msg)
        if wait:
            rospy.sleep(self.configs.GRIPPER.WAIT_MIN_TIME) 
Example #9
Source File: gripper.py    From pyrobot with MIT License 5 votes vote down vote up
def _setup_primitive_pub(self):
        self.primitive_pub = rospy.Publisher(
            self.configs.GRIPPER.ROSTOPIC_SET_PRIMITIVE, str_msg, queue_size=1
        ) 
Example #10
Source File: custom_callback_group.py    From examples with Apache License 2.0 5 votes vote down vote up
def timer_callback(self):
        msg = String()
        msg.data = 'Hello World: {0}'.format(self.i)
        self.i += 1
        self.get_logger().info('Publishing: "{0}"'.format(msg.data))
        self.pub.publish(msg) 
Example #11
Source File: subscriber_old_school.py    From examples with Apache License 2.0 5 votes vote down vote up
def main(args=None):
    global g_node
    rclpy.init(args=args)

    g_node = rclpy.create_node('minimal_subscriber')

    subscription = g_node.create_subscription(String, 'topic', chatter_callback, 10)
    subscription  # prevent unused variable warning

    while rclpy.ok():
        rclpy.spin_once(g_node)

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    g_node.destroy_node()
    rclpy.shutdown() 
Example #12
Source File: publisher_local_function.py    From examples with Apache License 2.0 5 votes vote down vote up
def main(args=None):
    rclpy.init(args=args)

    node = rclpy.create_node('minimal_publisher')
    publisher = node.create_publisher(String, 'topic', 10)

    msg = String()
    i = 0

    def timer_callback():
        nonlocal i
        msg.data = 'Hello World: %d' % i
        i += 1
        node.get_logger().info('Publishing: "%s"' % msg.data)
        publisher.publish(msg)

    timer_period = 0.5  # seconds
    timer = node.create_timer(timer_period, timer_callback)

    rclpy.spin(node)

    # Destroy the timer attached to the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    node.destroy_timer(timer)
    node.destroy_node()
    rclpy.shutdown() 
Example #13
Source File: publisher_member_function.py    From examples with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        super().__init__('minimal_publisher')
        self.publisher_ = self.create_publisher(String, 'topic', 10)
        timer_period = 0.5  # seconds
        self.timer = self.create_timer(timer_period, self.timer_callback)
        self.i = 0 
Example #14
Source File: sequence_code_executor.py    From niryo_one_ros with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.blockly_dir = rospy.get_param("~sequence_code_to_execute_path")
        self.python_file = str(self.blockly_dir) + '/generated_code.py'
        create_directory(self.blockly_dir)
        self.process = None
        self.cancel_flag = False
        self.is_paused = False

        # Highlight publisher (to highlight blocks in Blockly interface)
        self.highlight_block_publisher = rospy.Publisher('/niryo_one/blockly/highlight_block', String, queue_size=10) 
Example #15
Source File: callback_group.py    From examples with Apache License 2.0 5 votes vote down vote up
def timer_callback(self):
        msg = String()
        msg.data = 'Hello World: {0}'.format(self.i)
        self.i += 1
        self.get_logger().info('Publishing: "{0}"'.format(msg.data))
        self.pub.publish(msg) 
Example #16
Source File: listener.py    From examples with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        # Calls Node.__init__('listener')
        super().__init__('listener')
        self.sub = self.create_subscription(String, 'chatter', self.chatter_callback, 10) 
Example #17
Source File: pose_controller.py    From naoqi_bridge with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run(self):
        while self.is_looping():
            try:
                if self.getLifeStatePub.get_num_connections() > 0:
                    get_life_state_msg = String()
                    get_life_state_msg.data = self.lifeProxy.getState()
                    self.getLifeStatePub.publish(get_life_state_msg)

            except RuntimeError, e:
                print "Error accessing ALMotion, ALRobotPosture, ALAutonomousLife, exiting...\n"
                print e
                rospy.signal_shutdown("No NaoQI available anymore")

            self.rate.sleep() 
Example #18
Source File: callback_group.py    From examples with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        super().__init__('double_talker')

        self.i = 0
        self.pub = self.create_publisher(String, 'chatter', 10)

        # This type of callback group only allows one callback to be executed at a time
        self.group = MutuallyExclusiveCallbackGroup()
        # Pass the group as a parameter to give it control over the execution of the timer callback
        self.timer = self.create_timer(1.0, self.timer_callback, callback_group=self.group)
        self.timer2 = self.create_timer(0.5, self.timer_callback, callback_group=self.group) 
Example #19
Source File: teleoperation.py    From pyrobot with MIT License 5 votes vote down vote up
def __init__(self, cfg_file="teleop.yaml"):
        rospy.init_node("keyboard_teleoperation_client", anonymous=True)

        dir_path = os.path.dirname(os.path.realpath(__file__))
        root_path = os.path.dirname(os.path.dirname(dir_path))
        cfg_path = os.path.join(root_path, "config", cfg_file)
        with open(cfg_path, "r") as f:
            self.cfg = yaml.load(f)

        self.pub = rospy.Publisher(self.cfg["ROSTOPIC_TELEOP"], String, queue_size=1) 
Example #20
Source File: ros_tensorflow_classify.py    From ros_tensorflow with Apache License 2.0 5 votes vote down vote up
def __init__(self):
       
        self._session = tf.Session()
        self._cv_bridge = CvBridge()

        self._sub = rospy.Subscriber('usb_cam/image_raw', Image, self.callback, queue_size=1)
        self._pub = rospy.Publisher('/result_ripe', String, queue_size=1)
        self.score_threshold = rospy.get_param('~score_threshold', 0.1)
        self.use_top_k = rospy.get_param('~use_top_k', 5) 
Example #21
Source File: sequence_code_executor.py    From niryo_one_ros with GNU General Public License v3.0 5 votes vote down vote up
def cancel_execution(self):
        if self.process is None:
            return
        if self.is_executing_code():
            rospy.logwarn("Stopping sequence code execution")
            self.cancel_flag = True
            self.resume_execution()
            self.process.terminate()
            # Publish empty block ID for Blockly
            # Only visual, no functionality here
            msg = String()
            msg.data = ''
            self.highlight_block_publisher.publish(msg) 
Example #22
Source File: launchpad_node.py    From Learning-Robotics-using-Python-Second-Edition with MIT License 5 votes vote down vote up
def _WriteSerial(self, message):
		self._SerialPublisher.publish(String(str(self._Counter) + ", out: " + message))
		self._SerialDataGateway.Write(message)

####################################################################################################################### 
Example #23
Source File: jevois_ros_driver.py    From niryo_one_ros with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, jevois_manager):
        self.jevois_manager = jevois_manager

        self.change_module_server = rospy.Service(
            '/niryo_one/jevois/set_module', SetString,
            self.ros_callback_set_module)

        self.data_publisher = rospy.Publisher(
            '/niryo_one/jevois/data', String, queue_size=10)

        self.jevois_manager.set_data_callback(self.callback_data) 
Example #24
Source File: qrcode_example.py    From niryo_one_ros with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.jevois_sub = rospy.Subscriber(
            '/niryo_one/jevois/data', String, self.callback_jevois_data)

        self.load_module('qr_code') 
Example #25
Source File: SoundServer.py    From Cherry-Autonomous-Racecar with MIT License 5 votes vote down vote up
def cb_play_sound_file(self, data):
        if data is not None and data.data != "": # TODO add more input validation.
            sound_seconds = self.s.play(data.data)
            self.pub_status.publish(String(str(sound_seconds))) 
Example #26
Source File: SoundServer.py    From Cherry-Autonomous-Racecar with MIT License 5 votes vote down vote up
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() 
Example #27
Source File: cmdControl.py    From Cherry-Autonomous-Racecar with MIT License 5 votes vote down vote up
def __init__(self):
        self.throttleInitialized = False
        self.joy_timeout = 2.0
        self.lid_timeout = 0.30
        self.cnn_timeout = 0.1
        self.joy_time = time.time()
        self.lid_time = time.time()
        self.cnn_time = time.time()
        self.controller = XBox360()
        self.joy_cmd = TwistStamped()
        self.lid_cmd = TwistStamped()
        self.cnn_cmd = TwistStamped()
        self.cruiseControl = False
        self.cruiseThrottle = 0.5
        self.steeringAngle = 0.5
        self.throttle = 0.5
        self.trim = 0.0
        ##self.throttleLock = Lock()
        print "cmd_control"
       
        rospy.Subscriber("/imu", Imu, self.imuCB, queue_size=5)
        rospy.Subscriber("/lidar_twist", TwistStamped, self.lidarTwistCB, queue_size=5)
        rospy.Subscriber("/neural_twist", TwistStamped, self.neuralTwistCB, queue_size=5)
        rospy.Subscriber("/joy", Joy, self.joyCB, queue_size=5)
        self.vel_pub = rospy.Publisher("/cmd_vel", TwistStamped, queue_size = 1) 
        #self.state_pub = rospy.Publisher("/joint_states", JointState, queue_size=1)
        self.sound = rospy.Publisher("/sound_server/speech_synth", String, queue_size=1)        
        rospy.init_node ('cmd_control',anonymous=True)
        rate = rospy.Rate(66)
        while not rospy.is_shutdown():
            self.cmdRouter()
            rate.sleep() 
Example #28
Source File: launchpad_node (copy).py    From ROS-Programming-Building-Powerful-Robots with MIT License 5 votes vote down vote up
def _WriteSerial(self, message):
		self._SerialPublisher.publish(String(str(self._Counter) + ", out: " + message))
		self._SerialDataGateway.Write(message)

####################################################################################################################### 
Example #29
Source File: arduino (copy).py    From ROS-Programming-Building-Powerful-Robots with MIT License 5 votes vote down vote up
def _WriteSerial(self, message):
		self._SerialPublisher.publish(String(str(self._Counter) + ", out: " + message))
		self._SerialDataGateway.Write(message) 
Example #30
Source File: arduino_bkup.py    From ROS-Programming-Building-Powerful-Robots with MIT License 5 votes vote down vote up
def __init__(self, port="/dev/ttyUSB0", baudrate=9600):
		'''
		Initializes the receiver class. 
		port: The serial port to listen to.
		baudrate: Baud rate for the serial communication
		'''

		self._Counter = 0

		rospy.init_node('arduino')

		port = rospy.get_param("~port", "/dev/ttyUSB0")
		baudRate = int(rospy.get_param("~baudRate", 9600))

		rospy.loginfo("Starting with serial port: " + port + ", baud rate: " + str(baudRate))

		# subscriptions
		rospy.Subscriber("cmd_vel", Twist, self._HandleVelocityCommand)
		self._SerialPublisher = rospy.Publisher('serial', String)

		self._OdometryTransformBroadcaster = tf.TransformBroadcaster()
		self._OdometryPublisher = rospy.Publisher("odom", Odometry)

#		self._VoltageLowlimit = rospy.get_param("~batteryStateParams/voltageLowlimit", "12.0")
#		self._VoltageLowLowlimit = rospy.get_param("~batteryStateParams/voltageLowLowlimit", "11.7")

#		self._BatteryStatePublisher = rospy.Publisher("battery", BatteryState)
		
		self._SetDriveGainsService = rospy.Service('setDriveControlGains', SetDriveControlGains, self._HandleSetDriveGains)

		self._State = Arduino.CONTROLLER_RESET_REQUIRED

		self._SerialDataGateway = SerialDataGateway(port, baudRate,  self._HandleReceivedLine)