Skip to content

Commit d39d653

Browse files
committed
Modified turn-around and optimised alignment
1 parent 917ff6e commit d39d653

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

test_KickToP.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
21
print "In test GoToPoint"
32
from kubs import kubs, cmd_node
43
from velocity.run import *
4+
import velocity
55
import rospy,sys,os
66
import math
77
import time
@@ -73,7 +73,6 @@ def GUI_Callback(data):
7373

7474

7575

76-
7776
def function(id_,state):
7877
kub = kubs.kubs(id_,state,pub)
7978
kub.update_state(state)
@@ -90,15 +89,12 @@ def function(id_,state):
9089
g_fsm.spin()
9190
#
9291

93-
94-
95-
9692
def kp_callback(data):
9793
global st, planned, ramp_rampt, ramp_dnt, ramp_upt, case, tnow
9894

9995
ballpos = data.ballPos
100-
theta = angle_diff(target, ballpos)
101-
go_at = getPointBehindTheBall(ballpos, theta, 2)
96+
theta = angle_diff(ballpos, target) #Point1: ballpos; Point2: target
97+
go_at = getPointBehindTheBall(ballpos, theta, -2) #Modify getPoint*Behind*TheBall late on**. Factor should be negative.
10298

10399
print(radian_2_deg(theta))
104100
print(go_at.x)
@@ -108,21 +104,19 @@ def kp_callback(data):
108104
t = t.secs + 1.0*t.nsecs/pow(10,9)
109105
print(" t - start = ",t-start_time)
110106
[vx, vy, vw, REPLANNED] = Get_Vel(start_time, t, BOT_ID, go_at, data.homePos, data.awayPos, True, 1.2)
111-
#vx, vy, vw, replanned
107+
#vx, vy, vw, replanned
112108
print("------------------- REPLANNED = ",REPLANNED)
113109
if(REPLANNED):
114110
reset()
115111

116112
print("vx = ",vx)
117113
print("vy = ",vy)
118-
119-
mvx=vx
120-
mvy=vy
121114

122115
# print("kubs_id = ",kub.kubs_id)
123116

124117
curPos = Vector2D(int(data.homePos[BOT_ID].x),int(data.homePos[BOT_ID].y))
125118
#if vicinity_points(go_at, curPos, 4) == False:
119+
d=distance_(curPos,go_at)
126120
try:
127121
kub.move(vx, vy)
128122
print(vw)
@@ -133,39 +127,50 @@ def kp_callback(data):
133127
print("In except",e)
134128
pass
135129
print(dist(go_at, curPos))
136-
137-
if vx == 0 and vy == 0:
138-
139130

131+
132+
#READY TO TAKE STANCE
133+
if vx == 0 and vy == 0 and d < 1.2*BOT_BALL_THRESH:
134+
140135
print(data.homePos[BOT_ID].theta)
141-
print(theta)
136+
print("Target Alignment : ",theta)
142137
totalAngle = theta
143138
MAX_w = (MAX_BOT_OMEGA+MIN_BOT_OMEGA)/1.2
144-
# theta_left = float(homePos[kub_id].theta-totalAngle)
145-
theta_lft = normalize_angle(normalize_angle(data.homePos[BOT_ID].theta)-totalAngle)*-1.0+3.1412
146-
147-
if abs(theta_lft)<ROTATION_FACTOR/100:
139+
MIN_w = (MIN_BOT_OMEGA)
140+
141+
# theta2 = totalAngle :-- target angular alignment ; theta1 = current_bot_theta; New x-axis: Bot_theta_line
142+
# rotating standard axes
143+
deltheta = totalAngle-normalize_angle(data.homePos[BOT_ID].theta)
144+
modtheta = min(abs(deltheta),abs((2*math.pi)-deltheta)) #shortest turn
145+
sign = (normalize_angle(deltheta))/(abs(normalize_angle(deltheta)))
146+
147+
print "Remaining angle: ",modtheta," ",sign
148+
149+
theta_lft = modtheta * sign
150+
151+
if abs(theta_lft)<ROTATION_FACTOR/10:
148152
vw = 0.0
149153
READY_TO_KICK=True
150154
else:
151155
READY_TO_KICK=False
152-
vw = (theta_lft/2*math.pi)*MAX_w
153-
154-
if abs(vw)<1*MIN_BOT_OMEGA and READY_TO_KICK==False:
155-
vw = 1*MIN_BOT_OMEGA*(1 if vw>0 else -1)
156+
vw = 3.0*(theta_lft)/(math.pi)*MAX_w
157+
#vw = (theta_lft/2*math.pi)*MAX_w
156158

159+
if abs(vw)<1*MIN_w and READY_TO_KICK==False:
160+
vw = 1*MIN_w*(1 if vw>0 else -1)
161+
162+
if abs(vw) > MAX_w and READY_TO_KICK==False:
163+
vw = (vw/abs(vw))*MAX_w
157164

158165
if vw!=0:
159166
print("TURNING")
167+
#print("vw Hoon Main =",vw)
168+
print("BOT THETA: ",data.homePos[BOT_ID].theta)
169+
print "\nAngle Remaining : ",theta_lft
160170
else:
161-
print("DONE")
171+
print("DONE !!")
162172

163-
mvw=vw
164-
165-
166-
167-
print "Omega Return",vw
168-
print "TRY: ",mvw
173+
print "Omega Return: ",vw
169174
print READY_TO_KICK
170175
print "___________________________________________________________________"
171176
kub.reset()
@@ -180,7 +185,7 @@ def kp_callback(data):
180185

181186

182187
if __name__ == "__main__":
183-
global start_time, st, planned, case, mvw
188+
global start_time, st, planned, case
184189
case = -1
185190
st = None
186191
planned = False
@@ -199,15 +204,17 @@ def kp_callback(data):
199204

200205
sub2 = rospy.Subscriber('/gui_params', point_SF, GUI_Callback, queue_size = 1000)
201206

202-
print("Ho gya!!")
207+
print("Ho gya align!!")
203208
rospy.spin()
204209

205210
sub1.unregister()
206211
sub2.unregister()
207-
print "AB MAIN KARUNGAAA -------- KICKKK !!!"
212+
print "AB MAIN KARUNGA -------- KICKKK !!!"
208213

209214
command="python KickP.py %s %s %s"%(BOT_ID,target.x,target.y)
210-
print(command)
215+
print("______________________________________________________________")
216+
print("/n",command,"/n")
217+
print("______________________________________________________________\n")
211218
os.system(command)
212219

213220

0 commit comments

Comments
 (0)