Guest User

studentcode.py

a guest
Nov 3rd, 2021
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.26 KB | None | 0 0
  1. KOALA_BEAR = "6_1"
  2. LINE_FOLLOWER = "2_3"
  3. LIMIT_SWITCH = "limit_switch"
  4. ARM_MOTOR = "6_801"
  5. def autonomous_setup():
  6.     print("Autonomous mode has started!")
  7.     la = Robot.get_value(LINE_FOLLOWER, "right")
  8.     lb = Robot.get_value(LINE_FOLLOWER, "left")
  9.     lc = Robot.get_value(LINE_FOLLOWER, "center")
  10.     # in case of any needed motor inversions
  11.     Robot.set_value(KOALA_BEAR, "invert_b", False)
  12.     Robot.set_value(KOALA_BEAR, "invert_a", True)
  13. def autonomous_main():
  14.     right_motor_speed = 1
  15.     left_motor_speed = 1
  16.     la = Robot.get_value(LINE_FOLLOWER, "right")
  17.     lb = Robot.get_value(LINE_FOLLOWER, "left")
  18.     lc = Robot.get_value(LINE_FOLLOWER, "center")
  19.     # Robot following tape in a straight line
  20.     if (lb > lc and lb > la):
  21.         # print("left")
  22.         right_motor_speed = 0.45
  23.         left_motor_speed = 0.2
  24.         Robot.set_value(KOALA_BEAR, "velocity_a", right_motor_speed)
  25.         Robot.set_value(KOALA_BEAR, "velocity_b", left_motor_speed)
  26.     # Robot following tape that starts to go to the right, diagonally not a 90 degree turn
  27.     elif (la > lc and la > lb):
  28.         # print("right")
  29.         right_motor_speed = 0.2
  30.         left_motor_speed = 0.45
  31.         Robot.set_value(KOALA_BEAR, "velocity_a", right_motor_speed)
  32.         Robot.set_value(KOALA_BEAR, "velocity_b", left_motor_speed)
  33.     elif (lc > la and lc > lb):
  34.         # print("straight")
  35.         right_motor_speed = .55
  36.         left_motor_speed = .55
  37.         Robot.set_value(KOALA_BEAR, "velocity_a", right_motor_speed)
  38.         Robot.set_value(KOALA_BEAR, "velocity_b", left_motor_speed)
  39.     # Robot following tape that starts to go to the left, diagonally not a 90 degree turn
  40.     else:
  41.         pass
  42.         #print("broken, sad, and confused robot :(")
  43. def teleop_setup():
  44.     print("Teleop mode has started!")
  45.     # in case of any needed motor inversions
  46.     Robot.set_value(KOALA_BEAR, "invert_b", False)
  47.     Robot.set_value(KOALA_BEAR, "invert_a", True)
  48. def teleop_main():
  49.     right_motor_speed = 0
  50.     left_motor_speed = 0
  51.     arm_speed = 0
  52.     if Keyboard.get_value("w"):
  53.         right_motor_speed = 0.5
  54.         left_motor_speed = 0.5
  55.     elif Keyboard.get_value("s"):
  56.         right_motor_speed = -0.5
  57.         left_motor_speed = -0.5
  58.     if Keyboard.get_value("d"):
  59.         right_motor_speed = 0.075
  60.         left_motor_speed = 0.5
  61.     elif Keyboard.get_value("a"):
  62.         right_motor_speed = 0.5
  63.         left_motor_speed = 0.075
  64.     if Keyboard.get_value("t"):
  65.         right_motor_speed = 1
  66.         left_motor_speed = 1
  67.     elif Keyboard.get_value("g"):
  68.         right_motor_speed = -1
  69.         left_motor_speed = -1
  70.     if Keyboard.get_value("h"):
  71.         right_motor_speed = 0.3
  72.         left_motor_speed = 1
  73.     elif Keyboard.get_value("f"):
  74.         right_motor_speed = 1
  75.         left_motor_speed = 0.3
  76.     if Keyboard.get_value("up_arrow"):
  77.         arm_speed = 0.1
  78.     elif Keyboard.get_value("down_arrow"):
  79.         arm_speed = -0.1
  80.     Robot.set_value(KOALA_BEAR, "velocity_b", left_motor_speed)
  81.     Robot.set_value(KOALA_BEAR, "velocity_a", right_motor_speed)
  82.     # KOALA_BEAR below is the second motor controller for the arm specifically !!! CHANGE THE IDS WHEN DRIVING
  83.      Robot.set_value(ARM_MOTOR, "velocity_b", arm_speed)
Advertisement
Add Comment
Please, Sign In to add comment