Herowaree

bghfhjalf

Jan 8th, 2021 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. function getGraphics(solo_rbt_path, solo_rbt1, solo_rbt2, solo_rbt3,
  2. coop_rbt_path, coop_rbt1, coop_rbt2, coop_rbt3)
  3.  
  4. csv_reader = csv.reader(csv_file, delimiter=',')
  5.  
  6. % read files from solo experiment
  7. data_solo_path = dlmread(solo_rbt_path, ',', 0, 0); % robot path
  8. data_solo_rbt1 = dlmread(solo_rbt1, ',', 0, 0);
  9. data_solo_rbt2 = dlmread(solo_rbt2, ',', 0, 0);
  10. data_solo_rbt3 = dlmread(solo_rbt3, ',', 0, 0);
  11.  
  12. % read files from coop experiment
  13. data_coop_path = dlmread(coop_rbt_path, ',', 0, 0);
  14. data_coop_rbt1 = dlmread(coop_rbt1, ',', 0, 0);
  15. data_coop_rbt2 = dlmread(coop_rbt2, ',', 0, 0);
  16. data_coop_rbt3 = dlmread(coop_rbt3, ',', 0, 0);
  17.  
  18. timer = 1; % starts in second one
  19. step = 1; % 1 second step
  20.  
  21. % solo
  22. t_solo = [];
  23.  
  24. % counter for solo
  25. counter_solo_path = 1;
  26. counter_solo_rbt1 = 1;
  27. counter_solo_rbt2 = 1;
  28. counter_solo_rbt3 = 1;
  29.  
  30. % error of estimation
  31. erro_solo_rbt1 = [];
  32. erro_solo_rbt2 = [];
  33. erro_solo_rbt3 = [];
  34.  
  35. not_finished = true;
  36. while (not_finished)
  37. while (data_solo_path(counter_solo_path, 1) < timer)
  38. if (counter_solo_path + 1 <= rows(data_solo_path))
  39. counter_solo_path = counter_solo_path + 1;
  40. else
  41. not_finished = false;
  42. break;
  43. endif
  44. endwhile
  45.  
  46. while (data_solo_rbt1(counter_solo_rbt1, 1) < timer)
  47. if (counter_solo_rbt1 + 1 <= rows(data_solo_rbt1))
  48. counter_solo_rbt1 = counter_solo_rbt1 + 1;
  49. else
  50. not_finished = false;
  51. break;
  52. endif
  53. endwhile
  54.  
  55. while (data_solo_rbt2(counter_solo_rbt2, 1) < timer)
  56. if (counter_solo_rbt2 + 1 <= rows(data_solo_rbt2))
  57. counter_solo_rbt2 = counter_solo_rbt2 + 1;
  58. else
  59. not_finished = false;
  60. break;
  61. endif
  62. endwhile
  63.  
  64. while (data_solo_rbt3(counter_solo_rbt3, 1) < timer)
  65. if (counter_solo_rbt3 + 1 <= rows(data_solo_rbt3))
  66. counter_solo_rbt3 = counter_solo_rbt3 + 1;
  67. else
  68. not_finished = false;
  69. break;
  70. endif
  71. endwhile
  72.  
  73. % compute error estimation of robot 1
  74. if (data_solo_rbt1(counter_solo_rbt1, 8) == 1)
  75. e = sqrt(power(data_solo_rbt1(counter_solo_rbt1, 2) - data_solo_path(counter_solo_path, 2), 2) + power(data_solo_rbt1(counter_solo_rbt1, 3) - data_solo_path(counter_solo_path, 3), 2) + power(data_solo_rbt1(counter_solo_rbt1, 4) - data_solo_path(counter_solo_path, 4), 2));
  76. else
  77. e = NaN;
  78. endif
  79. erro_solo_rbt1 = [erro_solo_rbt1, e];
  80.  
  81. % compute error estimation of robot 2
  82. if (data_solo_rbt2(counter_solo_rbt2, 8) == 1)
  83. e = sqrt(power(data_solo_rbt2(counter_solo_rbt2, 2) - data_solo_path(counter_solo_path, 2), 2) + power(data_solo_rbt2(counter_solo_rbt2, 3) - data_solo_path(counter_solo_path, 3), 2) + power(data_solo_rbt2(counter_solo_rbt2, 4) - data_solo_path(counter_solo_path, 4), 2));
  84. else
  85. e = NaN;
  86. endif
  87. erro_solo_rbt2 = [erro_solo_rbt2, e];
  88.  
  89. % compute error estimation of robot 3
  90. if (data_solo_rbt3(counter_solo_rbt3, 8) == 1)
  91. e = sqrt(power(data_solo_rbt3(counter_solo_rbt3, 2) - data_solo_path(counter_solo_path, 2), 2) + power(data_solo_rbt3(counter_solo_rbt3, 3) - data_solo_path(counter_solo_path, 3), 2) + power(data_solo_rbt3(counter_solo_rbt3, 4) - data_solo_path(counter_solo_path, 4), 2));
  92. else
  93. e = NaN;
  94. endif
  95. erro_solo_rbt3 = [erro_solo_rbt3, e];
  96.  
  97. t_solo = [t_solo; timer];
  98.  
  99. % show time between each estimation
  100. %printf("Timer: %d - Path timer: %f - Robot 1: %f - Erro: %f\n", timer, data_solo_path(counter_solo_path - 1, 1), data_solo_rbt1(counter_solo_rbt1 - 1, 1), e);
  101.  
  102. timer = timer + step;
  103. endwhile
  104.  
  105.  
  106. % coop
  107. t_coop = [];
  108. timer = 1;
  109.  
  110. % counter for coop
  111. counter_coop_path = 1;
  112. counter_coop_rbt1 = 1;
  113. counter_coop_rbt2 = 1;
  114. counter_coop_rbt3 = 1;
  115.  
  116. % error of estimation
  117. erro_coop_rbt1 = [];
  118. erro_coop_rbt2 = [];
  119. erro_coop_rbt3 = [];
  120.  
  121. not_finished = true;
  122.  
  123. while (not_finished)
  124. while (data_coop_path(counter_coop_path, 1) < timer)
  125. if (counter_coop_path + 1 <= rows(data_coop_path))
  126. counter_coop_path = counter_coop_path + 1;
  127. else
  128. not_finished = false;
  129. break;
  130. endif
  131. endwhile
  132.  
  133. while (data_coop_rbt1(counter_coop_rbt1, 1) < timer)
  134. if (counter_coop_rbt1 + 1 <= rows(data_coop_rbt1))
  135. counter_coop_rbt1 = counter_coop_rbt1 + 1;
  136. else
  137. not_finished = false;
  138. break;
  139. endif
  140. endwhile
  141.  
  142. while (data_coop_rbt2(counter_coop_rbt2, 1) < timer)
  143. if (counter_coop_rbt2 + 1 <= rows(data_coop_rbt2))
  144. counter_coop_rbt2 = counter_coop_rbt2 + 1;
  145. else
  146. not_finished = false;
  147. break;
  148. endif
  149. endwhile
  150.  
  151. while (data_coop_rbt3(counter_coop_rbt3, 1) < timer)
  152. if (counter_coop_rbt3 + 1 <= rows(data_coop_rbt3))
  153. counter_coop_rbt3 = counter_coop_rbt3 + 1;
  154. else
  155. not_finished = false;
  156. break;
  157. endif
  158. endwhile
  159.  
  160. % compute error estimation of robot 1
  161. if (data_coop_rbt1(counter_coop_rbt1, 8) == 1)
  162. e = sqrt(power(data_coop_rbt1(counter_coop_rbt1, 2) - data_coop_path(counter_coop_path, 2), 2) + power(data_coop_rbt1(counter_coop_rbt1, 3) - data_coop_path(counter_coop_path, 3), 2) + power(data_coop_rbt1(counter_coop_rbt1, 4) - data_coop_path(counter_coop_path, 4), 2));
  163. else
  164. e = NaN;
  165. endif
  166. erro_coop_rbt1 = [erro_coop_rbt1, e];
  167.  
  168. % compute error estimation of robot 2
  169. if (data_coop_rbt2(counter_coop_rbt2, 8) == 1)
  170. e = sqrt(power(data_coop_rbt2(counter_coop_rbt2, 2) - data_coop_path(counter_coop_path, 2), 2) + power(data_coop_rbt2(counter_coop_rbt2, 3) - data_coop_path(counter_coop_path, 3), 2) + power(data_coop_rbt2(counter_coop_rbt2, 4) - data_coop_path(counter_coop_path, 4), 2));
  171. else
  172. e = NaN;
  173. endif
  174. erro_coop_rbt2 = [erro_coop_rbt2, e];
  175.  
  176. % compute error estimation of robot 3
  177. if (data_coop_rbt3(counter_coop_rbt3, 8) == 1)
  178. e = sqrt(power(data_coop_rbt3(counter_coop_rbt3, 2) - data_coop_path(counter_coop_path, 2), 2) + power(data_coop_rbt3(counter_coop_rbt3, 3) - data_coop_path(counter_coop_path, 3), 2) + power(data_coop_rbt3(counter_coop_rbt3, 4) - data_coop_path(counter_coop_path, 4), 2));
  179. else
  180. e = NaN;
  181. endif
  182. erro_coop_rbt3 = [erro_coop_rbt3, e];
  183.  
  184. t_coop = [t_coop; timer];
  185.  
  186. % show time between each estimation
  187. %printf("Timer: %d - Path timer: %f - Robot 1: %f - Erro: %f\n", timer, data_coop_path(counter_coop_path - 1, 1), data_coop_rbt1(counter_coop_rbt1 - 1, 1), e);
  188.  
  189. timer = timer + step;
  190. endwhile
  191.  
  192. max_erro_value = max([erro_solo_rbt1, erro_solo_rbt2, erro_solo_rbt3, erro_coop_rbt1, erro_coop_rbt2, erro_coop_rbt3]);
  193.  
  194. max_time_solo = rows(t_solo);
  195. max_time_coop = rows(t_coop);
  196.  
  197. hf = figure ();
  198.  
  199. % solo
  200. subplot(3, 2, 1);
  201. plot(t_solo, erro_solo_rbt1);
  202. ylim ([0.0, max_erro_value + 0.5]);
  203. xlim([0.0, max_time_solo + 5]);
  204. title("Estimation error of object position - Turtlebot 1\n Non-cooperative approach");
  205. xlabel("Time-step");
  206. ylabel("Error in world reference frame");
  207.  
  208. subplot(3, 2, 3);
  209. plot(t_solo, erro_solo_rbt2);
  210. ylim ([0.0, max_erro_value + 0.5]);
  211. xlim([0.0, max_time_solo + 5]);
  212. title("Estimation error of object position - Turtlebot 2\n Non-cooperative approach");
  213. xlabel("Time-step");
  214. ylabel("Error in world reference frame");
  215.  
  216. subplot(3, 2, 5);
  217. plot(t_solo, erro_solo_rbt3);
  218. ylim ([0.0, max_erro_value + 0.5]);
  219. xlim([0.0, max_time_solo + 5]);
  220. title("Estimation error of object position - Turtlebot 3\n Non-cooperative approach");
  221. xlabel("Time-step");
  222. ylabel("Error in world reference frame");
  223.  
  224. %% coop
  225. subplot(3, 2, 2);
  226. plot(t_coop, erro_coop_rbt1);
  227. ylim ([0.0, max_erro_value + 0.5]);
  228. xlim([0.0, max_time_coop + 5]);
  229. title("Estimation error of object position - Turtlebot 1\n Cooperative approach");
  230. xlabel("Time-step");
  231. ylabel("Error in world reference frame");
  232.  
  233. subplot(3, 2, 4);
  234. plot(t_coop, erro_coop_rbt2);
  235. ylim ([0.0, max_erro_value + 0.5]);
  236. xlim([0.0, max_time_coop + 5]);
  237. title("Estimation error of object position - Turtlebot 2\n Cooperative approach");
  238. xlabel("Time-step");
  239. ylabel("Error in world reference frame");
  240.  
  241. subplot(3, 2, 6);
  242. plot(t_coop, erro_coop_rbt3);
  243. ylim ([0.0, max_erro_value + 0.5]);
  244. xlim([0.0, max_time_coop + 5]);
  245. title("Estimation error of object position - Turtlebot 3\n Cooperative approach");
  246. xlabel("Time-step");
  247. ylabel("Error in world reference frame");
  248.  
  249. set(gca, "fontsize", 12);
  250. print (hf, "plot15_7.pdf", "-deps");
  251. endfunction
  252.  
Add Comment
Please, Sign In to add comment