combined the functionality of serial_capture.py into trajectory_permutation.py to simplify they logic.