Reputation: 1
current problem is that this bit of code is extremely buggy, could be logic errors but i'm not entirely sure, operating on pybricks orbit1 is movement given in directions 1 - 12
here's the code:
def orbit2():
global current_angle, aligned, new_direction, movetoball
values = ir_seeker.read(5)
direction = values[1]
ir_dis = values[0]
while ir_dis >= 65:
aligned = False
orbitdir = 2 if 0 < direction <= 6 else -2 #adjust values as needed after testing!!!
new_direction = (direction + orbitdir) % 12
values = ir_seeker.read(5)
direction = values[1]
ir_dis = values[0]
print(str(new_direction))
while not direction == 12:
current_angle = hub.imu.heading()
values = ir_seeker.read(5)
direction = values[1]
ir_dis = values[0]
orbit1(new_direction, current_angle, score_speed)
wait(15) #adjust this as well
print("orbiting in", direction)
if direction == 12:
while movetoball == False:
while not ir_dis >= 80:
orbit1(direction, current_angle, 100)
direction = values[1]
ir_dis = values[0]
movetoball = True
print("aligned to 12, now calculating angles")
aligned = True
break
tried everything basically, robot either acted funny or got stuck in certain loops (could be deep nested loops i'm not sure) help is appreciated, thanks :)
Upvotes: 0
Views: 12