How do I read input from an Xbox One Bluetooth Controller?

Hello,
I am writing a script that should control a Turtlebot 3 Burger via Bluetooth Controller through Matlab.
I have configured matlab and the turtlebots to communicate with one another, and I can send commands to the turtlebot to move around, read data, ect. The next part I have to figure out is how to read specific inputs from my blueooth controller.
I have connected my controller to my PC successfully, and can even recognize it in matlab using:
instrhwinfo('Bluetooth');
My question now is, I want to read inputs from the different joysticks, buttons, triggers, ect.
I want to use these inputs to create IF STATEMENTS to move the robot around.
What I have in mind is something like this:
tic
while toc<60
%Use Left joystick to move bot forward
if (leftJoystick.POS >= 1)
velocity_msg.Linear.X = 0.100;
send(velocity_pub, velocity_msg);
end
%Use Right joystick to turn bot
if (rightJoystick.POS >= 1)
velocity_msg.Angular.Z = 0.100;
send(velocity_pub, velocity_msg);
end
%Use Left Joystick and Right Trigger to increase forward velocity
if (leftJoystick.POS >= 1 && trigger.Right == true)
velocity_msg.Linear.X = velocity_msg.Linear.X + 0.005;
send(velocity_pub, velocity_msg);
end
%Use Right Joystick and Right Trigger to increase forward velocity
if (rightJoystick.POS >= 1 && trigger.Right == true)
velocity_msg.Angular.Z = velocity_msg.Angular.Z + 0.005;
send(velocity_pub, velocity_msg);
end
%Use Button A to stop robot.
if (button.A == true)
velocity_msg.Angular.Z = 0.0;
velocity_msg.Linear.X = 0.0;
send(velocity_pub, velocity_msg);
end
end
I'm definitely using the wrong variables, but its just the idea of how I want to structure my code to control the turtlebot.
Does anyone have any experience with this? I'm guessing someone has implemented this before, however, everywhere I look online, I only see things using USB connections. I want to control this using bluetooth so I can follow the robot around!
But when I use
fopen(b)
I get this error.
Error using icinterface/fopen (line 83)
Unsuccessful open: Cannot connect to the device. Possible reasons are another application
is connected or the device is not available.
Error in testing2 (line 4)
fopen(myDevice);

9 commentaires

Walter Roberson
Walter Roberson le 4 Août 2019
Modifié(e) : Walter Roberson le 4 Août 2019
https://core-electronics.com.au/tutorials/using-usb-and-bluetooth-controllers-with-python.html gives some information about how Bluetooth controller messages are structured and how they can be decoded in Python.
Thanks for this, I'll give it a good read because it looks like some information I may be able to use down the road, for now, however, I still need this to work on Matlab.
delete(instrfind('Bluetooth'))
might help, possibly... but not if some other process is using the device.
delete(instrfind('Bluetooth'))
Error using instrfind (line 57)
Invalid param-value pairs specified.
I already followed these steps.
At the step where I use
fopen(bt)
I do get an error.
The link you provided even says:
"If you do not get an error, the connection was made successfully. If you do get an error, follow the steps in the error message and/or check the previous steps listed here."
I'm assuming this error is a common one. There are no steps to follow in the error message, and I did re-check the steps provided. Very strange!
I did everything it said to do and it shows that 0 processes are using the device.
Then the device is not available.
You might want to use a more specific call, indicating exactly which device you want to connect to, in case it is selecting a different device.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Network Connection and Exploration dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by