Skip to content
GitLab
Explore
Sign in
Davide Ricci
SHINS
Compare revisions
85c2c9ca2748f3f131851260e04fa46f060ee9cf to d53cb61fec08e13aa2b59890addf39da7a79499d
Commits on Source (2)
Trying to simplify drawings. The dream is separate streams and send them in binary format
· 29e523b9
vertighel
authored
Mar 20, 2024
29e523b9
sandbox matrix from scratch
· d53cb61f
vertighel
authored
Mar 20, 2024
d53cb61f
Hide whitespace changes
Inline
Side-by-side
src/scripts/sandbox/socketio-server.py
View file @
d53cb61f
# server.py
from
flask
import
Flask
,
render_template
from
flask_socketio
import
SocketIO
from
flask_cors
import
CORS
import
numpy
as
np
import
json
app
=
Flask
(
__name__
)
CORS
(
app
)
socketio
=
SocketIO
(
app
,
async_mode
=
'
threading
'
,
)
# Function to generate a random NumPy matrix
def
generate_matrix
():
return
np
.
random
.
rand
(
3
,
3
)
# Function to send the matrix to the client
def
send_matrix
():
matrix
=
generate_matrix
()
matrix_json
=
json
.
dumps
(
matrix
.
tolist
())
socketio
.
emit
(
'
matrix
'
,
matrix_json
)
# Background thread to send the matrix every 5 seconds
def
background_thread
():
while
True
:
send_matrix
()
socketio
.
sleep
(
5
)
# Route for the HTML page
@app.route
(
'
/
'
)
def
index
():
...
...
@@ -30,4 +47,7 @@ def handle_message(message):
print
(
'
Received message:
'
,
message
)
if
__name__
==
'
__main__
'
:
socketio
.
run
(
app
,
host
=
"
sharknirws.shark-nir.lbto.org
"
,
port
=
5001
)
socketio
.
start_background_task
(
target
=
background_thread
)
socketio
.
run
(
app
,
host
=
"
0.0.0.0
"
,
port
=
5002
)
src/scripts/sandbox/templates/index.html
View file @
d53cb61f
...
...
@@ -5,31 +5,40 @@
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Flask-SocketIO Example
</title>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.4.0/socket.io.js"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.4.0/socket.io.js"
></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script> -->
<script>
// Connect to Socket.IO server
// var socket = io.connect('http://' + document.domain + ':' + location.port);
const
socket
=
io
.
connect
({
// transports: ['websocket'],
// transports: ['websocket'],
});
// Event handlers
socket
.
on
(
'
connect
'
,
()
=>
{
console
.
log
(
'
Connected
'
);
});
socket
.
on
(
'
disconnect
'
,
()
=>
{
console
.
log
(
'
Disconnected
'
);
});
socket
.
on
(
'
message
'
,
(
data
)
=>
{
console
.
log
(
'
Received message:
'
,
data
);
});
// Example: Sending a message
function
sendMessage
()
{
const
message
=
document
.
getElementById
(
'
message
'
).
value
;
socket
.
emit
(
'
message
'
,
message
);
}
// Event handlers
socket
.
on
(
'
connect
'
,
()
=>
{
console
.
log
(
'
Connected
'
);
});
socket
.
on
(
'
disconnect
'
,
()
=>
{
console
.
log
(
'
Disconnected
'
);
});
socket
.
on
(
'
message
'
,
(
data
)
=>
{
console
.
log
(
'
Received message:
'
,
data
);
});
socket
.
on
(
'
matrix
'
,
function
(
matrix_json
)
{
var
matrix
=
JSON
.
parse
(
matrix_json
);
console
.
log
(
'
Received matrix:
'
);
console
.
log
(
matrix
);
});
// // Example: Sending a message
// function sendMessage() {
// const message = document.getElementById('message').value;
// socket.emit('message', message);
// }
</script>
</head>
<body>
...
...
src/scripts/templates/util/rtc_access_object.py
View file @
d53cb61f
...
...
@@ -14,15 +14,24 @@ from util import variables as uvars
from
util.master_listener_davide
import
thread
from
util.mini_os
import
obsController
signs_list
=
[]
with
open
(
str
(
uvars
.
sign_map
),
"
r
"
)
as
f
:
for
line
in
f
:
for
x
in
line
.
split
():
signs_list
.
append
(
int
(
x
))
signs
=
np
.
array
(
signs_list
)
### Focus only on the 8x8 pixel matrix centered on the centroid
def
focus_on_centroid
(
a
,
cx
,
cy
,
s
=
4
):
# a is an array-like matrix , s is an Int
cx
=
int
(
cx
)
*
32
+
32
# cx and cy are normalized in [-1,1] -> now are renormalized in [0,64]
cy
=
int
(
cy
)
*
32
+
32
if
(
s
>
cx
or
s
>
cy
):
s
=
min
(
cx
,
cy
)
if
(
s
>
len
(
a
)
-
cx
or
s
>
len
(
a
)
-
cy
):
s
=
min
(
s
,
len
(
a
)
-
cx
,
len
(
a
)
-
cy
)
a_focused
=
a
[
cx
-
s
:
cx
+
s
,
cy
-
s
:
cy
+
s
]
return
a_focused
class
RtcObject
(
object
):
def
__init__
(
self
):
self
.
counter
=
0
self
.
todos
=
[]
...
...
@@ -33,11 +42,13 @@ class RtcObject(object):
self
.
thread
=
thread
self
.
obsController
=
obsController
def
reset
(
self
):
print
(
"
reset
"
)
status
=
self
.
obsController
.
RTCTTResetBCU
()
return
status
def
resurrect
(
self
):
print
(
"
import
"
)
from
SHINS_SW_TEST.SHINS_TEST_DEBUG
import
SHINS_TEST_DEBUG
...
...
@@ -50,6 +61,7 @@ class RtcObject(object):
print
(
status
)
return
status
def
resurrect2
(
self
):
print
(
'
resurrect2
'
)
rtc_s
=
uvars
.
rtc_s_base
.
copy
()
...
...
@@ -75,6 +87,7 @@ class RtcObject(object):
print
(
"
Exit status: {}
"
.
format
(
status
))
ufun
.
error_handler
(
status
,
"
RTCTTStart
"
)
def
uploadRTC
(
self
,
modal
=
True
):
rtc_s
=
uvars
.
rtc_s_base
.
copy
()
if
modal
:
...
...
@@ -110,8 +123,7 @@ class RtcObject(object):
mode
=
"
Modal
"
if
modal
else
"
Zonal
"
print
(
"
Enabling {} Mode... DONE
"
.
format
(
mode
))
def
zonalCommand
(
self
,
data
):
print
(
"
chiamata effettuata
"
)
normalize_strain
=
1
#6.666667
...
...
@@ -133,7 +145,8 @@ class RtcObject(object):
print
(
e
)
status
=
1
return
status
def
move_soul
(
self
,
data
,
apply_movement
=
False
):
self
.
soul_deltas
=
data
print
(
"
Received data: {}
"
.
format
(
data
))
...
...
@@ -215,51 +228,61 @@ class RtcObject(object):
print
(
"
Something went wrong, no action received
"
)
print
(
"
Reached end of command
"
)
return
status
def
read
(
self
,
id
):
for
todo
in
self
.
todos
:
if
todo
[
"
id
"
]
==
id
:
return
todo
def
create
(
self
,
data
):
todo
=
data
self
.
todos
.
append
(
todo
)
return
todo
def
update
(
self
,
id
,
data
):
todo
=
self
.
read
(
id
)
todo
.
update
(
data
)
return
todo
def
delete
(
self
,
id
):
todo
=
self
.
read
(
id
)
self
.
todos
.
remove
(
todo
)
@property
def
centroid
(
self
):
status
,
[
cx
,
cy
]
=
self
.
obsController
.
getInternalSeqFloatVariable
(
"
RtcCentroidOrigin
"
)
return
[
cx
,
cy
]
@centroid.setter
def
centroid
(
self
,
cx_cy
):
cx
,
cy
=
cx_cy
status
=
self
.
obsController
.
RTCTTSetCentroidPos
(
cx
,
cy
)
return
status
def
flatten
(
self
):
modes
=
[
0
]
*
96
#39
status
=
self
.
obsController
.
RTCTTModeUpload
(
modes
,
absolute
=
True
)
status
=
self
.
load_ncpa
(
name
=
"
zeri.txt
"
)
return
status
def
close_loop
(
self
):
status
=
self
.
obsController
.
RTCTTCloseLoop
()
return
status
def
open_loop
(
self
):
status
=
self
.
obsController
.
RTCTTOpenLoop
()
return
status
def
frequency
(
self
,
freq
):
"""
Set the loop frequency
"""
...
...
@@ -267,7 +290,8 @@ class RtcObject(object):
status
=
self
.
obsController
.
RTCTTExecuteSetup
(
rtc_s
)
return
status
def
tint
(
self
,
t
):
"""
Set integration time
"""
...
...
@@ -277,6 +301,7 @@ class RtcObject(object):
status
=
self
.
obsController
.
RTCTTExecuteSetup
(
rtc_s
)
return
status
def
patrol
(
self
,
b
):
"""
Set params to enable or disable patrol camera mode
"""
...
...
@@ -288,7 +313,7 @@ class RtcObject(object):
"
TTWINCOORDY
"
:
"
0
"
,
"
TTWINCOLS
"
:
"
640
"
,
"
TTWINROWS
"
:
"
512
"
,
"
TTFRAMERATE
"
:
"
200
"
,
#200
"
TTFRAMERATE
"
:
"
200
"
,
"
TTNSLOPEPIXELS
"
:
"
16
"
,
"
TTBIASFILE
"
:
""
,
"
TTPIXELGAINFILE
"
:
""
,
...
...
@@ -344,6 +369,7 @@ class RtcObject(object):
return
status
def
threshold
(
self
,
t
):
"""
Set the RTC Threshold
"""
...
...
@@ -351,6 +377,7 @@ class RtcObject(object):
return
status
def
get_threshold
(
self
):
"""
Get the RTC Threshold
"""
...
...
@@ -368,6 +395,7 @@ class RtcObject(object):
return
[
str
(
dark
.
name
).
decode
(
'
utf-8
'
)
for
dark
in
sorted
(
uvars
.
dark_path
.
glob
(
"
*.dat
"
))
]
def
new_dark
(
self
):
"""
Create a new dark
"""
...
...
@@ -385,6 +413,7 @@ class RtcObject(object):
return
filename
def
load_dark
(
self
,
name
):
"""
Load a dark file
"""
rtc_s
=
{
"
TTBIASFILE
"
:
name
}
...
...
@@ -392,6 +421,7 @@ class RtcObject(object):
return
status
def
get_current_dark
(
self
):
pass
...
...
@@ -404,6 +434,7 @@ class RtcObject(object):
return
[
str
(
gain
.
name
).
decode
(
'
utf-8
'
)
for
gain
in
sorted
(
uvars
.
gain_path
.
glob
(
"
*.dat
"
))
]
def
new_gain
(
self
,
gain_type
,
centroid_size
):
"""
Create a new gain
"""
rtc_s
=
{
...
...
@@ -413,6 +444,7 @@ class RtcObject(object):
status
=
self
.
obsController
.
RTCTTExecuteSetup
(
rtc_s
)
return
status
def
load_gain
(
self
,
name
):
"""
Load a gain file
"""
rtc_s
=
{
...
...
@@ -437,27 +469,28 @@ class RtcObject(object):
status
=
self
.
obsController
.
RTCTTExecuteSetup
(
rtc_s
)
return
status
def
tiptilt
(
self
,
modes
=
[
0
,
0
,
0
,
0
],
absolute
=
False
):
print
(
"
Loaded Modes {}
"
.
format
(
modes
))
status
=
self
.
obsController
.
RTCTTModeUpload
(
modes
=
modes
,
absolute
=
absolute
)
return
status
def
teccam_http_start
(
self
):
status
,
_
=
self
.
obsController
.
RTCTTSendCameraCommand
(
"
exec httpserver start
"
)
return
status
def
teccam_custom_command
(
self
,
command
):
status
,
res
=
self
.
obsController
.
RTCTTSendCameraCommand
(
command
)
return
res
def
save
(
self
):
data
=
self
.
data
()
now
=
Time
.
now
().
isot
filename
=
"
/data/rtc/rtc-panel-save-{}.json
"
.
format
(
now
)
with
open
(
filename
,
'
w
'
)
as
f
:
json
.
dump
(
data
,
f
)
return
filename
def
save_flat
(
self
):
"""
Save the current flat in a file
"""
...
...
@@ -468,12 +501,14 @@ class RtcObject(object):
print
(
flat_name
)
return
flat_name
def
cloud_samples
(
self
,
s
):
print
(
"
prima : samples = {}
"
.
format
(
self
.
thread
.
cloud_samples
))
status
=
self
.
thread
.
cloud_samples
=
s
print
(
"
dopo : samples = {}
"
.
format
(
self
.
thread
.
cloud_samples
))
return
status
def
get_cloud_samples
(
self
):
return
self
.
thread
.
cloud_samples
...
...
@@ -485,6 +520,7 @@ class RtcObject(object):
"""
List ncpa files
"""
return
[
str
(
ncpa
.
name
).
decode
(
'
utf-8
'
)
for
ncpa
in
sorted
(
uvars
.
ncpa_path
.
glob
(
"
*.txt
"
))
]
def
load_ncpa
(
self
,
name
):
"""
Load a ncpa file
"""
# load saved file
...
...
@@ -520,11 +556,18 @@ class RtcObject(object):
print
(
"
Finished
"
)
return
status
def
save_ncpa
(
self
):
"""
Save the current ncpa in a file
"""
ncpa_name
=
ufun
.
save_ncpa
(
os
=
self
.
obsController
)
print
(
ncpa_name
)
return
ncpa_name
def
getNCPARotationStatus
(
self
):
print
(
"
Status ncpa rotation in arrivo... status is {}
"
.
format
(
self
.
rotating_ncpa
))
return
self
.
rotating_ncpa
def
rotateNCPA
(
self
,
action
):
...
...
@@ -569,9 +612,9 @@ class RtcObject(object):
time
.
sleep
(
sleep
)
return
1
def
getNCPARotationStatus
(
self
):
print
(
"
Status ncpa rotation in arrivo... status is {}
"
.
format
(
self
.
rotating_ncpa
))
return
self
.
rotating_ncpa
##############
# Plot stuff #
##############
@property
...
...
@@ -666,7 +709,14 @@ class RtcObject(object):
return
gain
def
data_dm
(
self
,
imshape
):
def
data_dm
(
self
):
signs_list
=
[]
with
open
(
str
(
uvars
.
sign_map
),
"
r
"
)
as
f
:
for
line
in
f
:
for
x
in
line
.
split
():
signs_list
.
append
(
int
(
x
))
signs
=
np
.
array
(
signs_list
)
# Diagnostics
shape
=
self
.
thread
.
shape
...
...
@@ -680,12 +730,11 @@ class RtcObject(object):
"
actuators
"
:
uvars
.
actuators
.
tolist
(),
"
shape
"
:
(
shape
*
signs
).
tolist
(),
"
flat
"
:
(
np
.
array
(
dmflat
[
0
:
97
])).
tolist
(),
#"dm_shape_no_flat" : dm_shape_no_flat,
"
min
"
:
round
(
shape
.
min
(),
2
),
"
max
"
:
round
(
shape
.
max
(),
2
),
"
min_no_flat
"
:
round
(
min
(
dm_shape_no_flat
),
2
),
"
max_no_flat
"
:
round
(
max
(
dm_shape_no_flat
),
2
),
"
image_shape
"
:
list
(
imshape
),
#
"image_shape": list(imshape),
"
skp_cmd
"
:
self
.
thread
.
tt_cmd
[
1
]
}
...
...
@@ -699,9 +748,11 @@ class RtcObject(object):
def
data_cloud
(
self
,
imshape
,
centroid
):
# Diagnostics
centroids_x
=
self
.
thread
.
centroid_x
centroids_y
=
self
.
thread
.
centroid_y
cloud
=
np
.
flip
(
self
.
thread
.
centroid_matrix
.
T
,
1
)
cx
,
cy
=
centroid
rmsX
=
np
.
std
(
centroids_x
)
*
21
# px 2 mas, plate scale = 21 mas/px
rmsY
=
np
.
std
(
centroids_y
)
*
21
# px 2 mas
...
...
@@ -732,29 +783,18 @@ class RtcObject(object):
return
cld
def
data
(
self
):
# Diagnostics
image
=
self
.
rtc_image
imshape
=
image
.
shape
# OS
centroid
=
self
.
centroid
data_cloud
=
self
.
data_cloud
(
imshape
,
centroid
)
data_cred
=
self
.
data_cred
(
image
,
centroid
)
### Focus only on the 8x8 pixel matrix centered on the centroid
def
focus_on_centroid
(
a
,
cx
,
cy
,
s
=
4
):
# a is an array-like matrix , s is an Int
cx
=
int
(
cx
)
*
32
+
32
# cx and cy are normalized in [-1,1] -> now are renormalized in [0,64]
cy
=
int
(
cy
)
*
32
+
32
if
(
s
>
cx
or
s
>
cy
):
s
=
min
(
cx
,
cy
)
if
(
s
>
len
(
a
)
-
cx
or
s
>
len
(
a
)
-
cy
):
s
=
min
(
s
,
len
(
a
)
-
cx
,
len
(
a
)
-
cy
)
a_focused
=
a
[
cx
-
s
:
cx
+
s
,
cy
-
s
:
cy
+
s
]
return
a_focused
cropped_cred
=
focus_on_centroid
(
np
.
array
(
data_cred
[
"
data
"
])
,
data_cloud
[
"
cx
"
]
,
data_cloud
[
"
cy
"
],
s
=
4
)
...
...
@@ -772,7 +812,7 @@ class RtcObject(object):
response
=
{
"
cred
"
:
data_cred
,
"
gain
"
:
self
.
data_gain
(
imshape
),
"
dm
"
:
self
.
data_dm
(
imshape
),
"
dm
"
:
self
.
data_dm
(
),
# removed imshape as parameter
"
cloud
"
:
data_cloud
,
"
cx
"
:
centroid
[
0
],
"
cy
"
:
centroid
[
1
],
...
...
src/scripts/web/static/drawings.js
View file @
d53cb61f
...
...
@@ -18,17 +18,18 @@
$
(
"
#image-tot_flux-
"
+
id
).
text
(
totFlux
)
}
if
(
$
(
"
#image-wx-
"
+
id
)){
// cloud
$
(
"
#image-wx-
"
+
id
).
text
(
image
.
wx
/
2
*
image
.
image_shape
[
0
]
)
$
(
"
#image-wy-
"
+
id
).
text
(
image
.
wy
/
2
*
image
.
image_shape
[
1
]
)
$
(
"
#image-RMS_X-
"
+
id
).
text
(
image
.
RMS_X
/
2
*
image
.
image_shape
[
0
]
)
$
(
"
#image-RMS_Y-
"
+
id
).
text
(
image
.
RMS_Y
/
2
*
image
.
image_shape
[
1
]
)
// $("#image-cloud_samples"+id).text(image.RMS_X / 2 * image.image_shape[0] )
//console.log("AAAAA "+id)
//console.log(image.samples)
if
(
image
.
image_shape
)
{
if
(
$
(
"
#image-wx-
"
+
id
)){
// cloud
$
(
"
#image-wx-
"
+
id
).
text
(
image
.
wx
/
2
*
image
.
image_shape
[
0
]
)
$
(
"
#image-wy-
"
+
id
).
text
(
image
.
wy
/
2
*
image
.
image_shape
[
1
]
)
$
(
"
#image-RMS_X-
"
+
id
).
text
(
image
.
RMS_X
/
2
*
image
.
image_shape
[
0
]
)
$
(
"
#image-RMS_Y-
"
+
id
).
text
(
image
.
RMS_Y
/
2
*
image
.
image_shape
[
1
]
)
// $("#image-cloud_samples"+id).text(image.RMS_X / 2 * image.image_shape[0] )
//console.log("AAAAA "+id)
//console.log(image.samples)
}
}
return
[
min
,
max
]
...
...