Go to the documentation of this file.00001
00002 from rospy import Subscriber, Publisher
00003 import rospy
00004 import sys
00005 from nav_msgs.msg import Odometry
00006 from geometry_msgs.msg import Twist
00007
00008 rospy.init_node("OdomNode")
00009 limit = float(sys.argv[1])
00010 vel = float(sys.argv[2])
00011 pub = Publisher('/diff_driver/command', Twist, queue_size=50)
00012
00013
00014
00015 def main():
00016 global v
00017 global dir1
00018 v=vel
00019 dir1=1
00020 rate = rospy.Rate(10);
00021 Subscriber('/diff_driver/odometry', Odometry, odomCallBack)
00022 while not rospy.is_shutdown():
00023 rate.sleep()
00024
00025 def odomCallBack(msg):
00026 global v
00027 global dir1
00028 print msg.pose.pose.position.x
00029 if msg.pose.pose.position.x > limit and dir1==1:
00030 v=-vel
00031 dir1=-1
00032 elif msg.pose.pose.position.x < -limit and dir1==-1:
00033 v=vel
00034 dir1=1
00035
00036 send = Twist()
00037 send.linear.x = v
00038 pub.publish(send)
00039
00040 if __name__ == '__main__':
00041 main()
00042