|
@@ -23,12 +23,13 @@ type Point struct {
|
|
|
var (
|
|
|
|
|
|
//定义园区部门T字路口UTM坐标
|
|
|
- point3 = Point{35.5711 + 88.96626338170609, 150.49 + 40.553671177476645}
|
|
|
- point4 = Point{108.108 + 88.96626338170609, 197.537 + 40.553671177476645}
|
|
|
- point5 = Point{76.0262 + 88.96626338170609, 78.9898 + 40.553671177476645}
|
|
|
- point6 = Point{149.308 + 88.96626338170609, 118.211 + 40.553671177476645}
|
|
|
- point7 = Point{105.141 + 88.96626338170609, 21.5495 + 40.553671177476645}
|
|
|
- point8 = Point{180.037 + 88.96626338170609, 64.8318 + 40.553671177476645}
|
|
|
+ mindistance float64 = 999
|
|
|
+ point3 = Point{35.5711 + 88.96626338170609, 150.49 + 40.553671177476645}
|
|
|
+ point4 = Point{108.108 + 88.96626338170609, 197.537 + 40.553671177476645}
|
|
|
+ point5 = Point{76.0262 + 88.96626338170609, 78.9898 + 40.553671177476645}
|
|
|
+ point6 = Point{149.308 + 88.96626338170609, 118.211 + 40.553671177476645}
|
|
|
+ point7 = Point{105.141 + 88.96626338170609, 21.5495 + 40.553671177476645}
|
|
|
+ point8 = Point{180.037 + 88.96626338170609, 64.8318 + 40.553671177476645}
|
|
|
|
|
|
pointlist = []Point{point3, point4, point5, point6, point7, point8}
|
|
|
)
|
|
@@ -39,7 +40,7 @@ func Rule(data *geometry_msgs.PoseStamped) string {
|
|
|
fmt.Println("Recovered from panic:", r)
|
|
|
}
|
|
|
}()
|
|
|
- enterflag := IfEnter(pointlist, 20, data.Pose.Position.X, data.Pose.Position.Y)
|
|
|
+ enterflag := IfEnter(pointlist, 15, data.Pose.Position.X, data.Pose.Position.Y)
|
|
|
if enterflag {
|
|
|
return "EnterTjunction"
|
|
|
}
|
|
@@ -51,16 +52,18 @@ func IfEnter(pointlist []Point, radius float64, x, y float64) bool {
|
|
|
point1 := Point{X: x, Y: y}
|
|
|
for _, point := range pointlist {
|
|
|
d := distance(point1, point)
|
|
|
+ mindistance = min(d, mindistance)
|
|
|
if d <= radius {
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
|
+ fmt.Printf("mindistance=%f", mindistance)
|
|
|
+ mindistance = 999.0
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
// 计算两点之间的距离(米)
|
|
|
func distance(point1, point2 Point) float64 {
|
|
|
d := math.Sqrt((point2.X-point1.X)*(point2.X-point1.X) + (point2.Y-point1.Y)*(point2.Y-point1.Y))
|
|
|
-
|
|
|
return d
|
|
|
}
|