#!/usr/bin/env python3 from ev3dev2.motor import Motor, OUTPUT_A, OUTPUT_B, OUTPUT_C import struct # Declare motors left_motor = Motor(OUTPUT_B) right_motor = Motor(OUTPUT_C) steer_motor = Motor(OUTPUT_A) steer_motor.position = 0 # Initialize variables. # Assuming sticks are in the middle when starting. right_stick_x = 124 right_stick_y = 124 # A helper function for converting stick values (0 - 255) # to more usable numbers (-100 - 100) def scale(val, src, dst): """ Scale the given value from the scale of src to the scale of dst. val: float or int src: tuple dst: tuple example: print(scale(99, (0.0, 99.0), (-1.0, +1.0))) """ return (float(val - src[0]) / (src[1] - src[0])) * (dst[1] - dst[0]) + dst[0]
#! /usr/bin/python3 from ev3dev2.motor import Motor, SpeedDPS, SpeedPercent from time import sleep import os os.system('setfont Lat15-TerminusBold14') hand = Motor('A') hand.position = 0 hand.on_to_position(0.05, 20 / 360 * hand.count_per_rot, block=False) while True: sleep(1) print('\r', hand.position / hand.count_per_rot * 360, end='')