def main(): robot = robo.Snatch3r() my_delegate = MyDelegateEv3(robot) mqtt_client = com.MqttClient(my_delegate) my_delegate2 = Delegate2(robot, my_delegate, mqtt_client) mqtt_client2 = com.MqttClient(my_delegate2) mqtt_client.connect_to_pc() mqtt_client2.connect_to_pc() while True: wakeup() while my_delegate.startup: time.sleep(.01) print("robot done with startup") while my_delegate.main: time.sleep(.01) print("robot done with main") while my_delegate.running: my_delegate2.check_status() print("EV3", my_delegate.status) mqtt_client2.send_message("status_update", [my_delegate.status]) time.sleep(.01) print("robot done with running") robot.shutdown() time.sleep(5) my_delegate.reset()
def main(): ev3.Sound.speak("Remote Drive").wait() robot = robo.Snatch3r() mqtt_client = com.MqttClient(robot) mqtt_client.connect_to_pc() # mqtt_client.connect_to_pc("35.194.247.175") # Off campus IP address of a GCP broker robot.loop_forever() # Calls a function that has a while True: loop
def main(): print("--------------------------------------------") print(" Beacon pickup") print("--------------------------------------------") ev3.Sound.speak("Beacon pickup").wait() ##################################################### # There are no TODOs in this code. # Your only edits will be in the Snatch3r class. ##################################################### robot = robo.Snatch3r() try: while True: found_beacon = robot.seek_beacon() if found_beacon: ev3.Sound.speak("I got the beacon") robot.arm_up() time.sleep(1) robot.arm_down() command = input( "Hit enter to seek the beacon again or enter q to quit: ") if command == "q": break except: traceback.print_exc() ev3.Sound.speak("Error") print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Beacon seeking") print("--------------------------------------------") ev3.Sound.speak("Beacon seeking") robot = robo.Snatch3r() try: while found: seek_beacon(robot) # Done: 5. Save the result of the seek_beacon function (a bool), then use that value to only say "Found the # beacon" if the return value is True. (i.e. don't say "Found the beacon" if the attempts was cancelled.) ev3.Sound.speak("Found the beacon") command = input( "Hit enter to seek the beacon again or enter q to quit: ") if command == "q": break except: traceback.print_exc() ev3.Sound.speak("Error") print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): # -------------------------------------------------------------- # We have already implemented this module for you. # There are no TODOs in the code. Do NOT modify it. # You are not allowed to make any changes to this file. # -------------------------------------------------------------- print("--------------------------------------------") print(" Arm movement via library") print("--------------------------------------------") ev3.Sound.speak("Arm movement via library").wait() robot = robo.Snatch3r() while True: command_to_run = input( "Enter c (for calibrate), u (for up), d (for down), or q (for quit): " ) if command_to_run == 'c': print("Calibrate the arm") robot.arm_calibration() elif command_to_run == 'u': print("Move the arm to the up position") robot.arm_up() elif command_to_run == 'd': print("Move the arm to the down position") robot.arm_down() elif command_to_run == 'q': break else: print(command_to_run, "is not a known command. Please enter a valid choice.") ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Drive polygon") print("--------------------------------------------") ev3.Sound.speak("Drive polygon").wait() robot = robo.Snatch3r() while True: speed_deg_per_second = int(input("Speed (0 to 900 dps): ")) if speed_deg_per_second == 0: break sides = int(input("Number of sides: ")) # Tip for later, try a negative value for Number of sides: to drive CW around the polygon instead of CCW. if sides == 0: break turn_amount = 360 / sides edge_length_in = int(input("Length of each edge (inches): ")) if edge_length_in == 0: break # TODO: 2. Individually implement the code here to use your drive_inches and turn_degrees library methods to # drive a polygon with the correct number of sides. (Hint: You will add 3 lines of code. What are they?). for k in range(abs(sides)): robot.drive_inches(edge_length_in, speed_deg_per_second) robot.turn_degrees(turn_amount, speed_deg_per_second) # TODO: 3. Call over a TA or instructor to sign your team's checkoff sheet and do a code review. # You are done with the Motors unit! # # Observations you should make, by making library functions you can make this program in only 3 lines of code. print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): # -------------------------------------------------------------- # We have already implemented this module for you. # There are no TODOs in the code. Do NOT modify it. # You are not allowed to make any changes to this code. # -------------------------------------------------------------- print("--------------------------------------------") print(" Turn Degrees") print("--------------------------------------------") ev3.Sound.speak("Turn Degrees").wait() robot = robo.Snatch3r() # Connect two large motors on output ports B and C left_motor = ev3.LargeMotor(ev3.OUTPUT_B) right_motor = ev3.LargeMotor(ev3.OUTPUT_C) # Check that the motors are actually connected assert left_motor.connected assert right_motor.connected while True: speed_deg_per_second = int(input("Speed (0 to 900 dps): ")) if speed_deg_per_second == 0: break inches_target = int(input("Degrees: ")) if inches_target == 0: break robot.turn_degrees(inches_target, speed_deg_per_second) ev3.Sound.beep().wait() # Fun little beep print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): ev3.Sound.speak("Snake").wait() robot = robo.Snatch3r() dc = DataContainer() mqtt_client = com.MqttClient(robot) mqtt_client.connect_to_pc() color_sensor = ev3.ColorSensor() btn = ev3.Button() btn.on_backspace = lambda state: handle_shutdown(state, dc) while dc.running: if int(color_sensor.color) == ev3.ColorSensor.COLOR_RED: send_points(mqtt_client) time.sleep(1) ev3.Sound.speak("10 points").wait() if int(color_sensor.color) == ev3.ColorSensor.COLOR_BLACK: game_over(mqtt_client) time.sleep(1) ev3.Sound.speak("Game Over").wait() btn.process() time.sleep(0.01) ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Color tracking") print("--------------------------------------------") ev3.Sound.speak("Color tracking").wait() print("Press the touch sensor to exit this program.") # This code assumes you have setup the pixy object on the Snatch3r class. # Add the pixy property to that class if you have not done so already. robot = robo.Snatch3r() robot.pixy.mode = "SIG1" turn_speed = 100 while not robot.touch_sensor.is_pressed: x = robot.pixy.value(1) y = robot.pixy.value(2) print("(X, Y)= ({}, {})".format(x, y)) if x < 150: robot.left(turn_speed, turn_speed) elif x > 170: robot.right(turn_speed, turn_speed) elif x > 150 and x < 170: robot.stop() time.sleep(0.25) robot.stop() print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): ev3.Leds.all_off() robot = robo.Snatch3r() my_delegate = robot mqtt_client = com.MqttClient(my_delegate) my_delegate.mqtt_client = mqtt_client mqtt_client.connect_to_pc() btn = ev3.Button() btn.on_up = lambda state: handle_button_press( state, mqtt_client, "I have 100 points, Black is 70 points") btn.on_down = lambda state: handle_button_press(state, mqtt_client, "Green is 50 points, B") btn.on_left = lambda state: handle_button_press(state, mqtt_client, "Red is 30 points") btn.on_right = lambda state: handle_button_press(state, mqtt_client, "Yellow is 20 points") btn.on_backspace = lambda state: handle_shutdown(state, my_delegate) while my_delegate.running: btn.process() ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print("IR Remote") print(" - Use IR remote channel 1 to drive around") print(" - Use IR remote channel 2 to for the arm") print(" - Press the Back button on EV3 to exit") print("--------------------------------------------") ev3.Sound.speak("I R Remote") ev3.Leds.all_off() # Turn the leds off robot = robo.Snatch3r() dc = DataContainer() # Connect two large motors on output ports B and C left_motor = ev3.LargeMotor(ev3.OUTPUT_B) right_motor = ev3.LargeMotor(ev3.OUTPUT_C) # Check that the motors are actually connected assert left_motor.connected assert right_motor.connected # TODO: 4. Add the necessary IR handler callbacks as per the instructions above. # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below). # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below). rc1 = ev3.RemoteControl(channel=1) assert rc1.connected rc1.on_red_up = lambda state: handle_left_forward(state, dc) rc1.on_red_down = lambda state: handle_left_backward(state, dc) rc1.on_blue_up = lambda state: handle_right_forward(state, dc) rc1.on_blue_down = lambda state: handle_right_backward(state, dc) rc2 = ev3.RemoteControl(channel=2) assert rc2.connected rc2.on_red_up = lambda state: handle_arm_up_button(state, robot) rc2.on_red_down = lambda state: handle_arm_down_button(state, robot) rc2.on_blue_up = lambda state: handle_calibrate_button(state, robot) # For our standard shutdown button. btn = ev3.Button() btn.on_backspace = lambda state: handle_shutdown(state, dc) robot.arm_calibration() # Start with an arm calibration in this program. while dc.running: # done: 5. Process the RemoteControl objects. rc1.process() rc2.process() btn.process() time.sleep(0.01) # done: 2. Have everyone talk about this problem together then pick one # member to modify libs/robot_controller.py # as necessary to implement the method below as per the instructions in the opening doc string. Once the code has # been tested and shown to work, then have that person commit their work. All other team members need to do a # VCS --> Update project... # Once the library is implemented any team member should be able to run his code as stated in todo3. robot.shutdown()
def main(): """Run final project""" robot = robo.Snatch3r() mqtt_client = com.MqttClient(robot) robot.set_mqtt(mqtt_client) mqtt_client.connect_to_pc() robot.loop_forever()
def main(): print("--------------------------------------------") print("IR Remote") print(" - Use IR remote channel 1 to drive around") print(" - Use IR remote channel 2 to for the arm") print(" - Press the Back button on EV3 to exit") print("--------------------------------------------") ev3.Sound.speak("I R Remote") ev3.Leds.all_off() # Turn the leds off robot = robo.Snatch3r() dc = DataContainer() # TODO: 4. Add the necessary IR handler callbacks as per the instructions above. # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below). # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below). # For our standard shutdown button. btn = ev3.Button() btn.on_backspace = lambda state: handle_shutdown(state, dc) robot.arm_calibration() # Start with an arm calibration in this program. while dc.running: # TODO: 5. Process the RemoteControl objects. btn.process() time.sleep(0.01) # TODO: 2. Have everyone talk about this problem together then pick one member to modify libs/robot_controller.py # as necessary to implement the method below as per the instructions in the opening doc string. Once the code has # been tested and shown to work, then have that person commit their work. All other team members need to do a # VCS --> Update project... # Once the library is implemented any team member should be able to run his code as stated in todo3. robot.shutdown()
def main(): print("--------------------------------------------") print(" Pixy display") print(" Press the touch sensor to exit") print("--------------------------------------------") ev3.Sound.speak("Pixy display").wait() print("Press the touch sensor to exit this program.") # DONE: 2. Create an MqttClient (no delegate needed since EV3 will only send data, so an empty constructor is fine) # Then connect to the pc using the connect_to_pc method. mqtt_client = com.MqttClient() mqtt_client.connect_to_pc() robot = robo.Snatch3r() robot.pixy.mode = "SIG1" while not robot.touch_sensor.is_pressed: # TO DO: 3. Read the Pixy values for x, y, width, and height # Print the values (much like the print_pixy_readings example) print("(X, Y) = ({}, {}) Width = {} Height = {}".format( robot.pixy.value(1), robot.pixy.value(2), robot.pixy.value(3), robot.pixy.value(4))) time.sleep(0.5) # TO DO: 4. Send the Pixy values to the PC by calling the on_rectangle_update method x = robot.pixy.value(1) y = robot.pixy.value(2) width = robot.pixy.value(3) height = robot.pixy.value(4) # If you open m2_pc_pixy_display you can see the parameters for that method [x, y, width, height] mqtt_client.send_message('on_rectangle_update',[x,y,width,height]) time.sleep(0.25) print("Goodbye!") ev3.Sound.speak("Goodbye").wait() mqtt_client.close()
def main(): # -------------------------------------------------------------- # We have already implemented this module for you. # There are no TODOs in the code. Do NOT modify it. # You are not allowed to make any changes to this code. # -------------------------------------------------------------- print("--------------------------------------------") print(" Drive inches") print("--------------------------------------------") ev3.Sound.speak("Drive inches").wait() robot = robo.Snatch3r() while True: speed_deg_per_second = int(input("Speed (0 to 900 dps): ")) if speed_deg_per_second == 0: break inches_target = int(input("Distance (inches): ")) if inches_target == 0: break robot.drive_inches(inches_target, speed_deg_per_second) ev3.Sound.beep().wait() # Fun little beep print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): robot = robo.Snatch3r() mqtt_client = com.MqttClient(robot) mqtt_client.connect_to_pc() # mqtt_client.connect_to_pc("35.194.247.175") # Off campus IP address of a GCP broker robot.loop_forever( ) # Calls a function that has a while True: loop within it to avoid letting the program end.
def main(): # -------------------------------------------------------------- # We have already implemented this module for you. # There are no TODOs in the code. Do NOT modify it. # You are not allowed to make any changes to this code. # -------------------------------------------------------------- print("--------------------------------------------") print(" Turn Degrees") print("--------------------------------------------") ev3.Sound.speak("Turn degrees").wait() robot = robo.Snatch3r() while True: turn_speed_sp = int(input("Speed (0 to 900 dps): ")) if turn_speed_sp == 0: break degrees_to_turn = int(input("Degrees (degrees): ")) if degrees_to_turn == 0: break robot.turn_degrees(degrees_to_turn, turn_speed_sp) ev3.Sound.beep().wait() # Fun little beep print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Color tracking") print("--------------------------------------------") ev3.Sound.speak("Color tracking").wait() print("Press the touch sensor to exit this program.") # This code assumes you have setup the pixy object on the Snatch3r class. # Add the pixy property to that class if you have not done so already. robot = robo.Snatch3r() robot.pixy.mode = "SIG1" turn_speed = 100 while not robot.touch_sensor.is_pressed: # DONE: 2. Read the Pixy values for x and y # Print the values for x and y print("(X, Y)=({}, {})".format(robot.pixy.value(1), robot.pixy.value(2))) # DONE: 3. Use the x value to turn the robot # If the Pixy x value is less than 150 turn left (-turn_speed, turn_speed) # If the Pixy x value is greater than 170 turn right (turn_speed, -turn_speed) # If the Pixy x value is between 150 and 170 stop the robot # Continuously track the color until the touch sensor is pressed to end the program. if robot.pixy.value(1) < 150: robot.drive_forward(-turn_speed, turn_speed) elif robot.pixy.value(1) > 170: robot.drive_forward(turn_speed, -turn_speed) else: robot.drive_stop() time.sleep(0.25) print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Beep at hands") print("--------------------------------------------") ev3.Sound.speak("Beep at hands") print("Press the touch sensor to exit this program.") robot = robo.Snatch3r() # Note, it is assumed that you have a touch_sensor property on the Snatch3r class. # Presumably you added this in the digital_inputs unit, if not add it now so that # the code below works to monitor the touch_sensor. while not robot.touch_sensor.is_pressed: # done: 2. Implement the module as described in the opening comment block. # It is recommended that you add to your Snatch3r class's constructor the ir_sensor, as shown # self.ir_sensor = ev3.InfraredSensor() # assert self.ir_sensor # Then here you can use a command like robot.ir_sensor.proximity a = robot.ir_sensor.proximity print(a) if a < 10: ev3.Sound.beep() time.sleep(1.5) time.sleep(0.1) # done: 3. Call over a TA or instructor to sign your team's checkoff sheet. # # Observations you should make, the instance variable robot.ir_sensor.proximity is always updating with a distance. print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Color tracking") print("--------------------------------------------") ev3.Sound.speak("Color tracking").wait() print("Press the touch sensor to exit this program.") # This code assumes you have setup the pixy object on the Snatch3r class. # Add the pixy property to that class if you have not done so already. robot = robo.Snatch3r() robot.pixy.mode = "SIG3" turn_speed = 100 while not robot.touch_sensor.is_pressed: # Done: 2. Read the Pixy values for x and y x = robot.pixy.value(1) y = robot.pixy.value(2) print("(X, Y)=({}, {})".format(x, y)) # Done: 3. Use the x value to turn the robot # if x < 150: # robot.forward(-100, 100) # elif x > 170: # robot.forward(100, -100) # else: # robot.stop() time.sleep(0.1) print("Goodbye!") robot.stop() ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Drive to the color") print(" Up button goes to Red") print(" Down button goes to Blue") print(" Left button goes to Black") print(" Right button goes to White") print("--------------------------------------------") ev3.Sound.speak("Drive to the color").wait() print("Press Back to exit this program.") robot = robo.Snatch3r() dc = DataContainer() # For our standard shutdown button. btn = ev3.Button() # TODO: 2. Uncomment the lines below to setup event handlers for these buttons. btn.on_up = lambda state: drive_to_color(state, robot, ev3.ColorSensor. COLOR_RED) btn.on_down = lambda state: drive_to_color(state, robot, ev3.ColorSensor. COLOR_BLUE) btn.on_left = lambda state: drive_to_color(state, robot, ev3.ColorSensor. COLOR_BLACK) btn.on_right = lambda state: drive_to_color(state, robot, ev3.ColorSensor. COLOR_WHITE) btn.on_backspace = lambda state: handle_shutdown(state, dc) while dc.running: btn.process() time.sleep(0.01) print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Beep at blue") print("--------------------------------------------") ev3.Sound.speak("Beep at blue").wait() print("Press the touch sensor to exit this program.") robot = robo.Snatch3r() robot.pixy.mode = "SIG1" while not robot.touch_sensor.is_pressed: # DONE: 2. Implement the module as described in the opening comment block. # It is recommended that you add to your Snatch3r class's constructor the pixy object, as shown # self.pixy = ev3.Sensor(driver_name="pixy-lego") # assert self.pixy # Then here you can use a command like width = robot.pixy.value(3) x = robot.pixy.value(1) y = robot.pixy.value(2) width = robot.pixy.value(3) height = robot.pixy.value(4) if width > 0: ev3.Sound.beep() print(x, y, width, height) time.sleep(1) print("Goodbye!") ev3.Sound.speak("Goodbye").wait()
def main(): print("--------------------------------------------") print(" Pixy display") print(" Press the touch sensor to exit") print("--------------------------------------------") ev3.Sound.speak("Pixy display").wait() print("Press the touch sensor to exit this program.") # TODO: 2. Create an MqttClient (no delegate needed since EV3 will only send data, so an empty constructor is fine) # Then connect to the pc using the connect_to_pc method. mqtt_client = com.MqttClient() mqtt_client.connect_to_pc() pixy = ev3.Sensor(driver_name="pixy-lego") robot = robo.Snatch3r() robot.pixy.mode = "SIG1" while not robot.touch_sensor.is_pressed: # TODO: 3. Read the Pixy values for x, y, width, and height # Print the values (much like the print_pixy_readings example) print("value1: X", pixy.value(1)) print("value1: Y", pixy.value(2)) print("value1: Width", pixy.value(3)) print("value1: Height", pixy.value(4)) # TODO: 4. Send the Pixy values to the PC by calling the on_rectangle_update method # If you open m2_pc_pixy_display you can see the parameters for that method [x, y, width, height] time.sleep(0.25) print("Goodbye!") ev3.Sound.speak("Goodbye").wait() mqtt_client.close()
def main(): robot = robo.Snatch3r() mqtt_client = com.MqttClient(robot) mqtt_client.connect_to_pc() btn = ev3.Button() # mqtt_client.connect_to_pc("35.194.247.175") # Off campus IP address of a GCP broker #btn.on_down = lambda state: send_eighth(robot.color_sensor.color,mqtt_client) while robot.running: if btn.down: for k in range(30): time.sleep(0.1) if not btn.down: send_eighth(robot.color_sensor.color, mqtt_client) break if btn.down: send_rest(mqtt_client, beat_length / 2) if btn.up: for k in range(30): time.sleep(0.1) if not btn.up: send_quarter(robot.color_sensor.color, mqtt_client) break if btn.up: send_rest(mqtt_client, beat_length) if btn.left: for k in range(30): time.sleep(0.1) if not btn.left: send_half(robot.color_sensor.color, mqtt_client) break if btn.left: send_rest(mqtt_client, beat_length * 2) if btn.right: for k in range(30): time.sleep(0.1) if not btn.right: send_whole(robot.color_sensor.color, mqtt_client) break if btn.right: send_rest(mqtt_client, beat_length * 4) if btn.enter: for k in range(30): time.sleep(0.1) if not btn.enter: send_dotted_quarter(robot.color_sensor.color, mqtt_client) break if btn.enter: send_rest(mqtt_client, beat_length * 1.5) if btn.backspace: for k in range(30): time.sleep(0.1) if not btn.backspace: break if btn.backspace: mqtt_client.send_message("delete") btn.process() if robot.touch_sensor.is_pressed: robot.shutdown()
def main(): robot = robo.Snatch3r() mqtt_client = com.MqttClient(robot) mqtt_client.connect_to_pc() ev3.Sound.speak("Maze Runner 2.0 ").wait() robot.arm_calibration() robot.loop_forever()
def main(): my_delegate = MyDelegate() mqtt_client = com.MqttClient(my_delegate) my_delegate.mqtt_client = mqtt_client mqtt_client.connect_to_pc() robot = robo.Snatch3r() robot.arm_calibration() my_delegate.loop_forever()
def find_green_height(): """ :return: returns height read from SIG1 on pixy cam """ robot = robo.Snatch3r() robot.pixy.mode = "SIG1" green_height = robot.pixy.value(4) return green_height
def find_pink_height(): """ :return: returns height read from SIG2 on pixy cam """ robot = robo.Snatch3r() robot.pixy.mode = "SIG2" pink_height = robot.pixy.value(4) return pink_height
def __init__(self): self.robot = robo.Snatch3r() self.weight = 2 self.mqtt_client = com.MqttClient(self) self.mqtt_client.connect_to_pc("broker.mqttdashboard.com") self.robot.mqtt_client = self.mqtt_client self.mqtt_client.send_message("weight_change_display", [self.weight])
def main(): robot = robo.Snatch3r() mqtt_client = com.MqttClient(robot) mqtt_client.connect_to_pc() # speed = robot.speed # if speed > 0: # mqtt_client.send_message("check_off", ["True"]) robot.loop_forever()