-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathmove_motor.py
More file actions
executable file
·36 lines (31 loc) · 1.21 KB
/
move_motor.py
File metadata and controls
executable file
·36 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""
Used to adjust the position of a motor in an already assembled robot
where you can"t move the motor by hand.
"""
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, Motor
import argparse
import logging
# command line args
parser = argparse.ArgumentParser(description="Used to adjust the position of a motor in an already assembled robot")
parser.add_argument("motor", type=str, help="A, B, C or D")
parser.add_argument("degrees", type=int)
parser.add_argument("-s", "--speed", type=int, default=50)
args = parser.parse_args()
# logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)5s: %(message)s")
log = logging.getLogger(__name__)
if args.motor == "A":
motor = Motor(OUTPUT_A)
elif args.motor == "B":
motor = Motor(OUTPUT_B)
elif args.motor == "C":
motor = Motor(OUTPUT_C)
elif args.motor == "D":
motor = Motor(OUTPUT_D)
else:
raise Exception("%s is invalid, options are A, B, C, D")
if args.degrees:
log.info("Motor %s, current position %d, move to position %d, max speed %d" %
(args.motor, motor.position, args.degrees, motor.max_speed))
motor.run_to_rel_pos(speed_sp=args.speed, position_sp=args.degrees, stop_action='hold')