Value ranges depends on motor type:
- Small motor (essential):
-660
to660
- Medium motor:
-1110
to1110
- Large motor:
-1050
to1050
- If degrees are positive, motor will rotate clockwise, if negative, counter clockwise.
- If velocity is positive, motor will rotate forward, if negative, backward.
- So, having both values negative will cancel each other out and motor will move clockwise.
- run for
- go to position (absolute)
- go to position (relative)
- start motor
- stop motor
- set speed to
- power (value)
- position (absolute, value)
- position (relative, value)
- speed (value)
- set relative position to
- set motors brake
- set acceleration to
degree = 360
velocity = 1000
await _motor.run_for_degrees(port.A, degree, velocity)
# not await version
motor.run_for_degrees(port.A, degree, velocity)
rotations = 2
velocity = 1000
await _motor.run_for_degrees(port.A, rotations * 360, velocity)
# not await version
motor.run_for_degrees(port.A, rotations * 360, velocity)
miliseconds = 2000
velocity = 1000
await _motor.run_for_time(port.A, miliseconds, velocity)
# not await version
motor.run_for_time(port.A, miliseconds, velocity)
position = 180
velocity = 1000
await _motor.run_to_absolute_position(port.A, position, velocity, direction=motor.SHORTEST_PATH)
# not await version
motor.run_to_absolute_position(port.A, position, velocity, direction=motor.SHORTEST_PATH)
possible direction
values are: motor.SHORTEST_PATH
, motor.LONGEST_PATH
, motor.CLOCKWISE
, motor.COUNTERCLOCKWISE
position = 180
velocity = 1000
await _motor.run_to_relative_position(port.A, position, velocity)
# not await version
motor.run_to_relative_position(port.A, position, velocity)
velocity = 1000
motor.run(port.A, velocity)
motor.stop(port.A)
It might not get much sense, since we can pass velocity to every motor function, but it is here for completeness:
motor_A_speed = 1000
async def my_func(task_id):
global motor_A_speed
motor_A_speed = motor_A_speed * 0.75 # set speed to 75% of initial value
motor.run(port.A, motor_A_speed) # run motor A with 75% 'gloval' speed
You can also store and change speed locally:
async def my_func(task_id):
motor_A_speed = 750
motor.run(port.A, motor_A_speed) # run motor A with 75% 'local' speed
if you created global variable for motor speed, you can access it like this:
my_new_variable = motor_A_speed
motor.absolute_position(port.A)
usage:
position = motor.absolute_position(port.A)
# do something with position variable
motor.relative_position(port.A)
motor.velocity(port.A)
motor.reset_relative_position(port.A, 0)
in python, you can pass stop
value to almost every motor function, including motor.stop()
. If you really want, you can also make it global, like in (set speed to)[#set-speed-to] example.
await _motor.run_for_degrees(port.A, 360, 1000, stop=motor.BRAKE)
possible stop
values are: motor.COAST
, motor.BREAK
, motor.HOLD
, motor.CONTINUE
, motor.SMART_COAST
, motor.SMART_BRAKE
again, in python you can pass acceleration
value to almost every motor function:
motor.run(port.A, 1000, acceleration=5000)
there is also deceleration
parameter:
motor.run(port.A, 1000, acceleration=5000, deceleration=5000)
Possible values are from 0
to 10000
for both acceleration
and deceleration
.
Note: besides that spike app
states, that default is 1000
, it is not true. Default is more like 5000
for both acceleration and deceleration, if you dont pass it.