lawn_generator.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 '''
00003 Created on Feb 04, 2013
00004 
00005 @author: dnad
00006 '''
00007 import roslib; roslib.load_manifest("cart_sim");
00008 import rospy;
00009 from auv_msgs.msg import NavSts;
00010 import numpy
00011 import math
00012       
00013 class LawnGenerator:
00014     def __init__(self):
00015         self.out = rospy.Publisher("trajectory", NavSts);
00016         
00017         self.u = 0.5;
00018         self.Ts = 0.1;   
00019         
00020         self.points=[[0,0],[30,0],[30,30],[0,30]];
00021         self.lastPoint = numpy.array(self.points[0],dtype=numpy.float32);
00022         self.next = 1;
00023         self.nextPoint = numpy.array(self.points[self.next],
00024                                      dtype=numpy.float32);
00025         self.radius = 0.5;     
00026           
00027     def step(self):
00028         
00029         d = numpy.linalg.norm(self.lastPoint - self.nextPoint,2);
00030                
00031         if d < self.radius:
00032             self.next = (self.next+1) % len(self.points);
00033             self.nextPoint = numpy.array(self.points[self.next],
00034                                          dtype=numpy.float32);
00035             print "Change point to:",self.nextPoint;
00036             
00037         diff = self.nextPoint - self.lastPoint;
00038         yaw = math.atan2(diff[1], diff[0]);
00039         self.lastPoint += self.u*self.Ts*numpy.array(
00040                                             [math.cos(yaw),
00041                                              math.sin(yaw)]);
00042         
00043         pub = NavSts();
00044         pub.position.north = self.lastPoint[0];
00045         pub.position.east = self.lastPoint[1];
00046         self.out.publish(pub);
00047         
00048         #print "Last point:", self.lastPoint;
00049          
00050         
00051 if __name__ == "__main__":
00052     rospy.init_node("lawnGenerator");
00053     dp = LawnGenerator();
00054     
00055     rate = rospy.Rate(10.0);
00056         
00057     while not rospy.is_shutdown():
00058         dp.step();
00059         rate.sleep();
00060         
00061         


labust_uvapp
Author(s): Dula Nad
autogenerated on Sun Mar 1 2015 12:12:22