-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimple_test_benchmark.py
executable file
·156 lines (110 loc) · 4.38 KB
/
simple_test_benchmark.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import rospy, yaml
from rsbb_bmbox.BenchmarkObjects import BaseBenchmarkObject, GoalObject, ManualOperationObject
class BenchmarkObject (BaseBenchmarkObject):
#T def get_benchmark_code(self, hello): return "STB"
#T def get_benchmark_code(self): return 5
#T def get_benchmark_code(self): return "STB"
#T def execute_(self):
#T def execute(self, hello):
benchmark_code = "STB"
def execute(self):
N = 2
i = 1
execution_time = rospy.Duration(0.0)
print "params:\n", self.params
print "referee_score:\n", self.referee_score
##########################################
# MANUAL OPERATION #
##########################################
manual_operation_first = ManualOperationObject("First Manual Operation")
self.start_manual_operation(manual_operation_first)
self.wait_manual_operation()
##########################################
# CHECK RESULT AND UPDATE SCORE #
##########################################
if manual_operation_first.has_been_completed():
print "First Manual Operation result: %s" % manual_operation_first.get_result()
self.score["first_manual_operation"] = manual_operation_first.get_result()
self.save_and_publish_score()
else:
print "First Manual Operation NOT EXECUTED"
self.score["first_manual_operation"] = "not executed"
self.save_and_publish_score()
if not self.is_benchmark_running():
if self.has_benchmark_timed_out():
print "BENCHMARK TIMEOUT"
return
elif self.has_benchmark_been_stopped():
print "BENCHMARK STOPPED"
return
else:
print "BENCHMARK ABORTED"
return
while self.is_benchmark_running() and i <= N:
##########################################
# GOAL i #
##########################################
goal = GoalObject({"goal": "GOAL %d"%i, "details": 4}, 15.0)
self.request_goal(goal)
start_time = rospy.Time.now()
print "wait_goal_result"
self.wait_goal_result()
end_time = rospy.Time.now()
#T while not goal.has_been_completed() and not goal.has_timed_out(): rate.sleep(); self.complete_goal()
execution_time += end_time - start_time
rospy.loginfo("Execution time - %f" % execution_time.to_sec())
##########################################
# CHECK RESULT i AND UPDATE SCORE #
##########################################
self.score["goal_%i"%i] = {}
self.score["goal_%i"%i]["timeout"] = goal.has_timed_out()
self.score["goal_%i"%i]["completed"] = goal.has_been_completed()
if goal.has_timed_out():
print "GOAL TIMEOUT"
elif goal.has_been_completed():
print "GOAL COMPLETED:"
result = goal.get_result()
print "result:\n", result
self.score["goal_%i"%i]["result"] = result
else:
print "GOAL NOT COMPLETED"
self.save_and_publish_score()
if not self.is_benchmark_running():
print self.get_end_description()
if self.has_benchmark_timed_out():
print "BENCHMARK TIMEOUT"
elif self.has_benchmark_been_stopped():
print "BENCHMARK STOPPED"
else:
print "BENCHMARK ABORTED"
i += 1
##########################################
# MANUAL OPERATION #
##########################################
manual_operation_last = ManualOperationObject("Last Manual Operation")
self.request_manual_operation(manual_operation_last)
##########################################
# CHECK RESULT AND UPDATE SCORE #
##########################################
if manual_operation_last.has_been_completed():
print "Last Manual Operation result: %s" % manual_operation_last.get_result()
self.score["last_manual_operation"] = manual_operation_last.get_result()
self.save_and_publish_score()
else:
print "Last Manual Operation NOT EXECUTED"
self.score["last_manual_operation"] = "not executed"
self.save_and_publish_score()
if not self.is_benchmark_running():
if self.has_benchmark_timed_out():
print "BENCHMARK TIMEOUT"
elif self.has_benchmark_been_stopped():
print "BENCHMARK STOPPED"
else:
print "BENCHMARK ABORTED"
##########################################
# UPDATE SCORE #
##########################################
self.score["execution_time"] = execution_time.to_sec()
self.save_and_publish_score()