Commit 2113e608 authored by Barciś, Agata's avatar Barciś, Agata

working version

parent 30ce9ab6
......@@ -66,7 +66,7 @@ class CameraStream(Node, MissionExecutor):
qos_profile=CUSTOM_QOS,
# qos_profile=QoSPresetProfiles.get_from_short_key('SYSTEM_DEFAULT')
)
self.timer_period = 0.25
self.timer_period = 0.33
self.timer = None
self.cam_fps = 90
self.cam = cv2.VideoCapture(0)
......@@ -111,7 +111,7 @@ class CameraStream(Node, MissionExecutor):
# )
'msg_num': create_msgnum_constraint_violations(
msgnum=3,
timeslot=0.5,
timeslot=0.4,
)
},
......@@ -148,9 +148,10 @@ class CameraStream(Node, MissionExecutor):
self.timer_period = 1 / float(params.get('fps', 2))
def timer_callback(self):
if abs((datetime.now().timestamp() - self.t_start)%self.timer_period - self.offset) > 0.02:
if abs((datetime.now().timestamp() - self.t_start - 0.01)%self.timer_period - self.offset) > 0.02:
print("skipping")
return
all_start = datetime.now().timestamp()
for i in range(16):
start = datetime.now()
self.cam.grab()
......@@ -159,7 +160,7 @@ class CameraStream(Node, MissionExecutor):
break
frame = self.cam.retrieve()[1]
now = self.get_clock().now()
frame = cv2.resize(frame, (320, 240))
# frame = cv2.resize(frame, (320, 240))
mask = detect_red(frame)
red = np.round(np.sum(mask) / mask.size / 255, 5)
jpg = bytearray(cv2.imencode('.jpg', frame)[1])
......@@ -195,10 +196,13 @@ class CameraStream(Node, MissionExecutor):
msg.header.stamp.sec + msg.header.stamp.nanosec * 1e-9
) - self.t_start
)
msg_generated = datetime.now().timestamp()
try:
self.agent.generated(native_message)
except Exception as e:
print(e)
end = datetime.now().timestamp()
print(f'generated: {msg_generated-all_start}, agent: {end-msg_generated}')
def main():
......
......@@ -22,7 +22,7 @@ def generate_mission_context(agents, data_types, t_end, T):
'receivers': ['base_station'],
'T': T,
'sender': f'{agent}',
'initial_t_start': T/8 * i,
'initial_t_start': T/8 * i + 0.01,
},
weight=1
)
......
......@@ -92,7 +92,7 @@ class UtilityVideo(Utility):
t_rcv = m.t_rcv if m.t_rcv else m.t_gen
t_s = max(t_rcv, t_start)
t_l = t_rcv + 0.25
t_l = t_rcv + 0.33
red = m.data.red
log_part = 0
......@@ -104,20 +104,22 @@ class UtilityVideo(Utility):
# logarithmic part
t = t_l
t0 = t_l - t_rcv
t1 = t_end - t_rcv
fmax = 4
f1 = 2
S = 2
fmax = 3
f1 = 1.5
S = 0.2
base = 2
ln2 = math.log(base)
k = S / (1 - f1 / (2 * fmax * ln2))
m = 1 + math.log(1 / fmax, base) * k
t1 = t0 + 1
t1 = min(t_end - t_rcv, base**(1/k)/fmax)
log_part = max(0, (
(t1 * (1 - math.log(t1)) - t0 * (1 - math.log(t0))) / ln2 * k +
(t1 - t0) * m
))
# print("######log#### ", log_part)
else:
t = t_end
result = (t - t_s + log_part) * (1 + 1 * red)
result = (t - t_s + log_part) * (0.5 + 5 * red)
# print('!!!!', t_start, t_end, t_s, t_l, result)
return result
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment