angular_accelerate.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # License: BSD
4 # https://raw.github.com/yujinrobot/kobuki/hydro-devel/kobuki_testsuite/LICENSE
5 #
6 ##############################################################################
7 # Imports
8 ##############################################################################
9 
10 import threading
11 import rospy
12 import math
13 from geometry_msgs.msg import Twist
14 from std_msgs.msg import String
15 
16 ##############################################################################
17 # Classes
18 ##############################################################################
19 
20 '''
21  implements a rotating motion.
22 '''
23 
24 class AngularAccelerateTest(threading.Thread):
25  def __init__(self,cmd_vel_topic,log_topic, freq, accl):
26  threading.Thread.__init__(self)
27  self.pub_cmd = rospy.Publisher(cmd_vel_topic,Twist)
28  self.pub_log = rospy.Publisher(log_topic,String)
29 
30  twist = Twist()
31  twist.linear.x = 0
32  twist.linear.y = 0
33  twist.linear.z = 0
34  twist.angular.x = 0
35  twist.angular.y = 0
36  twist.angular.z = 0
37  self.twist = twist
38 
39  self.freq = freq
40  self.accl = accl
41 
42  self._stop = False
43 
44  def stop(self):
45  self._stop = True
46 
47  def run(self):
48  self._stop = False
49 
50  start = rospy.get_rostime()
51  rospy.sleep(0.5)
52  twist = self.twist
53  freq = self.freq
54  self.rate = rospy.Rate(freq)
55 
56  theta_dot_dot = self.accl
57  msg = "Time : " + str(rospy.get_rostime().secs) + " Vel : " +str(twist.angular.z)
58  while not rospy.is_shutdown() and not self._stop:
59  twist.angular.z = twist.angular.z + ( 1.0 / freq ) * theta_dot_dot
60  msg = "Time : " + str(rospy.get_rostime().secs) + " Vel : " +str(twist.angular.z)
61  self.log(msg)
62  self.pub_cmd.publish(twist)
63  self.rate.sleep()
64  twist.angular.z = 0
65  self.pub_cmd.publish(twist)
66 
67  def log(self,msg):
68  rospy.loginfo(msg)
69  t = String(msg)
70  self.pub_log.publish(t)
def __init__(self, cmd_vel_topic, log_topic, freq, accl)


kobuki_testsuite
Author(s): Jorge Santos Simon
autogenerated on Mon Jun 10 2019 13:45:22