Пример #1
0
def backward():

    print("Backward!")
    gopigo.bwd()  # Send the GoPiGo Backward
    time.sleep(1)  # for 1 second
    gopigo.stop()  # and then stop the GoPiGo.
    return render_template('backward.html')
Пример #2
0
 def perform_obstalce_based_acceleratioin_determination(self, dt):
     if self.obstacle_distance <= self.critical_distance:
         gopigo.stop()
         self.stop = True
     elif self.obstacle_distance <= self.safe_distance:
         if self.obstacle_acceleration is not None:
             self.current_acceleration = (
                 (self.obstacle_distance - self.safe_distance) /
                 (dt * dt)) + self.obstacle_acceleration
         else:
             self.current_acceleration = (self.obstacle_distance -
                                          self.safe_distance) / (dt * dt)
     elif self.obstacle_distance <= self.alert_distance:
         if self.obstacle_acceleration is not None:
             comfort_parameter = dt / SLOWDOWN_TIME
             self.current_acceleration = \
                 comfort_parameter*(((self.obstacle_distance - self.safe_distance)/(dt*dt)) + self.obstacle_acceleration)
         else:
             comfort_parameter = dt / SLOWDOWN_TIME
             self.current_acceleration = comfort_parameter * (
                 (self.obstacle_distance - self.safe_distance) / (dt * dt))
     else:
         comfort_parameter = dt / SLOWDOWN_TIME
         current_speed = (self.current_speed_left +
                          self.current_speed_right) / 2.0
         self.current_acceleration = comfort_parameter * (
             (self.user_set_speed - current_speed) / dt)
def command_handler(Line_list):
    print(Line_list)
    for command in Line_list:
        print(command)
        if command == "Forward":
            curr = absolute_line_pos()
            while True:
                curr = absolute_line_pos()
                if curr == mid or curr == small_l1 or curr == small_l or curr == small_r or curr == small_r1:
                    run_gpg(curr)
                if curr == all_white:
                    gopigo.stop()
                    time.sleep(1)
                    temp = absolute_line_pos()
                    temp = absolute_line_pos()
                    if temp == all_white:
                        print("White found")
                        break
                    else:
                        gopigo.forward()
                if curr == all_black:
                    break
                print(curr)
        elif command == "Left":
            turn_left()
            time.sleep(1)
        elif command == "Right":
            turn_right()
            time.sleep(1)
        elif command == "Turn Around":
            turn_around()
            time.sleep(1)
Пример #4
0
    def _act(self, action):
        if not gopigo_available:
            return False

        # Translate to action.
        if action == MotorAction.TURN_LEFT:
            action_call = gopigo.left
        elif action == MotorAction.TURN_RIGHT:
            action_call = gopigo.right
        elif action == MotorAction.FORWARD:
            action_call = gopigo.fwd
        elif action == MotorAction.BACKWARD:
            action_call = gopigo.bwd
        elif action == MotorAction.IDLE:
            action_call = gopigo.stop
        else:
            action_call = None
        assert action_call is not None

        # Perform action for `duration` seconds and stop afterwards.
        logging.info('performing motor action %d' % action)
        action_call()
        time.sleep(self.duration)
        gopigo.stop()
        return True
Пример #5
0
def main():
    hedge = MarvelmindHedge(tty="/dev/ttyACM0", adr=10,
                            debug=False)  # create MarvelmindHedge thread
    hedge.start()  # start thread
    sleep(.1)
    start_pos = convert2D(hedge.position())
    print hedge.position()
    print start_pos
    new_pos = start_pos
    dst = 0.0
    gopigo.set_speed(100)
    gopigo.fwd()
    try:
        while (abs(dst) < 1):
            sleep(.1)
            new_pos = convert2D(hedge.position())
            hedge.print_position()
            dst = distance(start_pos, new_pos)
            print "start: ", start_pos
            print "current: ", new_pos
            print "distance: ", dst
    except KeyboardInterrupt:
        hedge.stop()  # stop and close serial port
        gopigo.stop()
        sys.exit()
    hedge.stop()
    gopigo.stop()
Пример #6
0
    def __init__(self, default_motor_speed=50):
        gopigo.set_speed(default_motor_speed)
        gopigo.stop()
        #gopigo.fwd()

        self.lastServoSettingsSendTime = 0.0
        self.lastUpdateTime = 0.0
        self.lastMotionCommandTime = time.time()
Пример #7
0
def rescue():
    gopigo.stop()
    print("Rescue")
    time.sleep(1)
    gopigo.set_left_speed(130)
    gopigo.set_right_speed(130)
    gopigo.fwd()
    time.sleep(0.2)
Пример #8
0
    def __init__(self):
        gopigo.set_speed(200)
        gopigo.stop()
        #gopigo.fwd()

        self.lastServoSettingsSendTime = 0.0
        self.lastUpdateTime = 0.0
        self.lastMotionCommandTime = time.time()
Пример #9
0
  def __init__(self,default_motor_speed=50):
    gopigo.set_speed(default_motor_speed)
    gopigo.stop()
    #gopigo.fwd()

    self.lastServoSettingsSendTime = 0.0
    self.lastUpdateTime = 0.0
    self.lastMotionCommandTime = time.time()
Пример #10
0
 def __init__( self ):
     gopigo.set_speed(200)
     gopigo.stop()
     #gopigo.fwd()
     
     self.lastServoSettingsSendTime = 0.0
     self.lastUpdateTime = 0.0
     self.lastMotionCommandTime = time.time()
Пример #11
0
    def post(self):
        data = self.reqparse.parse_args()
        #print(data)         # uncomment this line to see the raw joystick input

        if not self._process_left_thumbstick(data) and not self._process_dpad(data):
            # No input was given, stop the motor
            gopigo.stop()

        return {}, 200
Пример #12
0
    def __init__(self):
        gopigo.set_speed(200)
        gopigo.stop()
        #gopigo.fwd()

        self.lastServoSettingsSendTime = 0.0  #son servo ayarları gonderme suresi
        self.lastUpdateTime = 0.0  #son guncelleme zamanı
        self.lastMotionCommandTime = time.time(
        )  #son hareket komutunun geldiği zaman
Пример #13
0
def stop_until_safe_distance():
    gopigo.stop()
    dist = get_dist()
    while (isinstance(dist, str)
           and dist != NOTHING_FOUND) or dist < SAFE_DISTANCE:
        dist = get_dist()

    gopigo.set_speed(0)
    gopigo.fwd()
Пример #14
0
def oneRun():
    leftStart = gpg.enc_read(0)
    rightStart = gpg.enc_read(1)
    gpg.motor_fwd()
    sleep(2)
    stop()
    sleep(0.5)
    leftEnd = gpg.enc_read(0)
    rightEnd = gpg.enc_read(1)
    return (leftEnd - leftStart, rightEnd - rightStart)
Пример #15
0
    def post(self):
        data = self.reqparse.parse_args()
        #print(data)         # uncomment this line to see the raw joystick input

        if not self._process_left_thumbstick(data) and not self._process_dpad(
                data):
            # No input was given, stop the motor
            gopigo.stop()

        return {}, 200
Пример #16
0
def forwardTicks(distance, speed):
    distance = max(1, min(distance, 500))
    speed = max(50, min(speed, 200))
    
    leftTicks = distance
    rightTicks = distance
    right_speed = speed
    left_speed = speed
    set_left_speed(left_speed)
    set_right_speed(right_speed)
    leftStart = gpg.enc_read(0)
    rightStart = gpg.enc_read(1)
    leftTarget = leftStart + leftTicks
    rightTarget = rightStart + rightTicks
    isLeftMoving = False
    isRightMoving = False
    adjustment_interval = 1
    last_left_check = leftStart
    last_right_check = rightStart
    
    while(True):
        leftReading = gpg.enc_read(0)
        rightReading = gpg.enc_read(1)
        leftToEnd = leftTarget - leftReading
        rightToEnd = rightTarget - rightReading
        
        if leftReading >= leftTarget and rightReading >= rightTarget:
            gpg.stop()
            break
        elif leftReading < leftTarget and rightReading < rightTarget:
            new_left_speed = speed
            new_right_speed = speed
            
            if (leftToEnd > rightToEnd + 1):
                extraFactor = float(leftToEnd - rightToEnd) / leftToEnd
                extraFactor = max(0.02, min(0.15, extraFactor))
                new_left_speed = int(speed * (1.0 + extraFactor))
            elif (rightToEnd > leftToEnd + 1):
                extraFactor = float(rightToEnd - leftToEnd) / rightToEnd
                extraFactor = max(0.02, min(0.15, extraFactor))
                new_right_speed = int(speed * (1.0 + extraFactor))
            
            if (left_speed != new_left_speed):
                set_left_speed(new_left_speed)
                left_speed = new_left_speed
            if (right_speed != new_right_speed):
                set_right_speed(new_right_speed)
                right_speed = new_right_speed
            
            if (not isLeftMoving) or (not isRightMoving):
                print "Forward!"
                gpg.motor_fwd()
                isLeftMoving = True
                isRightMoving = True
Пример #17
0
def dance():
	print("Dance!")
	for each in range(0,5):
		gopigo.right()
		time.sleep(0.25)
		gopigo.left()
		time.sleep(0.25)
		gopigo.bwd()
		time.sleep(0.25)
	gopigo.stop()
	return 'Dance!'
Пример #18
0
def forward(step):
    if int(step) <= 20:
        print("Forward: " + str(step))
        gopigo.fwd()
        time.sleep(int(step) * 0.5)  # sleep for step * 0.5 second.
        gopigo.stop()
        return 'Bot moved forward!'
    else:
        error_message = "Invalid forward command or value is > 20"
        print(error_message)
        return error_message
Пример #19
0
def dance():
    print("Dance!")
    for each in range(0, 5):
        gopigo.right()
        time.sleep(0.25)
        gopigo.left()
        time.sleep(0.25)
        gopigo.bwd()
        time.sleep(0.25)
    gopigo.stop()
    return 'Dance!'
def run_gpg(curr):

    while True:
        atexit.register(gopigo.stop)
        dist = us_dist(15)
        last_val = curr
        curr = absolute_line_pos()

        #If an obstacle is detected, turn around
        #print("Dist:",dist,'cm')
        if dist < distance_to_stop:
            print("Stopping")
            gopigo.stop()
            ic.total_turn()
            ic.full_map()
            sys.exit()

        #if the line is in the middle, keep moving straight
        #if the line is slightly left of right, keep moving straight
        elif curr == mid:
            go_straight()

    #If the line is towards the slight left, turn slight right
        elif curr == small_l or curr == small_l1:
            turn_slight_right()

    #If the line is towards the large left, turn large right
        elif curr == large_l2:
            turn_fast_right()

    #If the line is towards the slight right, turn slight left
        elif curr == small_r or curr == small_r1:
            turn_slight_left()

    #If the line is towards the large right, turn large left
        elif curr == large_r2:
            turn_fast_left()

    #If the line is right or an intersection is detected, turn right
        elif curr == right0 or curr == right1 or curr == inter:
            turn_right()

    #If the line is left, turn left
        elif curr == left0 or curr == left1:
            turn_left()

    #If a dead end is detected, turn around
        elif curr == turn_a:
            turn_around()

        else:
            curr == absolute_line_pos()
Пример #21
0
def handleCommand(command, keyPosition, price=0):

    # only uses pressing down of keys
    if keyPosition != "down":
        return

    print("handle command", command, keyPosition)

    if command == 'L':
        gopigo.left_rot()
        time.sleep(0.15)
        gopigo.stop()
    if command == 'R':
        gopigo.right_rot()
        time.sleep(0.15)
        gopigo.stop()
    if command == 'F':
        gopigo.forward()
        time.sleep(0.4)
        gopigo.stop()
    if command == 'B':
        gopigo.backward()
        time.sleep(0.3)
        gopigo.stop()

    robot_util.handleSoundCommand(command, keyPosition, price)
Пример #22
0
    def __stop_until_safe_distance(self):
        """
        Stops the rover until it achieves a safe distance from the obstacle.
        This can occur when/if the obstacle moves away from the rover.
        """
        gopigo.stop()
        self.obstacle_distance = get_dist()
        while (isinstance(self.obstacle_distance, str) and
            self.obstacle_distance != NOTHING_FOUND) or \
            self.obstacle_distance < self.safe_distance:
            self.obstacle_distance = get_dist()

        gopigo.set_speed(0)
        gopigo.fwd()
Пример #23
0
    def turn_right(self):
        gopigo.set_right_speed(0)
        gopigo.set_left_speed(25)
        gopigo.forward()
        time.sleep(2)
        while True:

            self.read_position()
            self.read_position()
            self.read_position()
            pos = self.read_position()
            print(pos)
            debug(pos)
            if pos == "center":
                gopigo.stop()
                break
def turn_right():
    if msg_en:
        print("Turn right")
    if gpg_en:
        gopigo.enc_tgt(0, 1, 15)
        gopigo.fwd()
        time.sleep(.9)
        gopigo.stop()
        time.sleep(1)
        gopigo.set_speed(80)
        gopigo.enc_tgt(1, 1, 35)
        gopigo.right_rot()
        time.sleep(.7)
        gopigo.stop()
        time.sleep(1)
        curr = absolute_line_pos()
        ic.right_turns += 1
Пример #25
0
def process_command(_command, _time):
    data = _command
    if not data:
        print "received data:", data

    if len(data) != 1:
        print ("Invalid command")
        return "Invalid command"
    elif data == 'w':
        gopigo.fwd()
        # return "Moving forward"
    elif data == 'x':
        gopigo.stop()
        # return "Stopping"
    elif data == 's':
        gopigo.bwd()
        # return "Moving back"
    elif data == 'a':
        gopigo.left()
        # return "Turning left"
    elif data == 'd':
        gopigo.right()
        # return "Turning right"
    elif data == 't':
        gopigo.increase_speed()
        # return "Increase speed"
    elif data == 'g':
        gopigo.decrease_speed()
        # return "Decrease speed"
    elif data == 'v':
        # print gopigo.volt(), 'V'
        return str(gopigo.volt())
    elif data == 'l':
        gopigo.led_on(0)
        gopigo.led_on(1)
        time.sleep(1)
        gopigo.led_off(0)
        gopigo.led_off(1)
        return "Flash LED"
    else:
        print ("Invalid command")
        return "Invalid command"  # run as a app

    if _time:
        time.sleep(_time)
        gopigo.stop()
Пример #26
0
 def follow_line(self, fwd_speed = 80):
     slight_turn_speed=int(.7*fwd_speed)
     while True:
         pos = self.read_position()
         debug(pos)
         if pos == "center":
             gopigo.forward()
         elif pos == "left":
             gopigo.set_right_speed(0)
             gopigo.set_left_speed(slight_turn_speed)
         elif pos == "right":
             gopigo.set_right_speed(slight_turn_speed)
             gopigo.set_left_speed(0)
         elif pos == "black":
             gopigo.stop()
         elif pos == "white":
             gopigo.stop()
Пример #27
0
def main():
    # Sets the intitial speed to 0
    go.set_speed(0)

    # Sets the initial state to 0 = NORMAL
    state = STATE()

    # Program loop
    while True:
        try:
            stateCheck(state)

        # Shuts the ACC down when a Ctrl + c command is issued
        except KeyboardInterrupt:
            print '\nACC shut off'
            go.stop()
            sys.exit()
Пример #28
0
 def follow_line(self, fwd_speed = 80):
     slight_turn_speed=int(.7*fwd_speed)
     while True:
         pos = self.read_position()
         debug(pos)
         if pos == "center":
             gopigo.forward()
         elif pos == "left":
             gopigo.set_right_speed(0)
             gopigo.set_left_speed(slight_turn_speed)
         elif pos == "right":
             gopigo.set_right_speed(slight_turn_speed)
             gopigo.set_left_speed(0)
         elif pos == "black":
             gopigo.stop()
         elif pos == "white":
             gopigo.stop()
def turn_around():
    if msg_en:
        print("Turn around")

    if gpg_en:
        gopigo.bwd()
        curr = absolute_line_pos()
        gopigo.enc_tgt(0, 1, 5)
        gopigo.stop()
        time.sleep(.5)
        gopigo.set_speed(80)
        gopigo.enc_tgt(1, 1, 35)
        gopigo.left_rot()
        time.sleep(.7)
        gopigo.stop()
        time.sleep(1)
        curr = absolute_line_pos()
        ic.turn += 1
Пример #30
0
def around():
    gopigo.set_left_speed(250)
    gopigo.set_right_speed(250)
    gopigo.left_rot()
    time.sleep(1.30)
    while True:
        time.sleep(0.2)
        marker, t = aruco.get_result()
        if t > 0.01:
            break
        gopigo.stop()
        gopigo.set_left_speed(250)
        gopigo.set_right_speed(250)
        gopigo.left_rot()

        time.sleep(0.2)
    gopigo.stop()
    time.sleep(0.2)
Пример #31
0
    def turn_around(self):
        gopigo.set_right_speed(35)
        gopigo.set_left_speed(35)
        gopigo.backward()
        time.sleep(1)
        gopigo.stop()
        time.sleep(1)
        gopigo.left_rot()
        time.sleep(2)
        while True:

            self.read_position()
            self.read_position()
            pos = self.read_position()
            print(pos)
            debug(pos)
            if pos == "center":
                gopigo.stop()
                break
Пример #32
0
    def on_message(self, message):

        try:
            message = str(message)
        except Exception:
            logging.warning(
                "Got a message that couldn't be converted to a string")
            return

        if isinstance(message, str):

            lineData = message.split(" ")
            if len(lineData) > 0:

                if lineData[0] == "Centre":

                    if robot != None:
                        robot.centreNeck()

                elif lineData[0] == "StartStreaming":
                    cameraStreamer.startStreaming()

                elif lineData[0] == "Shutdown":
                    cameraStreamer.stopStreaming()
                    gopigo.stop()
                    robot.disconnect()
                    sys.exit()

                elif lineData[0] == "Move" and len(lineData) >= 3:

                    motorJoystickX, motorJoystickY = \
                        self.extractJoystickData( lineData[ 1 ], lineData[ 2 ] )

                    if robot != None:
                        robot.setMotorJoystickPos(motorJoystickX,
                                                  motorJoystickY)
                elif lineData[0] == "PanTilt" and len(lineData) >= 3:

                    neckJoystickX, neckJoystickY = \
                        self.extractJoystickData( lineData[ 1 ], lineData[ 2 ] )

                    if robot != None:
                        robot.setNeckJoystickPos(neckJoystickX, neckJoystickY)
Пример #33
0
 def back10(self):
     _grab_read()
     try:
         val = gopigo.backward()
         time.sleep(1)
         val = gopigo.stop()
     except Exception as e:
         print("easygopigo bwd: {}".format(e))
         pass
     _release_read()
Пример #34
0
    def __main(self):
        """
        Runs the main loop of the ACC.

        If an exception is thrown in the main loop or the ACC is killed via
        Ctrl+c then the rover is stopped in order to prevent a collision.
        """
        try:
            gopigo.set_speed(0)
            gopigo.fwd()

            self.t = time.time()
            while self.power_on:
                self.__update_system_info()

                self.__process_commands()

                dt = time.time() - self.t
                self.t = time.time()

                self.__observe_obstacle(dt)
                self.__calculate_relevant_distances(dt)
                self.__validate_user_settings()
                self.__obstacle_based_acceleration_determination(dt)

                # Reset the speed if it becomes negative
                if self.speed < 0:
                    self.speed = 0

                # Reset the speed if it goes below the minimum speed
                if self.user_set_speed < MIN_SPEED:
                    self.speed = 0

                l_diff, r_diff = self.__straightness_correction()

                self.__actualize_power(l_diff, r_diff)

        # Catch any exceptions that occur
        except (KeyboardInterrupt, Exception):
            traceback.print_exc()
            gopigo.stop()           # Stop to prevent a collision
        gopigo.stop()
Пример #35
0
def main():
    # Sets the intitial speed to 0
    go.set_speed(50)
    # Sets the initial encoder values
    encoders = Encoders(*read_encoders())

    # Sets the initial state to 0 = NORMAL
    state = STATE()

    # Program loop
    while True:
        try:
            calculateEncodersError(encoders)
            stateCheck(state)

        # Shuts the ACC down when a Ctrl + c command is issued
        except KeyboardInterrupt:
            print '\nACC shut off'
            go.stop()
            sys.exit()
Пример #36
0
    def on_message( self, message ):
                
        try:
            message = str( message )
        except Exception:
            logging.warning( "Got a message that couldn't be converted to a string" )
            return

        if isinstance( message, str ):
            
            lineData = message.split( " " )
            if len( lineData ) > 0:
                
                if lineData[ 0 ] == "Centre":
                
                    if robot != None:
                        robot.centreNeck()
                
                elif lineData[ 0 ] == "StartStreaming":
                    cameraStreamer.startStreaming()
                    
                elif lineData[ 0 ] == "Shutdown":
                    cameraStreamer.stopStreaming()
                    gopigo.stop()
                    robot.disconnect()
                    sys.exit()
                
                elif lineData[ 0 ] == "Move" and len( lineData ) >= 3:
                    
                    motorJoystickX, motorJoystickY = \
                        self.extractJoystickData( lineData[ 1 ], lineData[ 2 ] )
                    
                    if robot != None:
                        robot.setMotorJoystickPos( motorJoystickX, motorJoystickY )     
                elif lineData[ 0 ] == "PanTilt" and len( lineData ) >= 3:
                    
                    neckJoystickX, neckJoystickY = \
                        self.extractJoystickData( lineData[ 1 ], lineData[ 2 ] )
                        
                    if robot != None:
                        robot.setNeckJoystickPos( neckJoystickX, neckJoystickY )
Пример #37
0
 def setMotorJoystickPos(self, joystickX, joystickY):
     joystickX, joystickY = self.normaliseJoystickData(joystickX, joystickY)
     if debug:
         print("Left joy", joystickX, joystickY)
         #print self.speed_l*joystickY
     #gopigo.set_left_speed(int(self.speed_l*joystickY))
     #gopigo.fwd()
     if joystickX > .5:
         print("Left")
         gopigo.left()
     elif joystickX < -.5:
         print("Right")
         gopigo.right()
     elif joystickY > .5:
         print("Fwd")
         gopigo.fwd()
     elif joystickY < -.5:
         print("Back")
         gopigo.bwd()
     else:
         print("Stop")
         gopigo.stop()
Пример #38
0
    def setMotorJoystickPos( self, joystickX, joystickY ):
        joystickX, joystickY = self.normaliseJoystickData( joystickX, joystickY )
        if debug:
			print "Left joy",joystickX, joystickY
			#print self.speed_l*joystickY
        #gopigo.set_left_speed(int(self.speed_l*joystickY))
        #gopigo.fwd()
        if joystickX > .5:
			print "Left"
			gopigo.left()
        elif joystickX <-.5:
			print "Right"
			gopigo.right()
        elif joystickY > .5:
			print "Fwd"
			gopigo.fwd()
        elif joystickY < -.5:
			print "Back"
			gopigo.bwd()
        else:
			print "Stop"
			gopigo.stop()
Пример #39
0
def wait_for_button():
	gopigo.stop()
	while (gopigo.digitalRead(button_pin) != 1):
		try:
			time.sleep(.5)
		except IOError:
			print ("Error")
	print "Button pressed!"
	
	gopigo.set_speed(gopigo_speed)
	distance = 100
	while (distance > distance_from_body):
		try:
			distance = gopigo.us_dist(distance_sensor_pin)
			print ("Distance: " + str(distance))
			time.sleep(.1)
			gopigo.fwd()
		except IOError:
			print ("Error")
	
	gopigo.stop()
	
	sound("Hello!")
Пример #40
0
def do_turn(d):
    global turn_angle, compass

    gopigo.set_left_speed(210)
    gopigo.set_right_speed(210)
    time.sleep(0.1)

    compass.turn_c(d)
    if d == "left":
        gopigo.turn_left_wait_for_completion(turn_angle)
    elif d == "around":
        around()

        gopigo.stop()
    else:
        try:
            gopigo.turn_right_wait_for_completion(turn_angle)
        except TypeError:
            do_turn(d)

    time.sleep(0.1)
    gopigo.fwd()
    drive_forwards(0.5)
Пример #41
0
def wait_for_button():
    gopigo.stop()
    while (gopigo.digitalRead(button_pin) != 1):
        try:
            time.sleep(.5)
        except IOError:
            print("Error")
    print "Button pressed!"

    gopigo.set_speed(gopigo_speed)
    distance = 100
    while (distance > distance_from_body):
        try:
            distance = gopigo.us_dist(distance_sensor_pin)
            print("Distance: " + str(distance))
            time.sleep(.1)
            gopigo.fwd()
        except IOError:
            print("Error")

    gopigo.stop()

    sound("Hello!")
Пример #42
0
def main():
    go.set_speed(MIN_SPEED)

    INIT_LEFT_ENC, INIT_RIGHT_ENC = read_encoders()
    print('Left:    ', INIT_LEFT_ENC, ' Right:    ', INIT_RIGHT_ENC)
    time.sleep(5)

    go.forward()
    while True:
        try:
            if STATE == 3:
                go.stop()
            else:
                go.forward()
            print 'MOTORS: ', go.read_motor_speed()
            rs.rs(INIT_LEFT_ENC, INIT_RIGHT_ENC)
            stateCheck()

        # Shuts the ACC down when a Ctrl + c command is issued
        except KeyboardInterrupt:
            print '\nACC shut off'
            go.stop()
            sys.exit()
Пример #43
0
def stop_now():
	if msg_en:
		print "Stop"
	if gpg_en:
		gopigo.stop()
Пример #44
0
def stop(kargs):
    r = {'return_value': gopigo.stop()}
    return r
def cleanup():
    gopigo.stop()
    my_buzzer.sound_off()
Пример #46
0
 def stop(self):
     # no locking is required here
     try:
         gopigo.stop()
     except:
         pass
Пример #47
0
distance_from_body = 50	# Distance the GoPiGo will stop from the human body.
gopigo_speed = 150		# Power of the motors.  Increase or decrease depending on how fast you want to go.

import argparse
import urllib2
import base64
import picamera
import json
from subprocess import call
import time
import datetime
import gopigo

import atexit
atexit.register(gopigo.stop())	# If we exit, stop the motors

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

button_pin = gopigo.digitalPort				# Grove Button goes on D11
distance_sensor_pin = gopigo.analogPort		# Ultrasonic Sensor goes on A1

gopigo.pinMode(button_pin,"INPUT")


#Calls the Espeak TTS Engine to read aloud a sentence
# This function is going to read aloud some text over the speakers
def sound(spk):
	#	-ven+m7:	Male voice
	#  The variants are +m1 +m2 +m3 +m4 +m5 +m6 +m7 for male voices and +f1 +f2 +f3 +f4 which simulate female voices by using higher pitches. Other variants include +croak and +whisper.
Пример #48
0
def back_away():
	gopigo.set_speed(gopigo_speed)
	gopigo.bwd()
	time.sleep(10)
	gopigo.stop()
Пример #49
0
def do_command(command=None):
    logging.debug(command)
    if command in ["forward", "fwd"]:
        gopigo.fwd()
    elif command == "left":
        gopigo.left()
    elif command == "left_rot":
        gopigo.left_rot()
    elif command == "right":
        gopigo.right()
    elif command == "right_rot":
        gopigo.right_rot()
    elif command == "stop":
        gopigo.stop()
    elif command == "leftled_on":
        gopigo.led_on(0)
    elif command == "leftled_off":
        gopigo.led_off(0)
    elif command == "rightled_on":
        gopigo.led_on(1)
    elif command == "rightled_off":
        gopigo.led_off(1)
    elif command in ["back", "bwd"]:
        gopigo.bwd()
    elif command == "speed":
        logging.debug("speed")
        speed = flask.request.args.get("speed")
        logging.debug("speed:" + str(speed))
        if speed:
            logging.debug("in if speed")
            gopigo.set_speed(int(speed))
        left_speed = flask.request.args.get("left_speed")
        logging.debug("left_speed:" + str(left_speed))
        if left_speed:
            logging.debug("in if left_speed")
            gopigo.set_left_speed(int(left_speed))
        right_speed = flask.request.args.get("right_speed")
        logging.debug("right_speed:" + str(right_speed))
        if right_speed:
            logging.debug("in if right_speed")
            gopigo.set_right_speed(int(right_speed))
        speed_result = gopigo.read_motor_speed()
        logging.debug(speed_result)
        return flask.json.jsonify({"speed": speed_result, "right": speed_result[0], "left": speed_result[1]})
    elif command == "get_data":
        speed_result = gopigo.read_motor_speed()
        enc_right = gopigo.enc_read(0)
        enc_left = gopigo.enc_read(1)
        volt = gopigo.volt()
        timeout = gopigo.read_timeout_status()
        return flask.json.jsonify(
            {
                "speed": speed_result,
                "speed_right": speed_result[0],
                "speed_left": speed_result[1],
                "enc_right": enc_right,
                "enc_left": enc_left,
                "volt": volt,
                "timeout": timeout,
                "fw_ver": gopigo.fw_ver(),
            }
        )
    elif command in ["enc_tgt", "step"]:
        tgt = flask.request.args.get("tgt")
        direction = flask.request.args.get("dir")
        if tgt:
            gopigo.gopigo.enc_tgt(1, 1, int(tgt))
            if dir:
                if dir == "bwd":
                    gopigo.bwd()
                else:
                    gopigo.fwd()
            else:
                gopigo.fwd()
    return ""
Пример #50
0
def backward():
	print("Backward!")
	gopigo.bwd()	# Send the GoPiGo Backward
	time.sleep(1)	# for 1 second
	gopigo.stop()	# and then stop the GoPiGo.
	return 'Backward!'
Пример #51
0
def left():
	print("Left!")
	gopigo.left()
	time.sleep(1)
	gopigo.stop()
	return 'Left!'
Пример #52
0
def right():
	print("Right!")
	gopigo.right()
	time.sleep(1)
	gopigo.stop()
	return 'Right!'
Пример #53
0
    def process_command(self, command):
        parts = command.split("/")

        if parts[1] == "poll":
            print "poll"
            self.us_dist = gopigo.us_dist(usdist_pin)
            self.enc_status = gopigo.read_status()[0]
            self.volt = gopigo.volt()
            self.fw_ver = gopigo.fw_ver()
            self.trim = gopigo.trim_read() - 100

            if self.enc_status == 0:
                self.waitingOn = None
        elif parts[1] == "stop":
            gopigo.stop()
        elif parts[1] == "trim_write":
            gopigo.trim_write(int(parts[2]))
            self.trim = gopigo.trim_read()
        elif parts[1] == "trim_read":
            self.trim = gopigo.trim_read() - 100
        elif parts[1] == "set_speed":
            if parts[2] == "left":
                self.left_speed = int(parts[3])
            elif parts[2] == "right":
                self.right_speed = int(parts[3])
            else:
                self.right_speed = int(parts[3])
                self.left_speed = int(parts[3])
            gopigo.set_left_speed(self.left_speed)
            gopigo.set_right_speed(self.right_speed)
        elif parts[1] == "leds":
            val = 0
            if parts[3] == "on":
                val = 1
            elif parts[3] == "off":
                val = 0
            elif parts[3] == "toggle":
                val = -1

            if parts[2] == "right" or parts[2] == "both":
                if val >= 0:
                    self.ledr = val
                else:
                    self.ledr = 1 - self.ledr

            if parts[2] == "left" or parts[2] == "both":
                if val >= 0:
                    self.ledl = val
                else:
                    self.ledl = 1 - self.ledl

            gopigo.digitalWrite(ledr_pin, self.ledr)
            gopigo.digitalWrite(ledl_pin, self.ledl)
        elif parts[1] == "servo":
            gopigo.servo(int(parts[2]))
        elif parts[1] == "turn":
            self.waitingOn = parts[2]
            direction = parts[3]
            amount = int(parts[4])
            encleft = 0 if direction == "left" else 1
            encright = 1 if direction == "left" else 0
            gopigo.enable_encoders()
            gopigo.enc_tgt(encleft, encright, int(amount / DPR))
            if direction == "left":
                gopigo.left()
            else:
                gopigo.right()
        elif parts[1] == "move":
            self.waitingOn = int(parts[2])
            direction = parts[3]
            amount = int(parts[4])
            gopigo.enable_encoders()
            gopigo.enc_tgt(1, 1, amount)
            if direction == "backward":
                gopigo.bwd()
            else:
                gopigo.fwd()
        elif parts[1] == "beep":
            gopigo.analogWrite(buzzer_pin, self.beep_volume)
            time.sleep(self.beep_time)
            gopigo.analogWrite(buzzer_pin, 0)
        elif parts[1] == "reset_all":
            self.ledl = 0
            self.ledr = 0

            gopigo.digitalWrite(ledl_pin, self.ledl)
            gopigo.digitalWrite(ledr_pin, self.ledr)
            gopigo.analogWrite(buzzer_pin, 0)
#           gopigo.servo(90)
            gopigo.stop()
Пример #54
0
def stop():
    _wait_for_read()
    _grab_read()
    gopigo.stop()
    _release_read()
Пример #55
0
 def stop(self):
   gopigo.stop()
Пример #56
0
def forward():
	print("Forward!")
	gopigo.fwd()	# Send the GoPiGo Forward
	time.sleep(1)	# for 1 second.
	gopigo.stop()	# the stop the GoPiGo
	return 'Alexabot moved forward!'
Пример #57
0
	#Accept an incoming connection
	conn, addr = s.accept()
	
	print '\nConnection address:', addr
	while 1:
		#Check the data
		data = conn.recv(BUFFER_SIZE)
		if not data: break	
		print "received data:", data
		if len(data) <> 1:
			print ("Invalid command")
			conn.send("Invalid command")
		elif data=='f':
			gopigo.fwd()
			conn.send("Moving forward")
		elif data=='s':
			gopigo.stop()
			conn.send("Stopping")
		elif data=='b':
			gopigo.bwd()
			conn.send("Moving back")
		elif data=='l':
			gopigo.left()
			conn.send("Turning left")
		elif data=='r':
			gopigo.right()
			conn.send("Turning right")
		else:
			print ("Invalid command")
			conn.send("Invalid command")
	conn.close()
Пример #58
0
 def stop_button_OnButtonClick(self,event):
     f=gopigo.stop()