我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用std_msgs.msg.Int32()。
def __init__(self): self.node_name = "hand_gestures" rospy.init_node(self.node_name) rospy.on_shutdown(self.cleanup) # self.cv_window_name = self.node_name # cv2.namedWindow("Depth Image", 1) # cv2.moveWindow("Depth Image", 20, 350) self.bridge = CvBridge() self.numFingers = RecognizeNumFingers() self.depth_sub = rospy.Subscriber("/asus/depth/image_raw", Image, self.depth_callback) self.num_pub = rospy.Publisher('num_fingers', Int32, queue_size=10, latch=True) # self.img_pub = rospy.Publisher('hand_img', Image, queue_size=10) rospy.loginfo("Waiting for image topics...")
def execute(): # define publisher and its topic pub = rospy.Publisher('read_coords',Int32,queue_size = 10) rospy.init_node('report_coords_node',anonymous = True) rate = rospy.Rate(10) # report once if len(sys.argv) == 1: pub.publish(1) time.sleep(0.1) print 'Current location is x: %2.2fcm, y: %2.2fcm, z: %2.2fcm.' %(rospy.get_param('current_x'),rospy.get_param('current_y'),rospy.get_param('current_z')) # report multiple time elif len(sys.argv) == 2: for i in range(0,int(sys.argv[1])): pub.publish(1) time.sleep(0.1) print 'Current location is x: %2.2fcm, y: %2.2fcm, z: %2.2fcm.' %(rospy.get_param('current_x'),rospy.get_param('current_y'),rospy.get_param('current_z')) elif len(sys.argv) == 3: for i in range(0,int(sys.argv[1])): pub.publish(1) time.sleep(0.1) print 'Current location is x: %2.2fcm, y: %2.2fcm, z: %2.2fcm.' %(rospy.get_param('current_x'),rospy.get_param('current_y'),rospy.get_param('current_z')) time.sleep(float(sys.argv[2])-0.1) else: raiseError() rate.sleep() # main function
def execute(): # define publisher and its topic pub = rospy.Publisher('read_angles',Int32,queue_size = 10) rospy.init_node('report_angles_node',anonymous = True) rate = rospy.Rate(10) # report once if len(sys.argv) == 1: pub.publish(1) time.sleep(0.15) print 'Four Servo Angles: %2.2f, %2.2f, %2.2f and %2.2f degrees.' %(rospy.get_param('servo_1'),rospy.get_param('servo_2'),rospy.get_param('servo_3'),rospy.get_param('servo_4')) # report multiple time elif len(sys.argv) == 2: for i in range(0,int(sys.argv[1])): pub.publish(1) time.sleep(0.15) print 'Four Servo Angles: %2.2f, %2.2f, %2.2f and %2.2f degrees.' %(rospy.get_param('servo_1'),rospy.get_param('servo_2'),rospy.get_param('servo_3'),rospy.get_param('servo_4')) elif len(sys.argv) == 3: for i in range(0,int(sys.argv[1])): pub.publish(1) time.sleep(0.15) print 'Four Servo Angles: %2.2f, %2.2f, %2.2f and %2.2f degrees.' %(rospy.get_param('servo_1'),rospy.get_param('servo_2'),rospy.get_param('servo_3'),rospy.get_param('servo_4')) time.sleep(float(sys.argv[2])-0.15) else: raiseError() rate.sleep() # main function
def listener(): print ' ' print 'Begin monitor mode - listening to all fucntional topics' print '=======================================================' print ' Use rqt_graph to check the connection ' print '=======================================================' rospy.init_node('uarm_core',anonymous=True) rospy.Subscriber("uarm_status",String, attchCallback) rospy.Subscriber("pump_control",UInt8, pumpCallack) rospy.Subscriber("pump_str_control",String, pumpStrCallack) rospy.Subscriber("read_coords",Int32, currentCoordsCallback) rospy.Subscriber("read_angles",Int32, readAnglesCallback) rospy.Subscriber("stopper_status",Int32, stopperStatusCallback) rospy.Subscriber("write_angles",Angles, writeAnglesCallback) rospy.Subscriber("move_to",Coords, moveToCallback) rospy.Subscriber("move_to_time",CoordsWithTime, moveToTimeCallback) rospy.Subscriber("move_to_time_s4",CoordsWithTS4, moveToTimeAndS4Callback) rospy.spin() pass # show eroors
def gripperApertureNode(): gripper = baxter_interface.Gripper('left') rospy.init_node('gripperApertureNode') pub = rospy.Publisher('/gripperAperture_values', Int32, queue_size=1) rate = rospy.Rate(20) while not rospy.is_shutdown(): ap = gripper.position() pub.publish(ap) rate.sleep()
def __init__(self): self.node_name = "move_tbot" rospy.init_node(self.node_name) rospy.on_shutdown(self._shutdown) self.bridge = CvBridge() self.turn = Twist() self.move = GoToPose() # self.face_recog_file = FaceRecognition() # self.get_person_data = GetPersonData() self.qr_data = [] self.all_face_names = [] self.face_names = [] self.counter = 0 self.qr_sub = rospy.Subscriber('ar_pose_marker', AlvarMarkers, self.qr_callback) self.odom_sub = rospy.Subscriber('odom', Odometry, self.odom_callback) self.num_fingers_sub = rospy.Subscriber('num_fingers', Int32, self.num_fingers_callback) # self.hand_img_sub = rospy.Subscriber('hand_img', Image, self.hand_img_callback) # self.face_img_sub = rospy.Subscriber('face_img', Image, self.face_img_callback) self.face_name_sub = rospy.Subscriber('face_names', StringArray, self.face_names_callback) self.all_face_names_sub = rospy.Subscriber('all_face_names', StringArray, self.all_face_names_callback) self.turn_pub = rospy.Publisher('cmd_vel_mux/input/navi', Twist, queue_size=10) self.rate = rospy.Rate(10) while not rospy.is_shutdown(): self.run_tbot_routine()
def talker(): pub = rospy.Publisher('servo_positions', Int32, queue_size=10) rospy.init_node('talker', anonymous=True) rate = rospy.Rate(10) # 1hz for joint in range (0, 10): # for all servos ... x = hand.get_position(joint) # get servo position rospy.loginfo('servo %d = %d ' , joint,x) pub.publish(x) # publish servo position rate.sleep()
def __init__(self): rospy.init_node('xm_tree', anonymous=False) # The root node BEHAVE = Sequence("BEHEAVE") # Initialize the ParallelAll task PARALLEL = ParallelAll("Listen_AND_CHECK") BEHAVE.add_child(PARALLEL) SPEECH_CMD = MonitorTask("SPEECH", "speech_sub", Int32, self.task_check_cb) CMD_EXE=Selector("CMD_LIST") PARALLEL.add_child(SPEECH_CMD) PARALLEL.add_child(CMD_EXE) with CMD_EXE: #CMD_EXE.add_child(Check_Cmd()) CMD_EXE.add_child(ExecuteTask()) pass print "Behavior Tree\n" print_tree(BEHAVE) rospy.loginfo("Starting simulated house cleaning test") # Run the tree while not rospy.is_shutdown(): BEHAVE.run() rospy.sleep(0.1) BEHAVE.reset() #rospy.loginfo("running")
def run(self): # subprocess.call(["espeak","I am following"]) rospy.Subscriber("speech_sub", Int32, self.follow_speech_cb) rospy.Subscriber('people_position_estimation',PositionMeasurement,self.people_msg_cb)
def main_fcn(): pub = rospy.Publisher('joint_states',JointState,queue_size = 10) pub2 = rospy.Publisher('read_angles',Int32,queue_size = 10) pub3 = rospy.Publisher('uarm_status',String,queue_size = 100) rospy.init_node('display',anonymous = True) rate = rospy.Rate(20) joint_state_send = JointState() joint_state_send.header = Header() joint_state_send.name = ['base_to_base_rot','base_rot_to_link_1','link_1_to_link_2' ,'link_2_to_link_3','link_3_to_link_end'] joint_state_send.name = joint_state_send.name+ ['link_1_to_add_1','link_2_to_add_4','link_3_to_add_2','base_rot_to_add_3','link_2_to_add_5'] angle = {} trigger = 1 while not rospy.is_shutdown(): joint_state_send.header.stamp = rospy.Time.now() pub2.publish(1) if trigger == 1: pub3.publish("detach") time.sleep(1) trigger = 0 angle['s1'] = rospy.get_param('servo_1')*math.pi/180 angle['s2'] = rospy.get_param('servo_2')*math.pi/180 angle['s3'] = rospy.get_param('servo_3')*math.pi/180 angle['s4'] = rospy.get_param('servo_4')*math.pi/180 joint_state_send.position = [angle['s1'],angle['s2'],-angle['s2']-angle['s3'],angle['s3'],angle['s4']] joint_state_send.position = joint_state_send.position + [-angle['s2']-angle['s3'],angle['s3'],PI/2-angle['s3']] joint_state_send.position = joint_state_send.position + [angle['s2']-PI,angle['s2']+angle['s3']-PI/2] joint_state_send.velocity = [0] joint_state_send.effort = [] pub.publish(joint_state_send) rate.sleep()
def execute(): # define publisher and its topic pub = rospy.Publisher('stopper_status',Int32,queue_size = 10) rospy.init_node('report_stopper_node',anonymous = True) rate = rospy.Rate(10) # report once if len(sys.argv) == 1: pub.publish(1) time.sleep(0.1) status = rospy.get_param('stopper_status') if status == 'HIGH': print 'Stopper is actived' elif status == 'LOW': print 'Stopper is not actived' # report multiple time elif len(sys.argv) == 2: for i in range(0,int(sys.argv[1])): pub.publish(1) time.sleep(0.1) status = rospy.get_param('stopper_status') if status == 'HIGH': print 'Stopper is actived' elif status == 'LOW': print 'Stopper is not actived' elif len(sys.argv) == 3: for i in range(0,int(sys.argv[1])): pub.publish(1) time.sleep(0.1) status = rospy.get_param('stopper_status') if status == 'HIGH': print 'Stopper is actived' elif status == 'LOW': print 'Stopper is not actived' time.sleep(float(sys.argv[2])-0.1) else: raiseError() rate.sleep() # main function