Skip to content

Latest commit

 

History

History
214 lines (147 loc) · 5.08 KB

01_MOTORS.md

File metadata and controls

214 lines (147 loc) · 5.08 KB

Motors

Velocities:

Value ranges depends on motor type:

  • Small motor (essential): -660 to 660
  • Medium motor: -1110 to 1110
  • Large motor: -1050 to 1050

Direction:

  • 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.

Table of contents

  1. run for
  2. go to position (absolute)
  3. go to position (relative)
  4. start motor
  5. stop motor
  6. set speed to
  7. power (value)
  8. position (absolute, value)
  9. position (relative, value)
  10. speed (value)
  11. set relative position to
  12. set motors brake
  13. set acceleration to

run for

alt text

degrees

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

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)

seconds

miliseconds = 2000
velocity = 1000
await _motor.run_for_time(port.A, miliseconds, velocity)
# not await version
motor.run_for_time(port.A, miliseconds, velocity)

go to position (absolute)

alt text

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

go to position (relative)

alt text

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)

start motor

alt text alt text

velocity = 1000
motor.run(port.A, velocity)

stop motor

alt text

motor.stop(port.A)

set speed to

alt text

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

power (value)

alt text

if you created global variable for motor speed, you can access it like this:

my_new_variable = motor_A_speed

position (absolute, value)

alt text

motor.absolute_position(port.A)

usage:

position = motor.absolute_position(port.A)
# do something with position variable

position (relative, value)

alt text

motor.relative_position(port.A)

speed (value)

alt text

motor.velocity(port.A)

set relative position to

alt text

motor.reset_relative_position(port.A, 0)

set motors brake

alt text

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

set acceleration to

alt text

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.