Exemplo n.º 1
0
def go_Forward(speed, running_time):
    global forward0, forward1
    motor.setSpeed(speed)
    motor.motor0(forward0)
    motor.motor1(forward1)
    time.sleep(running_time)
    motor.stop()
Exemplo n.º 2
0
def go_Backward(speed, running_time):
    global backward0, backward1
    motor.setSpeed(speed)
    motor.motor0(backward0)
    motor.motor1(backward1)
    time.sleep(running_time)
    motor.stop()
Exemplo n.º 3
0
def calibrate_motor_left_reverse(request):
	global forward0
	if forward0 == "True":
		forward0 = "False"
	else:
		forward0 = "True"
	motor.motor0(forward0)
	text = 'left motor reverse to ', forward0
	return HttpResponse(text)
def loop():
    global offset_x, offset_y, offset, forward0, forward1
    while True:
        print 'Waiting for connection...'
        # Waiting for connection. Once receiving a connection, the function accept() returns a separate
        # client socket for the subsequent communication. By default, the function accept() is a blocking
        # one, which means it is suspended before the connection comes.
        tcpCliSock, addr = tcpSerSock.accept()
        print '...connected from :', addr  # Print the IP address of the client connected with the server.

        while True:
            data = tcpCliSock.recv(
                BUFSIZ)  # Receive data sent from the client.
            # Analyze the command received and control the car accordingly.
            if not data:
                break
            #--------Motor calibration----------
            if data == 'motor_run':
                print 'motor moving forward'
                motor.setSpeed(50)
                motor.motor0(forward0)
                motor.motor1(forward1)
            elif data[0:9] == 'leftmotor':
                forward0 = data[9:]
                motor.motor0(forward0)
            elif data[0:10] == 'rightmotor':
                forward1 = data[10:]
                motor.motor1(forward1)
            elif data == 'motor_stop':
                print 'motor stop'
                motor.stop()
            #---------------------------------

            #-------Turing calibration------
            elif data[0:7] == 'offset=':
                offset = int(data[7:])
                car_dir.calibrate(offset)
            #--------------------------------

            #----------Mount calibration---------
            elif data[0:8] == 'offsetx=':
                offset_x = int(data[8:])
                print 'Mount offset x', offset_x
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsety=':
                offset_y = int(data[8:])
                print 'Mount offset y', offset_y
                video_dir.calibrate(offset_x, offset_y)
            #----------------------------------------

            else:
                print 'cmd error !'
def loop():
	global offset_x, offset_y, offset, forward0, forward1
	while True:
		print 'Waiting for connection...'
		# Waiting for connection. Once receiving a connection, the function accept() returns a separate 
		# client socket for the subsequent communication. By default, the function accept() is a blocking 
		# one, which means it is suspended before the connection comes.
		tcpCliSock, addr = tcpSerSock.accept() 
		print '...connected from :', addr     # Print the IP address of the client connected with the server.

		while True:
			data = tcpCliSock.recv(BUFSIZ)    # Receive data sent from the client. 
			# Analyze the command received and control the car accordingly.
			if not data:
				break
			#--------Motor calibration----------
			if data == 'motor_run':
				print 'motor moving forward'
				motor.setSpeed(50)
				motor.motor0(forward0)
				motor.motor1(forward1)
			elif data[0:9] == 'leftmotor':
				forward0 = data[9:]
				motor.motor0(forward0)
			elif data[0:10] == 'rightmotor':
				forward1 = data[10:]
				motor.motor1(forward1)
			elif data == 'motor_stop':
				print 'motor stop'
				motor.stop()
			#---------------------------------

			#-------Turing calibration------
			elif data[0:7] == 'offset=':
				offset = int(data[7:])
				car_dir.calibrate(offset)
			#--------------------------------

			#----------Mount calibration---------
			elif data[0:8] == 'offsetx=':
				offset_x = int(data[8:])
				print 'Mount offset x', offset_x
				video_dir.calibrate(offset_x, offset_y)
			elif data[0:8] == 'offsety=':
				offset_y = int(data[8:])
				print 'Mount offset y', offset_y
				video_dir.calibrate(offset_x, offset_y)
			#----------------------------------------

			else:
				print 'cmd error !'
Exemplo n.º 6
0
def loop():
    global offset_x, offset_y, offset, forward0, forward1
        while True:
            print 'Waiting for connection...'
                # Waiting for connection. Once receiving a connection, the function accept() returns a separate
                # client socket for the subsequent communication. By default, the function accept() is a blocking
                # one, which means it is suspended before the connection comes.
                tcpCliSock, addr = tcpSerSock.accept()
                print '...connected from :', addr     # Print the IP address of the client connected with the server.

                while True:
                    data = tcpCliSock.recv(BUFSIZ)    # Receive data sent from the client.
                        # Analyze the command received and control the car accordingly.
                        if not data:
                            break
                        #--------Motor calibration----------
                        if data == 'motor_run':
                            print 'motor moving forward'
                                motor.setSpeed(50)
                                motor.motor0(forward0)
                                motor.motor1(forward1)
                        elif data[0:9] == 'leftmotor':
                            forward0 = data[9:]
                                motor.motor0(forward0)
Exemplo n.º 7
0
def calibrate_motor_run(request):
	motor.setSpeed(50)
	motor.motor0(forward0)
	motor.motor1(forward1)
	return HttpResponse('Motors Runing')
Exemplo n.º 8
0
def loop():
    global offset_x, offset_y, offset, forward0, forward1
    while True:
        print 'Waiting for connection...'
        # Waiting for connection. Once receiving a connection, the function accept() returns a separate
        # client socket for the subsequent communication. By default, the function accept() is a blocking
        # one, which means it is suspended before the connection comes.
        tcpCliSock, addr = tcpSerSock.accept()
        print '...connected from :', addr  # Print the IP address of the client connected with the server.

        while True:
            data = tcpCliSock.recv(
                BUFSIZ)  # Receive data sent from the client.
            # Analyze the command received and control the car accordingly.
            if not data:
                break
            # --------Motor calibration----------
            if data == 'motor_run':
                print 'motor moving forward'
                motor.setSpeed(50)
                motor.motor0(forward0)
                motor.motor1(forward1)
            elif data[0:9] == 'leftmotor':
                forward0 = data[9:]
                motor.motor0(forward0)
            elif data[0:10] == 'rightmotor':
                forward1 = data[10:]
                motor.motor1(forward1)

            # -------------Added--------------
            elif data == 'leftreverse':
                if forward0 == "True":
                    forward0 = "False"
                else:
                    forward0 = "True"
                print "left motor reversed to", forward0
                motor.motor0(forward0)
            elif data == 'rightreverse':
                if forward1 == "True":
                    forward1 = "False"
                else:
                    forward1 = "True"
                print "right motor reversed to", forward1
                motor.motor1(forward1)
            elif data == 'motor_stop':
                print 'motor stop'
                motor.stop()
            # ---------------------------------

            # -------Turing calibration------
            elif data[0:7] == 'offset=':
                offset = int(data[7:])
                car_dir.calibrate(offset)
            # --------------------------------

            # ----------Mount calibration---------
            elif data[0:8] == 'offsetx=':
                offset_x = int(data[8:])
                print 'Mount offset x', offset_x
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsety=':
                offset_y = int(data[8:])
                print 'Mount offset y', offset_y
                video_dir.calibrate(offset_x, offset_y)
            # ----------------------------------------

            # -------Turing calibration 2------
            elif data[0:7] == 'offset+':
                offset = offset + int(data[7:])
                print 'Turning offset', offset
                car_dir.calibrate(offset)
            elif data[0:7] == 'offset-':
                offset = offset - int(data[7:])
                print 'Turning offset', offset
                car_dir.calibrate(offset)
            # --------------------------------

            # ----------Mount calibration 2---------
            elif data[0:8] == 'offsetx+':
                offset_x = offset_x + int(data[8:])
                print 'Mount offset x', offset_x
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsetx-':
                offset_x = offset_x - int(data[8:])
                print 'Mount offset x', offset_x
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsety+':
                offset_y = offset_y + int(data[8:])
                print 'Mount offset y', offset_y
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsety-':
                offset_y = offset_y - int(data[8:])
                print 'Mount offset y', offset_y
                video_dir.calibrate(offset_x, offset_y)
            # ----------------------------------------

            # ----------Confirm--------------------
            elif data == 'confirm':
                config = 'offset_x = %s\noffset_y = %s\noffset = %s\nforward0 = %s\nforward1 = %s\n ' % (
                    offset_x, offset_y, offset, forward0, forward1)
                print ''
                print '*********************************'
                print ' You are setting config file to:'
                print '*********************************'
                print config
                print '*********************************'
                print ''
                fd = open('config', 'w')
                fd.write(config)
                fd.close()

                motor.stop()
                tcpCliSock.close()
                quit()
            else:
                print 'Command Error! Cannot recognize command: ' + data
Exemplo n.º 9
0
                                motor.motor1(forward1)
                        elif data[0:9] == 'leftmotor':
                            forward0 = data[9:]
                                motor.motor0(forward0)
                        elif data[0:10] == 'rightmotor':
                            forward1 = data[10:]
                                motor.motor1(forward1)

                        # -------------Added--------------
                    elif data == 'leftreverse':
                        if forward0 == "True":
                            forward0 = "False"
                        else:
                            forward0 = "True"
                                print "left motor reversed to", forward0
                                motor.motor0(forward0)
                        elif data == 'rightreverse':
                            if forward1 == "True":
                                forward1 = "False"
                            else:
                                forward1 = "True"
                                print "right motor reversed to", forward1
                                motor.motor1(forward1)
                        elif data == 'motor_stop':
                            print 'motor stop'
                                motor.stop()
                        #---------------------------------

                        #-------Turing calibration------
                    elif data[0:7] == 'offset=':
                        offset = int(data[7:])
def loop():
	global offset_x, offset_y, offset, forward0, forward1
	while True:
		print 'Waiting for connection...'
		# Waiting for connection. Once receiving a connection, the function accept() returns a separate 
		# client socket for the subsequent communication. By default, the function accept() is a blocking 
		# one, which means it is suspended before the connection comes.
		tcpCliSock, addr = tcpSerSock.accept() 
		print '...connected from :', addr     # Print the IP address of the client connected with the server.

		while True:
			data = tcpCliSock.recv(BUFSIZ)    # Receive data sent from the client. 
			# Analyze the command received and control the car accordingly.
			if not data:
				break
			#--------Motor calibration----------
			if data == 'motor_run':
				print 'motor moving forward'
				motor.setSpeed(50)
				motor.motor0(forward0)
				motor.motor1(forward1)
			elif data[0:9] == 'leftmotor':
				forward0 = data[9:]
				motor.motor0(forward0)
			elif data[0:10] == 'rightmotor':
				forward1 = data[10:]
				motor.motor1(forward1)

			# -------------Added--------------
			elif data == 'leftreverse':
				if forward0 == "True":
					forward0 = "False"
				else:
					forward0 = "True"
				print "left motor reversed to", forward0
				motor.motor0(forward0)
			elif data == 'rightreverse':
				if forward1 == "True":
					forward1 = "False"
				else:
					forward1 = "True"
				print "right motor reversed to", forward1
				motor.motor1(forward1)
			elif data == 'motor_stop':
				print 'motor stop'
				motor.stop()
			#---------------------------------

			#-------Turing calibration------
			elif data[0:7] == 'offset=':
				offset = int(data[7:])
				car_dir.calibrate(offset)
			#--------------------------------

			#----------Mount calibration---------
			elif data[0:8] == 'offsetx=':
				offset_x = int(data[8:])
				print 'Mount offset x', offset_x
				video_dir.calibrate(offset_x, offset_y)
			elif data[0:8] == 'offsety=':
				offset_y = int(data[8:])
				print 'Mount offset y', offset_y
				video_dir.calibrate(offset_x, offset_y)
			#----------------------------------------

			#-------Turing calibration 2------
			elif data[0:7] == 'offset+':
				offset = offset + int(data[7:])
				print 'Turning offset', offset
				car_dir.calibrate(offset)
			elif data[0:7] == 'offset-':
				offset = offset - int(data[7:])
				print 'Turning offset', offset
				car_dir.calibrate(offset)
			#--------------------------------

			#----------Mount calibration 2---------
			elif data[0:8] == 'offsetx+':
				offset_x = offset_x + int(data[8:])
				print 'Mount offset x', offset_x
				video_dir.calibrate(offset_x, offset_y)
			elif data[0:8] == 'offsetx-':
				offset_x = offset_x - int(data[8:])
				print 'Mount offset x', offset_x
				video_dir.calibrate(offset_x, offset_y)
			elif data[0:8] == 'offsety+':
				offset_y = offset_y + int(data[8:])
				print 'Mount offset y', offset_y
				video_dir.calibrate(offset_x, offset_y)
			elif data[0:8] == 'offsety-':
				offset_y = offset_y - int(data[8:])
				print 'Mount offset y', offset_y
				video_dir.calibrate(offset_x, offset_y)
			#----------------------------------------

			#----------Confirm--------------------
			elif data == 'confirm':
				config = 'offset_x = %s\noffset_y = %s\noffset = %s\nforward0 = %s\nforward1 = %s\n ' % (offset_x, offset_y, offset, forward0, forward1)
				print ''
				print '*********************************'
				print ' You are setting config file to:'
				print '*********************************'
				print config
				print '*********************************'
				print ''
				fd = open('config', 'w')
				fd.write(config)
				fd.close()

				motor.stop()
				tcpCliSock.close()
				quit()
			else:
				print 'Command Error! Cannot recognize command: ' + data
Exemplo n.º 11
0
def loop():
    global offset_x, offset_y, offset, forward0, forward1
    while True:
        print 'Waiting for connection...'

        tcpCliSock, addr = tcpSerSock.accept()
        print '...connected from :', addr  # Print the IP address of the client connected with the server.

        while True:
            data = tcpCliSock.recv(BUFSIZ)  # Reception données du client
            # Analyser les commandes reçues et contrôler VirJo
            if not data:
                break
            #--------Motor calibration----------
            if data == 'motor_run':
                print 'motor moving forward'
                motor.setSpeed(50)
                motor.motor0(forward0)
                motor.motor1(forward1)
            elif data[0:9] == 'leftmotor':
                forward0 = data[9:]
                motor.motor0(forward0)
            elif data[0:10] == 'rightmotor':
                forward1 = data[10:]
                motor.motor1(forward1)

            # -------------Added--------------
            elif data == 'leftreverse':
                if forward0 == "True":
                    forward0 = "False"
                else:
                    forward0 = "True"
                print "left motor reversed to", forward0
                motor.motor0(forward0)
            elif data == 'rightreverse':
                if forward1 == "True":
                    forward1 = "False"
                else:
                    forward1 = "True"
                print "right motor reversed to", forward1
                motor.motor1(forward1)
            elif data == 'motor_stop':
                print 'motor stop'
                motor.stop()
            #---------------------------------

            #-------Turing calibration------
            elif data[0:7] == 'offset=':
                offset = int(data[7:])
                car_dir.calibrate(offset)
            #--------------------------------

            #----------Mount calibration---------
            elif data[0:8] == 'offsetx=':
                offset_x = int(data[8:])
                print 'Mount offset x', offset_x
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsety=':
                offset_y = int(data[8:])
                print 'Mount offset y', offset_y
                video_dir.calibrate(offset_x, offset_y)
            #----------------------------------------

            #-------Turing calibration 2------
            elif data[0:7] == 'offset+':
                offset = offset + int(data[7:])
                print 'Turning offset', offset
                car_dir.calibrate(offset)
            elif data[0:7] == 'offset-':
                offset = offset - int(data[7:])
                print 'Turning offset', offset
                car_dir.calibrate(offset)
            #--------------------------------

            #----------Mount calibration 2---------
            elif data[0:8] == 'offsetx+':
                offset_x = offset_x + int(data[8:])
                print 'Mount offset x', offset_x
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsetx-':
                offset_x = offset_x - int(data[8:])
                print 'Mount offset x', offset_x
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsety+':
                offset_y = offset_y + int(data[8:])
                print 'Mount offset y', offset_y
                video_dir.calibrate(offset_x, offset_y)
            elif data[0:8] == 'offsety-':
                offset_y = offset_y - int(data[8:])
                print 'Mount offset y', offset_y
                video_dir.calibrate(offset_x, offset_y)
            #----------------------------------------

            #----------Confirm--------------------
            elif data == 'confirm':
                config = 'offset_x = %s\noffset_y = %s\noffset = %s\nforward0 = %s\nforward1 = %s\n ' % (
                    offset_x, offset_y, offset, forward0, forward1)
                print ''
                print '*********************************'
                print ' You are setting config file to:'
                print '*********************************'
                print config
                print '*********************************'
                print ''
                fd = open('config', 'w')
                fd.write(config)
                fd.close()

                motor.stop()
                tcpCliSock.close()
                quit()
            else:
                print 'Command Error! Cannot recognize command: ' + data
Exemplo n.º 12
0
import motor
import car_dir
import time

motor.setup(busnum=1)
car_dir.setup()

motor.setSpeed(50)
motor.motor0('True')
motor.motor1('True')
t = time.time()

while time.time() < t + 1:
    pass

car_dir.turn_left()

while time.time() < t + 1.5:
    pass

car_dir.home()

while time.time() < t + 2.5:
    pass

motor.stop()
Exemplo n.º 13
0
 def backward(self, speed=50):
     """Similar to forward()"""
     motor.setSpeed(speed)
     motor.motor0('False')
     motor.motor1('False')
Exemplo n.º 14
0
 def forward(self, speed=50):
     """Will cause the car to start moving forward.
     Car will not stop until stop() is called"""
     motor.setSpeed(speed)
     motor.motor0('True')
     motor.motor1('True')