Skip to content

Instantly share code, notes, and snippets.

@znd4
Created December 6, 2023 21:35
Show Gist options
  • Save znd4/542239dd410d0a40fc908bda3f5a5e27 to your computer and use it in GitHub Desktop.
Save znd4/542239dd410d0a40fc908bda3f5a5e27 to your computer and use it in GitHub Desktop.
interview sample code
from frclib import Robot, Controller, get_environment
def main():
ROBOTS = [Robot()]
controller = Controller()
while True:
environment = get_environment()
for robot in ROBOTS:
control_loop(robot, environment, controller)
def control_loop(robot, environment, controller):
if (
environment.temperature > 100
or environment.temperature < 80
or environment.humidity > 80
):
robot.turn_off()
return "Robot is off"
else:
y = controller.left_joystick.y
if y > 0.1:
robot.motor_controller.motors[0].forward(y)
robot.motor_controller.motors[1].forward(y)
if y < -0.1:
robot.motor_controller.motors[0].backward(y)
robot.motor_controller.motors[1].backward(y)
x = controller.left_joystick.x
if x > 0.1:
robot.motor_controller.motors[0].forward(x)
robot.motor_controller.motors[1].backward(x)
if x < -0.1:
robot.motor_controller.motors[0].backward(x)
robot.motor_controller.motors[1].forward(x)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment