-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsGoWithDribble.py
178 lines (150 loc) · 7.69 KB
/
sGoWithDribble.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import skill_node
import math
import sys
from utils.config import *
from utils.geometry import *
from navigation_py.wrapperpy import *
from navigation_py.obstacle import Obstacle
from math import pi, exp
POINTPREDICTIONFACTOR = 2
def debug(param, state, bot_pos, target_pos, nextWP, nextNWP, speed, theta, omega, obs):
print '#'*50
print 'Current bot pos: {}, {}'.format(bot_pos.x, bot_pos.y)
print 'Target bot pos: {}, {}'.format(param.GoWithDribbleP.x, param.GoWithDribbleP.y)
print 'NextWP bot pos: {}, {}'.format(nextWP.x, nextWP.y)
print 'NextNWP bot pos: {}, {}'.format(nextNWP.x, nextNWP.y)
print 'speed: {}\ttheta: {}\tomega: {}'.format(speed, theta, omega)
print 'len(obs): {}'.format(len(obs))
print 'frame : {}'.format(state.frame_number)
print '#'*50
def execute(param,state,bot_id, pub):
point = Vector2D(int(param.GoWithDribbleP.x),int(param.GoWithDribbleP.y))
myPos = Vector2D(int(state.homePos[bot_id].x),int(state.homePos[bot_id].y))
distance = point.dist(myPos)
MAX_BOT_SPEED = 0.7*1800
speed= 2*distance*MAX_BOT_SPEED/(HALF_FIELD_MAXX)
from math import *
theta = myPos.angle(point)
print(theta)
theta = point.normalizeAngle(theta + state.homePos[bot_id].theta)
vel_x = speed*cos(theta)
vel_y = speed*sin(theta)
skill_node.send_command(pub, state.isteamyellow, bot_id, vel_x, vel_y, 0, 0,True)
# obs = Vector_Obstacle()
# for i in range(0,len(state.homeDetected)):
# if state.homeDetected[i] and i != bot_id:
# o = Obstacle()
# o.x=state.homePos[i].x
# o.y=state.homePos[i].y
# o.radius=3.3*BOT_RADIUS
# obs.push_back(o)
# for j in range(0,len(state.awayDetected)):
# if state.awayDetected[j]:
# o = Obstacle()
# o.x=state.awayPos[j].x
# o.y=state.awayPos[j].y
# o.radius=3.3*BOT_RADIUS
# obs.push_back(o)
# pointPos = Vector2D()
# pointPos.x = int(param.GoWithDribbleP.x)
# pointPos.y = int(param.GoWithDribbleP.y)
# point = Vector2D()
# nextWP = Vector2D()
# nextNWP = Vector2D()
# pathplanner = MergeSCurve()
# botPos = Vector2D(int(state.homePos[bot_id].x), int(state.homePos[bot_id].y))
# ballPos = Vector2D(int(state.ballPos.x),int(state.ballPos.y))
# thetadiff = botPos.angle(pointPos) - state.homePos[bot_id].theta
# print(thetadiff,SATISFIABLE_THETA)
# if thetadiff > SATISFIABLE_THETA or botPos.dist(ballPos)>DRIBBLER_BALL_THRESH and 0:
# import sDribbleTurn
# print("executing")
# param.DribbleTurnP.x = pointPos.x
# param.DribbleTurnP.y = pointPos.y
# sDribbleTurn.execute(param,state,bot_id,pub)
# else:
# #print "bot no "+str(bot_id)+" in sGoWithDribble currently in "+str(botPos.x)+","+str(botPos.y)
# #print "going for "+str(pointPos.x)+","+str(pointPos.y)+" angle="+str(param.GoWithDribbleP.finalslope*180/pi)
# pathplanner.plan(botPos,pointPos,nextWP,nextNWP,obs,len(obs),bot_id, True)
# v = Vector2D()
# distan = botPos.dist(pointPos)
# maxDisToTurn = distan
# angleToTurn = v.normalizeAngle((param.GoWithDribbleP.finalslope)-(state.homePos[bot_id].theta))
# minReachTime = maxDisToTurn / MAX_BOT_OMEGA
# maxReachTime = maxDisToTurn / MIN_BOT_OMEGA
# minTurnTime = angleToTurn / MAX_BOT_OMEGA
# maxTurnTime = angleToTurn / MIN_BOT_OMEGA
# speed = 0.0
# omega = angleToTurn * MAX_BOT_OMEGA / (2 * math.pi)
# if omega < MIN_BOT_OMEGA and omega > -MIN_BOT_OMEGA:
# if omega < 0:
# omega = -MIN_BOT_OMEGA
# else:
# omega = MIN_BOT_OMEGA
# #################### for testing
# # if maxDisToTurn > 0:
# # if minTurnTime > maxReachTime:
# # speed = MIN_BOT_SPEED
# # elif minReachTime > maxTurnTime:
# # speed = MAX_BOT_SPEED
# # elif minReachTime < minTurnTime:
# # speed = maxDisToTurn / minTurnTime
# # elif minTurnTime < minReachTime:
# # speed = MAX_BOT_SPEED
# # else:
# # speed = distan / MAX_FIELD_DIST * MAX_BOT_SPEED
# ##############################final
# speed= 2*maxDisToTurn*MAX_BOT_SPEED/(HALF_FIELD_MAXX)
# if (speed)< 16*MIN_BOT_SPEED:
# speed=16*MIN_BOT_SPEED
# # omega =0
# # distance = pointPos.dist(botPos)
# # optimaldistane = distance -590
# # if optimaldistane > 0:
# # optimaldistane = 0
# # else:
# # optimaldistane*=-1
# # speed = 1800*exp(-optimaldistane/90)
# vec = Vector2D()
# motionAngle = botPos.angle(nextWP)
# theta = motionAngle - state.homePos[bot_id].theta
# ballbotdistance = botPos.dist(Vector2D(int(state.ballPos.x),int(state.ballPos.y)))
# Dribbler = False
# if ballbotdistance<DRIBBLER_BALL_THRESH:
# Dribbler =True
# #debug(param, state, botPos, pointPos, nextWP, nextNWP, speed, theta, omega, obs)
# # print "Motion angle : {}".format(motionAngle)
# omeg=0
# if param.GoWithDribbleP.align == False:
# if distan < DRIBBLER_BALL_THRESH:
# if distan < 2*BOT_BALL_THRESH:
# skill_node.send_command(pub, state.isteamyellow, bot_id, 0, 0, 0, 0, Dribbler)
# turnAngleLeft = v.normalizeAngle((param.GoWithDribbleP.finalslope)-(state.homePos[bot_id].theta)) # Angle left to turn
# omega = turnAngleLeft * MAX_BOT_OMEGA/(2*math.pi); # Speedup turn
# omega =0
# if(omega < MIN_BOT_OMEGA/2 and omega > -MIN_BOT_OMEGA/2): # This is a rare used skill so believe in Accuracy more than speed. Hence reducing minimum Omega
# if(omega < 0): omega = -MIN_BOT_OMEGA/2
# else: omega = MIN_BOT_OMEGA/2
# #dist = ballPos.dist(botPos)
# #if(dist < DRIBBLER_BALL_THRESH):
# skill_node.send_command(pub, state.isteamyellow, bot_id, 0, 0, omega, 0,Dribbler)
# #else:
# # skill_node.send_command(pub, state.isteamyellow, bot_id, 0, 0, omega, 0,False)
# else:
# skill_node.send_command(pub, state.isteamyellow, bot_id, speed * math.sin(-theta), speed * math.cos(-theta), omega, 0, True)
# else:
# skill_node.send_command(pub, state.isteamyellow, bot_id, speed * math.sin(-theta), speed * math.cos(-theta), omega, 0, Dribbler)
# else:
# if distan > BOT_BALL_THRESH/4:
# skill_node.send_command(pub, state.isteamyellow, bot_id, speed * math.sin(-theta), speed * math.cos(-theta), 0, 0, Dribbler)
# else:
# skill_node.send_command(pub, state.isteamyellow, bot_id, 0, 0, 0, 0,Dribbler)
# turnAngleLeft = v.normalizeAngle((param.GoWithDribbleP.finalslope)-(state.homePos[bot_id].theta)) # Angle left to turn
# omega = turnAngleLeft * MAX_BOT_OMEGA/(2*math.pi); # Speedup turn
# omega =0
# if(omega < MIN_BOT_OMEGA/2 and omega > -MIN_BOT_OMEGA/2): # This is a rare used skill so believe in Accuracy more than speed. Hence reducing minimum Omega
# if(omega < 0): omega = -MIN_BOT_OMEGA/2
# else: omega = MIN_BOT_OMEGA/2
# #dist = ballPos.dist(botPos)
# #if(dist < DRIBBLER_BALL_THRESH):
# skill_node.send_command(pub, state.isteamyellow, bot_id, 0, 0, omega, 0,Dribbler)