|
@@ -1,6 +1,8 @@
|
|
|
|
|
|
-import gpsimu_pb2
|
|
|
-import mapdata_pb2
|
|
|
+import proto.gpsimu_pb2 as gpsimu_pb2
|
|
|
+#import gpsimu_pb2
|
|
|
+import proto.mapdata_pb2 as mapdata_pb2
|
|
|
+import proto.decition_pb2 as decition_pb2
|
|
|
|
|
|
import math
|
|
|
from typing import List
|
|
@@ -12,6 +14,7 @@ class Point2D:
|
|
|
def __init__(self, x, y):
|
|
|
self.mx = x
|
|
|
self.my = y
|
|
|
+
|
|
|
|
|
|
def __str__(self):
|
|
|
return f"Point2D({self.mx}, {self.my})"
|
|
@@ -19,6 +22,10 @@ class Point2D:
|
|
|
class DecisionDemo:
|
|
|
def __init__(self):
|
|
|
# 初始化代码...
|
|
|
+ self.mendacc = -0.7 #抵达终点时的舰速度为-0.7
|
|
|
+ self.mmaxwheel = 430 #最大方向盘角度
|
|
|
+ self.mdefaultacc = 1.0 #加速时的acc
|
|
|
+ self.mspeed = 10.0 #运行速度10km/h
|
|
|
pass
|
|
|
|
|
|
def CalcDecision(self,tracemap : mapdata_pb2.tracemap, msg_gpsimu : gpsimu_pb2.gpsimu):
|
|
@@ -36,9 +43,53 @@ class DecisionDemo:
|
|
|
|
|
|
realspeed = 3.6 * math.sqrt(math.pow(msg_gpsimu.vn,2) + math.pow(msg_gpsimu.ve,2))
|
|
|
|
|
|
+ acc,wheel,speed = self.CalcCmd(localpoints,realspeed)
|
|
|
+
|
|
|
+ #calc end acc, stop to end point
|
|
|
+ endacc = 0.0
|
|
|
+ if distoend > 0.1:
|
|
|
+ if distoend < math.pow(realspeed/3.6,2)/(2*math.fabs(self.mendacc)) :
|
|
|
+ endacc = math.pow(realspeed/3.6,2)/(2*distoend) *(-1.0)
|
|
|
+ print("endacc: ",endacc)
|
|
|
+ else :
|
|
|
+ endacc = self.mendacc
|
|
|
+
|
|
|
+ print("endacc: ",endacc)
|
|
|
+ if endacc<-1e-9:
|
|
|
+ acc = endacc
|
|
|
+
|
|
|
+ if acc < -5.0:
|
|
|
+ acc = -5.0
|
|
|
+
|
|
|
+
|
|
|
+ xdecisiion = decition_pb2.decition()
|
|
|
+ xdecisiion.wheelAngle = wheel
|
|
|
+ xdecisiion.accelerator = acc
|
|
|
+ xdecisiion.brake = 0
|
|
|
+ xdecisiion.speed = speed
|
|
|
+ print("acc = : ",acc)
|
|
|
+ if acc < 0:
|
|
|
+ xdecisiion.brake = acc
|
|
|
+ xdecisiion.torque = 0
|
|
|
+ else:
|
|
|
+ xdecisiion.brake = 0
|
|
|
+ fVehWeight = 1800
|
|
|
+ # fg = 9.8
|
|
|
+ fRollForce = 50
|
|
|
+ fRatio = 2.5
|
|
|
+ fNeed = fRollForce + fVehWeight*acc
|
|
|
+ xdecisiion.torque = fNeed/fRatio
|
|
|
+
|
|
|
+ return xdecisiion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def CalcCmd(self,localpoints : List[Point2D],realspeed):
|
|
|
- desiredspeed = 10
|
|
|
- defaultacc = 1.0
|
|
|
+ desiredspeed = self.mspeed
|
|
|
+ defaultacc = self.mdefaultacc
|
|
|
pd = realspeed * 0.3
|
|
|
if pd < 4.0 :
|
|
|
pd = 4.0
|
|
@@ -49,18 +100,19 @@ class DecisionDemo:
|
|
|
ppindex = 0
|
|
|
|
|
|
while i < size:
|
|
|
- sumdis = math.sqrt(math.pow(localpoints[i].mx - localpoints[i-1].mx,2)
|
|
|
+ sumdis = sumdis + math.sqrt(math.pow(localpoints[i].mx - localpoints[i-1].mx,2)
|
|
|
+ math.pow(localpoints[i].my - localpoints[i-1].my,2))
|
|
|
ppindex = i
|
|
|
if sumdis >= pd :
|
|
|
ppindex = i
|
|
|
break
|
|
|
+ i = i+1
|
|
|
acc = -0.5
|
|
|
wheel = 0.0
|
|
|
if ppindex < 3:
|
|
|
acc = 0.0
|
|
|
wheel = 0.0
|
|
|
- return acc,wheel
|
|
|
+ return acc,wheel,0
|
|
|
|
|
|
if desiredspeed > 0.1:
|
|
|
if realspeed < desiredspeed :
|
|
@@ -78,6 +130,7 @@ class DecisionDemo:
|
|
|
acc = 0.0
|
|
|
|
|
|
|
|
|
+ print("ppindex : ",ppindex)
|
|
|
denominator = 2 * localpoints[ppindex].mx *(-1);
|
|
|
numerator = math.pow(localpoints[ppindex].mx,2) + pow(localpoints[ppindex].my,2);
|
|
|
fRadius = 1e9;
|
|
@@ -90,9 +143,13 @@ class DecisionDemo:
|
|
|
kappa = 1.0/fRadius
|
|
|
wheel_base = 2.9
|
|
|
wheelratio = 13.6
|
|
|
- wheel = (-1.0)*kappa * wheel_base * wheelratio * 180.0/math.pi
|
|
|
+ wheel = (1.0)*kappa * wheel_base * wheelratio * 180.0/math.pi
|
|
|
+ if wheel>self.mmaxwheel:
|
|
|
+ wheel = self.mmaxwheel
|
|
|
+ if wheel<(self.mmaxwheel * (-1.0)):
|
|
|
+ wheel = self.mmaxwheel * (-1.0)
|
|
|
|
|
|
- return acc,wheel
|
|
|
+ return acc,wheel,self.mspeed
|
|
|
|
|
|
|
|
|
def FindNearIndex(self,tracemap : mapdata_pb2.tracemap,xgpsimu : gpsimu_pb2.gpsimu) :
|