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 件のコメント

Walter Roberson
Walter Roberson 2019 年 8 月 4 日
編集済み: Walter Roberson 2019 年 8 月 4 日
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.
Previn Savaya
Previn Savaya 2019 年 8 月 4 日
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.
Walter Roberson
Walter Roberson 2019 年 8 月 4 日
delete(instrfind('Bluetooth'))
might help, possibly... but not if some other process is using the device.
Previn Savaya
Previn Savaya 2019 年 8 月 4 日
delete(instrfind('Bluetooth'))
Error using instrfind (line 57)
Invalid param-value pairs specified.
Previn Savaya
Previn Savaya 2019 年 8 月 4 日
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!
Previn Savaya
Previn Savaya 2019 年 8 月 4 日
I did everything it said to do and it shows that 0 processes are using the device.
Walter Roberson
Walter Roberson 2019 年 8 月 4 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNetwork Connection and Exploration についてさらに検索

質問済み:

2019 年 8 月 4 日

コメント済み:

2019 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by