def reverse(): motor = Motor(Port.D, Direction.CLOCKWISE) starttime = utime.ticks_ms() b = 0 while (not touch.pressed()) and (b < 3000): motor.run(360) currenttime = utime.ticks_ms() b = currenttime - starttime if motor.stalled(): break motor = Motor(Port.D, Direction.COUNTERCLOCKWISE) turn(1, (gg.angle() - anglecounter * 10))
if 'gripper_open' in str(data): gripper_open() brick.sound.beep() data = None if 'gripper_close' in str(data): gripper_close() brick.sound.beep() data = None if 'gripper_calibrate' in str(data): gripper_calibrate() brick.sound.beep() data = None if 'get_gripper_stalled' in str(data): tx_string = 'grip_motor.stalled()=' + str(grip_motor.stalled()) + '\n' s.send(bytes(tx_string, 'utf-8')) data = None if 'get_gripper_angle' in str(data): tx_string = 'grip_motor.angle()=' + str(grip_motor.angle()) + '\n' s.send(bytes(tx_string, 'utf-8')) data = None if 'set_gripper_angle_0' in str(data): grip_motor.reset_angle(0) brick.sound.beep() data = None s.close()
motor = Motor(Port.D, Direction.CLOCKWISE) starttime = utime.ticks_ms() b = 0 while (not touch.pressed()) and (b < 3000): motor.run(360) currenttime = utime.ticks_ms() b = currenttime - starttime if motor.stalled(): break motor = Motor(Port.D, Direction.COUNTERCLOCKWISE) turn(1, (gg.angle() - anglecounter * 10)) def turn(dir, ang): if dir == 1: frontmotor.run_angle(100, ang) else: frontmotor.run_angle(100, -ang) while True: print("angle", gg.angle()) motor.run(360) if dist.distance() < 100 or motor.stalled(): motor.stop() reverse() anglecounter += 1 print(gg.angle() - anglecounter * 10) utime.sleep(10)
# rate of the drivebase to 1.2 degrees per second. # For example, if the light value deviates from the threshold by 10, the robot # steers at 10*1.2 = 12 degrees per second. PROPORTIONAL_GAIN = 3.0 # 1.2 # Drive forward up to 30 centimeters until the robot finds the line. while line_sensor.reflection() > threshold: robot.drive(DRIVE_SPEED, 0) ev3.speaker.beep() treadmill_motor.set_dc_settings(30, 0) treadmill_motor.run(-300) # Follow line until arm motor stalls. while (treadmill_motor.stalled() == False): # Calculate the deviation from the threshold. deviation = line_sensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) # You can wait for a short time or do other things in this loop. wait(10) ev3.speaker.beep() # Reset arm motor defaults. treadmill_motor.stop()