<commit_before>#!/usr/bin/env python

"""
Used to adjust the position of a motor in an already assembled robot
where you can"t move the motor by hand.
"""

from ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D
from ev3dev.helper import LargeMotor
import argparse
import logging
import sys

# 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.DEBUG,
                    format="%(asctime)s %(levelname)5s: %(message)s")
log = logging.getLogger(__name__)

# For this it doesn't really matter if it is a LargeMotor or a MediumMotor
if args.motor == "A":
    motor = LargeMotor(OUTPUT_A)
elif args.motor == "B":
    motor = LargeMotor(OUTPUT_B)
elif args.motor == "C":
    motor = LargeMotor(OUTPUT_C)
elif args.motor == "D":
    motor = LargeMotor(OUTPUT_D)
else:
    raise Exception("%s is invalid, options are A, B, C, D")

if not motor.connected:
    log.error("%s is not connected" % motor)
    sys.exit(1)

if args.degrees:
    log.info("Motor %s, move to position %d, max speed %d" % (args.motor, args.degrees, motor.max_speed))
    motor.run_to_rel_pos(speed_sp=args.speed,
                         position_sp=args.degrees,
                         # ramp_up_sp=500,
                         # ramp_down_sp=500,
                         stop_action='hold')
    motor.wait_for_running()
    motor.wait_for_stop()
    motor.stop(stop_action='brake')
    log.info("Motor %s stopped, final position %d" % (args.motor, motor.position))<commit_msg>Update move_motor.py to python3, make it work for all motors<commit_after>#!/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 ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_C, OUTPUT_D, Motor
import argparse
import logging
import sys

# 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 not motor.connected:
    log.error("%s is not connected" % motor)
    sys.exit(1)

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')
{'fraction_non_alphanumeric': 0.12407862407862408, 'fraction_numerical': 0.005835380835380835, 'mean_word_length': 3.511080332409972, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6676742', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1047, 'n_words': 308}