leftMotor.speed_sp = 360 rightMotor.speed_sp = 360 rampup = 5 spValue = 20 timeStep = 0.5 simDuration = 15 totalSteps = int(simDuration / timeStep) initial_angle = 0 final_angle = 720 ramp_up_down_left = int(rampup * 1000 * leftMotor.max_speed / leftMotor.speed_sp) ramp_up_down_right = int(rampup * 1000 * rightMotor.max_speed / rightMotor.speed_sp) leftMotor.ramp_up_sp = ramp_up_down_left leftMotor.ramp_down_sp = ramp_up_down_left rightMotor.ramp_up_sp = ramp_up_down_right rightMotor.ramp_down_sp = ramp_up_down_right startTime = time.time() leftMotor.on_for_seconds(SpeedPercent(spValue), simDuration, block=False) rightMotor.on_for_seconds(SpeedPercent(spValue), simDuration, block=True) stopTime = time.time() duration = stopTime - startTime print('Traveled for {0:0.2f} seconds'.format(duration)) leftMotor.reset() rightMotor.reset()
#!/usr/bin/env python3 from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedRPS, MoveSteering from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4 from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor, ColorSensor from time import sleep, time my_motor = LargeMotor(OUTPUT_A) my_motor.ramp_up_sp = 1000 # Takes 1000 ms to ramp up speed my_motor.ramp_down_sp = 1000 # Takes 1000 ms to ramp down speed ts = TouchSensor(INPUT_3) us = UltrasonicSensor(INPUT_2) cs = ColorSensor(INPUT_4) cs.mode = "RGB-RAW" #cs.mode = "COL-AMBIENT" t = time() while True: dist = us.distance_centimeters if time() - t > 1: print("dist:", dist) print("colr:", tuple(map(cs.value, [0, 1, 2]))) # print("colr:", cs.value()) t = time() if ts.is_pressed: speed = min(max(1, 100 - dist), 100) my_motor.on(speed) else: my_motor.stop() ''' rots = 10
print ("Please attach a motor to PORT_A") time.sleep(1) start_pos = 0 end_pos = 0 start_time = 0.0 end_time = 0.0 m = LargeMotor(OUTPUT_A) time.sleep(0.1) m.reset() time.sleep(0.1) start_time = time.time() m.stop_action ='coast' m.ramp_up_sp = 2000 #### supported on BrickPi3; ramp_up seems to work but ramp_down...not so well, at least with stop_action='brake' m.ramp_down_sp = 1000 #### supported on BrickPi3; ramp_up seems to work but ramp_down...not so well, at least with stop_action='brake' t1=time.time() for i in range(10, 500, 10): print("START --------> m.on...", round((time.time() - t1), 4)) #m.on_to_position(SpeedDPS(200), (i * 360), brake=False, block=True) ### this method FAILS TO BLOCK with PiStorms m.run_to_rel_pos(position_sp=(i * 360), speed_sp=900, stop_action="coast") ### no claim of blocking m.wait_until_not_moving() #m.on_for_degrees(SpeedDPS(900), (i * 360), brake=False, block=True) ### this method FAILS TO BLOCK with PiStorms #m.on_for_seconds(SpeedDPS(900), 15, brake=False, block=True) print ("target pos = ", (i * 360), "; actual pos = ", m.position, round((time.time() - t1), 4)) #print ("target pos = n/a (on_for_seconds); actual pos = ", m.position, round((time.time() - t1), 4)) time.sleep(.1) time.sleep(10)