Motion#
Introduction#
GO Motion commands let motors spin, hold position, and control velocity and torque with precision.
For the examples below, the configured motor will be named arm
. They will be used in all subsequent examples throughout this API documentation when referring to Motor
class methods.
Below is a list of all methods:
Actions – Control the movement of motors.
spin
– Spins a motor in a specified direction indefinitely.spin_for
– Spins a motor for a specified distance.spin_to_position
– Spins a motor to an absolute position.stop
– Stops a motor.
Mutators – Change the motor’s different attributes.
set_velocity
– Sets the default velocity for the motor.set_max_torque
– Sets the maximum torque for a motor.set_position
– Sets the motor’s position to a specific value.set_stopping
– Sets the stop behavior (brake, coast, or hold).set_timeout
– Limits how long a motor function waits before giving up if movement is blocked.
Getters – Return data from motors.
get_position
– Returns a motor’s current position.get_velocity
– Returns a motor’s current velocity.get_current
– Returns the current being used by a motor.is_stopped
– Returns whether a motor is currently not spinning.is_moving
– Returns whether a motor is currently spinning.
Actions#
spin#
spin
spins the motor in a specified direction indefinitely.
Usage:
arm.spin(direction)
Parameters |
Description |
---|---|
|
The direction in which to spin the motor:
|
# Build Used: Competition Advanced 2.0
def main():
# Spin motor in reverse, then stop
arm.spin(REVERSE)
wait(1, SECONDS)
arm.stop()
# Start threads — Do not delete
start_thread(main)
spin_for#
spin_for
spins the motor in a specified direction for a specific angle.
Usage:
arm.spin_for(direction, angle, wait)
Parameters |
Description |
---|---|
|
The direction in which to spin the motor:
|
|
The amount of degrees the motor will spin as a float or integer in degrees. |
|
Optional.
|
# Build Used: Competition Advanced 2.0
def main():
# Spin motor in both directions
arm.spin_for(REVERSE, 180)
arm.spin_for(FORWARD, 180)
# Start threads — Do not delete
start_thread(main)
spin_to_position#
spin_to_position
spins the motor to an absolute position.
Usage:
arm.spin_to_position(angle, wait)
Parameters |
Description |
---|---|
|
The position to spin the motor to as a float or integer. |
|
Optional.
|
# Build Used: Competition Advanced 2.0
def main():
# Put motor at 0 position after spinning
arm.set_position(0)
arm.spin(REVERSE)
wait(1, SECONDS)
arm.spin_to_position(0)
# Start threads — Do not delete
start_thread(main)
stop#
stop
stops a motor from spinning.
Usage:
arm.stop()
Parameters |
Description |
---|---|
This method has no parameters. |
# Build Used: Competition Advanced 2.0
def main():
# Spin motor in reverse, then stop
arm.spin(REVERSE)
wait(1, SECONDS)
arm.stop()
# Start threads — Do not delete
start_thread(main)
Mutators#
set_velocity#
set_velocity
sets the default velocity for a motor. This velocity setting will be used for subsequent calls to any Motor functions.
Usage:
arm.set_velocity(velocity)
Parameters |
Description |
---|---|
|
The velocity at which the motor will spin at as a percent. |
# Build Used: Competition Advanced 2.0
def main():
# Spin motor at different velocities
arm.spin_for(REVERSE, 180)
wait(1, SECONDS)
# Spin slower
arm.set_velocity(20)
arm.spin_for(FORWARD, 180)
wait(1, SECONDS)
# Spin faster
arm.set_velocity(100)
arm.spin_for(REVERSE, 180)
# Start threads — Do not delete
start_thread(main)
set_max_torque#
set_max_torque
sets the maximum torque for a motor.
Usage:
arm.set_max_torque(value)
Parameters |
Description |
---|---|
|
The new maximum torque for a motor as a float or integer. |
# Build Used: Competition Advanced 2.0
def main():
# Spin the motor at different torques
arm.spin_for(REVERSE, 180)
wait(1, SECONDS)
# Less torque
arm.set_max_torque(20)
arm.spin_for(FORWARD, 180)
wait(1, SECONDS)
# More torque
arm.set_max_torque(100)
arm.spin_for(REVERSE, 180)
# Start threads — Do not delete
start_thread(main)
set_position#
set_position
sets the position of a motor.
Usage:
arm.set_position(position)
Parameters |
Description |
---|---|
|
The new position as an integer in degrees. |
# Build Used: Competition Advanced 2.0
def main():
# Position the motor at the new 0 degrees
arm.set_position(180)
arm.spin_to_position(0)
# Start threads — Do not delete
start_thread(main)
set_stopping#
set_stopping
sets the stopping mode for a motor.
Usage:
arm.set_stopping(mode)
Parameters |
Description |
---|---|
|
How the motor will stop:
|
# Build Used: Competition Advanced 2.0
def main():
# Spin motor forward then coast to a stop
arm.set_velocity(100)
arm.set_stopping(COAST)
arm.spin(REVERSE)
wait(2, SECONDS)
arm.stop()
# Start threads — Do not delete
start_thread(main)
set_timeout#
set_timeout
sets a time limit for how long a motor function will wait to reach its target. If the motor cannot complete the movement within the set time, it will stop automatically and continue with the next function.
Note: The motor’s time limit is used to prevent motor functions that do not reach their target position from stopping the execution of the rest of the project.
Usage:
arm.set_timeout(value, units)
Parameters |
Description |
---|---|
|
The maximum number of seconds a motor function will run before stopping and moving to the next function as an integer or float. |
|
Optional. The unit that represents the time:
|
# Build Used: Competition Advanced 2.0
def main():
# Spin the motor for one and a half seconds then reset
arm.set_position(0)
arm.set_timeout(1.5, SECONDS)
arm.spin_for(REVERSE, 1000)
arm.spin_to_position(0)
# Start threads — Do not delete
start_thread(main)
Getters#
get_position#
get_position
returns the current position of a motor as an integer or as a float in degrees.
Usage:
arm.get_position()
Parameters |
Description |
---|---|
This method has no parameters. |
# Build Used: Competition Advanced 2.0
def main():
# Spin motor while monitoring the position
console.print("Start: ")
console.print(arm.get_position())
console.new_line
arm.spin(REVERSE)
wait(1, SECONDS)
arm.stop()
console.print("After: ")
console.print(arm.get_position())
# Start threads — Do not delete
start_thread(main)
get_velocity#
get_velocity
returns the current velocity of a motor as an integer or as a float in percent.
Usage:
arm.get_velocity()
Parameters |
Description |
---|---|
This method has no parameters. |
# Build Used: Competition Advanced 2.0
def main():
# Spin the motor and display the velocity
console.print("Start: ")
console.print(arm.get_velocity())
console.new_line()
arm.spin(REVERSE)
wait(1, SECONDS)
console.print("Moving: ")
console.print(arm.get_velocity())
arm.stop()
# Start threads — Do not delete
start_thread(main)
get_current#
get_current
returns the current of the motor in amps.
Usage:
arm.get_current()
Parameters |
Description |
---|---|
This method has no parameters. |
# Build Used: Competition Advanced 2.0
def main():
# Spin the motor and display the current
console.print("Start: ")
console.print(arm.get_current())
console.new_line()
arm.spin(REVERSE)
wait(1, SECONDS)
console.print("Moving: ")
console.print(arm.get_current())
arm.stop()
# Start threads — Do not delete
start_thread(main)
is_stopped#
is_stopped
returns a Boolean indicating whether the motor is stopped.
True
– The motor is stopped.False
– The motor is spinning.
Usage:
arm.is_stopped()
Parameters |
Description |
---|---|
This method has no parameters. |
# Build Used: Competition Advanced 2.0
def main():
# Turn the eye light on when moving
arm.spin_for(REVERSE, 200, wait=False)
wait(0.1, SECONDS)
while True:
if arm.is_stopped():
eye.set_light(OFF)
else:
eye.set_light(ON)
# Start threads — Do not delete
start_thread(main)
is_moving#
is_moving
returns a Boolean indicating whether the motor is spinning.
True
– The motor is spinning.False
– The motor is stopped.
Usage:
arm.is_moving()
Parameters |
Description |
---|---|
This method has no parameters. |
# Build Used: Competition Advanced 2.0
def main():
# Turn the eye light on while moving
arm.spin_for(FORWARD, 200, wait=False)
wait(0.1, SECONDS)
while True:
if arm.is_moving():
eye.set_light(ON)
else:
eye.set_light(OFF)
# Start threads — Do not delete
start_thread(main)