-
Notifications
You must be signed in to change notification settings - Fork 0
/
almoveto.py
82 lines (62 loc) · 2.43 KB
/
almoveto.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import time
from naoqi import ALProxy
class FaceTrackAndNavi:
def __init__(self, robot_ip_file_path):
self.robot_ip = self.get_robot_ip_from_file(robot_ip_file_path)
self.PORT = 9559
self.tracker_service = ALProxy("ALTracker", self.robot_ip, self.PORT)
self.targetName = "Face"
self.faceWidth = 0.1
def facetrack(self):
# Add target to track
self.tracker_service.registerTarget(self.targetName, self.faceWidth)
# Check if target is lost
target = self.tracker_service.isTargetLost()
if target==False:
print("Target lost, stopping FaceTrackAndNavi class")
self.tracker_service.stopTracker()
return False
# Do other face tracking logic here
print("Tracking face")
return True
def navi(self):
navigationProxy = ALProxy("ALNavigation", self.robot_ip, self.PORT)
navigationProxy.navigateTo(0.5, 0.2, [["SpeedFactor", 0.3]])
def get_robot_ip_from_file(self, file_path):
with open(file_path, 'r') as file:
ip_addresses = file.readline().strip()
return ip_addresses
def moveforward(self):
motion_service = ALProxy("ALMotion", self.robot_ip, self.PORT)
x = 0.2
y = 0.0
theta = 0.0
motion_service.moveTo(x, y, theta)
print("Moving forward")
def get_robot_ip_from_file(self, file_path):
with open(file_path, 'r') as file:
ip_addresses = file.readline().strip()
return ip_addresses
if __name__ == "__main__":
# Create instances of the classes
facetrack_navi = FaceTrackAndNavi('robot_ip.txt')
move_forward = MoveForward('robot_ip.txt')
while True:
try:
# Check if the target is lost
target = facetrack_navi.tracker_service.isTargetLost()
if target==False:
print("Target found, starting MoveForward class")
if facetrack_navi.facetrack():
continue
move_forward.moveforward()
elif target==True:
print("Target lost, starting FaceTrackAndNavi class")
if not facetrack_navi.facetrack():
continue
if not facetrack_navi.navi():
continue
time.sleep(1)
except Exception as e:
print(f"Error in main: {e}")
break