-
Notifications
You must be signed in to change notification settings - Fork 3
/
spike_pybricks_motorpair.py
34 lines (33 loc) · 1.28 KB
/
spike_pybricks_motorpair.py
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
from pybricks.hubs import PrimeHub
from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor, ForceSensor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import wait, StopWatch
class MotorPair:
def __init__(self, port1, port2):
self.motor1 = Motor(port1)
self.motor2 = Motor(port2)
self.timer = StopWatch()
def move_angle(self,amount,speed1,speed2, timeout = 1000):
self.motor1.reset_angle(0)
self.motor2.reset_angle(0)
self.timer.reset()
while abs(self.motor1.angle()) < amount or self.timer.time() < timeout:
while abs(self.motor2.angle()) < amount or self.timer.time() < timeout:
self.motor1.run(speed1)
self.motor2.run(-(speed2))
self.motor1.stop()
self.motor2.stop()
return "succeded"
def move_tank(self,amount, speed1, speed2):
self.motor1.run(speed1)
self.motor2.run(-(speed2))
wait(amount)
self.motor1.stop()
self.motor2.stop()
def start_tank(self, speed1, speed2):
self.motor1.run(speed1)
self.motor2.run(-(speed2))
def stop_tank(self):
self.motor1.hold()
self.motor2.hold()