Ch-5 clean
This commit is contained in:
parent
5c4ecaeb13
commit
481cac28de
@ -12,6 +12,7 @@ motor_A2.direction = digitalio.Direction.OUTPUT
|
||||
motor_B1.direction = digitalio.Direction.OUTPUT
|
||||
motor_B2.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
|
||||
def stop():
|
||||
motor_A1.value = False
|
||||
motor_A2.value = False
|
||||
|
||||
@ -12,6 +12,7 @@ motor_A2.direction = digitalio.Direction.OUTPUT
|
||||
motor_B1.direction = digitalio.Direction.OUTPUT
|
||||
motor_B2.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
|
||||
def stop():
|
||||
motor_A1.value = False
|
||||
motor_A2.value = False
|
||||
|
||||
@ -12,6 +12,7 @@ motor_A2.direction = digitalio.Direction.OUTPUT
|
||||
motor_B1.direction = digitalio.Direction.OUTPUT
|
||||
motor_B2.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
|
||||
def stop():
|
||||
motor_A1.value = False
|
||||
motor_A2.value = False
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
max_speed = 2**16-1
|
||||
max_speed = 2 ** 16 - 1
|
||||
|
||||
robot.motor_A1.duty_cycle = int(0.8 * max_speed)
|
||||
time.sleep(0.3)
|
||||
robot.stop()
|
||||
robot.stop()
|
||||
|
||||
@ -4,8 +4,8 @@ import pwmio
|
||||
|
||||
A1_PWM = pwmio.PWMOut(board.GP17)
|
||||
|
||||
A1_PWM.duty_cycle = 2**16-1
|
||||
A1_PWM.duty_cycle = 2 ** 16 - 1
|
||||
time.sleep(0.3)
|
||||
A1_PWM.duty_cycle = 2**15
|
||||
A1_PWM.duty_cycle = 2 ** 15
|
||||
time.sleep(0.3)
|
||||
A1_PWM.duty_cycle = 0
|
||||
|
||||
@ -3,8 +3,8 @@ import robot
|
||||
|
||||
try:
|
||||
for speed in range(5, 10):
|
||||
robot.set_left(speed/10)
|
||||
robot.set_right(speed/10)
|
||||
robot.set_left(speed / 10)
|
||||
robot.set_right(speed / 10)
|
||||
time.sleep(0.3)
|
||||
finally:
|
||||
robot.stop()
|
||||
|
||||
@ -1,20 +1,22 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
|
||||
def straight(speed, duration):
|
||||
robot.set_left(speed)
|
||||
robot.set_right(speed)
|
||||
time.sleep(duration)
|
||||
|
||||
|
||||
def left(speed, duration):
|
||||
robot.set_left(0)
|
||||
robot.set_right(speed)
|
||||
time.sleep(duration)
|
||||
|
||||
|
||||
try:
|
||||
for n in range(0, 4):
|
||||
straight(0.6, 1.0)
|
||||
left(0.6, 1)
|
||||
finally:
|
||||
robot.stop()
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ motor_B2 = pwmio.PWMOut(board.GP19)
|
||||
|
||||
right_motor = motor_A1, motor_A2
|
||||
left_motor = motor_B1, motor_B2
|
||||
max_speed = 2**16-1
|
||||
max_speed = 2 ** 16 - 1
|
||||
|
||||
|
||||
def stop():
|
||||
@ -25,7 +25,7 @@ def set_speed(motor, speed):
|
||||
speed = -speed
|
||||
else:
|
||||
direction = motor
|
||||
speed = min(speed, 1) # limit to 1.0
|
||||
speed = min(speed, 1) # limit to 1.0
|
||||
|
||||
direction[0].duty_cycle = int(max_speed * speed)
|
||||
direction[1].duty_cycle = 0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user