예제 #1
0
	def __init__(self):
		self.menu_items = [ "Forward", "Backward", "Leftward", "Rightward", "Both Up", "Both Down", "L Up", "L Down", "R Up", "R Down", "D Both Up", "D Both Down", "D L Up", "D L Down", "D R Up", "D R Down", "Turn CW", "Turn CCW" ]
		self.selected = 0
		self.scroll_top = 0
		self.scroll_bot = 5
		master_cmd({"command":"stop_all_motors"})
		GPIO.add_event_detect(7, GPIO.BOTH, callback=self.btn_edge, bouncetime=250)
예제 #2
0
    def key(self, key):
        global scr
        if key == 2:
            return constants.SCR_MENU
        elif key == 0:
            if self.selected > 0:
                self.selected -= 1
                if self.selected < self.scroll_top:
                    self.scroll_top -= 1
                    self.scroll_bot -= 1
        elif key == 1:
            if self.selected < (len(self.menu_items) - 1):
                self.selected += 1
                if self.selected >= self.scroll_bot:
                    self.scroll_top += 1
                    self.scroll_bot += 1
        elif key == 3:
            if self.selected == 0:
                return constants.SCR_ROUTE
            elif self.selected == 1:
                return constants.SCR_MOTOR_TEST
            elif self.selected == 2:
                return constants.SCR_CALIBRATION
            elif self.selected == 3:
                return constants.SCR_DUMP_TH
            elif self.selected == 4:
                master_cmd({"command": "set_request"})

        return constants.SCR_NONE
예제 #3
0
	def key(self, key):
		global scr
		if key == 2:
			return constants.SCR_MENU
		elif key == 0:
			if self.selected > 0:
				self.selected -= 1
				if self.selected < self.scroll_top:
					self.scroll_top -= 1
					self.scroll_bot -= 1
		elif key == 1:
			if self.selected < (len(self.menu_items)-1):
				self.selected += 1
				if self.selected >= self.scroll_bot:
					self.scroll_top += 1
					self.scroll_bot += 1
		elif key == 3:
			if self.selected == 0:
				return constants.SCR_ROUTE
			elif self.selected == 1:
				return constants.SCR_MOTOR_TEST
			elif self.selected == 2:
				return constants.SCR_CALIBRATION
			elif self.selected == 3:
				return constants.SCR_DUMP_TH
			elif self.selected == 4:
				master_cmd({"command":"set_request"})

		return constants.SCR_NONE
예제 #4
0
	def key(self, key):
		global scr
		if key == 2:
			return constants.SCR_SETTINGS

		if self.distance > 0:
			if key == 3:
				master_cmd({"command":"write_config","name":"bin_height","value":self.distance});
				return constants.SCR_SETTINGS

		return constants.SCR_NONE
예제 #5
0
	def key(self, key):
		global scr
		if key == 2:
			return constants.SCR_SETTINGS

		if self.status == 0:
			if key == 1:
				if self.threshold > 0: self.threshold -= 5
			elif key == 0:
				if self.threshold < 100: self.threshold += 5
			elif key == 3:
				master_cmd({"command":"write_config","name":"threshold","value":self.threshold});
				return constants.SCR_SETTINGS

		return constants.SCR_NONE
예제 #6
0
 def __init__(self):
     self.menu_items = [
         "Forward", "Backward", "Leftward", "Rightward", "Both Up",
         "Both Down", "L Up", "L Down", "R Up", "R Down", "D Both Up",
         "D Both Down", "D L Up", "D L Down", "D R Up", "D R Down",
         "Turn CW", "Turn CCW"
     ]
     self.selected = 0
     self.scroll_top = 0
     self.scroll_bot = 5
     master_cmd({"command": "stop_all_motors"})
     GPIO.add_event_detect(7,
                           GPIO.BOTH,
                           callback=self.btn_edge,
                           bouncetime=250)
예제 #7
0
    def key(self, key):
        global scr
        if key == 2:
            return constants.SCR_SETTINGS

        if self.distance > 0:
            if key == 3:
                master_cmd({
                    "command": "write_config",
                    "name": "bin_height",
                    "value": self.distance
                })
                return constants.SCR_SETTINGS

        return constants.SCR_NONE
예제 #8
0
	def __init__(self):
		res = master_cmd({"command":"dump_config"})
		if res == "":
			self.status = -1
		else:
			self.status = 0
			self.threshold = int(res["threshold"])
예제 #9
0
	def __init__(self):
		self.previous_update = time()
		res = master_cmd({"command":"status"})
		if res == "":
			self.distance = -1
		else:
			self.distance = int(res["distance"])
예제 #10
0
 def __init__(self):
     self.previous_update = time()
     res = master_cmd({"command": "status"})
     if res == "":
         self.distance = -1
     else:
         self.distance = int(res["distance"])
예제 #11
0
 def __init__(self):
     res = master_cmd({"command": "dump_config"})
     if res == "":
         self.status = -1
     else:
         self.status = 0
         self.threshold = int(res["threshold"])
예제 #12
0
 def __init__(self):
     self.selected = 0
     res = master_cmd({"command": "dump_config"})
     if res == "":
         self.status = -1
     else:
         self.status = 0
         self.route = res["route"]
         self.build_menu()
예제 #13
0
    def key(self, key):
        global scr
        if key == 2:
            return constants.SCR_SETTINGS

        if self.status == 0:
            if key == 1:
                if self.threshold > 0: self.threshold -= 5
            elif key == 0:
                if self.threshold < 100: self.threshold += 5
            elif key == 3:
                master_cmd({
                    "command": "write_config",
                    "name": "threshold",
                    "value": self.threshold
                })
                return constants.SCR_SETTINGS

        return constants.SCR_NONE
예제 #14
0
    def render(self, draw):
        draw.rectangle((0, 0, 128, 64), outline=0, fill=0)
        draw.text((20, 0),
                  strftime("%Y-%m-%d %H:%M:%S"),
                  fill=255,
                  font=font_time)
        draw.line([(0, 12), (128, 12)], fill=255, width=1)

        if (time() - self.previous_update) < 1:
            if self.status == -1:
                draw.text((0, 28),
                          "Can't connect to master",
                          fill=255,
                          font=font)
                draw.text((0, 38), "Retrying..", fill=255, font=font)
                return
            elif self.status == 0:
                draw.text((13, 28), "Idle", fill=255, font=font_status)
            elif self.status == 1:
                draw.text((13, 28), "Move", fill=255, font=font_status)
            elif self.status == 2:
                draw.text((13, 28), "Dump", fill=255, font=font_status)

            draw.bitmap((80, 15), trashcan, fill=255)
            draw.text((45, 50 - (35 * self.level / 100)),
                      ("{0:g}".format(self.level) + "% -").rjust(6, " "),
                      fill=255,
                      font=font)
            return

        self.previous_update = time()

        res = master_cmd({"command": "status"})

        if res == "":
            draw.text((0, 28), "Can't connect to master", fill=255, font=font)
            draw.text((0, 38), "Retrying..", fill=255, font=font)
            self.status = -1
        else:
            self.status = res["status"]
            self.level = res["level"]
            if res["status"] == 0:
                draw.text((13, 28), "Idle", fill=255, font=font_status)
            elif res["status"] == 1:
                draw.text((13, 28), "Move", fill=255, font=font_status)
            elif res["status"] == 2:
                draw.text((13, 28), "Dump", fill=255, font=font_status)

            draw.bitmap((80, 15), trashcan, fill=255)
            draw.text((45, 50 - (35 * res["level"] / 100)),
                      ("{0:g}".format(res["level"]) + "% -").rjust(6, " "),
                      fill=255,
                      font=font)
예제 #15
0
	def render(self, draw):
		draw.rectangle((0, 0, 128, 64), outline=0, fill=0)
		draw.text((0, 0), "Calibration", fill=255, font=font_status)
		if (time() - self.previous_update) > 1:
			self.previous_update = time()
			res = master_cmd({"command":"status"})
			if res == "":
				self.distance = -1
			else:
				self.distance = int(res["distance"])

		if self.distance == -1:
			draw.text((0, 28), "Can't connect to master", fill=255, font=font)
			draw.text((0, 38), "Retrying..", fill=255, font=font)
		else:
			draw.text((52, 20), ("{0:g}".format(self.distance) + " cm"), fill=255, font=font_status)
예제 #16
0
    def render(self, draw):
        draw.rectangle((0, 0, 128, 64), outline=0, fill=0)
        draw.text((0, 0), "Calibration", fill=255, font=font_status)
        if (time() - self.previous_update) > 1:
            self.previous_update = time()
            res = master_cmd({"command": "status"})
            if res == "":
                self.distance = -1
            else:
                self.distance = int(res["distance"])

        if self.distance == -1:
            draw.text((0, 28), "Can't connect to master", fill=255, font=font)
            draw.text((0, 38), "Retrying..", fill=255, font=font)
        else:
            draw.text((52, 20), ("{0:g}".format(self.distance) + " cm"),
                      fill=255,
                      font=font_status)
예제 #17
0
	def render(self, draw):
		draw.rectangle((0, 0, 128, 64), outline=0, fill=0)
		draw.text((20, 0), strftime("%Y-%m-%d %H:%M:%S"), fill=255, font=font_time)
		draw.line([(0, 12), (128, 12)], fill=255, width=1)

		if (time() - self.previous_update) < 1:
			if self.status == -1:
				draw.text((0, 28), "Can't connect to master", fill=255, font=font)
				draw.text((0, 38), "Retrying..", fill=255, font=font)
				return
			elif self.status == 0:
				draw.text((13, 28), "Idle", fill=255, font=font_status)
			elif self.status == 1:
				draw.text((13, 28), "Move", fill=255, font=font_status)
			elif self.status == 2:
				draw.text((13, 28), "Dump", fill=255, font=font_status)
			
			draw.bitmap((80, 15), trashcan, fill=255)
			draw.text((45, 50-(35*self.level/100)), ("{0:g}".format(self.level) + "% -").rjust(6, " "), fill=255, font=font)
			return

		self.previous_update = time()

		res = master_cmd({"command":"status"})

		if res == "":
			draw.text((0, 28), "Can't connect to master", fill=255, font=font)
			draw.text((0, 38), "Retrying..", fill=255, font=font)
			self.status = -1
		else:
			self.status = res["status"]
			self.level = res["level"]
			if res["status"] == 0:
				draw.text((13, 28), "Idle", fill=255, font=font_status)
			elif res["status"] == 1:
				draw.text((13, 28), "Move", fill=255, font=font_status)
			elif res["status"] == 2:
				draw.text((13, 28), "Dump", fill=255, font=font_status)

			draw.bitmap((80, 15), trashcan, fill=255)
			draw.text((45, 50-(35*res["level"]/100)), ("{0:g}".format(res["level"]) + "% -").rjust(6, " "), fill=255, font=font)
예제 #18
0
import RPi.GPIO as GPIO
from comms import master_cmd
from time import sleep

from constants import hall_scalar

master_cmd({"command": "stop_all_motors"})

current_distance = 0
mode = 0


def move_hall_edge(channel):
    global current_distance, mode
    if mode == 0:
        print current_distance
        current_distance += hall_scalar[0]
    else:
        print current_distance
        current_distance += hall_scalar[1]


GPIO.setmode(GPIO.BOARD)

GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)

GPIO.remove_event_detect(16)
GPIO.remove_event_detect(18)
예제 #19
0
	def btn_edge(self, channel):
		if GPIO.input(7):
			print "Released!"
			master_cmd({"command":"stop_all_motors"})
		else:
			if self.selected == 0:
				master_cmd({"command":"motor","motor":2,"direction":1})
				master_cmd({"command":"motor","motor":3,"direction":1})
			elif self.selected == 1:
				master_cmd({"command":"motor","motor":2,"direction":-1})
				master_cmd({"command":"motor","motor":3,"direction":-1})
			elif self.selected == 2:
				master_cmd({"command":"motor","motor":0,"direction":1})
				master_cmd({"command":"motor","motor":1,"direction":1})
			elif self.selected == 3:
				master_cmd({"command":"motor","motor":0,"direction":-1})
				master_cmd({"command":"motor","motor":1,"direction":-1})
			elif self.selected == 4:
				master_cmd({"command":"motor","motor":4,"direction":1})
				master_cmd({"command":"motor","motor":5,"direction":1})
			elif self.selected == 5:
				master_cmd({"command":"motor","motor":4,"direction":-1})
				master_cmd({"command":"motor","motor":5,"direction":-1})
			elif self.selected == 6:
				master_cmd({"command":"motor","motor":4,"direction":1})
			elif self.selected == 7:
				master_cmd({"command":"motor","motor":4,"direction":-1})
			elif self.selected == 8:
				master_cmd({"command":"motor","motor":5,"direction":1})
			elif self.selected == 9:
				master_cmd({"command":"motor","motor":5,"direction":-1})
			elif self.selected == 10:
				master_cmd({"command":"motor","motor":6,"direction":1})
				master_cmd({"command":"motor","motor":7,"direction":1})
			elif self.selected == 11:
				master_cmd({"command":"motor","motor":6,"direction":-1})
				master_cmd({"command":"motor","motor":7,"direction":-1})
			elif self.selected == 12:
				master_cmd({"command":"motor","motor":6,"direction":1})
			elif self.selected == 13:
				master_cmd({"command":"motor","motor":6,"direction":-1})
			elif self.selected == 14:
				master_cmd({"command":"motor","motor":7,"direction":1})
			elif self.selected == 15:
				master_cmd({"command":"motor","motor":7,"direction":-1})
			elif self.selected == 16:
				master_cmd({"command":"motor","motor":2,"direction":1})
				master_cmd({"command":"motor","motor":3,"direction":-1})
			elif self.selected == 17:
				master_cmd({"command":"motor","motor":2,"direction":-1})
				master_cmd({"command":"motor","motor":3,"direction":1})
예제 #20
0
				mcp.output(i*2, GPIO.LOW)
				mcp.output(i*2+1, GPIO.HIGH)
			else:
				pca.set_pwm(i*2, 0, 0)
				pca.set_pwm(i*2+1, 0, 4095)
		else:
			if i < 4:
				mcp.output(i*2, GPIO.HIGH)
				mcp.output(i*2+1, GPIO.LOW)
			else:
				pca.set_pwm(i*2, 0, 4095)
				pca.set_pwm(i*2+1, 0, 0)
	else:
		stop(i)

stop_all()

motors = [0, 0, 0, 0, 0, 0, 0, 0]

while True:
	sleep(0.1)
	resp = master_cmd({"command":"get_motors"})
	if resp["status"] != "ok": continue

	new_motors = resp["motors"]
	for i in range(8):
		if not motors[i] == new_motors[i]:
			print "move motor" + str(i)
			move(i, new_motors[i])
			motors[i] = new_motors[i]
예제 #21
0
import RPi.GPIO as GPIO
from comms import master_cmd
from time import sleep

from constants import hall_scalar

master_cmd({"command":"stop_all_motors"})

current_distance = 0
mode = 0

def move_hall_edge(channel):
	global current_distance, mode
	if mode == 0:
		print current_distance
		current_distance += hall_scalar[0]
	else:
		print current_distance
		current_distance += hall_scalar[1]

GPIO.setmode(GPIO.BOARD)

GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)

GPIO.remove_event_detect(16)
GPIO.remove_event_detect(18)
GPIO.add_event_detect(16, GPIO.BOTH, callback=move_hall_edge, bouncetime=5)
GPIO.add_event_detect(18, GPIO.BOTH, callback=move_hall_edge, bouncetime=5)
예제 #22
0
def full_route():
    global current_distance, mode
    resp = master_cmd({"command": "dump_config"})
    route = resp["route"]
    master_cmd({"command": "set_status", "status": 1})

    GPIO.output(23, GPIO.HIGH)
    sleep(0.4)
    GPIO.output(23, GPIO.LOW)

    # 1> MOVE
    for seg in route:
        current_distance = 0
        print "Move - " + str(seg)
        if seg["direction"] == 0:
            mode = 0
            master_cmd({"command": "motor", "motor": 2, "direction": 1})
            master_cmd({"command": "motor", "motor": 3, "direction": 1})
        elif seg["direction"] == 1:
            mode = 1
            master_cmd({"command": "motor", "motor": 2, "direction": 1})
            master_cmd({"command": "motor", "motor": 3, "direction": -1})

        while (current_distance + 7) < seg["distance"]:
            sleep(0.1)

        master_cmd({"command": "stop_all_motors"})
        sleep(1)

    master_cmd({"command": "set_status", "status": 2})

    # 2> LIFT
    master_cmd({"command": "motor", "motor": 4, "direction": 1})
    master_cmd({"command": "motor", "motor": 5, "direction": 1})
    while GPIO.input(24):
        sleep(0.1)

    master_cmd({"command": "motor", "motor": 4, "direction": -1})
    master_cmd({"command": "motor", "motor": 5, "direction": -1})
    while not GPIO.input(24):
        sleep(0.05)

    master_cmd({"command": "stop_all_motors"})

    # 3> DUMP
    master_cmd({"command": "motor", "motor": 6, "direction": -1})
    master_cmd({"command": "motor", "motor": 7, "direction": -1})

    sleep(2.9)

    master_cmd({"command": "stop_all_motors"})

    sleep(1)

    master_cmd({"command": "motor", "motor": 6, "direction": 1})
    master_cmd({"command": "motor", "motor": 7, "direction": 1})

    sleep(2.9)

    master_cmd({"command": "stop_all_motors"})

    # 4> DOWN
    master_cmd({"command": "motor", "motor": 4, "direction": -1})
    master_cmd({"command": "motor", "motor": 5, "direction": -1})
    while GPIO.input(26):
        sleep(0.1)

    master_cmd({"command": "motor", "motor": 4, "direction": 1})
    master_cmd({"command": "motor", "motor": 5, "direction": 1})
    while not GPIO.input(26):
        sleep(0.05)

    master_cmd({"command": "stop_all_motors"})
    master_cmd({"command": "set_status", "status": 1})

    # 5> TURN AROUND
    print "5"

    current_distance = 0
    mode = 1
    around_distance = 180
    if len(route) > 0:
        if route[-1]["direction"] == 1 and route[-1]["distance"] < 180:
            around_distance = 180 - route[-1]["distance"]
            route.pop()

    master_cmd({"command": "motor", "motor": 2, "direction": 1})
    master_cmd({"command": "motor", "motor": 3, "direction": -1})
    while (current_distance + 7) < around_distance:
        sleep(0.1)

    master_cmd({"command": "stop_all_motors"})

    sleep(1)

    # 6> GO BACK
    print "6"
    for seg in route:
        current_distance = 0
        print "Move - " + str(seg)
        if seg["direction"] == 0:
            mode = 0
            master_cmd({"command": "motor", "motor": 2, "direction": 1})
            master_cmd({"command": "motor", "motor": 3, "direction": 1})
        elif seg["direction"] == 1:
            seg["distance"] = 360 - seg["distance"]
            mode = 1
            master_cmd({"command": "motor", "motor": 2, "direction": 1})
            master_cmd({"command": "motor", "motor": 3, "direction": -1})

        while (current_distance + 7) < seg["distance"]:
            sleep(0.1)

        master_cmd({"command": "stop_all_motors"})
        sleep(1)

    # 7> TURN AROUND AGAIN

    current_distance = 0
    mode = 1
    around_distance = 180

    master_cmd({"command": "motor", "motor": 2, "direction": 1})
    master_cmd({"command": "motor", "motor": 3, "direction": -1})
    while (current_distance + 7) < around_distance:
        sleep(0.1)

    master_cmd({"command": "stop_all_motors"})

    print "Completed!"

    for i in range(3):
        GPIO.output(23, GPIO.HIGH)
        sleep(0.15)
        GPIO.output(23, GPIO.LOW)
        sleep(0.15)

    master_cmd({"command": "set_status", "status": 0})
    pass
예제 #23
0
from comms import master_cmd
from time import sleep
from constants import hall_scalar

import RPi.GPIO as GPIO

master_cmd({"command": "set_status", "status": 0})
master_cmd({"command": "stop_all_motors"})

current_distance = 0
mode = 0


def move_hall_edge(channel):
    global current_distance, mode
    if mode == 0:
        print current_distance
        current_distance += hall_scalar[0]
    else:
        print current_distance
        current_distance += hall_scalar[1]


def full_route():
    global current_distance, mode
    resp = master_cmd({"command": "dump_config"})
    route = resp["route"]
    master_cmd({"command": "set_status", "status": 1})

    GPIO.output(23, GPIO.HIGH)
    sleep(0.4)
예제 #24
0
def full_route():
	global current_distance, mode
	resp = master_cmd({"command":"dump_config"})
	route = resp["route"]
	master_cmd({"command":"set_status","status":1})

	GPIO.output(23, GPIO.HIGH)
	sleep(0.4)
	GPIO.output(23, GPIO.LOW)

	# 1> MOVE
	for seg in route:
		current_distance = 0
		print "Move - " + str(seg)
		if seg["direction"] == 0:
			mode = 0
			master_cmd({"command":"motor","motor":2,"direction":1})
			master_cmd({"command":"motor","motor":3,"direction":1})
		elif seg["direction"] == 1:
			mode = 1
			master_cmd({"command":"motor","motor":2,"direction":1})
			master_cmd({"command":"motor","motor":3,"direction":-1})

		while (current_distance + 7) < seg["distance"]:
			sleep(0.1)

		master_cmd({"command":"stop_all_motors"})
		sleep(1)

	master_cmd({"command":"set_status","status":2})

	# 2> LIFT
	master_cmd({"command":"motor","motor":4,"direction":1})
	master_cmd({"command":"motor","motor":5,"direction":1})
	while GPIO.input(24):
		sleep(0.1)

	master_cmd({"command":"motor","motor":4,"direction":-1})
	master_cmd({"command":"motor","motor":5,"direction":-1})
	while not GPIO.input(24):
		sleep(0.05)

	master_cmd({"command":"stop_all_motors"})

	# 3> DUMP
	master_cmd({"command":"motor","motor":6,"direction":-1})
	master_cmd({"command":"motor","motor":7,"direction":-1})

	sleep(2.9)

	master_cmd({"command":"stop_all_motors"})

	sleep(1)

	master_cmd({"command":"motor","motor":6,"direction":1})
	master_cmd({"command":"motor","motor":7,"direction":1})

	sleep(2.9)

	master_cmd({"command":"stop_all_motors"})

	# 4> DOWN
	master_cmd({"command":"motor","motor":4,"direction":-1})
	master_cmd({"command":"motor","motor":5,"direction":-1})
	while GPIO.input(26):
		sleep(0.1)

	master_cmd({"command":"motor","motor":4,"direction":1})
	master_cmd({"command":"motor","motor":5,"direction":1})
	while not GPIO.input(26):
		sleep(0.05)

	master_cmd({"command":"stop_all_motors"})
	master_cmd({"command":"set_status","status":1})

	# 5> TURN AROUND
	print "5"

	current_distance = 0
	mode = 1
	around_distance = 180
	if len(route) > 0:
		if route[-1]["direction"] == 1 and route[-1]["distance"] < 180:
			around_distance = 180 - route[-1]["distance"]
			route.pop()

	master_cmd({"command":"motor","motor":2,"direction":1})
	master_cmd({"command":"motor","motor":3,"direction":-1})
	while (current_distance + 7) < around_distance:
		sleep(0.1)

	master_cmd({"command":"stop_all_motors"})

	sleep(1)


	# 6> GO BACK
	print "6"
	for seg in route:
		current_distance = 0
		print "Move - " + str(seg)
		if seg["direction"] == 0:
			mode = 0
			master_cmd({"command":"motor","motor":2,"direction":1})
			master_cmd({"command":"motor","motor":3,"direction":1})
		elif seg["direction"] == 1:
			seg["distance"] = 360 - seg["distance"]
			mode = 1
			master_cmd({"command":"motor","motor":2,"direction":1})
			master_cmd({"command":"motor","motor":3,"direction":-1})

		while (current_distance + 7) < seg["distance"]:
			sleep(0.1)

		master_cmd({"command":"stop_all_motors"})
		sleep(1)

	# 7> TURN AROUND AGAIN

	current_distance = 0
	mode = 1
	around_distance = 180

	master_cmd({"command":"motor","motor":2,"direction":1})
	master_cmd({"command":"motor","motor":3,"direction":-1})
	while (current_distance + 7) < around_distance:
		sleep(0.1)


	master_cmd({"command":"stop_all_motors"})

	print "Completed!"

	for i in range(3):
		GPIO.output(23, GPIO.HIGH)
		sleep(0.15)
		GPIO.output(23, GPIO.LOW)
		sleep(0.15)
		
	master_cmd({"command":"set_status","status":0})
	pass
예제 #25
0
from comms import master_cmd
from time import sleep
from constants import hall_scalar

import RPi.GPIO as GPIO

master_cmd({"command":"set_status","status":0})
master_cmd({"command":"stop_all_motors"})

current_distance = 0
mode = 0

def move_hall_edge(channel):
	global current_distance, mode
	if mode == 0:
		print current_distance
		current_distance += hall_scalar[0]
	else:
		print current_distance
		current_distance += hall_scalar[1]

def full_route():
	global current_distance, mode
	resp = master_cmd({"command":"dump_config"})
	route = resp["route"]
	master_cmd({"command":"set_status","status":1})

	GPIO.output(23, GPIO.HIGH)
	sleep(0.4)
	GPIO.output(23, GPIO.LOW)
예제 #26
0
    def key(self, key):
        if self.status == -1:
            if key == 2:
                return constants.SCR_SETTINGS
            else:
                return constants.SCR_NONE
        elif self.status == 0:
            if key == 0:
                if self.selected > 0:
                    self.selected -= 1
                    if self.selected < self.scroll_top:
                        self.scroll_bot -= 1
                        self.scroll_top -= 1
                return constants.SCR_NONE
            elif key == 1:
                if self.selected < (len(self.list_items) - 1):
                    self.selected += 1
                    if self.selected >= self.scroll_bot:
                        self.scroll_bot += 1
                        self.scroll_top += 1
                return constants.SCR_NONE
            elif key == 2:
                return constants.SCR_SETTINGS
            else:
                if self.selected == (len(self.list_items) - 1):
                    master_cmd({
                        "command": "write_config",
                        "name": "route",
                        "value": self.route
                    })
                    return constants.SCR_SETTINGS
                elif self.selected == (len(self.list_items) - 2):
                    self.temp_segment = {"direction": 0, "distance": 0}
                    self.status = 1
                    return constants.SCR_NONE
                else:
                    self.status = 3
                    return constants.SCR_NONE
        elif self.status == 1:
            if key == 1:
                self.temp_segment["direction"] -= 1
                if self.temp_segment["direction"] < 0:
                    self.temp_segment["direction"] = 1
            elif key == 0:
                self.temp_segment["direction"] += 1
                if self.temp_segment["direction"] > 1:
                    self.temp_segment["direction"] = 0
            elif key == 2:
                self.status = 0
            else:
                self.status = 2
            return constants.SCR_NONE
        elif self.status == 2:
            if key == 1:
                if self.temp_segment["distance"] > 0:
                    self.temp_segment["distance"] -= 5
            elif key == 0:
                self.temp_segment["distance"] += 5
            elif key == 2:
                self.status = 1
            else:
                self.route.append(self.temp_segment)
                self.build_menu()
                self.status = 0
            return constants.SCR_NONE
        elif self.status == 3:
            if key == 2:
                self.status = 0
            elif key == 3:
                self.route.pop(self.selected)
                self.build_menu()
                self.status = 0

            return constants.SCR_NONE

        return constants.SCR_NONE
예제 #27
0
 def btn_edge(self, channel):
     if GPIO.input(7):
         print "Released!"
         master_cmd({"command": "stop_all_motors"})
     else:
         if self.selected == 0:
             master_cmd({"command": "motor", "motor": 2, "direction": 1})
             master_cmd({"command": "motor", "motor": 3, "direction": 1})
         elif self.selected == 1:
             master_cmd({"command": "motor", "motor": 2, "direction": -1})
             master_cmd({"command": "motor", "motor": 3, "direction": -1})
         elif self.selected == 2:
             master_cmd({"command": "motor", "motor": 0, "direction": 1})
             master_cmd({"command": "motor", "motor": 1, "direction": 1})
         elif self.selected == 3:
             master_cmd({"command": "motor", "motor": 0, "direction": -1})
             master_cmd({"command": "motor", "motor": 1, "direction": -1})
         elif self.selected == 4:
             master_cmd({"command": "motor", "motor": 4, "direction": 1})
             master_cmd({"command": "motor", "motor": 5, "direction": 1})
         elif self.selected == 5:
             master_cmd({"command": "motor", "motor": 4, "direction": -1})
             master_cmd({"command": "motor", "motor": 5, "direction": -1})
         elif self.selected == 6:
             master_cmd({"command": "motor", "motor": 4, "direction": 1})
         elif self.selected == 7:
             master_cmd({"command": "motor", "motor": 4, "direction": -1})
         elif self.selected == 8:
             master_cmd({"command": "motor", "motor": 5, "direction": 1})
         elif self.selected == 9:
             master_cmd({"command": "motor", "motor": 5, "direction": -1})
         elif self.selected == 10:
             master_cmd({"command": "motor", "motor": 6, "direction": 1})
             master_cmd({"command": "motor", "motor": 7, "direction": 1})
         elif self.selected == 11:
             master_cmd({"command": "motor", "motor": 6, "direction": -1})
             master_cmd({"command": "motor", "motor": 7, "direction": -1})
         elif self.selected == 12:
             master_cmd({"command": "motor", "motor": 6, "direction": 1})
         elif self.selected == 13:
             master_cmd({"command": "motor", "motor": 6, "direction": -1})
         elif self.selected == 14:
             master_cmd({"command": "motor", "motor": 7, "direction": 1})
         elif self.selected == 15:
             master_cmd({"command": "motor", "motor": 7, "direction": -1})
         elif self.selected == 16:
             master_cmd({"command": "motor", "motor": 2, "direction": 1})
             master_cmd({"command": "motor", "motor": 3, "direction": -1})
         elif self.selected == 17:
             master_cmd({"command": "motor", "motor": 2, "direction": -1})
             master_cmd({"command": "motor", "motor": 3, "direction": 1})