Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 import rospy
00022 from sensor_msgs.msg import JointState
00023
00024
00025 class CurrentPlay(object):
00026 def __init__(self):
00027 self.last_msg = None
00028 self.js_sub = rospy.Subscriber('/joint_states',
00029 JointState,
00030 self.joint_states_cb,
00031 queue_size=1)
00032 rospy.loginfo(
00033 "Subscribed to: '" + str(self.js_sub.resolved_name) + "' topic.")
00034 self.run()
00035
00036 def joint_states_cb(self, msg):
00037 """
00038 :type msg: JointState
00039 """
00040 self.last_msg = msg
00041
00042 def run(self):
00043 """Show information on what was found in the joint states current"""
00044 rospy.loginfo("Waiting for first JointState message...")
00045 while not rospy.is_shutdown() and self.last_msg is None:
00046 rospy.sleep(0.2)
00047
00048
00049 r = rospy.Rate(5)
00050 while not rospy.is_shutdown():
00051 self.do_stuff_with_last_msg()
00052 r.sleep()
00053
00054 def do_stuff_with_last_msg(self):
00055 """Print funny sentences about what we can guess of our status thanks to the currents read"""
00056 currents_sum = sum(self.last_msg.effort)
00057 rospy.loginfo("Looks like we are consuming " + str(currents_sum) + " ampers with our motors!")
00058
00059
00060 if __name__ == '__main__':
00061 rospy.init_node('current_play')
00062 cp = CurrentPlay()
00063 rospy.spin()