我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用std_msgs.msg.String()。
def talker(): pub = rospy.Publisher('chatter', String, queue_size=10) rospy.init_node('talker', anonymous=True) rate = rospy.Rate(10) # 10hz while not rospy.is_shutdown(): hello_str = "hello world %s" % rospy.get_time() rospy.loginfo(hello_str) pub.publish(hello_str) rate.sleep() # rate = rospy.Rate(10) # hello_str = "hello world" # rospy.loginfo(hello_str) # pub.publish(hello_str) # rospy.spin() # exit(0)
def ros_loop(test): while True: rospy.Subscriber('human_turn_topic', String, human_turn) rospy.Subscriber('human_chosen_topic', String, have_chosen) rospy.Subscriber('human_predict_turn_topic', String, human_predict) rospy.Subscriber('robot_turn_topic', String, robot_turn) rospy.Subscriber('robot_chosen_topic', String, have_chosen) rospy.Subscriber('story_telling', String, new_phrase) rospy.Subscriber('new_element', String, new_element) rospy.sleep(0.1) rospy.spin() ################################################
def main(): rospy.init_node("actions") loginfo("Creating action handler...") action_handler = ActionHandler() loginfo("Registering services...") get_service_handler(CallFunction).register_service( lambda func_name, kwargs: action_handler.call_func(func_name, **json.loads(kwargs)) ) rospy.Subscriber("/aide/update_apis", String, lambda x: action_handler.reload_api_references(x.data)) get_service_handler(GetActionProvider).register_service(lambda name: action_handler.get_action_provider(name) or ()) get_service_handler(GetAllActionProviders).register_service(action_handler.get_all_action_providers) get_service_handler(AddActionProvider).register_service(action_handler.add_action_provider) get_service_handler(DeleteActionProvider).register_service(action_handler.remove_action_provider) loginfo("Registered services. Spinning.") rospy.spin()
def main(): rospy.init_node("api_handler") loginfo("Creating api handler...") notify_publisher = rospy.Publisher("/aide/update_apis", String, queue_size=50) api = ApiHandler(lambda x: notify_publisher.publish(x)) loginfo("Registering services...") get_service_handler(GetApi).register_service(lambda **args: api.get_api(**args) or ()) get_service_handler(GetAllApis).register_service(api.get_all_apis) get_service_handler(AddApi).register_service(api.add_api) get_service_handler(DeleteApi).register_service(api.remove_api) loginfo("Registered services. Spinning.") rospy.spin()
def listenerDomainNameProblem(self): ''' listen on the topic domain_problem_from_controller_topic It get a String msg structured like [problemDirectory__problemName] The callback function is resolvProblemAsTopic which take the data received in parameter :param: void :return: void ''' rospy.Subscriber("domain_problem_from_controller_topic", String, self.resolvProblemAsTopic) print(">> Ready to be requested, waiting a std_msgs/String...") print(">> Topic : /domain_problem_from_controller_topic...") print(">> Callback : resolvProblemAsTopic...") print("############################" + "######################################") rospy.spin()
def main(): rospy.init_node("listener") sub = rospy.Subscriber("/chatter_topic", String, callback) rospy.spin()
def __init__(self): rospy.init_node('gaze', anonymous=False) self.lock = threading.RLock() with self.lock: self.current_state = GazeState.IDLE self.last_state = self.current_state # Initialize Variables self.glance_timeout = 0 self.glance_timecount = 0 self.glance_played = False self.idle_timeout = 0 self.idle_timecount = 0 self.idle_played = False rospy.loginfo('\033[92m[%s]\033[0m waiting for bringup social_mind...'%rospy.get_name()) rospy.wait_for_service('environmental_memory/read_data') rospy.wait_for_service('social_events_memory/read_data') self.rd_memory = {} self.rd_memory['environmental_memory'] = rospy.ServiceProxy('environmental_memory/read_data', ReadData) self.rd_memory['social_events_memory'] = rospy.ServiceProxy('social_events_memory/read_data', ReadData) rospy.Subscriber('raising_events', RaisingEvents, self.handle_raising_events) rospy.Subscriber('gaze_focusing', String, self.handle_gaze_focusing) self.pub_gaze_cmd = rospy.Publisher('gaze_command', GazeCommand, queue_size=10) self.pub_viz_gaze_cmd = rospy.Publisher('visualization_gaze_cmd', PointStamped, queue_size=10) rospy.Timer(rospy.Duration(GAZE_CONTROLLER_PERIOD), self.handle_gaze_controller) rospy.loginfo('\033[92m[%s]\033[0m initialized...'%rospy.get_name()) rospy.spin()
def abort(self, req=None): """ Service function for the aborting the task '[name]_abort'. handles a shutdown of the task but instead of calling signal_complete, this method calls `signal_aborted`, which lets the task server know that it can proceed with launching a mayday task (as opposed to queueing up another general task). Args: msg (std_msgs.msg.String): the message received through the subscriber channel. """ if not self.active: logwarn("Can't abort {} because task isn't active.".format(self.name)) return False self.instruct() self.prep_shutdown(did_fail=True) return True
def __init__(self): self.listen = tf.TransformListener() self.broadcast = tf.TransformBroadcaster() self.obj_pose_sub = rospy.Subscriber("/pick_frame_name", String, self.set_pick_frame, queue_size=1) self.obj_pose_sub = rospy.Subscriber("/place_frame_name", String, self.set_place_frame, queue_size=1) self.obj_pose_sub = rospy.Subscriber("/num_objects", Int64, self.broadcast_frames, queue_size=1) self.place_frame = '' self.pick_frame = '' self.tower_size = 1 self.tower_size_sub = rospy.Subscriber("/tower_size",Int64,self.set_tower_size)
def __init__(self): self.services = {'set_iteration': {'name': 'learning/set_iteration', 'type': SetIteration}, 'set_focus': {'name': 'learning/set_interest', 'type': SetFocus}, 'assess': {'name': 'controller/assess', 'type': Assess}, 'get_interests': {'name': 'learning/get_interests', 'type': GetInterests}} rospy.Subscriber('learning/current_focus', String, self._cb_focus) rospy.Subscriber('learning/user_focus', String, self._cb_user_focus) rospy.Subscriber('learning/ready_for_interaction', Bool, self._cb_ready) self.current_focus = "" self.user_focus = "" self.ready_for_interaction = False for service_name, service in self.services.items(): rospy.loginfo("User node is waiting service {}...".format(service['name'])) rospy.wait_for_service(service['name']) service['call'] = rospy.ServiceProxy(service['name'], service['type']) rospy.loginfo("User node started!")
def __init__(self): if_continue='' while not rospy.is_shutdown() and if_continue == '': self.define() self.recode() words = self.reg() reg = rospy.Publisher('Rog_result', String, queue_size=1) reg.publish(words) #self.savewav("testing")#testing if_continue = raw_input('pls input ????? to continue')
def __init__(self, topic_name, msg_type=None, queue_size=None, preprocessor=None): super(RosTopicPublisher, self).__init__(topic_name, msg_type, queue_size, preprocessor) self.msg_type = std_msgs.String if msg_type is None else msg_type self.queue_size = 10 if preprocessor is None: if self.msg_type is std_msgs.String: def default_preprocessor(msg): return MsgUtils.serialize(msg) self.preprocessor = default_preprocessor self._publisher = rospy.Publisher(name=self.topic_name, data_class=self.msg_type, queue_size=self.queue_size)
def __init__(self, topic_name, msg_type=None, queue_size=None, postprocessor=None): super(RosTopicSubscriber, self).__init__(topic_name=topic_name, msg_type=std_msgs.String if msg_type is None else msg_type, queue_size=1 if queue_size is None else queue_size, postprocessor=postprocessor) if postprocessor is None: if self.msg_type is std_msgs.String: def default_postprocessor(msg): return MsgUtils.deserialize(RosMsgUtils.unwrap(msg, 'data')) self.postprocessor = default_postprocessor self._subscriber = rospy.Subscriber(name=self.topic_name, data_class=self.msg_type, callback=self._subscribe, callback_args=None, queue_size=self.queue_size)
def __init__(self): self.petrone = Petrone() # subscriber self.sub_flight = rospy.Subscriber('cmd_fly', Int8, self.cb_fly, queue_size=1) self.sub_cmd = rospy.Subscriber('cmd_vel_raw', Twist, self.cb_cmd, queue_size=1) self.sub_color = rospy.Subscriber('led_color', String, self.cb_color, queue_size=1) # publisher self.pub_battery = rospy.Publisher('battery', Float32, queue_size=1) self.pub_status_flight = rospy.Publisher('status/flight', Int8, queue_size=1) self.pub_status_system = rospy.Publisher('status/system', Int8, queue_size=1) self.pub_imu = rospy.Publisher('imu', Imu, queue_size=1) # cache self.is_disconnected = True self.last_values = defaultdict(lambda: 0) # flight parameters self.twist = Twist() self.twist_at = 0
def __init__(self): rospy.loginfo("Initializing AudioFilePlayer...") self.current_playing_process = None self.afp_as = SimpleActionServer(rospy.get_name(), AudioFilePlayAction, self.as_cb, auto_start=False) self.afp_sub = rospy.Subscriber('~play', String, self.topic_cb, queue_size=1) # By default this node plays files using the aplay command # Feel free to use any other command or flags # by using the params provided self.command = rospy.get_param('~/command', 'play') self.flags = rospy.get_param('~/flags', '') self.feedback_rate = rospy.get_param('~/feedback_rate', 10) self.afp_as.start() # Needs to be done after start self.afp_as.register_preempt_callback(self.as_preempt_cb) rospy.loginfo( "Done, playing files from action server or topic interface.")
def __init__(self): ''' Instance variables ''' #use this for small step accerleration self.last_speed=0 self.e1 = 0 self.e2 = 0 ''' Node setup and start ''' self.drive = rospy.Publisher('/vesc/ackermann_cmd_mux/input/navigation', AckermannDriveStamped, queue_size=5) rospy.Subscriber('scan', LaserScan, self.laserCall) rospy.Subscriber('/color', String, self.blobCall) ''' Leave the robot going until roscore dies, then set speed to 0 ''' self.drive.publish(AckermannDriveStamped()) print ("init")
def _WriteSerial(self, message): self._SerialPublisher.publish(String(str(self._Counter) + ", out: " + message)) self._SerialDataGateway.Write(message) #######################################################################################################################
def main(): rospy.init_node("talker") pub = rospy.Publisher("/chatter_topic", String, queue_size=1) rate = rospy.Rate(10) # 10 Hertz ile çal???yor while not rospy.is_shutdown(): message = "Naber Dünya? %s" % (rospy.get_time()) rospy.loginfo("Mesaj haz?rland?: %s" % message) pub.publish(message) rate.sleep()
def talker(fromDavid): pub = rospy.Publisher('/recognizer/output', String, queue_size=10) action = fromDavid #rospy.loginfo(action) pub.publish(action)
def __init__(self): rospy.init_node('nav_asr', anonymous = True) rospy.Subscriber("/recognizer/output", String, self.SpeechUpdateGoal) rospy.Subscriber("/WPsOK", String, self.GetWayPoints) self.waypoint_list = dict() self.marker_list = list() self.makerArray = MarkerArray() self.makerArray_pub = rospy.Publisher("Waypoint_Array",MarkerArray,queue_size=5) rospy.on_shutdown(self.shutdown) # @@@@ # How long in seconds should the robot pause at each location? self.rest_time = rospy.get_param("~rest_time", 2) # Are we running in the fake simulator? self.fake_test = rospy.get_param("~fake_test", True) # Publisher to manually control the robot (e.g. to stop it, queue_size=5) self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=5) # Subscribe to the move_base action server self.move_base = actionlib.SimpleActionClient("move_base", MoveBaseAction) rospy.loginfo("Waiting for move_base action server...") # Wait 60 seconds for the action server to become available self.move_base.wait_for_server(rospy.Duration(60)) rospy.loginfo("Connected to move base server") # Create the waypoints list from txt
def pubDataStaus(dataStatus): pub = rospy.Publisher('WPsOK', String, queue_size=10) pub.publish(dataStatus)
def publish_str(word): rospy.loginfo("Pub --> {}".format(word)) st = String() st.data = word[::-1] str_pub.publish(st)
def str_pub(self, word): rospy.loginfo("Pub --> {}".format(word)) st = String() st.data = word[::-1] return st
def str_pub(word): rospy.loginfo("Pub --> {}".format(word)) st = String() st.data = word[::-1] return st
def run(self): pass #rospy.init_node(self._node_name) #send1 = send.Send('hello_world', String) #receive1 = receive.Receive('hello_world_2', String, self.on_received1)#?FunctionUnit?????? #rospy.spin()
def contr( keynumber ): rospy.init_node('talker', anonymous=True) pub = rospy.Publisher('number', String, queue_size=10) rate = rospy.Rate(1) # 10hz while not rospy.is_shutdown(): num = str('%d'%keynumber) pub.publish(num) rospy.loginfo(num) rate.sleep() # num = str('%d'%keynumber) # pub.publish(num) # rospy.loginfo(num)
def robot_turn(msg): global last_message if msg.data!=last_message: last_message = msg.data received_msg = String() received_msg.data = "receives: " + msg.data pub_reception.publish(received_msg) label, _, items, name = read_msg(msg) p1.robot(label, items, name) p1.mainframe.tkraise()
def human_turn(msg): global last_message if msg.data!=last_message: last_message = msg.data received_msg = String() received_msg.data = "receives: " + msg.data pub_reception.publish(received_msg) label, _, items, name = read_msg(msg) p1.human(label, items, name) p1.mainframe.tkraise()
def human_predict(msg): global last_message if msg.data!=last_message: last_message = msg.data received_msg = String() received_msg.data = "receives: " + msg.data pub_reception.publish(received_msg) label, _, items, name = read_msg(msg) p1.human_predict(label, items, name) p1.mainframe.tkraise()
def have_chosen(msg): global last_message if msg.data!=last_message: last_message = msg.data received_msg = String() received_msg.data = "receives: " + msg.data pub_reception.publish(received_msg) label, choice, items, name = read_msg(msg) p1.chosen(label, items, choice,name) p1.mainframe.tkraise()
def new_phrase(msg): global last_message if msg.data!=last_message: last_message = msg.data received_msg = String() received_msg.data = "receives: " + msg.data pub_reception.publish(received_msg) p1.telling(msg.data) p1.mainframe.tkraise()
def human_choice(choice): rospy.loginfo("human choice "+choice) msg = String() msg.data = choice pub_human_choice.publish(msg)
def human_prediction(choice): rospy.loginfo("human predict "+choice) msg = String() msg.data = choice pub_human_prediction.publish(msg)
def look_at(target): msg = String() msg.data = target pub_robot_target.publish(msg)
def say(to_say): msg = String() msg.data = to_say pub_robot_say.publish(msg)
def point(robot_choice): msg = String() msg.data = robot_choice; rospy.loginfo("robot_choice "+robot_choice) pub_robot_point.publish(msg)
def ending(test): msg = String() msg.data = "" pub_exit.publish(msg)
def robot_turn(label, items, name="false"): msg = String() msg.data = label+",_,"+"-".join(items)+','+name pub_robot_turn.publish(msg)
def human_turn(label, items, name="false"): msg = String() msg.data = label+",_,"+"-".join(items)+','+name pub_human_turn.publish(msg)
def human_predict(label, items, name="false"): msg = String() msg.data = label+",_,"+"-".join(items)+','+name pub_human_predict.publish(msg)
def robot_chosen(label, items, choice, name="false"): msg1 = String() msg2 = String() msg1.data = label+","+choice+","+"-".join(items)+','+name pub_robot_chosen.publish(msg1) msg2.data = "(Nando) "+label+"\n" pub_new_element.publish(msg2) ######################################## reacting
def story_telling(phrase): msg = String() msg.data = phrase pub_story_telling.publish(msg) ############################################# what if new action message
def new_element(msg): global last_message if msg.data!=last_message: last_message = msg.data received_msg = String() received_msg.data = "receives: " + msg.data pub_reception.publish(received_msg) p1.update_trace(msg.data) p1.mainframe.tkraise() ################################################ for the trace