Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/goto0
Original file line number Diff line number Diff line change
@@ -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()
17 changes: 17 additions & 0 deletions examples/goto1
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions examples/goto180
Original file line number Diff line number Diff line change
@@ -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()
24 changes: 13 additions & 11 deletions examples/one_axis_variablespeedtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
13 changes: 13 additions & 0 deletions examples/slew.py
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 14 additions & 0 deletions examples/slowgoto.py
Original file line number Diff line number Diff line change
@@ -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)

1 change: 1 addition & 0 deletions examples/synscan
14 changes: 14 additions & 0 deletions logging.py
Original file line number Diff line number Diff line change
@@ -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
42 changes: 29 additions & 13 deletions synscan/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
'''
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 19 additions & 7 deletions synscan/motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
#
Expand All @@ -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):
'''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'''
Expand All @@ -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):
Expand Down