コード例 #1
0
class DCMOTOR_ROTATION:
	def __init__(self,baudrate):
		self.baudrate=baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.pin1=9
		self.pin2=10
		self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2)
		self.obj_arduino.cmd_dcmotor_run(1,1,100)
		sleep(2)
		self.obj_arduino.cmd_dcmotor_release(1,1)
		
		
			

	def exit(self):
		self.obj_arduino.close_serial()
コード例 #2
0
class DCMOTOR_ROTATION:
	def __init__(self,baudrate):
		self.baudrate=baudrate
		self.setup()
		self.run()
		self.exit()

	def setup(self):
		self.obj_arduino=Arduino()
		self.port=self.obj_arduino.locateport()
		self.obj_arduino.open_serial(1,self.port,self.baudrate)

	def run(self):
		self.pin1=9
		self.pin2=10
		self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2)
		self.obj_arduino.cmd_dcmotor_run(1,1,100)
		sleep(2)
		self.obj_arduino.cmd_dcmotor_release(1,1)
		
		
			

	def exit(self):
		self.obj_arduino.close_serial()
コード例 #3
0
ファイル: interrupt.py プロジェクト: sbavlani/IR-Interrupt
class SENSE:
    def __init__(self,baudrate):
        self.baudrate=baudrate
        self.setup()
        self.run()
        self.exit()
    def setup(self):
        self.obj_arduino=Arduino()
        self.port=self.obj_arduino.locateport()      #Locates the port 
        self.obj_arduino.open_serial(1,self.port,self.baudrate)
    def run(self):
        jlast=0
        k=0
        j=0
        self.pin1=9
        self.pin2=10
        self.intrp=5
        ilast=self.obj_arduino.cmd_digital_in(1,self.intrp)
        self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2)  # Initialize motor of the interrupt
        for s in range(5000):
            self.obj_arduino.cmd_dcmotor_run(1,1,100)    # Rotate the motor
            i=self.obj_arduino.cmd_digital_in(1,self.intrp)  # Read the signal of the receiver of IR sensor
            if i!=ilast:  # Check whether the motor is rotating
                if i=='1':  # Condition when the receiver receives the signal from transmitter
                    j=j+1
                sleep(0.01)
            ilast=i
            if j!=jlast:  
                print j
                if j%17==0 and j!=0:  # Condition for one complete rotation
                    k=k+1   # No of rotations
                    print 'number of rotations completed are',k
            jlast=j
        self.obj_arduino.cmd_dcmotor_release(1,1)

    def exit(self):
        self.obj_arduino.close_serial()
コード例 #4
0
ファイル: encoderdc.py プロジェクト: sbavlani/Rotary-encoder
class ENCODER:
    def __init__(self,baudrate):
        self.baudrate=baudrate
        self.setup()
        self.run()
        self.exit()

    def setup(self):
        self.obj_arduino=Arduino()
        self.port=self.obj_arduino.locateport()  #Locates the port 
        self.obj_arduino.open_serial(1,self.port,self.baudrate)

    def run(self):
        count=0;
        self.pwm1=9
        self.pwm2=10
        self.pin1=3
        self.pin2=4
        pinAlast=self.obj_arduino.cmd_digital_in(1,self.pin1)
        self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pwm1,self.pwm2)  # Initialize DC motor
        for i in range(2000):
            aVal=self.obj_arduino.cmd_digital_in(1,self.pin1)  
            if aVal!=pinAlast:                                   # To check whether encoder has rotated or not
                bVal=self.obj_arduino.cmd_digital_in(1,self.pin2)
                if bVal!=aVal:               # encoder has rotated in CW direction
                    count=count+1
                    print 'clockwise  ',count  
                    if count>0 and count<15:     # Speed control of DC motor
                        self.obj_arduino.cmd_dcmotor_run(1,1,40)
                        sleep(2)
                        self.obj_arduino.cmd_dcmotor_run(1,1,0)
                        sleep(1)
                    if count>=15 and count<30:
                        self.obj_arduino.cmd_dcmotor_run(1,1,80)
                        sleep(2)
                        self.obj_arduino.cmd_dcmotor_run(1,1,0)
                        sleep(1)
                    if count<0:
                        self.obj_arduino.cmd_dcmotor_run(1,1,120)
                        sleep(2)
                        self.obj_arduino.cmd_dcmotor_run(1,1,0)
                        sleep(1)
                else:                     # encoder has rotated in CCW direction
                    count=count-1
                    print 'anticlockwise  ',count
                    if count>-15 and count<0:    # Speed control of DC motor
                        self.obj_arduino.cmd_dcmotor_run(1,1,-40)
                        sleep(2)
                        self.obj_arduino.cmd_dcmotor_run(1,1,0)
                        sleep(1)
                    if count>-30 and count<=-15:
                        self.obj_arduino.cmd_dcmotor_run(1,1,-80)
                        sleep(2)
                        self.obj_arduino.cmd_dcmotor_run(1,1,0)
                        sleep(1)
                    if count>0:
                        self.obj_arduino.cmd_dcmotor_run(1,1,-120)
                        sleep(2)
                        self.obj_arduino.cmd_dcmotor_run(1,1,0)
                        sleep(1)
            pinAlast=aVal
        self.obj_arduino.cmd_dcmotor_release(1,1)
        
    def exit(self):
        self.obj_arduino.close_serial()