Camera disconnects from IDE when running script (sometimes)

Discussion related to "under the hood" OpenMV topics.
trevor
Posts: 5
Joined: Wed Nov 29, 2017 1:39 pm

Camera disconnects from IDE when running script (sometimes)

Postby trevor » Wed Nov 29, 2017 1:56 pm

Hello,

So I am having an issue with the camera (M7) disconnecting when I try to run a script. I will click the green play button and it will hang for a few seconds, and then disconnect without running the script.

I saw this problem mentioned here: viewtopic.php?t=315
I followed the three steps listed there:
1. green button stays green indefinitely
2. Frame buffer disabled, script runs indefinitely
3. Frame buffer enabled, script runs indefinitely

This is true for all of the example scripts I have tried.

However, when I try to run my own script ( based mostly on example scripts ), is when the problem happens. I have noticed that if the file has been edited in a different text editor (in my case Vim and Sublime) the problem will happen. Furthermore, if I copy/paste code from another one of my scripts the problem happens. Lastly, sharing work with my group mates and implementing it in my own code will also cause this problem. If I remove the copy and pasted code, it WILL run the script, but if I then try to further edit that file within the IDE the script will not run and the camera disconnects. This is causing huge issues since it is making it very difficult to collaborate with my classmates without having this problem occur.

I am running OSX 10.12.3

Thanks in advance for any help!
User avatar
kwagyeman
Posts: 1310
Joined: Sun May 24, 2015 2:10 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby kwagyeman » Wed Nov 29, 2017 2:31 pm

Hi, there's a work around for this in the mean time that might work for you.

1. Disconnect from the camera.
2. Go to tools - open terminal and open a serial terminal to your OpenMV Cam at 115200 baud.
3. Then press enter and you should get REPL prompt.
4. Edit code in the main window and then hit the green run button in the open Terminal window to send the script to the camera over REPL.
5. To see what the camera sees add: print(img.compressed_for_ide()) at the end of the while loop.

Doing this bypasses our serial debug stack which seems to have an issue on MAC. I'd like to solve this problem but I can determine the exact issue because I can't reproduce it. All my MACs I have work fine. I did write some code to solve what I thought the problem was... But, I don't have a computer that has that same problem to test with.

If you're willing to help me I can release a version of the IDE and the firmware with the fix I think will solve this issue. But, I need you to test and confirm it. The last guy didn't respond after I put the work into fixing this issue to let me know if my fix worked.
Nyamekye,
trevor
Posts: 5
Joined: Wed Nov 29, 2017 1:39 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby trevor » Wed Nov 29, 2017 2:43 pm

Yep, I'd love to help!

I will be able to test the work around you provided in the next hour or so. Just let me know what I need to do to help.
User avatar
kwagyeman
Posts: 1310
Joined: Sun May 24, 2015 2:10 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby kwagyeman » Wed Nov 29, 2017 3:44 pm

I'll build the test image thingy this weekend for you. The work around should keep you okay until then.
Nyamekye,
trevor
Posts: 5
Joined: Wed Nov 29, 2017 1:39 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby trevor » Wed Nov 29, 2017 5:16 pm

Okay I might need a little clarification on the work around.

My step 2 looks like: open terminal>new terminal>connect to serial port>[select serial port]cu.Blutooth-Incoming-Port>[baud rate] 115200

This opens up what looks like another serial terminal. But from here, when I connect the camera and click the green play button I don't see any option to send the script to the camera over REPL. I think there is something I'm missing here.
User avatar
kwagyeman
Posts: 1310
Joined: Sun May 24, 2015 2:10 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby kwagyeman » Wed Nov 29, 2017 6:19 pm

The port you are selecting should not be a Bluetooth port. It should say cu.usb something.

Note that the secondary serial terminal overrides the ability for the main IDE to connect. It it connected correctly you should be able to press the enter button in the serial terminal window and get a repl prompt.

Um, see the OpenMV Video channel about the Open Terminal feature to see how to use this.
Nyamekye,
trevor
Posts: 5
Joined: Wed Nov 29, 2017 1:39 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby trevor » Sat Dec 02, 2017 3:46 pm

That was the only port available from the drop down. No usb option. In the mean time, we have been using my teammate's Windows machine which runs the same scripts just fine. I'll check out the video channel in the mean time. Thanks!
User avatar
kwagyeman
Posts: 1310
Joined: Sun May 24, 2015 2:10 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby kwagyeman » Sat Dec 02, 2017 4:38 pm

Weird... OpenMV IDE shouldn't have been able to find the camera in the first place.
Nyamekye,
User avatar
falko
Posts: 6
Joined: Mon Dec 04, 2017 9:23 am
Location: Germany
Contact:

Re: Camera disconnects from IDE when running script (sometimes)

Postby falko » Mon Dec 04, 2017 9:28 am

I'm also having trouble running a script from the main window on my mac.
The workaround via a serial terminal works fine, so I'm not blocked from continuing my work.
But let me know if I can help resolving this issue. :)
User avatar
kwagyeman
Posts: 1310
Joined: Sun May 24, 2015 2:10 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby kwagyeman » Mon Dec 04, 2017 10:48 am

Okay, I'm almost done releasing the next version of the IDE. It has the possible bug fix built-in but it will only activate it on firmware with a version of 9.9.9 so I'll build a version of the firmware once I'm done releasing with the possible fix.
Nyamekye,
trevor
Posts: 5
Joined: Wed Nov 29, 2017 1:39 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby trevor » Tue Dec 05, 2017 1:29 pm

Awesome, thanks for your help. Will the new IDE version be on this site or the openmv github?

Also, do you think this is something that could be remedied by updating OSX to the latest version? Or is it more likely a usb port issue?
User avatar
kwagyeman
Posts: 1310
Joined: Sun May 24, 2015 2:10 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby kwagyeman » Tue Dec 05, 2017 11:47 pm

I honestly don't know what causes this error. I believe it's a hardware issue. As far as I understand the problem comes from the MAC hardware dropping USB bytes since we're not using the USB CDC class in exactly the way it was designed for. I got a hint of the possible problem when a person showed me the USB trace and I saw the camera delivered the bytes to the application but the application did not receive all the data... meaning that bytes were dropped in the kernel.

So, I implemented some MTU learning code in the IDE. On first connect it will learn the max transfer size through the kernel and break up image reads by that. This trick doesn't affect performance too much. (The IDE learns the MTU by doing image reads and checking to see how many bytes made it back... I have to bypass a lot of error checking in the IDE to make this work).

...

Anyway, please give me some time to release the next IDE version and I will then roll a version of the firmware with this fix. Please use the work around in the mean time.
Nyamekye,
User avatar
kwagyeman
Posts: 1310
Joined: Sun May 24, 2015 2:10 pm

Re: Camera disconnects from IDE when running script (sometimes)

Postby kwagyeman » Thu Dec 28, 2017 4:01 pm

Hi, here's a version of the firmware that has the Mac MTU size fix implemented. The OpenMV Cam will send packets of data to the IDE that are of a max MTU size. Since I don't have a computer with the failing issue I can't tell if this fixes the error on my end but I can verify the code is working and breaking packets up. Load the firmware.bin file or openmv.dfu file. Either one will work.
Attachments
openmv.zip
(2.09 MiB) Downloaded 2 times
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 4 guests