我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用std_msgs.msg.Int16()。
def callback(data): msg = Int16(data.a + data.b) rospy.loginfo(str(data.a) + " + " + str(data.b) + " = " + str(msg)) pub.publish(msg)
def talker_listener(): rospy.init_node('two_ints_publisher_node', anonymous=True) global pub pub = rospy.Publisher("sum", Int16, queue_size=1) rospy.Subscriber("two_ints", TwoInts, callback) rospy.spin()
def __init__(self): self._coll_checked = False self._pub_joints = rospy.Publisher('joint_state_check', numpy_msg(Float32MultiArray), queue_size = 10, latch=True) self._sub = rospy.Subscriber('collision_check', Int16, self.sub_cb) # self._pub_path = rospy.Publisher('joint_path',numpy_msg(Float32MultiArray), queue_size = 10) self._pub_traj = rospy.Publisher('joint_traj',numpy_msg(Float32MultiArray), queue_size = 10) self._iter = 0 self._executing = True self._sub_demo_state = rospy.Subscriber('demo_state', Int16, self.sub_demo) self._sub_pos_state = rospy.Subscriber('pos_state', Int16, self.sub_pos) self._plot_demo = get_param('plot_demo', False) rospy.loginfo("Here's my demo state: ") rospy.loginfo(self._plot_demo) self._plotIndex = -1
def main(): rospy.init_node('set_catch_position') sub_pos_state = rospy.Subscriber('pos_state', Int16, sub_cb) rospy.spin()
def __init__(self): # create subscribers, timers, clients, etc. try: rospy.wait_for_service("/check_state_validity", timeout=5) except ROSException: rospy.logwarn("[check_collisions_node] Done waiting for /check_state_validity service... service not found") rospy.logwarn("shutting down...") rospy.signal_shutdown("service unavailable") except ROSInterruptException: pass self.coll_client = rospy.ServiceProxy("check_state_validity", GetStateValidity) self.js_sub = rospy.Subscriber("joint_state_check", numpy_msg(Float32MultiArray), self.js_cb) self.js_pub = rospy.Publisher("collision_check", Int16, queue_size = 10) return
def __init__(self): rospy.init_node("follow") rospy.on_shutdown(self.shutdown) self.state = None self.sm_follow=StateMachine(outcomes=['succeeded','aborted','preempted']) # ????follow with self.sm_follow: self.co_follow=Concurrence(outcomes=['succeeded','preempted','aborted'], default_outcome='succeeded', # outcome_cb = self.co_follow_outcome_cb , # child_termination_cb=self.co_follow_child_cb ) with self.co_follow: Concurrence.add('mo_L',MonitorState('people_position_estimation',PositionMeasurement, self.pos_M_cb)) self.sm_nav=StateMachine(outcomes=('succeeded','aborted','preempted')) with self.sm_nav: # StateMachine.add('wait',MonitorState('sr_data',Int16,self.wait_cb),transitions={'valid':'wait','invalid':'nav_speech','preempted':'nav_speech'}) self.speech_nav=Concurrence(outcomes=['get_in','succeeded'], default_outcome='succeeded', outcome_cb=self.speech_nav_outcome_cb, child_termination_cb=self.speech_nav_child_termination_cb ) with self.speech_nav: Concurrence.add('speech',MonitorState('sr_data',Int16,self.nav_speech_cb)) Concurrence.add('nav', Nav2Waypoint()) StateMachine.add('nav_speech',self.speech_nav,transitions={'get_in':'Get_in',}) self.get_in_speech=Concurrence(outcomes=['get_out','succeeded'], default_outcome='succeeded', outcome_cb=self.speech_get_in_outcome_cb, child_termination_cb=self.speech_get_in_child_termination_cb ) with self.get_in_speech: Concurrence.add('speech',MonitorState('sr_data',Int16,self.get_in_speech_cb)) Concurrence.add('get_in',Get_in()) StateMachine.add('Get_in',self.get_in_speech,transitions={'get_out':'Get_out'}) StateMachine.add('Get_out',Get_out(), transitions={'succeeded':'nav_speech','preempted':'','aborted':'Get_out' }) Concurrence.add('Nav',self.sm_nav) StateMachine.add('Nav_top',self.co_follow) a=self.sm_follow.execute()
def __init__(self): rospy.init_node("follow") rospy.on_shutdown(self.shutdown) self.state = None self.sm_follow=StateMachine(outcomes=['succeeded','aborted','preempted']) # ????follow with self.sm_follow: self.co_follow=Concurrence(outcomes=['succeeded','preempted','aborted'], default_outcome='succeeded', # outcome_cb = self.co_follow_outcome_cb , # child_termination_cb=self.co_follow_child_cb ) with self.co_follow: Concurrence.add('mo_L',MonitorState('people_position_estimation',PositionMeasurement, self.pos_M_cb)) Concurrence.add('nav', Nav2Waypoint()) # self.sm_nav=StateMachine(outcomes=('succeeded','aborted','preempted')) # with self.sm_nav: # # StateMachine.add('wait',MonitorState('sr_data',Int16,self.wait_cb),transitions={'valid':'wait','invalid':'nav_speech','preempted':'nav_speech'}) # # self.speech_nav=Concurrence(outcomes=['get_in','succeeded'], # default_outcome='succeeded', # outcome_cb=self.speech_nav_outcome_cb, # child_termination_cb=self.speech_nav_child_termination_cb # ) # with self.speech_nav: # Concurrence.add('speech',MonitorState('sr_data',Int16,self.nav_speech_cb)) # Concurrence.add('nav', Nav2Waypoint()) # StateMachine.add('nav_speech',self.speech_nav,transitions={'get_in':'Get_in',}) # self.get_in_speech=Concurrence(outcomes=['get_out','succeeded'], # default_outcome='succeeded', # outcome_cb=self.speech_get_in_outcome_cb, # child_termination_cb=self.speech_get_in_child_termination_cb # # ) # with self.get_in_speech: # Concurrence.add('speech',MonitorState('sr_data',Int16,self.get_in_speech_cb)) # Concurrence.add('get_in',Get_in()) # StateMachine.add('Get_in',self.get_in_speech,transitions={'get_out':'Get_out'}) # StateMachine.add('Get_out',Get_out(), transitions={'succeeded':'nav_speech','preempted':'','aborted':'Get_out' }) # Concurrence.add('Nav',self.sm_nav) StateMachine.add('Nav_top',self.co_follow) a=self.sm_follow.execute()
def move_to(pos): pub_demo_state = rospy.Publisher('demo_state',Int16, queue_size = 10) if (pos == 1): catch = np.array([.65, .2, 0]) # my .7? R = np.array([[ 0.26397895, -0.34002068, 0.90260791], [-0.01747676, -0.93733484, -0.34799134], [ 0.96437009, 0.07608772, -0.25337913]]) elif (pos == 2): catch = np.array([.68, -.05, 0]) R = np.array([[0,0,1],[0,-1,0],[1,0,0]]) elif (pos == 3): catch = np.array([.72, .1, 0]) R = np.array([[ 0.26397895, -0.34002068, 0.90260791], [-0.01747676, -0.93733484, -0.34799134], [ 0.96437009, 0.07608772, -0.25337913]]) else: pass th_init = np.array([-.3048, -.2703, -.1848, 1.908, .758, -1.234, -3.04]) X = RpToTrans(R,catch) # Find end joint angles with IK robot = URDF.from_parameter_server() base_link = robot.get_root() kdl_kin = KDLKinematics(robot, base_link, 'left_gripper_base') seed = 0 q_ik = kdl_kin.inverse(X, th_init) while q_ik == None: seed += 0.01 q_ik = kdl_kin.inverse(X, th_init+seed) if (seed>1): # return False break q_goal = q_ik print q_goal limb_interface = baxter_interface.limb.Limb('left') angles = limb_interface.joint_angles() for ind, joint in enumerate(limb_interface.joint_names()): angles[joint] = q_goal[ind] limb_interface.move_to_joint_positions(angles) # rospy.sleep(5) print 'done' pub_demo_state.publish(1)