|
@@ -0,0 +1,66 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "fmt"
|
|
|
|
+ "github.com/bluenviron/goroslib/v2/pkg/msgs/geometry_msgs"
|
|
|
|
+ "math"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func Topic() string {
|
|
|
|
+ return "/robot_pose"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Label todo 禁止存在下划线_
|
|
|
|
+func Label() string {
|
|
|
|
+ return "EnterTjunction"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type Point struct {
|
|
|
|
+ X float64
|
|
|
|
+ Y float64
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+var (
|
|
|
|
+
|
|
|
|
+ //定义园区部门T字路口UTM坐标
|
|
|
|
+ point3 = Point{35.5711, 150.49}
|
|
|
|
+ point4 = Point{108.108, 197.537}
|
|
|
|
+ point5 = Point{76.0262, 78.9898}
|
|
|
|
+ point6 = Point{149.308, 118.211}
|
|
|
|
+ point7 = Point{105.141, 21.5495}
|
|
|
|
+ point8 = Point{180.037, 64.8318}
|
|
|
|
+
|
|
|
|
+ pointlist = []Point{point3, point4, point5, point6, point7, point8}
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func Rule(data *geometry_msgs.PoseStamped) string {
|
|
|
|
+ defer func() {
|
|
|
|
+ if r := recover(); r != nil {
|
|
|
|
+ fmt.Println("Recovered from panic:", r)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ enterflag := IfEnter(pointlist, 15, data.Pose.Position.X, data.Pose.Position.Y)
|
|
|
|
+ if enterflag {
|
|
|
|
+ return "EnterTjunction"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ""
|
|
|
|
+}
|
|
|
|
+func IfEnter(pointlist []Point, radius float64, x, y float64) bool {
|
|
|
|
+ // 判断是否进入点列表中的区域
|
|
|
|
+ point1 := Point{X: x, Y: y}
|
|
|
|
+ for _, point := range pointlist {
|
|
|
|
+ d := distance(point1, point)
|
|
|
|
+ if d <= radius {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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
|
|
|
|
+}
|