Trying to make a tank #2634
Replies: 3 comments
-
|
I don't see any obvious issues with the program. Can you describe more about the expected behavior and what the tank is actually doing instead? One small tip, you can use |
Beta Was this translation helpful? Give feedback.
-
|
Hello, I made the change David suggested and I removed the "wait for controller" as the program does not proceed if the controller is not connected. Removed the minus on the left_input and right_input. from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Direction, Port
from pybricks.tools import wait
from pybricks.iodevices import XboxController
# SETTINGS
LEFT_PORT = Port.D
RIGHT_PORT = Port.E
MAX_SPEED = 1000
DEADZONE = 5
hub = PrimeHub()
left_motor = Motor(LEFT_PORT, positive_direction=Direction.COUNTERCLOCKWISE)
right_motor = Motor(RIGHT_PORT)
controller = XboxController()
# print("Waiting for controller...")
# while not controller.connected():
# wait(100)
print("Controller connected!")
wait(500) # small delay to ensure controller is fully initialized
def apply_deadzone(value, threshold):
return 0 if abs(value) < threshold else value
while True:
try:
left_y = controller.joystick_left()[1]
right_y = controller.joystick_right()[1]
except OSError:
left_y = 0
right_y = 0
left_input = apply_deadzone(left_y, DEADZONE)
right_input = apply_deadzone(right_y, DEADZONE)
left_speed = (left_input / 100) * MAX_SPEED
right_speed = (right_input / 100) * MAX_SPEED
left_motor.run(left_speed)
right_motor.run(right_speed)
wait(20)Maybe you want to set counterclockwise on the other motor, but that is just a small thing. You talked about a block program where you had a problem. Bert |
Beta Was this translation helpful? Give feedback.
-
|
Perfect fix. Thank you both very much. He'll be quite happy when I see him. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've got a student trying to make a tank. It's working well in block coding, but I'd like to use the Xbox controllers and have it move backwards. I don't see that as an option for block coding. I tried having Chatgpt create the code for me in python but it isn't working ethier.
I was hoping someone would be able to point me in the right direction.
Beta Was this translation helpful? Give feedback.
All reactions