Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3d4ff41be | ||
|
|
adfad36ec5 | ||
|
|
db716dbdde | ||
|
|
b7737b6214 | ||
|
|
fc83748ccd |
@@ -41,20 +41,21 @@ right_end = steering.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
steering.reset_angle((right_end - left_end)/2)
|
||||
steering.reset_angle((right_end - left_end) / 2)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set steering angle
|
||||
steering_angle = (((right_end - left_end)/2)-5)
|
||||
steering_angle = ((right_end - left_end) / 2) - 5
|
||||
|
||||
# Set variable for gear
|
||||
gear_total = 2 # Total number of gears.
|
||||
gear_old = None # Empty variable to set later on (keep
|
||||
# empty!).
|
||||
gear = 1 # Gear at start (must be higher than 0 and
|
||||
# lower or eaqual to gear_total).
|
||||
gear_color = ["BLUE", "RED"] # Number of colors should at least be
|
||||
# equal to gear_total.
|
||||
# Total number of gears.
|
||||
gear_total = 2
|
||||
# Empty variable to set later on (keep empty!).
|
||||
gear_old = None
|
||||
# Gear at start (must be higher than 0 and lower or eaqual to gear_total).
|
||||
gear = 1
|
||||
# Number of colors should at least be equal to gear_total.
|
||||
gear_color = ["BLUE", "RED"]
|
||||
|
||||
# Battery variables
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -77,7 +78,7 @@ while True:
|
||||
if gear_old > 1:
|
||||
gear -= 1
|
||||
while Button.LEFT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -86,14 +87,14 @@ while True:
|
||||
if gear_old < gear_total:
|
||||
gear += 1
|
||||
while Button.RIGHT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
# Set speed according to the choosen gear.
|
||||
if gear is not gear_old:
|
||||
remote.light.on(Color[gear_color[gear-1]])
|
||||
speed = (100/gear_total)*gear
|
||||
remote.light.on(Color[gear_color[gear - 1]])
|
||||
speed = (100 / gear_total) * gear
|
||||
gear_old = gear
|
||||
|
||||
# Choose the drive speed based on the left controls.
|
||||
@@ -106,7 +107,7 @@ while True:
|
||||
# Apply the selected speed.
|
||||
driving_1.dc(drive_speed)
|
||||
driving_2.dc(drive_speed)
|
||||
|
||||
|
||||
# Show battery status by hub LED.
|
||||
# Get current voltage and gradually up or down the value.
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -123,6 +124,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -15,12 +15,8 @@
|
||||
################################################################################
|
||||
# Rebrickable: https://rebrickable.com/mocs/MOC-105180/ #
|
||||
################################################################################
|
||||
# #
|
||||
# Changelog #
|
||||
# #
|
||||
################################################################################
|
||||
# v0.0.0 09-07-2022 #
|
||||
# First version. #
|
||||
# LEGO® is a trademark of the LEGO Group of companies which does not sponsor, #
|
||||
# authorize or endorse this project. #
|
||||
################################################################################
|
||||
|
||||
from pybricks.pupdevices import Motor, Remote
|
||||
@@ -75,7 +71,7 @@ while True:
|
||||
crane_top_speed = 100
|
||||
elif Button.RIGHT in pressed:
|
||||
crane_top_speed = -100
|
||||
|
||||
|
||||
if Button.CENTER in pressed:
|
||||
if engine_speed is engine_speed_set or engine_speed is -engine_speed_set:
|
||||
engine_speed = 0
|
||||
@@ -83,7 +79,7 @@ while True:
|
||||
else:
|
||||
engine_speed = engine_speed_set
|
||||
while Button.CENTER in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -100,7 +96,7 @@ while True:
|
||||
|
||||
if engine_speed_measured < 100:
|
||||
if engine_fail_counter > 0:
|
||||
engine_fail_counter = engine_fail_counter-1
|
||||
engine_fail_counter = engine_fail_counter - 1
|
||||
else:
|
||||
engine_speed = -engine_speed
|
||||
engine_fail_counter = engine_fail_counter_set
|
||||
@@ -123,6 +119,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -15,12 +15,8 @@
|
||||
################################################################################
|
||||
# Rebrickable: https://rebrickable.com/mocs/MOC-105180/ #
|
||||
################################################################################
|
||||
# #
|
||||
# Changelog #
|
||||
# #
|
||||
################################################################################
|
||||
# v0.0.0 09-07-2022 #
|
||||
# First version. #
|
||||
# LEGO® is a trademark of the LEGO Group of companies which does not sponsor, #
|
||||
# authorize or endorse this project. #
|
||||
################################################################################
|
||||
|
||||
from pybricks.pupdevices import Motor, Remote
|
||||
@@ -89,6 +85,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -47,20 +47,21 @@ right_end = steering.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
steering.reset_angle((right_end - left_end)/2)
|
||||
steering.reset_angle((right_end - left_end) / 2)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set steering angle
|
||||
steering_angle = (((right_end - left_end)/2)-5)
|
||||
steering_angle = ((right_end - left_end) / 2) - 5
|
||||
|
||||
# Set variable for gear
|
||||
gear_total = 3 # Total number of gears.
|
||||
gear_old = None # Empty variable to set later on (keep
|
||||
# empty!).
|
||||
gear = 1 # Gear at start (must be higher than 0 and
|
||||
# lower or eaqual to gear_total).
|
||||
gear_color = ["BLUE", "WHITE", "RED"] # Number of colors should at least be
|
||||
# equal to gear_total.
|
||||
# Total number of gears.
|
||||
gear_total = 3
|
||||
# Empty variable to set later on (keep empty!).
|
||||
gear_old = None
|
||||
# Gear at start (must be higher than 0 and lower or eaqual to gear_total).
|
||||
gear = 1
|
||||
# Number of colors should at least be equal to gear_total.
|
||||
gear_color = ["BLUE", "WHITE", "RED"]
|
||||
|
||||
# Battery variables
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -83,7 +84,7 @@ while True:
|
||||
if gear_old > 1:
|
||||
gear -= 1
|
||||
while Button.LEFT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -92,14 +93,14 @@ while True:
|
||||
if gear_old < gear_total:
|
||||
gear += 1
|
||||
while Button.RIGHT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
# Set speed according to the choosen gear.
|
||||
if gear is not gear_old:
|
||||
remote.light.on(Color[gear_color[gear-1]])
|
||||
speed = (100/gear_total)*gear
|
||||
remote.light.on(Color[gear_color[gear - 1]])
|
||||
speed = (100 / gear_total) * gear
|
||||
gear_old = gear
|
||||
|
||||
# Choose the drive speed based on the left controls.
|
||||
@@ -111,7 +112,7 @@ while True:
|
||||
|
||||
# Apply the selected speed.
|
||||
driving.dc(drive_speed)
|
||||
|
||||
|
||||
# Show battery status by hub LED.
|
||||
# Get current voltage and gradually up or down the value.
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -128,6 +129,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -27,9 +27,8 @@
|
||||
# Changelog #
|
||||
# #
|
||||
################################################################################
|
||||
# v0.0.0 20-06-2022 #
|
||||
# First version. #
|
||||
# Based on v0.1.0 15-06-2022 of 42109 - RC Truck v.3 by ufotografol #
|
||||
# LEGO® is a trademark of the LEGO Group of companies which does not sponsor, #
|
||||
# authorize or endorse this project. #
|
||||
################################################################################
|
||||
|
||||
from pybricks.pupdevices import Motor, Remote
|
||||
@@ -44,15 +43,7 @@ driving = Motor(Port.A, Direction.CLOCKWISE)
|
||||
# Connect to the remote.
|
||||
remote = Remote()
|
||||
|
||||
# Read the current settings
|
||||
old_kp, old_ki, old_kd, _, _ = gearbox.control.pid()
|
||||
old_kp, old_ki, old_kd, _, _ = steering.control.pid()
|
||||
|
||||
# Set new values
|
||||
gearbox.control.pid(kp=old_kp*4, kd=old_kd*0.4)
|
||||
steering.control.pid(kp=old_kp*4, kd=old_kd*0.4)
|
||||
|
||||
#Find the gearing endpoints but keep trying if value is below threshold of 200.
|
||||
# Find the gearing endpoints but keep trying if value is below threshold of 200.
|
||||
gear_angle = 0
|
||||
while gear_angle < 200:
|
||||
# Find the steering endpoint on the left and right.
|
||||
@@ -61,8 +52,8 @@ while gear_angle < 200:
|
||||
right_end_gearbox = gearbox.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# Set gearing angle
|
||||
gear_angle = (((right_end_gearbox - left_end_gearbox)/2)-5)
|
||||
print('Gear angle measured:',gear_angle)
|
||||
gear_angle = ((right_end_gearbox - left_end_gearbox) / 2) - 5
|
||||
print("Gear angle measured:", gear_angle)
|
||||
|
||||
# Find the steering endpoint on the left and right.
|
||||
# The middle is in between.
|
||||
@@ -71,21 +62,21 @@ right_end_steering = steering.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# Set gearing angle
|
||||
# Real angle of gear mechanism is 270 degrees (135 both sides from center).
|
||||
gear_angle = 270/2
|
||||
gear_angle = 270 / 2
|
||||
gear_angle_1 = gear_angle
|
||||
gear_angle_2 = gear_angle-(((gear_angle+gear_angle)/3)*1)
|
||||
gear_angle_3 = gear_angle-(((gear_angle+gear_angle)/3)*2)
|
||||
gear_angle_2 = gear_angle - (((gear_angle + gear_angle) / 3) * 1)
|
||||
gear_angle_3 = gear_angle - (((gear_angle + gear_angle) / 3) * 2)
|
||||
gear_angle_tipper = -gear_angle
|
||||
print('Gear angle real:',gear_angle)
|
||||
print("Gear angle real:", gear_angle)
|
||||
# Set steering angle
|
||||
steer_angle = (((right_end_steering - left_end_steering)/2)-5)
|
||||
print('steer angle:',steer_angle)
|
||||
steer_angle = ((right_end_steering - left_end_steering) / 2) - 5
|
||||
print("steer angle:", steer_angle)
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
gearbox.reset_angle((right_end_gearbox - left_end_gearbox)/2)
|
||||
gearbox.reset_angle((right_end_gearbox - left_end_gearbox) / 2)
|
||||
gearbox.run_target(1400, gear_angle, Stop.HOLD, False)
|
||||
steering.reset_angle((right_end_steering - left_end_steering)/2)
|
||||
steering.reset_angle((right_end_steering - left_end_steering) / 2)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set variable for gear
|
||||
@@ -107,7 +98,7 @@ while True:
|
||||
else:
|
||||
gear = 1
|
||||
while Button.RIGHT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -122,7 +113,7 @@ while True:
|
||||
else:
|
||||
gear = 3
|
||||
while Button.LEFT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -149,7 +140,7 @@ while True:
|
||||
if gear_old is 1:
|
||||
wait(500)
|
||||
gear_old = 4
|
||||
# Wait before going on so changing gear won't happen while driving.
|
||||
# Wait before going on so changing gear won't happen while driving.
|
||||
wait(250)
|
||||
|
||||
# Choose the steering angle based on the right controls.
|
||||
@@ -167,6 +158,3 @@ while True:
|
||||
driving.dc(-100)
|
||||
else:
|
||||
driving.dc(0)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
@@ -38,20 +38,21 @@ right_end = steering.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
steering.reset_angle((right_end - left_end)/2)
|
||||
steering.reset_angle((right_end - left_end) / 2)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set steering angle
|
||||
steering_angle = (((right_end - left_end)/2)-5)
|
||||
steering_angle = ((right_end - left_end) / 2) - 5
|
||||
|
||||
# Set variable for gear
|
||||
gear_total = 3 # Total number of gears.
|
||||
gear_old = None # Empty variable to set later on (keep
|
||||
# empty!).
|
||||
gear = 1 # Gear at start (must be higher than 0 and
|
||||
# lower or eaqual to gear_total).
|
||||
gear_color = ["BLUE", "WHITE", "RED"] # Number of colors should at least be
|
||||
# equal to gear_total.
|
||||
# Total number of gears.
|
||||
gear_total = 3
|
||||
# Empty variable to set later on (keep empty!).
|
||||
gear_old = None
|
||||
# Gear at start (must be higher than 0 and lower or eaqual to gear_total).
|
||||
gear = 1
|
||||
# Number of colors should at least be equal to gear_total.
|
||||
gear_color = ["BLUE", "WHITE", "RED"]
|
||||
|
||||
# Battery variables
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -74,7 +75,7 @@ while True:
|
||||
if gear_old > 1:
|
||||
gear -= 1
|
||||
while Button.LEFT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -83,14 +84,14 @@ while True:
|
||||
if gear_old < gear_total:
|
||||
gear += 1
|
||||
while Button.RIGHT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
# Set speed according to the choosen gear.
|
||||
if gear is not gear_old:
|
||||
remote.light.on(Color[gear_color[gear-1]])
|
||||
speed = (100/gear_total)*gear
|
||||
remote.light.on(Color[gear_color[gear - 1]])
|
||||
speed = (100 / gear_total) * gear
|
||||
gear_old = gear
|
||||
|
||||
# Choose the drive speed based on the left controls.
|
||||
@@ -102,7 +103,7 @@ while True:
|
||||
|
||||
# Apply the selected speed.
|
||||
driving.dc(drive_speed)
|
||||
|
||||
|
||||
# Show battery status by hub LED.
|
||||
# Get current voltage and gradually up or down the value.
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -119,6 +120,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -41,20 +41,21 @@ right_end = steering.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
steering.reset_angle((right_end - left_end)/2)
|
||||
steering.reset_angle((right_end - left_end) / 2)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set steering angle
|
||||
steering_angle = (((right_end - left_end)/2)-5)
|
||||
steering_angle = ((right_end - left_end) / 2) - 5
|
||||
|
||||
# Set variable for gear
|
||||
gear_total = 2 # Total number of gears.
|
||||
gear_old = None # Empty variable to set later on (keep
|
||||
# empty!).
|
||||
gear = 1 # Gear at start (must be higher than 0 and
|
||||
# lower or eaqual to gear_total).
|
||||
gear_color = ["BLUE", "RED"] # Number of colors should at least be
|
||||
# equal to gear_total.
|
||||
# Total number of gears.
|
||||
gear_total = 2
|
||||
# Empty variable to set later on (keep empty!).
|
||||
gear_old = None
|
||||
# Gear at start (must be higher than 0 and lower or eaqual to gear_total).
|
||||
gear = 1
|
||||
# Number of colors should at least be equal to gear_total.
|
||||
gear_color = ["BLUE", "RED"]
|
||||
|
||||
# Battery variables
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -77,7 +78,7 @@ while True:
|
||||
if gear_old > 1:
|
||||
gear -= 1
|
||||
while Button.LEFT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -86,14 +87,14 @@ while True:
|
||||
if gear_old < gear_total:
|
||||
gear += 1
|
||||
while Button.RIGHT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
# Set speed according to the choosen gear.
|
||||
if gear is not gear_old:
|
||||
remote.light.on(Color[gear_color[gear-1]])
|
||||
speed = (100/gear_total)*gear
|
||||
remote.light.on(Color[gear_color[gear - 1]])
|
||||
speed = (100 / gear_total) * gear
|
||||
gear_old = gear
|
||||
|
||||
# Choose the drive speed based on the left controls.
|
||||
@@ -106,7 +107,7 @@ while True:
|
||||
# Apply the selected speed.
|
||||
driving_1.dc(drive_speed)
|
||||
driving_2.dc(drive_speed)
|
||||
|
||||
|
||||
# Show battery status by hub LED.
|
||||
# Get current voltage and gradually up or down the value.
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -123,6 +124,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -186,6 +186,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
+17
-19
@@ -45,22 +45,23 @@ steering_correction = +3
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
steering.reset_angle(((right_end - left_end)/2)+steering_correction)
|
||||
steering.reset_angle(((right_end - left_end) / 2) + steering_correction)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set steering angle
|
||||
steering_angle = (((right_end - left_end)/2)-5)
|
||||
steering_angle_left = -steering_angle-steering_correction
|
||||
steering_angle_right = steering_angle+steering_correction
|
||||
steering_angle = ((right_end - left_end) / 2) - 5
|
||||
steering_angle_left = -steering_angle - steering_correction
|
||||
steering_angle_right = steering_angle + steering_correction
|
||||
|
||||
# Set variable for gear
|
||||
gear_total = 2 # Total number of gears.
|
||||
gear_old = None # Empty variable to set later on (keep
|
||||
# empty!).
|
||||
gear = 1 # Gear at start (must be higher than 0 and
|
||||
# lower or eaqual to gear_total).
|
||||
gear_color = ["BLUE", "RED"] # Number of colors should at least be
|
||||
# equal to gear_total.
|
||||
# Total number of gears.
|
||||
gear_total = 2
|
||||
# Empty variable to set later on (keep empty!).
|
||||
gear_old = None
|
||||
# Gear at start (must be higher than 0 and lower or eaqual to gear_total).
|
||||
gear = 1
|
||||
# Number of colors should at least be equal to gear_total.
|
||||
gear_color = ["BLUE", "RED"]
|
||||
|
||||
# Battery variables
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -83,7 +84,7 @@ while True:
|
||||
if gear_old > 1:
|
||||
gear -= 1
|
||||
while Button.LEFT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -92,14 +93,14 @@ while True:
|
||||
if gear_old < gear_total:
|
||||
gear += 1
|
||||
while Button.RIGHT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
# Set speed according to the choosen gear.
|
||||
if gear is not gear_old:
|
||||
remote.light.on(Color[gear_color[gear-1]])
|
||||
speed = (100/gear_total)*gear
|
||||
remote.light.on(Color[gear_color[gear - 1]])
|
||||
speed = (100 / gear_total) * gear
|
||||
gear_old = gear
|
||||
|
||||
# Choose the drive speed based on the left controls.
|
||||
@@ -112,7 +113,7 @@ while True:
|
||||
# Apply the selected speed.
|
||||
driving_1.dc(drive_speed)
|
||||
driving_2.dc(drive_speed)
|
||||
|
||||
|
||||
# Show battery status by hub LED.
|
||||
# Get current voltage and gradually up or down the value.
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -129,6 +130,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -41,20 +41,21 @@ right_end = steering.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
steering.reset_angle((right_end - left_end)/2)
|
||||
steering.reset_angle((right_end - left_end) / 2)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set steering angle
|
||||
steering_angle = (((right_end - left_end)/2)-5)
|
||||
steering_angle = ((right_end - left_end) / 2) - 5
|
||||
|
||||
# Set variable for gear
|
||||
gear_total = 2 # Total number of gears.
|
||||
gear_old = None # Empty variable to set later on (keep
|
||||
# empty!).
|
||||
gear = 1 # Gear at start (must be higher than 0 and
|
||||
# lower or eaqual to gear_total).
|
||||
gear_color = ["BLUE", "RED"] # Number of colors should at least be
|
||||
# equal to gear_total.
|
||||
# Total number of gears.
|
||||
gear_total = 2
|
||||
# Empty variable to set later on (keep empty!).
|
||||
gear_old = None
|
||||
# Gear at start (must be higher than 0 and lower or eaqual to gear_total).
|
||||
gear = 1
|
||||
# Number of colors should at least be equal to gear_total.
|
||||
gear_color = ["BLUE", "RED"]
|
||||
|
||||
# Battery variables
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -77,7 +78,7 @@ while True:
|
||||
if gear_old > 1:
|
||||
gear -= 1
|
||||
while Button.LEFT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
@@ -86,14 +87,14 @@ while True:
|
||||
if gear_old < gear_total:
|
||||
gear += 1
|
||||
while Button.RIGHT in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
# Set speed according to the choosen gear.
|
||||
if gear is not gear_old:
|
||||
remote.light.on(Color[gear_color[gear-1]])
|
||||
speed = (100/gear_total)*gear
|
||||
remote.light.on(Color[gear_color[gear - 1]])
|
||||
speed = (100 / gear_total) * gear
|
||||
gear_old = gear
|
||||
|
||||
# Choose the drive speed based on the left controls.
|
||||
@@ -106,7 +107,7 @@ while True:
|
||||
# Apply the selected speed.
|
||||
driving_1.dc(drive_speed)
|
||||
driving_2.dc(drive_speed)
|
||||
|
||||
|
||||
# Show battery status by hub LED.
|
||||
# Get current voltage and gradually up or down the value.
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -123,6 +124,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -42,20 +42,21 @@ right_end = steering.run_until_stalled(200, then=Stop.HOLD)
|
||||
|
||||
# We are now at the right. Reset this angle to be half the difference.
|
||||
# That puts zero in the middle.
|
||||
steering.reset_angle((right_end - left_end)/2)
|
||||
steering.reset_angle((right_end - left_end) / 2)
|
||||
steering.run_target(speed=200, target_angle=0, wait=False)
|
||||
|
||||
# Set steering angle
|
||||
steering_angle = (((right_end - left_end)/2)-5)
|
||||
steering_angle = ((right_end - left_end) / 2) - 5
|
||||
|
||||
# Set variable for gear
|
||||
gear_total = 2 # Total number of gears.
|
||||
gear_old = None # Empty variable to set later on (keep
|
||||
# empty!).
|
||||
gear = 1 # Gear at start (must be higher than 0 and
|
||||
# lower or eaqual to gear_total).
|
||||
gear_color = ["BLUE", "RED"] # Number of colors should at least be
|
||||
# equal to gear_total.
|
||||
# Total number of gears.
|
||||
gear_total = 2
|
||||
# Empty variable to set later on (keep empty!).
|
||||
gear_old = None
|
||||
# Gear at start (must be higher than 0 and lower or eaqual to gear_total).
|
||||
gear = 1
|
||||
# Number of colors should at least be equal to gear_total.
|
||||
gear_color = ["BLUE", "RED"]
|
||||
|
||||
# Battery variables
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -80,14 +81,14 @@ while True:
|
||||
else:
|
||||
gear = 1
|
||||
while Button.CENTER in pressed:
|
||||
# Button debounce
|
||||
# Button debounce
|
||||
wait(10)
|
||||
pressed = remote.buttons.pressed()
|
||||
|
||||
# Set speed according to the choosen gear.
|
||||
if gear is not gear_old:
|
||||
remote.light.on(Color[gear_color[gear-1]])
|
||||
speed = (100/gear_total)*gear
|
||||
remote.light.on(Color[gear_color[gear - 1]])
|
||||
speed = (100 / gear_total) * gear
|
||||
gear_old = gear
|
||||
|
||||
# Choose the drive speed based on the left controls.
|
||||
@@ -100,7 +101,7 @@ while True:
|
||||
# Apply the selected speed.
|
||||
driving_1.dc(drive_speed)
|
||||
driving_2.dc(drive_speed)
|
||||
|
||||
|
||||
# Choose the winch speed based on the red buttons.
|
||||
winch_speed = 0
|
||||
if Button.LEFT in pressed:
|
||||
@@ -110,7 +111,7 @@ while True:
|
||||
|
||||
# Apply the selected speed.
|
||||
winch.dc(winch_speed)
|
||||
|
||||
|
||||
# Show battery status by hub LED.
|
||||
# Get current voltage and gradually up or down the value.
|
||||
voltage_current = hub.battery.voltage()
|
||||
@@ -127,6 +128,3 @@ while True:
|
||||
hub.light.on(Color.ORANGE)
|
||||
else:
|
||||
hub.light.on(Color.RED)
|
||||
|
||||
# Wait.
|
||||
wait(10)
|
||||
|
||||
@@ -10,15 +10,11 @@ This is mainly needed to get no code errors and make use of IntelliSense.
|
||||
|
||||
[Based on the information on this support topic on GitHub.](https://github.com/pybricks/support/issues/10)
|
||||
|
||||
* Click the right mouse button under the last file in the explorer pane.
|
||||
* Click **Open in integrated Terminal**
|
||||
* Execute the following in the Terminal:
|
||||
|
||||
```sh
|
||||
python3 -m venv .venv
|
||||
```
|
||||
|
||||
* Open the Command Pallette (Ctrl + Shift + P) and search for **Python: Create Terminal**.
|
||||
* Open the Command Pallette (from the menu bar: open Help → Show All Commands or just press Ctrl + Shift + P) and search for **Python: Create Environment...**.
|
||||
* Select **Venv** to create a .venv environment.
|
||||
* Select the python version.
|
||||
* A .venv folder should now be created.
|
||||
* Open the Command Pallette (from the menu bar: open Help → Show All Commands or just press Ctrl + Shift + P) again and search for **Python: Create Terminal**.
|
||||
* Execute the following in the Terminal:
|
||||
|
||||
```sh
|
||||
|
||||
Reference in New Issue
Block a user