raacampbell / openstage

Arduino-based microscope stage controller
GNU Lesser General Public License v3.0
41 stars 15 forks source link

Bluetooth lag #11

Closed hughchurchill closed 7 years ago

hughchurchill commented 7 years ago

First, let me say that openstage is awesome. After frustrating SPI issues using Mega2560 + USB Host Shield, it was extremely easy to get it working after switching to a Mega ADK.

Using a PS4 gamepad via USB works very well, and while I can control the stage via bluetooth, there is significant lag (about 1 second). I'm wondering if other users have experienced this and whether there is a known solution?

Using the same hardware and running the USB Host Shield example PS4BT, hat positions are printed with no lag, so there must be something in the openstage code that is slowing things down.

Thanks!

raacampbell commented 7 years ago

I'm glad it's useful! I never got bluetooth working at all, so you're doing better than me there. I'll ask a colleague of mine who I think is using OpenStage whether he tried bluetooth.

Did you try bluetooth with really stripped down example code to see whether the lag is still present?

raacampbell commented 7 years ago

Nope, he hasn't tried bluetooth.

hughchurchill commented 7 years ago

Yes, using really stripped down example code from the USB host shield library, the game pad is read via Bluetooth with no lag.

I'll poke around in the open stage code and will post here if I figure anything out.

Thanks again for this project and the quick reply!

raacampbell commented 7 years ago

How odd. Let me know what you find.

hughchurchill commented 7 years ago

In e_mainLoop, I dropped ncycles from 3000 to 100 and it's working great, no lag!

To get bluetooth working, the only trick is to buy the right dongle, and the list on the USB host shield site gets outdated very quickly. I am using this one.

I have to upload OpenStage to Mega ADK with this code in c_userSettings the first time to pair (press and hold SHARE and PS buttons):

//Create wired connection to PS3 gamepad on USB host shield. If you were to attempt a wireless (bluetooth) //connection you'd want to edit the following code.
//#include //these are included in a_includes //#include

ifdef DO_GAMEPAD

USB Usb; // PS4USB PS4(&Usb); //apparently some dongles need this, mine didn't BTD Btd(&Usb); PS4BT PS4(&Btd, PAIR);

endif

and after that, change to this code, upload OpenStage to Mega ADK, press PS button when serial asks:

//Create wired connection to PS3 gamepad on USB host shield. If you were to attempt a wireless (bluetooth) //connection you'd want to edit the following code.
//#include //#include

ifdef DO_GAMEPAD

USB Usb; // PS4USB PS4(&Usb); //apparently some dongles need this, mine didn't BTD Btd(&Usb); PS4BT PS4(&Btd);

endif

raacampbell commented 7 years ago

Thanks. I've linked to this Issue from the README.