{"id":2289,"date":"2018-05-31T15:13:10","date_gmt":"2018-05-31T14:13:10","guid":{"rendered":"https:\/\/www.macerobotics.com\/?p=2289"},"modified":"2018-05-31T15:23:55","modified_gmt":"2018-05-31T14:23:55","slug":"creation-dune-carte-avec-le-robot-mrpiz","status":"publish","type":"post","link":"https:\/\/www.macerobotics.com\/?p=2289","title":{"rendered":"Cr\u00e9ation d&#8217;une carte avec le robot MRPiZ"},"content":{"rendered":"<p>Voici un exemple de cr\u00e9ation d&#8217;une carte avec le robot MRPiZ en utilisant le capteur de distance laser VL53L0X :<\/p>\n<div class=\"ttfmake-embed-wrapper aligncenter\" style=\"max-width: 960px;\"><iframe loading=\"lazy\" title=\"MRPiZ mapping - raspberry pi robot\" width=\"960\" height=\"540\" src=\"https:\/\/www.youtube.com\/embed\/JbZSjChobPQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/div>\n<h2>Le programme python de la cr\u00e9ation d&#8217;une carte :<\/h2>\n<ul>\n<li>Le robot tourne \u00e0 360\u00b0 et lit le capteur de distance,<\/li>\n<li>Enregistrement de l&#8217;orientation du robot et de la distance du capteur dans un fichier csv.<\/li>\n<\/ul>\n<pre><strong>from mrpiZ_lib import *<\/strong>\r\n<strong>import time, csv<\/strong>\r\n\r\n<strong>NameFile = 'carte.csv'<\/strong>\r\n\r\n<strong>def read_laser():<\/strong>\r\n<strong>  p3_1 = proxSensor(3)<\/strong>\r\n<strong>  p3_2 = proxSensor(3)<\/strong>\r\n<strong>  p3_3 = proxSensor(3)<\/strong>\r\n<strong>  p3_4 = proxSensor(3)<\/strong>\r\n<strong>  p3_5 = proxSensor(3)<\/strong>\r\n<strong>  p3 = (p3_1 + p3_2 + p3_3 + p3_4 + p3_5)\/5<\/strong>\r\n<strong>  return p3<\/strong>\r\n\r\n\r\n<span style=\"color: #008000;\"><strong>############################################# MAIN<\/strong><\/span>\r\n\r\n<span style=\"color: #008000;\"><strong># wait init<\/strong><\/span>\r\n<strong>time.sleep(2)<\/strong>\r\n\r\n<strong>Fichier = open(NameFile,'w')<\/strong>\r\n<strong>Robot_tourne = 0<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong># enable asv control<\/strong><\/span>\r\n<strong>controlEnable()<\/strong>\r\n\r\n<strong>while 1:<\/strong>\r\n<span style=\"color: #008000;\"><strong>  # read laser distance sensor<\/strong><\/span>\r\n<strong>  distance = read_laser()<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong>  # read robot orientation<\/strong><\/span>\r\n<strong>  orientation = robotPositionO()<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong>  # write in file<\/strong><\/span>\r\n<strong>  Fichier.write(str(distance))<\/strong>\r\n<strong>  Fichier.write(\";\")<\/strong>\r\n<strong>  Fichier.write(str(orientation))<\/strong>\r\n<strong>  Fichier.write(\"\\r\\n\")# nouvelle ligne<\/strong>\r\n\r\n<strong>  if(Robot_tourne == 0):<\/strong>\r\n<strong>    turnLeftDegree(8,360)<\/strong>\r\n<strong>    Robot_tourne = 1<\/strong>\r\n\r\n<strong>Fichier.close()<\/strong>\r\n<strong>exit()<\/strong><\/pre>\n<h2>Le programme de lecture et d&#8217;affichage de la carte&nbsp; :<\/h2>\n<pre><strong>import numpy as np<\/strong>\r\n<strong>import math<\/strong>\r\n<strong>import matplotlib.pyplot as plt<\/strong>\r\n<strong>import numpy as np<\/strong>\r\n<strong>import csv<\/strong>\r\n\r\n<strong>liste_distance = []<\/strong>\r\n<strong>liste_orientation = []<\/strong>\r\n\r\n<strong>fichier = open(\"carte.csv\", \"r\")<\/strong>\r\n\r\n<strong>c = 0\r\n<\/strong>\r\n<span style=\"color: #008000;\"><strong># lecture fichier<\/strong><\/span>\r\n<strong>while True:<\/strong>\r\n<strong>  ligne = fichier.readline()<\/strong>\r\n<strong>  if ligne =='':<\/strong>\r\n<strong>    break # fin fichier<\/strong>\r\n<span style=\"color: #008000;\"><strong>  # lecture de la distance (capteur distance)<\/strong><\/span>\r\n<strong>  distance = ligne.split(';')[0]<\/strong>\r\n<span style=\"color: #008000;\"><strong>  # lecture orientation<\/strong><\/span>\r\n<strong>  orientation = ligne.split(';')[1]<\/strong>\r\n<span style=\"color: #008000;\"><strong>  # correction de la distance par rapport au centre du robot et la position du capteur<\/strong><\/span>\r\n<strong>  distance = float(distance) + 50<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong>  # conversion en radian<\/strong><\/span>\r\n<strong>  if float(orientation) &gt; 0:<\/strong>\r\n<strong>    orientation = (float(orientation)*3.14)\/180<\/strong>\r\n\r\n<strong>  liste_distance.append(float(distance))<\/strong>\r\n<strong>  liste_orientation.append(float(orientation))<\/strong>\r\n<strong>  c = c + 1\r\n<\/strong>\r\n<strong>ax = plt.subplot(111, projection='polar')<\/strong>\r\n<strong>ax.plot(liste_orientation, liste_distance)<\/strong>\r\n<strong>ax.grid(True)<\/strong>\r\n<strong>plt.show()<\/strong><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Exemple d&#8217;affichage :&nbsp;<\/strong><\/p>\n<p><a href=\"https:\/\/www.macerobotics.com\/wp-content\/uploads\/2018\/05\/map_1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2295\" src=\"https:\/\/www.macerobotics.com\/wp-content\/uploads\/2018\/05\/map_1.png\" alt=\"\" width=\"1363\" height=\"715\" srcset=\"https:\/\/www.macerobotics.com\/wp-content\/uploads\/2018\/05\/map_1.png 1363w, https:\/\/www.macerobotics.com\/wp-content\/uploads\/2018\/05\/map_1-300x157.png 300w, https:\/\/www.macerobotics.com\/wp-content\/uploads\/2018\/05\/map_1-768x403.png 768w, https:\/\/www.macerobotics.com\/wp-content\/uploads\/2018\/05\/map_1-1024x537.png 1024w, https:\/\/www.macerobotics.com\/wp-content\/uploads\/2018\/05\/map_1-600x315.png 600w\" sizes=\"auto, (max-width: 1363px) 100vw, 1363px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Voici un exemple de cr\u00e9ation d&#8217;une carte avec le robot MRPiZ en utilisant le capteur de distance laser VL53L0X : Le programme python de la cr\u00e9ation d&#8217;une carte : Le robot tourne \u00e0 360\u00b0 et lit le capteur de distance, Enregistrement de l&#8217;orientation du robot et de la distance du capteur dans un fichier csv. &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,45,46],"tags":[],"class_list":["post-2289","post","type-post","status-publish","format-standard","hentry","category-mrpiz","category-raspberry-pi","category-robot"],"_links":{"self":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2289"}],"version-history":[{"count":7,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2289\/revisions"}],"predecessor-version":[{"id":2297,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2289\/revisions\/2297"}],"wp:attachment":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}