Exemple #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')
def go_backwards(backwards_distance):
	
	gopigo.enable_encoders()
	encoder_steps_required = int(backwards_distance / DISTANCE_PER_ENCODER_STEP)
	gopigo.set_speed(DEFAULT_ROBOT_SPEED)
	gopigo.enc_tgt(1, 1, encoder_steps_required)
	gopigo.bwd()
	wait_till_encoder_target_reached()
	RobotPosePrediction.currentRobotPose = RobotPosePrediction.getPredictedRobotPose(currentRobotPose = RobotPosePrediction.currentRobotPose, movementType = RobotPosePrediction.MOVEMENT_TYPE_FORWARD, movementAmount = -1 * encoder_steps_required * DISTANCE_PER_ENCODER_STEP)
	RobotPosePrediction.currentRobotLocationUncertainty = RobotPosePrediction.getPredictedRobotUncertainty(currentRobotLocationUncertainty = RobotPosePrediction.currentRobotLocationUncertainty, movementType = RobotPosePrediction.MOVEMENT_TYPE_FORWARD, movementAmount = -1 * encoder_steps_required * DISTANCE_PER_ENCODER_STEP, currentRobotPose = RobotPosePrediction.currentRobotPose)
Exemple #3
0
def bwd_cm(dist=None):
    '''
    Move chassis bwd by a specified number of cm.
    This function sets the encoder to the correct number
     of pulses and then invokes bwd().
    '''
    if dist is not None:
        pulse = int(cm2pulse(dist))
        enc_tgt(1,1,pulse)
    bwd()
Exemple #4
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!'
Exemple #5
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!'
Exemple #6
0
    def get(self):
        left = int(self.get_argument("left"))
        right = int(self.get_argument("right"))

        gopigo.set_left_speed(abs(left))
        gopigo.set_right_speed(abs(right))

        if (left > 0):
            gopigo.fwd()
        else:
            gopigo.bwd()
Exemple #7
0
    def main(self, motor1, motor2):
        """
        Takes in 2 ints and rotates accordingly
        """
        gopigo.set_left_speed(motor1)
        gopigo.set_right_speed(motor2)

        if motor1 >= 0 and motor2 >= 0:

            gopigo.fwd()
        else:
            gopigo.bwd()
Exemple #8
0
 def move(self, dist, how="F"):
     """this takes care of moving the robot.
     how can be
     F: which is forward, dist is in cm
     L: which is left (right motor on left motor off), dist is in degrees
     R: which is right (left motor on right motor off), dist is in degrees
     B: which is backward.  dist is in cm
     TL: rotate in place, to the left (tank steering) dist is in pulses
     TR: rotate in place, to the right (tank steering) dist is in pulses
     """
     if (dist < 30 and (how == "F" or how == "B")):
         #If dist <30 the robot will
         #try to move 0 distance which means go for ever. Bad news!
         return -1
     elif (dist < 8 and (how == "L" or how == "R")):
         #also the robot rotates for ever if the angle is less than 8
         return -1
     else:
         #take an initial record
         #self.recordEncoders()
         #save the current position because we're about to reset it
         #self.keyframe = self.timerecord[-1][:-1]
         #basically we are recording our position while moving.
         #prevtime = int(time.time())
         #go forward! this runs in the background pretty much
         if (how == "F"):
             go.fwd(dist)
         elif (how == "L"):
             go.turn_left(dist)
         elif (how == "R"):
             go.turn_right(dist)
         elif (how == "B"):
             go.bwd(dist)
         elif (how == "TR"):
             go.enc_tgt(0, 1, dist)
             go.right_rot()
         elif (how == "TL"):
             go.enc_tgt(0, 1, dist)
             go.left_rot()
         #record while we haven't reached our destination
         #while(go.read_enc_status()):
         #this resets both encoders so we start counting from zero!
         #this next part should only trigger once per recordFreq
         #if(time.time()-prevtime>self.recordFreq):
         #prevtime = time.time() #make sure to reset the timer...
         #tell the recordEncoders function which direction
         #we are going
         #dir = "forward"
         #if(how=="B"):
         #    dir = "backward"
         #self.recordEncoders(dir=dir)
         return 1
Exemple #9
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()
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
def go_backwards(backwards_distance):

    gopigo.enable_encoders()
    encoder_steps_required = int(backwards_distance /
                                 DISTANCE_PER_ENCODER_STEP)
    gopigo.set_speed(DEFAULT_ROBOT_SPEED)
    gopigo.enc_tgt(1, 1, encoder_steps_required)
    gopigo.bwd()
    wait_till_encoder_target_reached()
    RobotPosePrediction.currentRobotPose = RobotPosePrediction.getPredictedRobotPose(
        currentRobotPose=RobotPosePrediction.currentRobotPose,
        movementType=RobotPosePrediction.MOVEMENT_TYPE_FORWARD,
        movementAmount=-1 * encoder_steps_required * DISTANCE_PER_ENCODER_STEP)
    RobotPosePrediction.currentRobotLocationUncertainty = RobotPosePrediction.getPredictedRobotUncertainty(
        currentRobotLocationUncertainty=RobotPosePrediction.
        currentRobotLocationUncertainty,
        movementType=RobotPosePrediction.MOVEMENT_TYPE_FORWARD,
        movementAmount=-1 * encoder_steps_required * DISTANCE_PER_ENCODER_STEP,
        currentRobotPose=RobotPosePrediction.currentRobotPose)
Exemple #12
0
	def setMotorJoystickPos( self, joystickX, joystickY ):
		joystickX, joystickY = self.normaliseJoystickData( joystickX, joystickY )
		if debug:
			print( "Left joy",joystickX, joystickY)
		
		if joystickX > 0.5:
			print( "Right")
			gopigo.left(50)
		elif joystickX <-0.5:
			print ("Left")
			gopigo.right50
		elif joystickY > 0.5:
			print ("Fwd")
			gopigo.fwd(80)
		elif joystickY < -0.5:
			print ("Back")
			gopigo.bwd(80)
		else:
			print ("Stop")
			gopigo.fwd(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()
Exemple #14
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()
 def bwd_button_OnButtonClick(self,event):
     f=gopigo.bwd()  
 def bwd_button_OnButtonClick(self, event):
     f = gopigo.bwd()
Exemple #17
0
def back(aTicks):
    if checkTicks(aTicks):
        gpg.enc_tgt(1, 1, aTicks)
        gpg.bwd()
        waitForTarget()
Exemple #18
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!'
Exemple #19
0
def back_away():
	gopigo.set_speed(gopigo_speed)
	gopigo.bwd()
	time.sleep(10)
	gopigo.stop()
import gopigo
import time

# Assign pin 15 or A1 port to the IR sensor
gopigo.ir_recv_pin(15)
print "Press any button on the remote to control the GoPiGo"

while True:
	ir_data_back=gopigo.ir_read_signal()
	if ir_data_back[0]==-1:		#IO Error
		pass
	elif ir_data_back[0]==0:	#Old signal
		pass
	else:
		sig=ir_data_back[1:]		#Current signal from IR remote
		if sig[9]==82 and sig[10]==83:		#Assign the button with 82 and 83 in position 9 and 10 in the signal to forward command
			print "fwd"
			gopigo.fwd()
		elif sig[9]==114 and sig[10]==115:
			print "left"
			gopigo.left()
		elif sig[9]==242 and sig[10]==243:
			print "right"
			gopigo.right()
		elif sig[9]==210 and sig[10]==211:
			print "back"
			gopigo.bwd()
		elif sig[9]==43 and sig[10]==42:
			print "Stop"
			gopigo.stop()
	time.sleep(.1)
Exemple #21
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()
Exemple #22
0
    while 1:
        dataFromClient, address = server_socket.recvfrom(
            256)  # Receive data from client

        # Data is received as a bit stream, so it needs to be decoded first
        dataFromClient = dataFromClient.decode("utf-8").strip(
        )  # To avoid any errors in comparison when a line ending is appended

        print(dataFromClient)  # To see what is received

        if dataFromClient == 'F':
            print("fwd")
            go.fwd()

        elif dataFromClient == 'B':
            print("bwd")
            go.bwd()

        elif dataFromClient == 'S':
            print("stop")
            go.stop()
        # <-- You should implement the rest of the necessary commands!

finally:
    # Close the socket if any error occurs
    go.stop(
    )  # Make sure to always stop the robot if the server stops for any reason
    print("exiting")
    server_socket.close()
Exemple #23
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!'
 def bwd(dist):
     go.bwd(dist)
Exemple #25
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 ""
def go_back():
    if msg_en:
        print("Go Back")
    if gpg_en:
        gopigo.set_speed(turn_speed)
        gopigo.bwd()
Exemple #27
0
def bwd(kargs):
    r = {'return_value': gopigo.bwd()}
    return r
Exemple #28
0
def go_back():
	if msg_en:
		print "Go Back"
	if gpg_en:
		gopigo.set_speed(turn_speed)
		gopigo.bwd()
Exemple #29
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()
Exemple #30
0
def back_away():
    gopigo.set_speed(gopigo_speed)
    gopigo.bwd()
    time.sleep(10)
    gopigo.stop()