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

20 Ansichten (letzte 30 Tage)
Previn Savaya
Previn Savaya am 4 Aug. 2019
Kommentiert: Walter Roberson am 4 Aug. 2019
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 Kommentare
Previn Savaya
Previn Savaya am 4 Aug. 2019
I did everything it said to do and it shows that 0 processes are using the device.
Walter Roberson
Walter Roberson am 4 Aug. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Network Connection and Exploration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by