linear_accelerate.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #       
00003 # License: BSD
00004 #   https://raw.github.com/yujinrobot/kobuki/hydro-devel/kobuki_testsuite/LICENSE
00005 #
00006 ##############################################################################
00007 # Imports
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 # Classes
00018 ##############################################################################
00019 
00020 '''
00021     implements a rotating motion.
00022 '''
00023 
00024 class LinearAccelerateTest(threading.Thread):
00025     def __init__(self,cmd_vel_topic,log_topic, freq, accl, max_speed):
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         self.max_speed = max_speed
00042 
00043         self._stop = False
00044 
00045     def stop(self):
00046         self._stop = True
00047 
00048     def run(self):
00049         self._stop = False
00050 
00051         start = rospy.get_rostime()
00052         rospy.sleep(0.5)
00053         twist = self.twist
00054         freq = self.freq
00055         self.rate = rospy.Rate(freq)
00056         a = self.accl
00057         max_speed = self.max_speed
00058 
00059         msg = "Time : " + str(rospy.get_rostime().secs) + " Vel : " +str(twist.linear.x)
00060         finish = False
00061         while not rospy.is_shutdown() and not self._stop:
00062             if not finish: 
00063                 twist.linear.x = twist.linear.x + ( 1.0 / freq ) * a 
00064             if twist.linear.x > max_speed:
00065                 finish = True
00066                 twist.linear.x = 0.0
00067             msg = "Time : " + str(rospy.get_rostime().secs) + " Vel : " +str(twist.angular.z)
00068             self.log(msg)
00069             self.pub_cmd.publish(twist)
00070             self.rate.sleep()
00071         twist.linear.x = 0
00072         self.pub_cmd.publish(twist)
00073 
00074     def log(self,msg):
00075         rospy.loginfo(msg)
00076         t = String(msg)
00077         self.pub_log.publish(t)


kobuki_testsuite
Author(s): Jorge Santos Simon
autogenerated on Thu Jun 6 2019 17:38:11