11# coding=utf-8
22
3+ import time
34import threading
4- import serial
55
66from pymycobot .close_loop import CloseLoop
77from pymycobot .error import calibration_parameters
88from pymycobot .common import ProtocolCode
99
1010
1111class Pro630 (CloseLoop ):
12- def __init__ (self , port = "/dev/ttyAMA1" , baudrate = "115200" , timeout = 0.1 , debug = False , save_serial_log = False ):
12+ def __init__ (self , port , baudrate = "115200" , timeout = 0.1 , debug = False ):
1313 """
1414 Args:
1515 port : port string
@@ -18,15 +18,15 @@ def __init__(self, port="/dev/ttyAMA1", baudrate="115200", timeout=0.1, debug=Fa
1818 debug : whether show debug info
1919 """
2020 super (Pro630 , self ).__init__ (debug )
21- # self.calibration_parameters = calibration_parameters
22- # import RPi.GPIO as GPIO
23- # self.power_control_1 = 3
24- # self.power_control_2 = 4
25- # GPIO.setmode(GPIO.BCM)
26- # GPIO.setwarnings(False )
27- # GPIO.setup(self.power_control_1, GPIO.IN )
28- # GPIO.setup(self.power_control_2 , GPIO.OUT )
29- self .save_serial_log = save_serial_log
21+ self .calibration_parameters = calibration_parameters
22+ import serial
23+ import RPi . GPIO as GPIO
24+ self .power_control_1 = 3
25+ self . power_control_2 = 4
26+ GPIO .setmode ( GPIO . BCM )
27+ GPIO .setwarnings ( False )
28+ GPIO .setup (self .power_control_1 , GPIO .IN )
29+ GPIO . setup ( self .power_control_2 , GPIO . OUT )
3030 self ._serial_port = serial .Serial ()
3131 self ._serial_port .port = port
3232 self ._serial_port .baudrate = baudrate
@@ -265,69 +265,69 @@ def close(self):
265265 self ._serial_port .close ()
266266
267267 def power_on (self , delay = 2 ):
268- # import RPi.GPIO as GPIO
269- # GPIO.output(self.power_control_2, GPIO.HIGH)
270- # time.sleep(delay)
268+ import RPi .GPIO as GPIO
269+ GPIO .output (self .power_control_2 , GPIO .HIGH )
270+ time .sleep (delay )
271271 return super (Pro630 , self ).power_on ()
272272
273273 def power_off (self ):
274- # import RPi.GPIO as GPIO
274+ import RPi .GPIO as GPIO
275275 res = super (Pro630 , self ).power_off ()
276- # GPIO.output(self.power_control_2, GPIO.LOW)
276+ GPIO .output (self .power_control_2 , GPIO .LOW )
277277 return res
278278
279- # def power_on_only(self):
280- # import RPi.GPIO as GPIO
281- # GPIO.output(self.power_control_2, GPIO.HIGH)
279+ def power_on_only (self ):
280+ import RPi .GPIO as GPIO
281+ GPIO .output (self .power_control_2 , GPIO .HIGH )
282282
283- # def set_basic_output(self, pin_no, pin_signal):
284- # """Set basic output.IO low-level output high-level, high-level output high resistance state
283+ def set_basic_output (self , pin_no , pin_signal ):
284+ """Set basic output.IO low-level output high-level, high-level output high resistance state
285285
286- # Args:
287- # pin_no: pin port number. range 1 ~ 6
288- # pin_signal: 0 / 1
289- # """
290- # import RPi.GPIO as GPIO
291- # if pin_no == 1:
292- # pin_no = 17
293- # elif pin_no == 2:
294- # pin_no = 27
295- # elif pin_no == 3:
296- # pin_no = 22
297- # elif pin_no == 4:
298- # pin_no = 5
299- # elif pin_no == 5:
300- # pin_no = 6
301- # elif pin_no == 6:
302- # pin_no = 19
303- # GPIO.setup(pin_no, GPIO.OUT)
304- # GPIO.output(pin_no, pin_signal)
286+ Args:
287+ pin_no: pin port number. range 1 ~ 6
288+ pin_signal: 0 / 1
289+ """
290+ import RPi .GPIO as GPIO
291+ if pin_no == 1 :
292+ pin_no = 17
293+ elif pin_no == 2 :
294+ pin_no = 27
295+ elif pin_no == 3 :
296+ pin_no = 22
297+ elif pin_no == 4 :
298+ pin_no = 5
299+ elif pin_no == 5 :
300+ pin_no = 6
301+ elif pin_no == 6 :
302+ pin_no = 19
303+ GPIO .setup (pin_no , GPIO .OUT )
304+ GPIO .output (pin_no , pin_signal )
305305
306- # def get_basic_input(self, pin_no):
307- # """Get basic input.
306+ def get_basic_input (self , pin_no ):
307+ """Get basic input.
308308
309- # Args:
310- # pin_no: pin port number. range 1 ~ 6
309+ Args:
310+ pin_no: pin port number. range 1 ~ 6
311311
312- # Return:
313- # 1 - high
314- # 0 - low
315- # """
316- # import RPi.GPIO as GPIO
317- # if pin_no == 1:
318- # pin_no = 26
319- # elif pin_no == 2:
320- # pin_no = 21
321- # elif pin_no == 3:
322- # pin_no = 20 #23
323- # elif pin_no == 4:
324- # pin_no = 16
325- # elif pin_no == 5:
326- # pin_no = 24
327- # elif pin_no == 6:
328- # pin_no = 23
329- # GPIO.setup(pin_no, GPIO.IN)
330- # return GPIO.input(pin_no)
312+ Return:
313+ 1 - high
314+ 0 - low
315+ """
316+ import RPi .GPIO as GPIO
317+ if pin_no == 1 :
318+ pin_no = 26
319+ elif pin_no == 2 :
320+ pin_no = 21
321+ elif pin_no == 3 :
322+ pin_no = 20 #23
323+ elif pin_no == 4 :
324+ pin_no = 16
325+ elif pin_no == 5 :
326+ pin_no = 24
327+ elif pin_no == 6 :
328+ pin_no = 23
329+ GPIO .setup (pin_no , GPIO .IN )
330+ return GPIO .input (pin_no )
331331
332332 def send_angles_sync (self , angles , speed ):
333333 self .calibration_parameters (class_name = self .__class__ .__name__ , angles = angles , speed = speed )
0 commit comments