def speak_and_rotate(): sound = Sound() os.system('setfont Lat15-TerminusBold14') mL = LargeMotor('outB') mL.stop_action = 'hold' mR = LargeMotor('outC') mR.stop_action = 'hold' print('Hello, my name is EV3D4!') str_en = 'Hello, my name is E V 3 D 4!' opts = '-a 200 -s 150 -p 70 -v' sound.speak(str_en, espeak_opts=opts + 'en+f5') sleep(2) str_en = "Performing perimeter scan" sound.speak(str_en, espeak_opts=opts + 'en+f5') # Sound.speak('Hello, my name is Evie, 3 D 4!').wait() mL.run_to_rel_pos(position_sp=1662, speed_sp=300) mR.run_to_rel_pos(position_sp=-1662, speed_sp=300) #mL.wait_while('running') #mR.wait_while('running') sleep(1) str_en = "At your command Big Daddy" sound.speak(str_en, espeak_opts=opts + 'en+f5') sleep(1)
# added IR polarCoordsIRr = np.array( [], dtype=np.int32) # list to hold 'r' - IR distance r (in arb units) polarCoordsIRmean = np.array( [], dtype=np.int32) # list to hold processed data IR-mean polarCoordsIRstd = np.array( [], dtype=np.int32) # list to hold processed data IR-stdev # setup motors mL = LargeMotor(OUTPUT_A) time.sleep(0.5) mL.reset() time.sleep(2) mLspd = 0 mL.stop_action = 'coast' # mL.polarity = 'inversed' mL.position = 0 mR = LargeMotor(OUTPUT_B) time.sleep(0.5) mR.reset() time.sleep(2) mRspd = 0 mR.stop_action = 'coast' # mR.polarity = 'inversed' mR.position = 0 spd = 0 # set this value to -30 to +90; use to set outer wheel/motor speed; default to mL for driving straight turnRatio = 0.0 # set this value to -0.5 to +0.5; subtract from 1 to set turn ratio; multiply * spd to set inside motor speed
# import time, tty, sys from ev3dev2.motor import LargeMotor, OUTPUT_D, SpeedPercent, SpeedDPS, MoveTank from ev3dev2.sensor import INPUT_1 tty.setcbreak(sys.stdin) mShuttle = LargeMotor(OUTPUT_D) time.sleep(0.5) mShuttle.reset() time.sleep(2) mShuttle.duty_cycle_sp = 0 mShuttleDtyMax = 22 mShuttle.stop_action = 'coast' mShuttle.polarity = 'inversed' mShuttle.position = 0 prev_mShuttle_pos = 0 # Turn motor on with run_direct and duty_cycle_sp of '0' mShuttle.run_direct() print ("Ready for keyboard commands...") while (True): x = ord(sys.stdin.read(1)) if x == 120: # x key pushed - exit mShuttle.duty_cycle_sp = 0 mShuttle.off(brake=False)
from ev3dev2.sensor import INPUT_1 print("Please attach a motor to BAM1") time.sleep(3) 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 = 'brake' # m.ramp_up_sp(5000) #### unsupported (on PiStorms only?) # m._ramp_down_sp(5000) #### unsupported (on PiStorms only?) m.on(SpeedDPS(0)) t1 = time.time() for i in range(0, 910, 10): # print("START --------> m.on...", round((time.time() - t1), 4)) print(i, " Increment SpeedDPS --------> m.on(SpeedDPS(i)) ", round((time.time() - t1), 4)) m.on(SpeedDPS(i)) #m.on_to_position(SpeedDPS(100), (i * 360), brake=False, block=True) ### this method FAILS TO BLOCK #m.run_to_rel_pos(position_sp=(i * 360), speed_sp=600, stop_action="hold") ### no claim of blocking #m.on_for_degrees(SpeedDPS(900), (i * 360), brake=True, block=True) ### this method FAILS TO BLOCK # m.on_for_seconds(speed=i, seconds=8, brake=False)
d_deg = 0 t1 = 0.0 dt = 0.0 tachospeed = 0.0 # degrs Per Sec ev3dev2_speed = 0 d_deg_avg = 0.0 tachospeed_avg = 0.0 start_pos = 0 end_pos = 0 start_time = 0.0 end_time = 0.0 m = LargeMotor(OUTPUT_A) time.sleep(0.1) #m.reset() m.stop_action = 'coast' m.stop() m.position = 0 time.sleep(0.1) start_time = time.time() #m.on(SpeedDPS(800)) while True: for i in range(6000): t1 = time.time() old_pos = encoder_pos time.sleep(0.05) encoder_pos = m.position dt = time.time() - t1 d_deg = encoder_pos - old_pos tachospeed = d_deg / dt
# 3/22/2020 Ron King v2.0 - change from regulated 'on', 'speed' to duty_cycle # Removed all traces of Pistorms version (issues and comments) import time, tty, sys from ev3dev2.motor import LargeMotor, OUTPUT_C, OUTPUT_D, SpeedPercent, SpeedDPS, MoveTank from ev3dev2.sensor import INPUT_1 tty.setcbreak(sys.stdin) mLift = LargeMotor(OUTPUT_C) time.sleep(0.5) mLift.reset() time.sleep(2) mLift.duty_cycle_sp = 0 mLiftDtyMax = 36 mLift.stop_action = 'coast' mLift.polarity = 'inversed' mLift.position = 0 mGrab = LargeMotor(OUTPUT_D) time.sleep(0.5) mGrab.reset() time.sleep(2) mGrab.duty_cycle_sp = 0 mGrabDtyMax = 36 mGrab.stop_action = 'coast' mGrab.polarity = 'inversed' mGrab.position = 0 # Turn motors on with run_direct and duty_cycle_sp of '0' mLift.run_direct()
from ev3dev2.sensor import INPUT_1 print("Please attach a motor to BAM1") time.sleep(3) 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 = 'hold' for i in range(1, 11): #print("START --------> m.on_to_position ... or on_for_degrees") m.on_to_position(SpeedDPS(200), (i * 360), brake=True, block=True) ### this method FAILS TO BLOCK # m.on_for_degrees(SpeedDPS(200), (i * 360), brake=False, block=True) ### this method FAILS TO BLOCK #print("END --------> m.on_to_position ... or on_for_degrees") print("stop_action is ", m.stop_action) print("state is ", m.state) print("START --------> m.wait_while...blah") m.wait_while('stalled') #print("END --------> m.wait_while...blah") print("stop_action is ", m.stop_action) print("state is ", m.state) time.sleep(3)