File Exchange

image thumbnail

Sphero MATLAB Interface

version 1.16.0.0 (1.06 MB) by Yi Jui Lee
This interface enables MATLAB to connect and control the robot, Sphero through Bluetooth.

3 Downloads

Updated 02 Sep 2015

View Version History

View License

This simple interface offers basic control over Sphero. For more comprehensive features and control, please refer to Mark's interface:
http://www.mathworks.com/matlabcentral/fileexchange/52746-sphero-api-matlab-sdk
This interface is made possible utilizing the Instrument Control Toolbox (R2011b or higher). This interface consists of 2 files. Sphero.m is the source code, and sphero_workfile.m provides working examples to the source code. This application also allows MATLAB to send commands and receive feedback (position and velocity) from Sphero.

Sphero API 1.50 is the API provided by Orbotix. It is also available at http://orbotixinc.github.io/Sphero-Docs/docs/sphero-api/packet-structures.html. This work was done as part of the NSF Research Experience for Undergraduates (REU) and the IEEE Robotics and Automation Society (RAS) project at the ARMLAB (Automation, Robotics and Mechatronics Lab) http://mechatronics.eng.buffalo.edu/ at University at Buffalo http://www.mae.buffalo.edu/.

Author:
Yi Jui Lee (yijuilee@buffalo.edu)
Mark Tomaszewski (marktoma@buffalo.edu)

Cite As

Yi Jui Lee (2021). Sphero MATLAB Interface (https://www.mathworks.com/matlabcentral/fileexchange/48359-sphero-matlab-interface), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

Sophon Sae-Sim

I give you a wrong
correct E-mail : sosa00sc@hs-esslingen.de.

Sophon Sae-Sim

Hi!, I'm new with Sphero by using matlab. Could you tell me how to start program writing and how about the controlling ?
you can srnt me the email.
here is me E-mail: s0sa00sc@hs-esslingen.de

Mark Tomaszewski

@Beviz

This should do it for a super simple sleep implementation for Yi Jui's code. Add this method inside the "methods ... end" block of Sphero.m

function sleep(s,wakeup)
% sleep Put Sphero to sleep for wakeup seconds
% CODE NOT TESTED (written on a mobile phone)
T = uint16(wakeup);
T_LSB = uint8(bitand(T,255));
T_MSB = uint8(bitshift(T,-8));
data = [T_MSB,T_LSB,0,0,0];
% did = 00h, cid = 22h
s.sendCommand(0,34,0,6,data);
end

%% example usage
% assume s is a connected Sphero object...
% sleep forever
s.sleep(0)
% sleep for 3 seconds then wakes up
s.sleep(3)
% attempt to deep-sleep and possibly return error if unsupported
s.sleep(maxint('uint16'))

I've implemented this API in my package, but I haven't released the update yet due to limited time for testing and lack of community interest.
http://www.mathworks.com/matlabcentral/fileexchange/52746-sphero-api-matlab-sdk

Feel free to email me with questions!

Yi Jui Lee

Hi Beviz,

Thanks for the feedback!
We believe that it is not possible to wake Sphero up, using Bluetooth, at an arbitrary time.
Depending on your application, you could potentially leverage the core commands for Sleep and Set Inactivity Timeout. The documentation indicates that you are able to set the number of seconds where Sphero goes to sleep, and then automatically reawakens; or set how long it stays awake when idle.

Mark has been looking into adding these commands into his interface (linked above) You can contact him if you have any questions regarding this implementation.
Hope this helps.
-Yi Jui

Beviz Elek

Hi,

Thanks for the interface!
Is it possible to wake it up without hit the sphero, but somehow with bluetooth?
The problem is, when it goes to sleep I lost the connetion. So can I wake it up, by trying to establish connection with it or somehow else?
Thank you in advance!

Tatiana Pelc

Mark and Yi Jui, thank you for the very good and only Matlab interface for Sphero.It is very useful for my neuroscience experiments with rats.
Very impressive work, should be included in the list of projects on the official website. Also, I really appreciate your personal attention and help I received.

Goran

Mark Tomaszewski

Hey R T,

Thanks for the feedback!

If Sphero turns blue (indicating Bluetooth connection established) after calling the connectBluetooth() method, then we don't currently have the ability to assist you in debugging this issue (more on this below).

Our best advice is that you minimize any possible sources of noise/interference, check configuration settings for your Bluetooth device (i.e. try turning off power-savings modes), ensure your Bluetooth driver is up-to-date, etc.

We may be revisiting this code for further development in the coming months. Additional expressed interest will surely motivate the best improvements to the Sphero class. We hope to provide more Sphero-API functionality (that will help with maintaining connection status, etc.) and some debugging features in future releases!

~Mark T.

P.S.

My known-good system configuration is: Lenovo T420s with OEM Bluetooth 3.0 (Broadcom); Windows 7 Professional SP1 (64-bit); Matlab r2013a

R T

Thanks for your response.
The problem allways occurs in about 30 seconds from calling s.connectBluetooth function. No matter if it is inactive or moving.
My co-worker doesn't have this problem even if testing same ball under same conditions using different computer with external USB Bluetooth.
It looks like the problem is in my integrated laptop Bluetooth modul. (Using different Matlab version nor OS do not help)

Yi Jui Lee

Hi RT,
Sorry for my delayed response.

Did it disconnect itself 20~30s after inactivity or did it occur in the middle of a run?

If it occurred during a run, then I have had similar experience and it happened when other people's smartphone/device tried to connect/pair to Sphero with Bluetooth, thus stopping the connection.

Let me know if this was not the case.

R T

I have a problem when using this interface. The ball disconnects itself after approximately 20 or 30 secs of being connected. Have you met this problem? Do you have an idea how to fix it? Thank you for your help.

Yi Jui Lee

I have uploaded a demo video at Youtube for your convenience. https://www.youtube.com/watch?v=QcTfVxD2NaQ

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Sphero API MATLAB SDK

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!