Esempio n. 1
0
 def __init__(self,
              dict,
              serial_port,
              baudrate,
              readTimeout=0.03,
              SerialComInstance=SerialCom()):
     self.dict = dict
     self.serial_port = serial_port
     self.baudrate = baudrate
     self.readTimeout = readTimeout
     self.serial = SerialComInstance
     self.lock = threading.Lock()
#!/usr/bin/env python
import sys
from serial_com import SerialCom
import time
if __name__ == "__main__" :
	#try:                      # turns on fatal error catching
	sc = SerialCom()
	#SerialCom.bedReferenceTest(sc)
	print("metascript trying to set a bed position")
		
	#SerialCom.bedReferenceTest(sc)
	#SerialCom.setBedPosition(sc,116.6)
	
	theta = 116.6
	ctr = 0
	while(1) :
		print("Changing target : ")
		if(theta == 116.6):
			theta = 156.6
		elif(theta == 156.6):
			theta = 116.6
		
	#	while(theta!= sc.checkTarget()):
		sc.setBedPosition(theta)
		
		while(ctr<10):
			
			#sc.setBedReference(223.4)
			sc.setBedPosition(theta)
			time.sleep(1)
			sc.logBedData()
#!/usr/bin/python
from serial_com import SerialCom
import sys
import time

if __name__ == "__main__" :
	print 'Number of arguments:', len(sys.argv), 'arguments.'
	print 'Argument' , str(sys.argv[1])
	desPos = sys.argv[1]
	sc = SerialCom()

	while(1):
		print desPos
		sc.setBedPosition(float(desPos))
		time.sleep(1)
		sc.logBedData()
		print("----------------")	
		time.sleep(1)
def celestial_body_func():
	# Log everything, and send it to stderr.
	FORMAT = "%(asctime)-15s %(message)s"
	logging.basicConfig(format=FORMAT,level=logging.DEBUG,datefmt='%Y-%m-%d %H:%M:%S')

	#Object creation
	
	sc = SerialCom()
	#sc.resetBedFromLog()
	

	while 1:
		logging.debug("-----------------------------")
		logging.debug("READING JSON FILE")
		data = json.load(open(EXCHANGE_JSON_FILE))
		'''
		with open(EXCHANGE_JSON_FILE) as data_file:
		data = json.load(data_file)
		'''
		goto = data["goto"]
		logging.debug("goto: " + goto)
	# where are we heading to?
		if not CELESTIAL_BODY[goto]:
			logging.debug("OUT OF ORBIT - could not match celestial body from json file")
			continue
		celestial_body = CELESTIAL_BODY[goto]

		if celestial_body["datatype"] == 'pyephem':
			logging.debug("using pyephem")
			city = eval(OBSERVER)
			position = eval(celestial_body["class"])
			position.compute(city)
			position = position.az * degrees_per_radian

		elif celestial_body["datatype"] == 'nasacsv':
			logging.debug("using nasa_csvparser")
			csvfile =  celestial_body["sourcefile"]
			position = nasa_csvparser.get_position(csvfile)
			logging.debug("London GMT / UTC time:" + position["date"])
			position = float(position["azi"])
		elif celestial_body["datatype"] == 'tle':
			logging.debug("using tle parser")
			tle_file =  open (celestial_body["sourcefile"])
			city = eval(OBSERVER)
			satelite_name = celestial_body["parsekey"] #goto
			position = tle_parser.get_tle_az(tle_file, satelite_name, city) * degrees_per_radian
		else:
			logging.debug("ERRRRRRRRRRRROR. Config file is wrong")
			continue
	# send to serial port

		#print("PositionText:"+str(int(float(position)*10)))
		# hack of 360 - angle added for compensating the clockwise reversed motion of the bed
		positionTruncInt = int(10*float(360.0 - position))
		positionTruncFloat = float(positionTruncInt)/10
		#print(positionTruncFloat)
				
		sc.setBedPosition(positionTruncFloat)
		logging.debug("Sending to serial:")
		logging.debug(positionTruncFloat)

		time.sleep(1)
		sc.receiveData()
		sc.logBedData()