Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 import threading
00011 import rospy
00012 import math
00013 from geometry_msgs.msg import Twist
00014 from std_msgs.msg import String
00015
00016
00017
00018
00019
00020 '''
00021 implements a rotating motion.
00022 '''
00023
00024 class AngularAccelerateTest(threading.Thread):
00025 def __init__(self,cmd_vel_topic,log_topic, freq, accl):
00026 threading.Thread.__init__(self)
00027 self.pub_cmd = rospy.Publisher(cmd_vel_topic,Twist)
00028 self.pub_log = rospy.Publisher(log_topic,String)
00029
00030 twist = Twist()
00031 twist.linear.x = 0
00032 twist.linear.y = 0
00033 twist.linear.z = 0
00034 twist.angular.x = 0
00035 twist.angular.y = 0
00036 twist.angular.z = 0
00037 self.twist = twist
00038
00039 self.freq = freq
00040 self.accl = accl
00041
00042 self._stop = False
00043
00044 def stop(self):
00045 self._stop = True
00046
00047 def run(self):
00048 self._stop = False
00049
00050 start = rospy.get_rostime()
00051 rospy.sleep(0.5)
00052 twist = self.twist
00053 freq = self.freq
00054 self.rate = rospy.Rate(freq)
00055
00056 theta_dot_dot = self.accl
00057 msg = "Time : " + str(rospy.get_rostime().secs) + " Vel : " +str(twist.angular.z)
00058 while not rospy.is_shutdown() and not self._stop:
00059 twist.angular.z = twist.angular.z + ( 1.0 / freq ) * theta_dot_dot
00060 msg = "Time : " + str(rospy.get_rostime().secs) + " Vel : " +str(twist.angular.z)
00061 self.log(msg)
00062 self.pub_cmd.publish(twist)
00063 self.rate.sleep()
00064 twist.angular.z = 0
00065 self.pub_cmd.publish(twist)
00066
00067 def log(self,msg):
00068 rospy.loginfo(msg)
00069 t = String(msg)
00070 self.pub_log.publish(t)