commit
aa62695178
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.DS_Store
|
||||
*.pyc
|
||||
BIN
ch-3/Robot.FCStd
BIN
ch-3/Robot.FCStd
Binary file not shown.
10
ch-5/1-tests/motors_test_1_pin.py
Normal file
10
ch-5/1-tests/motors_test_1_pin.py
Normal file
@ -0,0 +1,10 @@
|
||||
import time
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
motor_A1 = digitalio.DigitalInOut(board.GP18)
|
||||
motor_A1.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
motor_A1.value = True
|
||||
time.sleep(0.3)
|
||||
motor_A1.value = False
|
||||
6
ch-5/1-tests/motors_test_1_pin_short.py
Normal file
6
ch-5/1-tests/motors_test_1_pin_short.py
Normal file
@ -0,0 +1,6 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
robot.motor_A1.value = True
|
||||
time.sleep(0.3)
|
||||
robot.motor_A1.value = False
|
||||
29
ch-5/1-tests/motors_test_all_pins.py
Normal file
29
ch-5/1-tests/motors_test_all_pins.py
Normal file
@ -0,0 +1,29 @@
|
||||
import time
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
motor_A1 = digitalio.DigitalInOut(board.GP17)
|
||||
motor_A2 = digitalio.DigitalInOut(board.GP16)
|
||||
motor_B1 = digitalio.DigitalInOut(board.GP18)
|
||||
motor_B2 = digitalio.DigitalInOut(board.GP19)
|
||||
|
||||
motor_A1.direction = digitalio.Direction.OUTPUT
|
||||
motor_A2.direction = digitalio.Direction.OUTPUT
|
||||
motor_B1.direction = digitalio.Direction.OUTPUT
|
||||
motor_B2.direction = digitalio.Direction.OUTPUT
|
||||
|
||||
motor_A1.value = True
|
||||
time.sleep(0.3)
|
||||
motor_A1.value = False
|
||||
time.sleep(0.3)
|
||||
motor_A2.value = True
|
||||
time.sleep(0.3)
|
||||
motor_A2.value = False
|
||||
time.sleep(0.3)
|
||||
motor_B1.value = True
|
||||
time.sleep(0.3)
|
||||
motor_B1.value = False
|
||||
time.sleep(0.3)
|
||||
motor_B2.value = True
|
||||
time.sleep(0.3)
|
||||
motor_B2.value = False
|
||||
18
ch-5/1-tests/motors_test_all_pins_short.py
Normal file
18
ch-5/1-tests/motors_test_all_pins_short.py
Normal file
@ -0,0 +1,18 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
robot.motor_A1.value = True
|
||||
time.sleep(0.3)
|
||||
robot.motor_A1.value = False
|
||||
time.sleep(0.3)
|
||||
robot.motor_A2.value = True
|
||||
time.sleep(0.3)
|
||||
robot.motor_A2.value = False
|
||||
time.sleep(0.3)
|
||||
robot.motor_B1.value = True
|
||||
time.sleep(0.3)
|
||||
robot.motor_B1.value = False
|
||||
time.sleep(0.3)
|
||||
robot.motor_B2.value = True
|
||||
time.sleep(0.3)
|
||||
robot.motor_B2.value = False
|
||||
19
ch-5/1-tests/robot.py
Executable file
19
ch-5/1-tests/robot.py
Executable file
@ -0,0 +1,19 @@
|
||||
# Write your code here :-)
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
motor_A1 = digitalio.DigitalInOut(board.GP17)
|
||||
motor_A2 = digitalio.DigitalInOut(board.GP16)
|
||||
motor_B1 = digitalio.DigitalInOut(board.GP18)
|
||||
motor_B2 = digitalio.DigitalInOut(board.GP19)
|
||||
|
||||
motor_A1.direction = digitalio.Direction.OUTPUT
|
||||
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
|
||||
motor_B1.value = False
|
||||
motor_B2.value = False
|
||||
8
ch-5/2-forward-back/motors_backward.py
Executable file
8
ch-5/2-forward-back/motors_backward.py
Executable file
@ -0,0 +1,8 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
robot.motor_A2.value = True
|
||||
robot.motor_B2.value = True
|
||||
time.sleep(0.3)
|
||||
robot.motor_A2.value = False
|
||||
robot.motor_B2.value = False
|
||||
8
ch-5/2-forward-back/motors_forward.py
Normal file
8
ch-5/2-forward-back/motors_forward.py
Normal file
@ -0,0 +1,8 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
robot.motor_A1.value = True
|
||||
robot.motor_B1.value = True
|
||||
time.sleep(0.3)
|
||||
robot.motor_A1.value = False
|
||||
robot.motor_B1.value = False
|
||||
19
ch-5/2-forward-back/robot.py
Executable file
19
ch-5/2-forward-back/robot.py
Executable file
@ -0,0 +1,19 @@
|
||||
# Write your code here :-)
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
motor_A1 = digitalio.DigitalInOut(board.GP17)
|
||||
motor_A2 = digitalio.DigitalInOut(board.GP16)
|
||||
motor_B1 = digitalio.DigitalInOut(board.GP18)
|
||||
motor_B2 = digitalio.DigitalInOut(board.GP19)
|
||||
|
||||
motor_A1.direction = digitalio.Direction.OUTPUT
|
||||
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
|
||||
motor_B1.value = False
|
||||
motor_B2.value = False
|
||||
6
ch-5/3-turning/motors_1_motor_turn.py
Normal file
6
ch-5/3-turning/motors_1_motor_turn.py
Normal file
@ -0,0 +1,6 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
robot.motor_A1.value = True
|
||||
time.sleep(0.3)
|
||||
robot.stop()
|
||||
7
ch-5/3-turning/motors_2_motor_turn.py
Normal file
7
ch-5/3-turning/motors_2_motor_turn.py
Normal file
@ -0,0 +1,7 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
robot.motor_A1.value = True
|
||||
robot.motor_B2.value = True
|
||||
time.sleep(0.3)
|
||||
robot.stop()
|
||||
19
ch-5/3-turning/robot.py
Executable file
19
ch-5/3-turning/robot.py
Executable file
@ -0,0 +1,19 @@
|
||||
# Write your code here :-)
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
motor_A1 = digitalio.DigitalInOut(board.GP17)
|
||||
motor_A2 = digitalio.DigitalInOut(board.GP16)
|
||||
motor_B1 = digitalio.DigitalInOut(board.GP18)
|
||||
motor_B2 = digitalio.DigitalInOut(board.GP19)
|
||||
|
||||
motor_A1.direction = digitalio.Direction.OUTPUT
|
||||
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
|
||||
motor_B1.value = False
|
||||
motor_B2.value = False
|
||||
8
ch-5/4-pwm/motors_convert_speed.py
Normal file
8
ch-5/4-pwm/motors_convert_speed.py
Normal file
@ -0,0 +1,8 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
max_speed = 2**16-1
|
||||
|
||||
robot.motor_A1.duty_cycle = int(0.8 * max_speed)
|
||||
time.sleep(0.3)
|
||||
robot.stop()
|
||||
11
ch-5/4-pwm/motors_pwm_drive_slower.py
Normal file
11
ch-5/4-pwm/motors_pwm_drive_slower.py
Normal file
@ -0,0 +1,11 @@
|
||||
import time
|
||||
import board
|
||||
import pwmio
|
||||
|
||||
A1_PWM = pwmio.PWMOut(board.GP17)
|
||||
|
||||
A1_PWM.duty_cycle = 2**16-1
|
||||
time.sleep(0.3)
|
||||
A1_PWM.duty_cycle = 2**15
|
||||
time.sleep(0.3)
|
||||
A1_PWM.duty_cycle = 0
|
||||
9
ch-5/4-pwm/motors_pwm_gentle_turn.py
Normal file
9
ch-5/4-pwm/motors_pwm_gentle_turn.py
Normal file
@ -0,0 +1,9 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
try:
|
||||
robot.set_left(1.0)
|
||||
robot.set_right(0.5)
|
||||
time.sleep(1)
|
||||
finally:
|
||||
robot.stop()
|
||||
10
ch-5/4-pwm/motors_pwm_multispeed.py
Normal file
10
ch-5/4-pwm/motors_pwm_multispeed.py
Normal file
@ -0,0 +1,10 @@
|
||||
import time
|
||||
import robot
|
||||
|
||||
try:
|
||||
for speed in range(5, 10):
|
||||
robot.set_left(speed/10)
|
||||
robot.set_right(speed/10)
|
||||
time.sleep(0.3)
|
||||
finally:
|
||||
robot.stop()
|
||||
35
ch-5/4-pwm/with_helpers/robot.py
Executable file
35
ch-5/4-pwm/with_helpers/robot.py
Executable file
@ -0,0 +1,35 @@
|
||||
import board
|
||||
import pwmio
|
||||
|
||||
motor_A1 = pwmio.PWMOut(board.GP17)
|
||||
motor_A2 = pwmio.PWMOut(board.GP16)
|
||||
motor_B1 = pwmio.PWMOut(board.GP18)
|
||||
motor_B2 = pwmio.PWMOut(board.GP19)
|
||||
|
||||
def stop():
|
||||
motor_A1.duty_cycle = 0
|
||||
motor_A2.duty_cycle = 0
|
||||
motor_B1.duty_cycle = 0
|
||||
motor_B2.duty_cycle = 0
|
||||
|
||||
max_speed = 2**16-1
|
||||
right_motor = motor_A1, motor_A2
|
||||
left_motor = motor_B1, motor_B2
|
||||
|
||||
def set_speed(motor, speed):
|
||||
# Swap motor pins if we reverse the speed
|
||||
if speed < 0:
|
||||
direction = motor[1], motor[0]
|
||||
speed = -speed
|
||||
else:
|
||||
direction = motor
|
||||
speed = min(speed, 1) # limit to 1.0
|
||||
|
||||
direction[0].duty_cycle = int(max_speed * speed)
|
||||
direction[1].duty_cycle = 0
|
||||
|
||||
def set_left(speed):
|
||||
set_speed(left_motor, speed)
|
||||
|
||||
def set_right(speed):
|
||||
set_speed(right_motor, speed)
|
||||
14
ch-5/4-pwm/with_pwm/robot.py
Executable file
14
ch-5/4-pwm/with_pwm/robot.py
Executable file
@ -0,0 +1,14 @@
|
||||
import board
|
||||
import pwmio
|
||||
|
||||
motor_A1 = pwmio.PWMOut(board.GP17)
|
||||
motor_A2 = pwmio.PWMOut(board.GP16)
|
||||
motor_B1 = pwmio.PWMOut(board.GP18)
|
||||
motor_B2 = pwmio.PWMOut(board.GP19)
|
||||
|
||||
def stop():
|
||||
motor_A1.duty_cycle = 0
|
||||
motor_A2.duty_cycle = 0
|
||||
motor_B1.duty_cycle = 0
|
||||
motor_B2.duty_cycle = 0
|
||||
|
||||
20
ch-5/5-path/pwm_drive_square.py
Normal file
20
ch-5/5-path/pwm_drive_square.py
Normal file
@ -0,0 +1,20 @@
|
||||
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()
|
||||
|
||||
36
ch-5/5-path/robot.py
Executable file
36
ch-5/5-path/robot.py
Executable file
@ -0,0 +1,36 @@
|
||||
import board
|
||||
import pwmio
|
||||
|
||||
motor_A1 = pwmio.PWMOut(board.GP17)
|
||||
motor_A2 = pwmio.PWMOut(board.GP16)
|
||||
motor_B1 = pwmio.PWMOut(board.GP18)
|
||||
motor_B2 = pwmio.PWMOut(board.GP19)
|
||||
|
||||
right_motor = motor_A1, motor_A2
|
||||
left_motor = motor_B1, motor_B2
|
||||
|
||||
def stop():
|
||||
motor_A1.duty_cycle = 0
|
||||
motor_A2.duty_cycle = 0
|
||||
motor_B1.duty_cycle = 0
|
||||
motor_B2.duty_cycle = 0
|
||||
|
||||
def set_speed(motor, speed):
|
||||
# Swap motor pins if we reverse the speed
|
||||
if speed < 0:
|
||||
direction = motor[1], motor[0]
|
||||
speed = -speed
|
||||
else:
|
||||
direction = motor
|
||||
speed = min(speed, 1) # limit to 1.0
|
||||
max_speed = 2**16-1
|
||||
|
||||
|
||||
direction[0].duty_cycle = int(max_speed * speed)
|
||||
direction[1].duty_cycle = 0
|
||||
|
||||
def set_left(speed):
|
||||
set_speed(left_motor, speed)
|
||||
|
||||
def set_right(speed):
|
||||
set_speed(right_motor, speed)
|
||||
19
ch-5/6-all/robot.py
Executable file
19
ch-5/6-all/robot.py
Executable file
@ -0,0 +1,19 @@
|
||||
# Write your code here :-)
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
motor_A1 = digitalio.DigitalInOut(board.GP17)
|
||||
motor_A2 = digitalio.DigitalInOut(board.GP16)
|
||||
motor_B1 = digitalio.DigitalInOut(board.GP18)
|
||||
motor_B2 = digitalio.DigitalInOut(board.GP19)
|
||||
|
||||
motor_A1.direction = digitalio.Direction.OUTPUT
|
||||
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
|
||||
motor_B1.value = False
|
||||
motor_B2.value = False
|
||||
Loading…
x
Reference in New Issue
Block a user