I have to make a 2D Map of an outline around which I moved my robot

3 ビュー (過去 30 日間)
Muhammad
Muhammad 2022 年 12 月 8 日
回答済み: Ayush 2023 年 9 月 5 日
I have the x coordinates, the y coordinates from the starting point. I also have the angle and the distance from the obstacle from the left side of the robot using an IR sensor. I have the formula on how tto do it + what the expected result might look like. I am not very experienced in Matlab so am not able to write the code. Like I have to take sin of a whole table of values which results in an error. The graph is supposed to be localized from the starting point as the origin which also I do not understand how to do. The sample output and the reading are attached below if they help.

回答 (1 件)

Ayush
Ayush 2023 年 9 月 5 日
Hi Muhammad,
I understand that you would like to create a 2D map for your robot’s movement.
It can be done in the following manner:
1. After importing the table from the .xlsx file as a matrix, extract the columns individually for “x”, “y”, “theta” and “r”.
2. With the given equation, use the “sin” and “cos” function to calculate the values with the theta column. You can refer to the below documentation to know more about the “sin” and “cos” function:
3. Solve for “x1” and “y1” by doing symbolic array multiplication using the “.*operation. You can refer to the below documentation to know more about symbolic array multiplication:
Here is the code snippet for the same:
x1=x+xr.*theta_vec_cos-yr.*theta_vec_sin;
y1=y+xr.*theta_vec_sin+yr.*theta_vec_cos;
4. Use the “scatter” function to plot the resulting “x1” and “y1” vectors. You can refer to the below documentation to know more about the “scatter” function:
Hope it helps,
Regards,
Ayush Misra

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by