Closed AndreaFavero71 closed 1 year ago
optim_moves2 fails if the solution only has two moves.
Cube status (via BGR color distance): UUUUUUDDDBFFRRRRRRLLLBFFBFFUDDUDDUDDBBFLLLLLLRRRBBFBBF
Camera warm-up, camera setting, cube status (BGR), and solution, in: 38.4 secs
Cube solution: 2 moves U1 L2
pre optim 16
Robot moves string: not optimization type 1 needed
moves at opt1: F1R1S3S3F3R1S3R1
len moves at opt1: 16
optim1 16
Traceback (most recent call last):
File "Cubotino_T.py", line 3809, in <module>
reset_camera = start_solving(solv_cycle) # start_solving function is called
File "Cubotino_T.py", line 3070, in start_solving
cubeAF() # cube reading/solving function is called
File "Cubotino_T.py", line 3587, in cubeAF
HSV_detected, start_time, camera_ready_time, cube_detect_time, cube_solution_time)
File "Cubotino_T.py", line 2668, in robot_solve_cube
_, robot_moves, total_robot_moves = rm.robot_required_moves(solution, solution_Text)
File "/home/pi/cubotino/src/Cubotino_T_moves.py", line 366, in robot_required_moves
moves = optim_moves2(moves) # removes eventual unnecessary flips
File "/home/pi/cubotino/src/Cubotino_T_moves.py", line 274, in optim_moves2
if F_list[-1] == 'F3' and F_list[-2] == 'F2': # case the second-last flip is 'F3' and last flip is 'F2'
IndexError: list index out of range
(.virtualenvs) root@cubotino:/home/pi/cubotino/src#
Hi John, you're fully right. I made a very basic mistake, now is solved.
Try this:
Align cube with Green at Front, White Up
Apply R1
Place in Cubotino, and run python Cubotino_T.py --debug
Cube solution: 1 moves R3
Traceback (most recent call last):
File "Cubotino_T.py", line 3816, in <module>
reset_camera = start_solving(solv_cycle) # start_solving function is called
File "Cubotino_T.py", line 3077, in start_solving
cubeAF() # cube reading/solving function is called
File "Cubotino_T.py", line 3594, in cubeAF
HSV_detected, start_time, camera_ready_time, cube_detect_time, cube_solution_time)
File "Cubotino_T.py", line 2675, in robot_solve_cube
_, robot_moves, total_robot_moves = rm.robot_required_moves(solution, solution_Text)
File "/home/pi/cubotino/src/Cubotino_T_moves.py", line 358, in robot_required_moves
moves = optim_moves2(moves) # removes eventual unnecessary flips
File "/home/pi/cubotino/src/Cubotino_T_moves.py", line 271, in optim_moves2
if F_list[-1] == 'F3' and F_list[-2] == 'F2': # case the second-last flip is 'F3' and last flip is 'F2'
IndexError: list index out of range
(.virtualenvs) root@cubotino:/home/pi/cubotino/src#
optim_moves2
crashes there is only 1 move in the solution, because F_list[-2]
doesn't exist.
I think line 271 could change to
if F_count == 2 and F_list[-1] == 'F3' and F_list[-2] == 'F2': # case the second-last flip is 'F3' and last flip is 'F2'
Only check the F moves if you found a F-pair.
Hi John, as always you're fully right. The proposed solution is simple and to the point: Update is just committed. Thank you
Hi John, on the optim_moves2 function there still was one case not covered, leading to failure :-( I believe Latest Cubotino_T_moves.py, committed as V3.16_2, works working properly.
V3.15: Improved Automated cycles; Added arguments for Cubotino_T.py, s_mode parameter (PiCamera V2), 'personalizations' folder