Skip to content

Instantly share code, notes, and snippets.

View cocoazawa's full-sized avatar

cocoazawa cocoazawa

  • Tokyo
  • 10:28 (UTC +09:00)
View GitHub Profile
@cocoazawa
cocoazawa / robotics-ifStatements.py
Created November 2, 2025 11:56
This gist is for Robotics! It demonstrates (albeit... with a lot of comments) how to use If statements to differentially control the robot.
# NOTE: this code should go in your userControl or "user_control" function
# NOTE: I am assuming that you have the motor groups and other things defined before the constant-loop.
while True:
# the axis may be wrong, I'm blind coding this (not looking at the API docs for the axis)
velocityMultiplier = controller.axis4.position() / 100 # get the current position (0-100) and divide it by 100 (becomes 0 or 1 or 0.something)
sidewaysMultiplier = controller.axis3.position() / 100 # get the current position (0-100) and divide it by 100 (becomes 0 or 1 or 0.something)
# HEY!!! new function!
# the `abs(number)` function is literally the |number| in math. It gets the absolute value of whatever the number is.