<s> import trajoptpy , openravepy <EOL> import sys <EOL> def animate_traj ( traj , robot , pause = True , step_viewer = <NUM_LIT:1> , restore = True , callback = None , execute_step_cond = None ) : <EOL> """<STR_LIT>""" <EOL> if restore : _saver = openravepy . RobotStateSaver ( robot ) <EOL> if step_viewer or pause : viewer = trajoptpy . GetViewer ( robot . GetEnv ( ) ) <EOL> for ( i , dofs ) in enumerate ( traj ) : <EOL> sys . stdout . write ( "<STR_LIT>" % ( i + <NUM_LIT:1> , len ( traj ) ) ) <EOL> sys . stdout . flush ( ) <EOL> if callback is not None : callback ( i ) <EOL> if execute_step_cond is not None and not execute_step_cond ( i ) : continue <EOL> robot . SetActiveDOFValues ( dofs ) <EOL> if pause : viewer . Idle ( ) <EOL> elif step_viewer != <NUM_LIT:0> and ( i % step_viewer == <NUM_LIT:0> or i == len ( traj ) - <NUM_LIT:1> ) : viewer . Step ( ) <EOL> sys . stdout . write ( "<STR_LIT:\n>" ) </s>
