Example #1
0
def right_forward():
	turn.home()
	print("turn right")
	turn.turn_right()
	motor.forwardWithSpeed(spd=100)
	time.sleep(1)
	motor.stop()
	turn.home()
Example #2
0
def left_forward():
	print("turn left")
	turn.home()
	turn.turn_left()
	motor.forwardWithSpeed(spd=100)
	time.sleep(1)
	motor.stop()
	turn.home()
Example #3
0
 def forward(self, speed=None):
     if speed is None:
         motor.forward()
     else:
         motor.forwardWithSpeed(int(speed))
     return self.ack()
Example #4
0
def mover():
    #Init variables for the control loop
    counter = 1
    bDriving = False
    bEndLoops = False

    sRobotDirection = Direction()

    rospy.init_node('mover', anonymous=True)

    rospy.Subscriber("motioncommand", String,
                     sRobotDirection.direction_callback)

    scooper_dir.setup(busnum=busnum)
    car_dir.setup(busnum=busnum)

    # Initialize the Raspberry Pi GPIO connected to the DC motor.
    motor.setup(busnum=busnum)

    #video_dir.home_x_y()
    #scooper_dir.servo_test ()
    car_dir.home()

    # Loop to wait for received commands.
    while (bEndLoops == False):

        # Loop to perform movement controls while input received.
        while (bEndLoops == False):

            data = sRobotDirection.directionMsg

            # Analyze the command received and control the car accordingly.
            #doAction (data, counter)
            #counter += 1
            #print counter

            if not data:
                break

            if data == ctrl_cmd[0]:
                print 'ELFF WILL DRIVE'
                counter += 1
                print counter

                try:
                    spd = 20
                    #print "Moving forward with speed!"
                    motor.forwardWithSpeed(spd)
                except:
                    print 'Error speed =' + str(spd)

            elif data == ctrl_cmd[1]:
                print 'ELFF WILL REVERSE'
                counter += 1
                print counter

                try:
                    spd = 20
                    #print "Moving backward with speed!"
                    motor.backwardWithSpeed(spd)
                except:
                    print 'Error speed =' + str(spd)

            elif data == ctrl_cmd[2]:
                print 'ELFF WILL GO LEFT'
                counter += 1
                car_dir.turn_left()

            elif data == ctrl_cmd[3]:
                print 'ELFF WILL GO RIGHT'
                counter += 1
                car_dir.turn_right()

            elif data == ctrl_cmd[4]:
                print 'ELFF WILL SCOOP'

                scooper_dir.home_x_y()
                scooper_dir.doScoop()
                scooper_dir.home_x_y()

            # Used with publisher.py only as a debug method.
            elif data == ctrl_cmd[5]:
                print 'ELFF WILL RESET POSITION'
                scooper_dir.home_x_y()
                car_dir.home()
                motor.ctrl(0)

                bEndLoops = True

            elif data == ctrl_cmd[6]:
                print 'ELFF WILL STOP'
                counter += 1
                print counter
                try:
                    spd = 0
                    motor.forwardWithSpeed(spd)
                except:
                    print 'Error speed =' + str(spd)

            else:
                print 'Waiting to receive a command...'
Example #5
0
def forward():
	turn.home()
	print("go forward")
	motor.forwardWithSpeed(spd=100)
	time.sleep(1)
	motor.stop()
                    spd = 24
                motor.setSpeed(spd)
        elif data[0:5] == 'turn=':  #Turning Angle
            print('data =', data)
            angle = data.split('=')[1]
            try:
                angle = int(angle)
                car_dir.turn(angle)
            except:
                print('Error: angle =', angle)
        elif data[0:8] == 'forward=':
            print('data =', data)
            spd = data[8:]
            try:
                spd = int(spd)
                motor.forwardWithSpeed(spd)
            except:
                print('Error speed =', spd)
        elif data[0:9] == 'backward=':
            print('data =', data)
            spd = data.split('=')[1]
            try:
                spd = int(spd)
                motor.backwardWithSpeed(spd)
            except:
                print('ERROR, speed =', spd)
        else:
            print('Command Error! Cannot recognize command: ' + data)

tcpSerSock.close()
Example #7
0
    else:
        print(data)

    if '1' in re.findall('1', data):  #find voice1 command in burst data
        print('tts command received')
        motor.stop()
        print('tts speaching')
        tts_guide(corpus[0])
    elif '2' in re.findall('2', data):  #find voice2 command in burst data
        print('tts command received')
        motor.stop()
        print('tts speaching')
        tts_guide(corpus[1])

    if data == "Forward-Right":
        motor.forwardWithSpeed(70)
        car_dir.turn_right()
    elif data == "Forward-Left":
        motor.forwardWithSpeed(70)
        car_dir.turn_left()
        motor.forward()
    elif data == "Forward":
        car_dir.home()
        motor.forwardWithSpeed(70)
    elif data == "Home":
        car_dir.home()
        motor.stop()
    elif data == "Stop" or "Stop" in re.findall("Stop", data):
        motor.stop()

motor_socket.close()
    # 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 = ''
        data = tcpCliSock.recv(BUFSIZ)  # Receive data sent from the client.
        # Analyze the command received and control the car accordingly.
        if not data:
            break
        if data == ctrl_cmd[0]:
            print('motor moving forward')
            motor.forwardWithSpeed()
        elif data == ctrl_cmd[1]:
            print('recv backward cmd')
            motor.backwardWithSpeed()
        elif data == ctrl_cmd[2]:
            print('recv left cmd')
            car_dir.turn_left()
        elif data == ctrl_cmd[3]:
            print('recv right cmd')
            car_dir.turn_right()
        elif data == ctrl_cmd[6]:
            print('recv home cmd')
            car_dir.home()
        elif data == ctrl_cmd[4]:
            print('recv stop cmd')
            motor.ctrl(0)
Example #9
0
 def motor_run(self, speed=35):
     motor.forwardWithSpeed(speed)