Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tau2 with TeaxGrabber - timeouts in fpa and housing temperatures #34

Open
navotoz opened this issue Oct 14, 2020 · 7 comments
Open

Tau2 with TeaxGrabber - timeouts in fpa and housing temperatures #34

navotoz opened this issue Oct 14, 2020 · 7 comments

Comments

@navotoz
Copy link

navotoz commented Oct 14, 2020

Hello,

I'm using Tau2 with the TeaxGrabber.

get_fpa_temperatures() and get_housing_temperatures() sometimes returns the correct values, and sometimes returns errors such as:

Initial packet byte incorrect. Byte was: 67
Error reply from camera. Try re-sending command, or check parameters.

Initial packet byte incorrect. Byte was: 93
Error reply from camera. Try re-sending command, or check parameters.

Initial packet byte incorrect. Byte was: 0
Error reply from camera. Try re-sending command, or check parameters.
.....

I noticed no pattern - sometimes I'm able to get 5 measurements in a row, sometimes it fails after just 1 measurement.
I tried adding sleep() between sending to receiving, without results.
I tried reconnecting the Tau2, and resetting the PC a couple of times.

Thanks for the great package (again :-))

flirpy/flirpy/camera/tau.py

Lines 153 to 176 in b48b643

def get_fpa_temperature(self):
function = ptc.READ_SENSOR_TEMPERATURE
argument = struct.pack(">h", 0x00)
self._send_packet(function, argument)
res = self._read_packet(function)
temperature = struct.unpack(">h", res[7])[0]
temperature /= 10.0
log.info("FPA temp: {}C".format(temperature))
return temperature
def get_housing_temperature(self):
function = ptc.READ_SENSOR_TEMPERATURE
argument = struct.pack(">h", 0x0A)
self._send_packet(function, argument)
time.sleep(1)
res = self._read_packet(function)
temperature = struct.unpack(">h", res[7])[0]
temperature /= 100.0
log.info("Housing temp: {}C".format(temperature))
return temperature

@jveitchmichaelis
Copy link
Contributor

jveitchmichaelis commented Oct 14, 2020

Yep this is currently a bit buggy due to the way the serial stream is implemented. I think it's just losing sync when the messages are sent back from the camera. Not sure if there's an easy fix here without re-writing the stream handling code to be more like a proper state machine.

But we can do the same as before - if you can dump the serial buffer just before the error I can take a look and see if we can figure something out :)

In theory what should happen is when you query the camera, we start looking for a magic string in the buffer and process the response as normal a normal Tau2. By the way in the code, the calls to receive packets are actually overriden by the Teax class.

flirpy/flirpy/camera/tau.py

Lines 658 to 668 in b48b643

def _receive_data(self, length):
length += length*5
data = self._sync_uart()
if len(data) < length:
data += self._read(n_bytes=length-len(data))
return data[:length][5::6]

flirpy/flirpy/camera/tau.py

Lines 616 to 631 in b48b643

def _sync_uart(self, allow_timeout=False):
data = self._read()
magic = b"UART"
t = time.time()
while data.find(magic) == -1:
data = self._read()
if not allow_timeout and time.time()-t > 0.2:
log.warn("Timeout in command sync")
break
elif time.time() -t > 0.2:
break
return data[data.find(magic):]

As before, we can try changing data = self._read() to data += self._read().

One concern is perhaps we accidentally discard the data before waiting for it.

But.. the problem you're getting isn't a timeout in command sync otherwise you'd get that warning. So it does seems like a packet decode problem - if you can send me a serial dump I'll take a look. The temp read function is pretty well unit tested on the Tau so I would lean towards we're just incorrectly getting data out of the stream, rather than the decoder is wrong.

@navotoz
Copy link
Author

navotoz commented Oct 14, 2020

I changed to data += self._read() on both functions, without results.

Here are the logs:
log_first_fail.txt
log_fourth_fail.txt

@jveitchmichaelis
Copy link
Contributor

jveitchmichaelis commented Oct 14, 2020

Can you save the entire data buffer from _sync_uart? (e.g. just before the return - so it should start with "UART")

@navotoz
Copy link
Author

navotoz commented Oct 14, 2020

log__sync_uart_failed_2.txt
log__sync_uart_failed_7.txt
Is this what you meant?

@jveitchmichaelis
Copy link
Contributor

jveitchmichaelis commented Oct 14, 2020

Try (as when you had trouble with image capture):

 np.save("dump.dat", data)

just before:

 return data[data.find(magic):] 

But this is interesting, it looks like each byte is packed. Ok should be quite easy to fix this, probably needs a new function that will read out a certain number of UART bytes.

UART\x01nUART\x01\x00UART\x01\x00UART\x01 UART\x01\x00UART\x01\x02UART\x01yUART\x01?UART\x01\x0cUART\x01IUART\x01\x9cUART

I'm curious about the case when this works though... it seems like the format isn't always like that. Maybe this happens when the data are interleaved.

@navotoz
Copy link
Author

navotoz commented Oct 14, 2020

@navotoz
Copy link
Author

navotoz commented Oct 15, 2020

I tried using pickle instead:

import pickle
with open("dump.pkl", "wb") as fp:
    dump(data, fp)

Results:
dumps_pickle.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants