-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.py
61 lines (47 loc) · 1.5 KB
/
robot.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import time
import math
import robomasterpy
import cv2
class Robot:
ip: str
robo: robomasterpy.client.Commander
def __init__(self, ip=robomasterpy.get_broadcast_ip()):
#self.ip = robomasterpy.get_broadcast_ip()
self.ip = ip
self.robo = robomasterpy.Commander(self.ip)
print("Successfully connected to robot. IP Address: " + self.ip)
self.robo.stream(True)
self.cap = cv2.VideoCapture(f'tcp://{self.ip}:{40921}')
r, f = self.cap.read()
if r:
print("Robot Camera Initiated")
def returnPosition(self):
robo = self.robo
x = robo.get_chassis_position()
pos = []
for attribute, value in x.__dict__.items():
pos.append(value)
return pos
#---DRIVE---
# robo.chassis_wheel(front left, rear left, rear right, front right)
# robo.chassis_wheel(-forward, +forward, -forward, +forward)
def stop(self):
robo = self.robo
robo.chassis_wheel(0, 0, 0, 0)
def moveForward(self):
robo = self.robo
robo.chassis_wheel(-50, 50, -50, 50)
def moveBackward(self):
robo = self.robo
robo.chassis_wheel(50, -50, 50, -50)
def rotateRight(self):
robo = self.robo
robo.chassis_speed(z=90)
robo.chassis_move(z=40)
def rotateLeft(self):
robo = self.robo
robo.chassis_speed(z=90)
robo.chassis_move(z=-40)
def videoStream(self):
robo = self.robo
robo.stream(True)