Преглед на файлове

Merge remote-tracking branch 'origin/master'

zwh преди 10 месеца
родител
ревизия
c1a729c9d7

+ 1 - 1
aarch64/pjibot_delivery/common/service/rosbag_upload.go

@@ -143,7 +143,7 @@ outLoop:
 		err = commonConfig.OssBucket.PutObject(objectKey3+"callback.json", strings.NewReader(callBackJson))
 		commonConfig.OssMutex.Unlock()
 		if err != nil {
-			c_log.GlobalLogger.Error("上传 callback.json 或 mapBuf 文件失败:", err)
+			c_log.GlobalLogger.Error("上传 callback.json 文件失败:", err)
 		}
 
 		// 删除本地所有已上传的bag文件

+ 1 - 1
aarch64/pjibot_delivery/control/main.go

@@ -31,7 +31,7 @@ func main() {
 	lastStatus := "NONE"
 	//  轮询任务接口判断是否有更新
 	for {
-		time.Sleep(time.Duration(2) * time.Second)
+		time.Sleep(time.Duration(60) * time.Second)
 		// 1 获取当前设备的任务的 status
 		status, err := commonConfig.GetStatus(commonConfig.PlatformConfig.TaskConfigId)
 		if err != nil {

+ 1 - 1
aarch64/pjibot_guide/control/main.go

@@ -31,7 +31,7 @@ func main() {
 	lastStatus := "NONE"
 	//  轮询任务接口判断是否有更新
 	for {
-		time.Sleep(time.Duration(2) * time.Second)
+		time.Sleep(time.Duration(60) * time.Second)
 		// 1 获取当前设备的任务的 status
 		status, err := commonConfig.GetStatus(commonConfig.PlatformConfig.TaskConfigId)
 		if err != nil {

+ 1 - 1
aarch64/pjibot_patrol/common/service/rosbag_upload.go

@@ -143,7 +143,7 @@ outLoop:
 		err = commonConfig.OssBucket.PutObject(objectKey3+"callback.json", strings.NewReader(callBackJson))
 		commonConfig.OssMutex.Unlock()
 		if err != nil {
-			c_log.GlobalLogger.Error("上传 callback.json 或 mapBuf 文件失败:", err)
+			c_log.GlobalLogger.Error("上传 callback.json 文件失败:", err)
 		}
 
 		// 删除本地所有已上传的bag文件

+ 1 - 1
aarch64/pjibot_patrol/control/main.go

@@ -31,7 +31,7 @@ func main() {
 	lastStatus := "NONE"
 	//  轮询任务接口判断是否有更新
 	for {
-		time.Sleep(time.Duration(2) * time.Second)
+		time.Sleep(time.Duration(60) * time.Second)
 		// 1 获取当前设备的任务的 status
 		status, err := commonConfig.GetStatus(commonConfig.PlatformConfig.TaskConfigId)
 		if err != nil {

+ 6 - 6
deploy/build-pji.sh

@@ -6,11 +6,11 @@ mkdir -p ./deploy/exe/pjibot_guide/
 mkdir -p ./deploy/exe/pjibot_patrol/
 
 # 配送机器人
-go build -o ./deploy/exe/pjibot_delivery/pji_control.exe ./aarch64/pjibot_delivery/control/main.go
-go build -o ./deploy/exe/pjibot_delivery/pji_master.exe ./aarch64/pjibot_delivery/master/main.go
+go build -o ./deploy/exe/pjibot_delivery/pji-control.exe ./aarch64/pjibot_delivery/control/main.go
+go build -o ./deploy/exe/pjibot_delivery/pji-master.exe ./aarch64/pjibot_delivery/master/main.go
 # 引导机器人
-go build -o ./deploy/exe/pjibot_guide/pji_control.exe ./aarch64/pjibot_guide/control/main.go
-go build -o ./deploy/exe/pjibot_guide/pji_master.exe ./aarch64/pjibot_guide/master/main.go
+go build -o ./deploy/exe/pjibot_guide/pji-control.exe ./aarch64/pjibot_guide/control/main.go
+go build -o ./deploy/exe/pjibot_guide/pji-master.exe ./aarch64/pjibot_guide/master/main.go
 # 巡检机器人
-go build -o ./deploy/exe/pjibot_patrol/pji_control.exe ./aarch64/pjibot_patrol/control/main.go
-go build -o ./deploy/exe/pjibot_patrol/pji_master.exe ./aarch64/pjibot_patrol/master/main.go
+go build -o ./deploy/exe/pjibot_patrol/pji-control.exe ./aarch64/pjibot_patrol/control/main.go
+go build -o ./deploy/exe/pjibot_patrol/pji-master.exe ./aarch64/pjibot_patrol/master/main.go

+ 64 - 6
test/goroslib_test.go

@@ -10,6 +10,14 @@ import (
 	"time"
 )
 
+type Object struct {
+	ID            uint32
+	StableAge     int
+	LastExistTime float64
+}
+
+var objectsStability = make(map[uint32]Object)
+
 // speedCheck 目标物速度检测
 func speedCheck(obj *pjisuv_msgs.PerceptionObject) bool {
 	var targetMinSpeed float32 = 2 / 3.6  // m/s
@@ -71,17 +79,67 @@ func Rule(msg *pjisuv_msgs.PerceptionObjects) string {
 
 	CGCS2000_X := 456256.260152
 	CGCS2000_Y := 4397809.886833
+	existingFrameThreshold := 5  // frame
+	existingTimeThreshold := 0.5 // s
+
+	//for _, obj := range msg.Objs {
+	//	//fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
+	//	//	obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-CGCS2000_X, obj.Yabs-CGCS2000_Y, obj.Speed, obj.Length, obj.Width, obj.Height))
+	//
+	//	// todo: 对各判断条件单独进行稳定性校验?
+	//	if speedCheck(&obj) && posCheck(&obj) && (typeCheck(&obj) || sizeCheck(&obj)) {
+	//		fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
+	//			obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-CGCS2000_X, obj.Yabs-CGCS2000_Y, obj.Speed, obj.Length, obj.Width, obj.Height))
+	//		//fmt.Println("!!!")
+	//		return "LowSpdTruckAhead"
+	//	}
+	//}
+	//return ""
 
 	fmt.Println()
-	fmt.Println(time.Unix(int64(msg.Header.TimeStamp), 0).Format(time.DateTime))
+	fmt.Println(time.Unix(int64(msg.Header.TimeStamp), int64(msg.Header.TimeStamp*1e9)%1e9).Format(time.StampNano))
 	for _, obj := range msg.Objs {
-		fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
-			obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-CGCS2000_X, obj.Yabs-CGCS2000_Y, obj.Speed, obj.Length, obj.Width, obj.Height))
+		//fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
+		//	obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-CGCS2000_X, obj.Yabs-CGCS2000_Y, obj.Speed, obj.Length, obj.Width, obj.Height))
 
-		// todo: 对各判断条件单独进行稳定性校验?
+		// 判断目标物是否满足筛选条件
 		if speedCheck(&obj) && posCheck(&obj) && (typeCheck(&obj) || sizeCheck(&obj)) {
-			fmt.Println("!!!")
-			//return "LowSpdTruckAhead"
+
+			// 目标物初见存档
+			if prevObjRecord, exists := objectsStability[obj.Id]; exists == false {
+				objectsStability[obj.Id] = Object{
+					ID:            obj.Id,
+					StableAge:     1,
+					LastExistTime: msg.Header.TimeStamp,
+				}
+				fmt.Println("create: ", objectsStability[obj.Id])
+			} else {
+				currObjRecord := Object{
+					ID:            obj.Id,
+					StableAge:     1,
+					LastExistTime: msg.Header.TimeStamp,
+				}
+
+				// 目标物确认/更新/重置
+				if currObjRecord.LastExistTime-prevObjRecord.LastExistTime <= existingTimeThreshold { // 目标物消失不超过0.5s
+					currObjRecord.StableAge = prevObjRecord.StableAge + 1
+					if existingFrameThreshold == currObjRecord.StableAge {
+						fmt.Println("found: ", currObjRecord)
+						fmt.Println(fmt.Sprintf("id: [%d], type: [%d], x/yrel: [%f, %f], x/yabs: [%f, %f], speed: [%f], size: [%f/%f/%f]",
+							obj.Id, obj.Type, obj.X, obj.Y, obj.Xabs-CGCS2000_X, obj.Yabs-CGCS2000_Y, obj.Speed, obj.Length, obj.Width, obj.Height))
+						delete(objectsStability, obj.Id)
+
+						continue // todo
+						//return "LowSpdTruckAhead"
+					} else {
+
+					}
+				} else {
+					fmt.Println("reset: ", currObjRecord)
+				}
+				objectsStability[obj.Id] = currObjRecord
+				fmt.Println("update: ", currObjRecord)
+			}
 		}
 	}
 	return ""

+ 215 - 0
test/http_test.go

@@ -0,0 +1,215 @@
+package test
+
+import (
+	"bytes"
+	"cicv-data-closedloop/common/util"
+	"encoding/json"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"net/url"
+	"testing"
+)
+
+func TestHttp(t *testing.T) {
+	request1 := make(map[string]string)
+	request1["equipmentNo"] = "pjibot-P1YNYD1M227000115"
+	request1["secretKey"] = "P1YNYD1M227000115"
+	resp1 := PostData2("http://36.110.106.156:11121/device/auth", request1)
+
+	toMap, _ := util.JsonStringToMap(resp1)
+	dataMap, _ := toMap["data"].(map[string]interface{})
+	token, _ := dataMap["accessToken"].(string)
+
+	request2 := make(map[string]string)
+	request2["equipmentNo"] = "pjibot-P1YNYD1M227000115"
+	header2 := make(map[string]string)
+	header2["token"] = token
+	resp2 := GetData3("http://36.110.106.156:11121/device/task/poll", request2, header2)
+
+	fmt.Println(resp2)
+}
+
+func PostData2(url string, params map[string]string) string {
+	defer func() {
+		if r := recover(); r != nil {
+			fmt.Println("Recovered from panic:", r)
+		}
+	}()
+
+	// Convert the map to JSON
+	jsonData, err := json.Marshal(params)
+	if err != nil {
+		fmt.Println("Error marshaling params to JSON:", err)
+		return ""
+	}
+
+	// Create a new HTTP POST request
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
+	if err != nil {
+		fmt.Println("Error creating HTTP request:", err)
+		return ""
+	}
+
+	// Set the appropriate headers
+	req.Header.Set("Content-Type", "application/json")
+
+	// Create a new HTTP client and send the request
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Println("Error sending HTTP request:", err)
+		return ""
+	}
+	defer resp.Body.Close()
+
+	// Read the response body
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		fmt.Println("Error reading response body:", err)
+		return ""
+	}
+
+	return string(body)
+}
+
+func PostData3(url string, params map[string]string, headers map[string]string) string {
+	defer func() {
+		if r := recover(); r != nil {
+			fmt.Println("Recovered from panic:", r)
+		}
+	}()
+
+	// Convert the map to JSON
+	jsonData, err := json.Marshal(params)
+	if err != nil {
+		fmt.Println("Error marshaling params to JSON:", err)
+		return ""
+	}
+
+	// Create a new HTTP POST request
+	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
+	if err != nil {
+		fmt.Println("Error creating HTTP request:", err)
+		return ""
+	}
+
+	// Set the appropriate headers
+	req.Header.Set("Content-Type", "application/json")
+	for key, value := range headers {
+		req.Header.Set(key, value)
+	}
+
+	// Create a new HTTP client and send the request
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Println("Error sending HTTP request:", err)
+		return ""
+	}
+	defer resp.Body.Close()
+
+	// Read the response body
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		fmt.Println("Error reading response body:", err)
+		return ""
+	}
+
+	return string(body)
+}
+
+func GetData2(baseURL string, params map[string]string) string {
+	defer func() {
+		if r := recover(); r != nil {
+			fmt.Println("Recovered from panic:", r)
+		}
+	}()
+
+	// Build the URL with query parameters
+	u, err := url.Parse(baseURL)
+	if err != nil {
+		fmt.Println("Error parsing URL:", err)
+		return ""
+	}
+	q := u.Query()
+	for key, value := range params {
+		q.Set(key, value)
+	}
+	u.RawQuery = q.Encode()
+
+	// Create a new HTTP GET request
+	req, err := http.NewRequest("GET", u.String(), nil)
+	if err != nil {
+		fmt.Println("Error creating HTTP request:", err)
+		return ""
+	}
+
+	// Create a new HTTP client and send the request
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Println("Error sending HTTP request:", err)
+		return ""
+	}
+	defer resp.Body.Close()
+
+	// Read the response body
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		fmt.Println("Error reading response body:", err)
+		return ""
+	}
+
+	return string(body)
+}
+
+func GetData3(baseURL string, params map[string]string, headers map[string]string) string {
+	defer func() {
+		if r := recover(); r != nil {
+			fmt.Println("Recovered from panic:", r)
+		}
+	}()
+
+	// Build the URL with query parameters
+	u, err := url.Parse(baseURL)
+	if err != nil {
+		fmt.Println("Error parsing URL:", err)
+		return ""
+	}
+	q := u.Query()
+	for key, value := range params {
+		q.Set(key, value)
+	}
+	u.RawQuery = q.Encode()
+
+	// Create a new HTTP GET request
+	req, err := http.NewRequest("GET", u.String(), nil)
+	if err != nil {
+		fmt.Println("Error creating HTTP request:", err)
+		return ""
+	}
+
+	// Set the appropriate headers
+	for key, value := range headers {
+		req.Header.Set(key, value)
+	}
+
+	// Create a new HTTP client and send the request
+	client := &http.Client{}
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Println("Error sending HTTP request:", err)
+		return ""
+	}
+	defer resp.Body.Close()
+
+	// Read the response body
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		fmt.Println("Error reading response body:", err)
+		return ""
+	}
+
+	return string(body)
+}

+ 1 - 3
trigger/pjisuv/tpperception/lowSpdTruckAhead/main/lowSpdTruckAhead.go

@@ -75,9 +75,7 @@ func Rule(msg *pjisuv_msgs.PerceptionObjects) string {
 	}()
 
 	for _, obj := range msg.Objs {
-
-		// todo: 对各判断条件单独进行稳定性校验?
-		if speedCheck(&obj) && posCheck(&obj) && (typeCheck(&obj) || sizeCheck(&obj)) {
+		if speedCheck(&obj) && posCheck(&obj) && (typeCheck(&obj)) {
 			return "LowSpdTruckAhead"
 		}
 	}