Plotting multiple inputs with a Simulated TurtleBot

2 views (last 30 days)
Hi
I’m working with a Simulated TurtleBot in the Gazebo environment (Get Started with Gazebo and Simulated TurtleBot - MATLAB & Simulink - MathWorks Benelux). I can give commands to this TurtleBot via MATLAB to plot arbitrary trajectories, as shown in Figure ;
I defined a function for each English alphabet in which the output will be the plotted letter. I can call these functions from another script related to the TurtleBot, and it will start to print the desired note, as follows
% function path_A = A
% Start with figure
f = figure();
xlim([1 118])
ylim([1 20])
hold on
grid on
% letter A
x1=[0,5,2.5,7.5,5,7.5,10];
y1=[0,10,5,5,10,5,0];
plot(x1,y1,'r','LineWidth',2);
%path
A=[x1;y1];
A=A.';
path_A=A;
% end
The challenge that I face now, I want to give more than one input;
%Insert a letter:
Usertext = input('Insert a letter:');
Unable to run the 'fevalJSON' function because it calls the 'input' function, which is not supported for this product offering.
it’s important to notice I need to shift the x values of each second letter, third letter, etc., maybe with the following command:
%example
path_O=[1 4;2 3; 3 2;4 1];
path_O = path_O + [2*ones(length(path_O),1),zeros(length(path_O),1)];
To have a meaningful name or word at the end.
  • How can I give multiple inputs (in my case, letters representing a list with two columns and multiple rows) with a predefined space between each note?
I do appreciate your consideration,
regards,

Accepted Answer

Sakshay
Sakshay on 1 Dec 2022
Hello Mohammad,
As per my understanding, you want to receive multiple inputs from a user to give to the robot.
The "input()" function in MATLAB is capable of taking as input, different kinds of data types. These data types can be, integers, double, vector, matrix, string and so on. For your case, to take multiple character inputs, you can take a string as an input from the user. A string is a vector/list of characters which will act as multiple inputs. After taking this string from the user, you can loop over the alphabets in the string one by one and perform your operations accordingly. A sample code would look like:
% Take input from user
% Sample inputs: 'PATH', 'TURTLE', 'BOT', etc...
uinput = input('Enter string\n');
% Loop over the alphabets of the string
for i=1:length(uinput)
disp(uinput(i));
% Other processing for each alphabet
end
You can refer to the documentation on "input()" for more information on the same:

More Answers (0)

Categories

Find more on Network Connection and Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!