-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht1b_react.py
executable file
·61 lines (47 loc) · 1.42 KB
/
t1b_react.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import matplotlib.pyplot as plt
sys.path.append('hexapod_robot')
#import hexapod robot
import HexapodRobot as hexapod
#import communication messages
from messages import *
if __name__=="__main__":
robot = hexapod.HexapodRobot(0)
#turn on the robot
robot.turn_on()
#start navigation thread
robot.start_navigation()
time.sleep(3)
#assign goal for navigation
goals = [
Pose(Vector3(3.5,3.5,0),Quaternion(1,0,0,0)),
Pose(Vector3(0,0,0),Quaternion(1,0,0,0)),
]
path = Path()
#go from goal to goal
for goal in goals:
robot.goto_reactive(goal)
while robot.navigation_goal is not None:
#sample the current odometry
if robot.odometry_ is not None:
path.poses.append(robot.odometry_.pose)
#wait
time.sleep(0.1)
#check the robot distance to goal
odom = robot.odometry_.pose
#compensate for the height of the robot as we are interested only in achieved planar distance
odom.position.z = 0
#calculate the distance
dist = goal.dist(odom)
print("[t1b_eval] distance to goal: %.2f" % dist)
robot.stop_navigation()
robot.turn_off()
#plot the robot path
fig, ax = plt.subplots()
path.plot(ax, 30)
plt.xlabel('x[m]')
plt.ylabel('y[m]')
plt.axis('equal')
plt.show()