Last active
May 20, 2025 22:17
-
-
Save soulen3/9834268c71232ec70ff547afe65357a7 to your computer and use it in GitHub Desktop.
Send Serial Commands to OAT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import serial | |
| import sys | |
| import argparse | |
| DEFAULT_DEVICE = "/dev/serial/by-id/usb-Raspberry_Pi_Pico_E662608797224B29-if00" | |
| parser = argparse.ArgumentParser("OAT Command Script") | |
| parser.add_argument("-d", "--device", help="Serial Device Port.", type=str) | |
| parser.add_argument( | |
| "-c", "--config", action="store_true", help="Get Device configuration." | |
| ) | |
| parser.add_argument( | |
| "-mc", "--motor_config", action="store_true", help="Get Motor configuration." | |
| ) | |
| parser.add_argument( | |
| "-hr", "--home", action="store_true", help="Home RA Axis using HAL sensor." | |
| ) | |
| parser.add_argument("-sh", "--set_home", action="store_true", help="Set Home point.") | |
| parser.add_argument( | |
| "-ro", "--ra_offset", action="store_true", help="Offset for RA Axis." | |
| ) | |
| parser.add_argument("-sro", "--set_ra_offset", help="Offset for RA Axis.", type=int) | |
| parser.add_argument( | |
| "-mh", "--move_home", action="store_true", help="Move RA Axis home." | |
| ) | |
| parser.add_argument( | |
| "-hs", "--home_status", action="store_true", help="Auto Homing Status." | |
| ) | |
| parser.add_argument("-s", "--status", action="store_true", help="Print device status.") | |
| parser.add_argument( | |
| "-et", "--enable_tracking", action="store_true", help="Start tracking" | |
| ) | |
| parser.add_argument( | |
| "-dt", "--disable_tracking", action="store_true", help="Disable tracking" | |
| ) | |
| parser.add_argument( | |
| "-i", "--initialize", action="store_true", help="Initialize device." | |
| ) | |
| parser.add_argument("-v", "--verbose", action="store_true", help="Echo command.") | |
| parser.add_argument("-ps", "--park_and_stop", action="store_true", help="Stop Motors.") | |
| parser.add_argument("--stop", action="store_true", help="Stop Motors.") | |
| parser.add_argument("-mr", "--move_ra", help="Move RA Axis by x steps.", type=int) | |
| parser.add_argument("-md", "--move_dec", help="Move DEC Axis by x steps.", type=int) | |
| parser.add_argument( | |
| "-mf", "--move_foc", help="Move Focus stepper by x steps.", type=int | |
| ) | |
| parser.add_argument("-mz", "--move_az", help="Move Az Axis by x steps.", type=int) | |
| parser.add_argument( | |
| "-gs", "--get_slew_status", action="store_true", help="Check is axis is slewing." | |
| ) | |
| parser.add_argument("-ss", "--set_slew", help="Set Slew rate.", type=int) | |
| parser.add_argument( | |
| "-t", "--tracking_status", action="store_true", help="Check device is tracking." | |
| ) | |
| args = parser.parse_args() | |
| if len(sys.argv) == 1: | |
| parser.print_help(sys.stderr) | |
| exit() | |
| if args.device: | |
| DEFAULT_DEVICE = args.device | |
| ser = serial.Serial(DEFAULT_DEVICE, 9600, timeout=0.001) | |
| def write(command): | |
| command = f":{command}#" | |
| if args.verbose: | |
| print(command) | |
| ser.write(bytes(command, "utf-8")) | |
| print(ser.readline()) | |
| commands = { | |
| "stop": "Q", | |
| "status": "GX", | |
| "initialize": "I", | |
| "move_home": "hF", | |
| "park_and_stop": "SHP", | |
| "set_home": "SHP", | |
| "tracking_status": "GIT", | |
| "config": "XGM", | |
| "motor_config": "XGMS", | |
| "home": "MHRL", | |
| "home_status": "XGAH", | |
| "ra_offset": "XGHR", | |
| "set_ra_offset": "XSHD", | |
| "enable_tracking": "MT1", | |
| "disable_tracking": "MT0", | |
| "move_ra": "MXr", | |
| "move_dec": "MXd", | |
| "move_foc": "MXf", | |
| "move_az": "MXz", | |
| "move_alt": "MXt", | |
| "get_slew_status": "GIS", | |
| "set_slew": "Rs", | |
| } | |
| for key in commands: | |
| if not hasattr(args, key): | |
| continue | |
| attr = getattr(args, key) | |
| if attr: | |
| if isinstance(attr, bool): | |
| write(commands[key]) | |
| else: | |
| write(f"{commands[key]}{attr}") | |
| ser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment