Пример #1
0
 def left(self):
     _grab_read()
     try:
         gopigo.left()
     except:
         pass
     _release_read()
Пример #2
0
 def left(self):
     _ifMutexAcquire(self.use_mutex)
     try:
         gopigo.left()
     except:
         pass
     finally:
         _ifMutexRelease(self.use_mutex)
Пример #3
0
 def left(self):
     _ifMutexAcquire(self.use_mutex)
     try:
         gopigo.left()
     except:
         pass
     finally:
         _ifMutexRelease(self.use_mutex)
Пример #4
0
def left_deg(deg=None):
    '''
    Turn chassis left by a specified number of degrees.
    DPR is the #deg/pulse (Deg:Pulse ratio)
    This function sets the encoder to the correct number
     of pulses and then invokes left().
    '''
    if deg is not None:
        pulse= int(deg/DPR)
        enc_tgt(0,1,pulse)
    left()
Пример #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!'
Пример #6
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!'
Пример #7
0
def bang_bang(linelocation):

    if (linelocation) < 300:
        go.left()
    elif (linelocation) > 300:
        go.right()
    else:
        go.forward()
    # This function should use the line location to implement a simple bang-bang controller.
    # YOUR CODE HERE

    return
Пример #8
0
def bang_bang_with_hysteresis(linelocation):

    higher = 320
    lower = 300
    if (linelocation) < higher:
        go.left()
    elif (linelocation) > lower:
        go.right()

    # This function should use the line location to implement bang-bang controller with hysteresis.
    # YOUR CODE HERE

    return
Пример #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()
Пример #10
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)
Пример #11
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()
Пример #12
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()
Пример #13
0
def left(aTicks):
    if checkTicks(aTicks):
        gpg.enc_tgt(0, 1, aTicks)
        gpg.left()
        waitForTarget()
 def left_button_OnButtonClick(self, event):
     f = gopigo.left()
Пример #15
0
def left(t):
    go.left()
    time.sleep(t)
    go.stop()
Пример #16
0
def left():
    print("Left!")
    gopigo.left()
    time.sleep(1)
    gopigo.stop()
    return render_template('left.html')
Пример #17
0
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)
Пример #18
0
def left():
    _wait_for_read()
    _grab_read()
    gopigo.left()
    _release_read()
Пример #19
0
def left():
    _wait_for_read()
    _grab_read()
    gopigo.left()
    _release_read()
Пример #20
0
def left():
    print("Left!")
    gopigo.left()
    time.sleep(1)
    gopigo.stop()
    return 'Left!'
Пример #21
0
def left():
	print("Left!")
	gopigo.left()
	time.sleep(1)
	gopigo.stop()
	return 'Left!'
Пример #22
0
def turn_left():
	if msg_en:
		print("Turn left")
	if gpg_en:
		gopigo.set_speed(turn_speed)
		gopigo.left()
Пример #23
0
def left():
    I2C_Mutex_Acquire()
    gopigo.left()
    I2C_Mutex_Release()
Пример #24
0
def turn_left():
	if msg_en:
		print "Turn left"
	if gpg_en:
		gopigo.set_speed(turn_speed)
		gopigo.left()
Пример #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 ""
Пример #26
0
import gopigo as gpg
import time
import time


gpg.forward()
time.sleep(10)
gpg.stop()
gpg.right()
time.sleep(1)
gpg.stop()
gpg.forward()
time.sleep(10)
gpg.stop()
gpg.left()
time.sleep(5)
gpg.stop()
gpg.forward()
time.sleep(5)
gpg.stop()
Пример #27
0
go.fwd()
go.led_on(0)
go.led_on(1)
time.sleep(1.9)
go.led_off(0)
go.led_off(1)
go.right()
go.led_on(0)
time.sleep(0.2)
go.fwd()
go.led_on(0)
go.led_on(1)
time.sleep(0.8)
go.led_off(0)
go.led_off(1)
go.left()
go.led_on(1)
time.sleep(0.8)

for i in range(4):
    go.right()
    go.led_on(0)
    time.sleep(0.1)
    go.fwd()
    go.led_on(0)
    go.led_on(1)
    time.sleep(0.2)
    go.led_off(0)
    go.led_off(1)

go.stop()
Пример #28
0
 def left_button_OnButtonClick(self,event):
     f=gopigo.left()
Пример #29
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()
Пример #30
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()
Пример #31
0
def left(kargs):
    r = {'return_value': gopigo.left()}
    return r