diff --git a/examples/goto0 b/examples/goto0 new file mode 100755 index 0000000..ecf2e55 --- /dev/null +++ b/examples/goto0 @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +import synscan + +'''Goto example''' +def run(): + smc=synscan.motors() + #Slow down long goto + smc.axis_set_long_goto_step_period(1, 3000); # AZ + smc.axis_set_long_goto_step_period(2, 3000); # ALT + #move to 2° lower left before final point + #for 0,0 AZ should be 2° less, ALT should be 2° less + smc.goto(-2,-2,synchronous=True) + #Return to original position and exit without wait + smc.goto(0,0,synchronous=False) + +run() diff --git a/examples/goto1 b/examples/goto1 new file mode 100755 index 0000000..6732a51 --- /dev/null +++ b/examples/goto1 @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +import synscan + +'''Goto example''' +def run(): + smc=synscan.motors() + #Slow down long goto + smc.axis_set_long_goto_step_period(1, 3000); # AZ + smc.axis_set_long_goto_step_period(2, 3000); # ALT + #Move forward and wait to finish + smc.goto(-1,-1,synchronous=True) + print(smc.axis_get_pos(1),smc.axis_get_pos(2)) + #Return to original position and exit without wait + smc.goto(0,0,synchronous=False) + print(smc.axis_get_pos(1),smc.axis_get_pos(2)) + +run() diff --git a/examples/goto180 b/examples/goto180 new file mode 100755 index 0000000..c280ac7 --- /dev/null +++ b/examples/goto180 @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +import synscan + +'''Goto example''' +def run(): + smc=synscan.motors() + #Slow down long goto + smc.axis_set_long_goto_step_period(1, 3000); # AZ + smc.axis_set_long_goto_step_period(2, 3000); # ALT + #If counts per revolution are correct, after both axis turn 180 + #the telescope should point to same target as 0,0 + #smc.goto(180,180,synchronous=True) + #move to 2° lower left before final point + #for 180,180 AZ should be 2° less, ALT should be 2° more + smc.goto(177,178,synchronous=True) + #If counts per revolution are not correct + #experiment with this until telescope points to 0,0 + smc.goto(179+17/60,175+46/60,synchronous=False) + +run() diff --git a/examples/one_axis_variablespeedtrack.py b/examples/one_axis_variablespeedtrack.py index 488b1b6..e73edb2 100644 --- a/examples/one_axis_variablespeedtrack.py +++ b/examples/one_axis_variablespeedtrack.py @@ -3,24 +3,26 @@ '''One axis variable speed track example''' smc=synscan.motors() -AXIS=2 -#FORWARD -#RAMP UP -for speed in range(0,50,1): +def run(): + AXIS=2 + #FORWARD + #RAMP UP + for speed in range(0,50,1): time.sleep(.1) smc.axis_track(AXIS,speed/10) -#RAMP DOWN -for speed in range(50,0,-1): + #RAMP DOWN + for speed in range(50,0,-1): time.sleep(.1) smc.axis_track(AXIS,speed/10) -#BACKWARDS -#RAMP UP -for speed in range(0,50,1): + #BACKWARDS + #RAMP UP + for speed in range(0,50,1): time.sleep(.1) smc.axis_track(AXIS,-speed/10) -#RAMP DOWN -for speed in range(50,0,-1): + #RAMP DOWN + for speed in range(50,0,-1): time.sleep(.1) smc.axis_track(AXIS,-speed/10) +run() diff --git a/examples/slew.py b/examples/slew.py new file mode 100755 index 0000000..5458b20 --- /dev/null +++ b/examples/slew.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +import synscan +import time + +'''Goto example''' +def run(): + smc=synscan.motors() + smc._set_T1_preset(1, 3000); # AZ + smc.axis_start_motion(1) + time.sleep(1) + smc.axis_stop_motion(1) + +run() diff --git a/examples/slowgoto.py b/examples/slowgoto.py new file mode 100644 index 0000000..fd24a1e --- /dev/null +++ b/examples/slowgoto.py @@ -0,0 +1,14 @@ +import synscan + +'''Goto example''' +smc=synscan.motors() +#Slow down long goto +smc.axis_set_long_goto_step_period(1, 3000); # AZ +smc.axis_set_long_goto_step_period(2, 3000); # ALT +#Synchronize mount actual position to (0,0) +smc.set_pos(0,0) +#Move forward and wait to finish +smc.goto(30,30,synchronous=True) +#Return to original position and exit without wait +smc.goto(0,0,synchronous=False) + diff --git a/examples/synscan b/examples/synscan new file mode 120000 index 0000000..840bda0 --- /dev/null +++ b/examples/synscan @@ -0,0 +1 @@ +../synscan \ No newline at end of file diff --git a/logging.py b/logging.py new file mode 100644 index 0000000..e435498 --- /dev/null +++ b/logging.py @@ -0,0 +1,14 @@ +# micropython compatibility replacement +# for logging + +def info(x): + return + +def debug(x): + return + +def warning(x): + return + +def basicConfig(format,level): + return diff --git a/synscan/comm.py b/synscan/comm.py index ba28538..16b28ff 100644 --- a/synscan/comm.py +++ b/synscan/comm.py @@ -3,19 +3,20 @@ # pysynscan # Copyright (c) July 2020 Nacho Mas - import socket import logging import os import select -import threading - - - -UDP_IP = os.getenv("SYNSCAN_UDP_IP","192.168.4.1") -UDP_PORT = int(os.getenv("SYNSCAN_UDP_PORT",11880)) -LOGGING_LEVEL=os.getenv("SYNSCAN_LOGGING_LEVEL",logging.INFO) +try: + from os import getenv + UDP_IP = getenv("SYNSCAN_UDP_IP","192.168.4.1") + UDP_PORT = int(getenv("SYNSCAN_UDP_PORT",11880)) + LOGGING_LEVEL=getenv("SYNSCAN_LOGGING_LEVEL",logging.INFO) +except: + UDP_IP = None + UDP_PORT = 11880 + LOGGING_LEVEL=0 class commUDP: ''' @@ -29,10 +30,14 @@ def __init__(self,udp_ip=UDP_IP,udp_port=UDP_PORT): self.udp_ip=udp_ip self.udp_port=udp_port self.commOK=False - self.lock= threading.Lock() + try: + import threading + self.lock= threading.Lock() + except: + self.lock=None def cmd(self,cmd,timeout_in_seconds=2): - '''Low level send command function ''' + ''' Low level send command function ''' with self.lock: self._sock.sendto(cmd,(self.udp_ip,self.udp_port)) ready = select.select([self._sock], [], [], timeout_in_seconds) @@ -56,11 +61,15 @@ def __init__(self,serial_dev): import serial ''' Init the serial port ''' self.serial = serial.Serial(serial_dev, 9600, timeout=.02) - self.lock = threading.Lock() + try: + import threading + self.lock= threading.Lock() + except: + self.lock=None self.commOK=False def cmd(self,cmd,timeout_in_seconds=2): - '''Low level send command function ''' + ''' Low level send command function ''' with self.lock: self.serial.write(cmd) response = self.serial.readline() @@ -93,7 +102,14 @@ def __init__(self,udp_ip=UDP_IP,udp_port=UDP_PORT,serial_dev=None): if serial_dev: self.comm = commSerial(serial_dev) else: - self.comm = commUDP(udp_ip,udp_port) + if udp_ip: + self.comm = commUDP(udp_ip,udp_port) + else: # "syn" is local python interface with syn.cmd() + # esp32blesynscan/micropython/ + # rename synscan.py -> syn.py + # mpremote cp synscan.py :/syn.py + import syn + self.comm = syn def _send_raw_cmd(self,cmd,timeout_in_seconds=2): return self.comm.cmd(cmd, timeout_in_seconds) diff --git a/synscan/motors.py b/synscan/motors.py index 44134ae..6eb42c2 100644 --- a/synscan/motors.py +++ b/synscan/motors.py @@ -8,6 +8,7 @@ # G Set Motion Mode # I Set Step Period (T1 preset value) # S Set Goto Target +# T Set Long Goto Step Period # H SetGotoTargetIncrement # M SetBreakPointIncrement # E Set Position / SetAxisPosition @@ -37,6 +38,7 @@ # # Tested successfully on: # - SkyWatcher AZ-GTI +# - SkyWatcher Virtuoso GTi firmware 3.40.AF # - open-synscan # - Star Adventurer Mini (AXIS1 only), but goto does not stop. # @@ -45,14 +47,19 @@ # https://inter-static.skywatcher.com/downloads/skywatcher_motor_controller_command_set.pdf import os -import logging from synscan.comm import comm import time +import logging -UDP_IP = os.getenv("SYNSCAN_UDP_IP","192.168.4.1") -UDP_PORT = int(os.getenv("SYNSCAN_UDP_PORT",11880)) - -LOGGING_LEVEL=os.getenv("SYNSCAN_LOGGING_LEVEL",logging.INFO) +try: + from os import getenv + UDP_IP = getenv("SYNSCAN_UDP_IP","192.168.4.1") + UDP_PORT = int(getenv("SYNSCAN_UDP_PORT",11880)) + LOGGING_LEVEL=getenv("SYNSCAN_LOGGING_LEVEL",logging.INFO) +except: + UDP_IP = None # use python interface syn.cmd() + UDP_PORT = 11880 + LOGGING_LEVEL=0 class motors(comm): ''' @@ -155,7 +162,7 @@ def get_parameters(self): Some of this parameters are needed for all calculations so they have to be available to the rest of the code - Parameters are stored in a dict with te following keys: + Parameters are stored in a dict with the following keys: * countsPerRevolution * TimerInterruptFreq @@ -305,6 +312,11 @@ def axis_set_goto_targetCounts(self,axis,targetCounts): response=self._send_cmd('S',axis,targetCounts+0x800000) # SetGotoTarget return response + def axis_set_long_goto_step_period(self,axis,stepPeriod): + logging.info(f'AXIS{axis}: Setting long goto step period to {stepPeriod}') + response=self._send_cmd('T',axis,stepPeriod) # long goto step period + return response + def axis_set_goto_targetIncrementCounts(self,axis,targetCounts): #NOT IN USE. HAVE TO BE TESTED!! '''GoTo Target increment in StepsCounts. Motors has to be stopped''' @@ -315,7 +327,7 @@ def axis_set_goto_targetIncrementCounts(self,axis,targetCounts): #Position values are offseting by 0x800000 response=self._send_cmd('H',axis,targetCounts+0x800000) # SetGotoTargetIncrement #Set Brake Point Increment - response=self._send_cmd('M',axis,0x000DAC) # SetBreakPointIncrement + response=self._send_cmd('M',axis,0x000DAC) # SetBrakePointIncrement return response def axis_wait2stop(self,axis):