Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
tlemsl authored Aug 9, 2020
1 parent d39e702 commit a6fb9f6
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions Planning/planning_tools/example_global_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import rospy
import threading
import math
import numpy as np

from std_msgs.msg import Float64MultiArray
from std_msgs.msg import Float64
from visualization_msgs.msg import MarkerArray
from visualization_msgs.msg import Marker

global_node = [] #input global node
try:
global node_arr = np.array(global_node).reshape(2,len(global_node)/2)
except:
print("check global node")
global PI = math.pi
class init_navi:
def __init__(self):
self.x = 0
self.y = 0
self.yaw = 0
Th1 = threading.Thread(target=self.subscribe)
Th1.daemon = True
Th1.start()
def subscribe(self):
self.utm_subscriber = rospy.Subscriber("utm_fix", Float64MultiArray, self.utm_callback)
self.gpsy_subscriber = rospy.Subscriber("gps_yaw",Float64,self.gps_callback)
rospy.spin()
def utm_callback(self, data):
self.x = data.data[0]
self.y = data.data[1]
def gps_callback(self, data):
self.yaw = data.data
def pub(self):
navi = Navi()
while not rospy.is_shutdown():
navi.navigation(self.x, self.y)

class Navi:
def __init__(self,yaw):
self.converted_node = np.array([[math.cos(-yaw), -math.sin(-yaw)], [math.sin(-yaw), math.cos(-yaw)]]) @ node_arr
self.pub_global_path = rospy.Publisher("check_path", MarkerArray, queue_size = 1)
self.points = Float64MultiArray()
self.sub_point_p = []
self.sub_point_n = []
def navigation(self, x,y):
cntn1 = 0
cntn2 = 0
cntp1 = 0
cntp2 = 0
for point in self.converted_node:
dx = (point[0] - x)
dy = (point[1] - y)
d = math.sqrt(dx**2+dy**2)
if d>1 and d<10:
if cntn1>0 and cntp1>0:
break
if dx>1 and cntp1 == 0:
self.points.append(point[0])
self.points.append(point[1])
cntp1+=1
if dx<-1 and cntn1==0:
self.points.append(point[0])
self.points.append(point[1])
cntn1+=1
cnt+=1
elif d>=10 and d<20:
if cntn2>0 and cntp2>0:
continue
if dx>1 and cntp2 == 0:
self.sub_point_p.append(point[0])
self.sub_point_p.append(point[1])
cntp2+=1
if dx<-1 and cntn2==0:
self.sub_point_n.append(point[0])
self.sub_point_n.append(point[1])
cntn2+=1
if cntp1 == 0:
if cntp2>0:
self.points.append(self.sub_point_p[len(self.sub_point_p)/2])
self.points.append(self.sub_point_p[len(self.sub_point_p)/2+1])
else:
checkp = 1
if cntn1 == 0:
if cntp2>0:
self.points.append(self.sub_point_n[len(self.sub_point_n)/2])
self.points.append(self.sub_point_n[len(self.sub_point_n)/2+1])
else:
checkn = 1

if len(self.points)<4:
print("# WARNING: not enough global path")
return
else:
pub_global_path.publish(self.points)

0 comments on commit a6fb9f6

Please sign in to comment.