{"id":2284,"date":"2018-05-27T13:50:05","date_gmt":"2018-05-27T12:50:05","guid":{"rendered":"https:\/\/www.macerobotics.com\/?p=2284"},"modified":"2018-05-27T13:53:40","modified_gmt":"2018-05-27T12:53:40","slug":"imitation-learning-with-mrpiz-robot","status":"publish","type":"post","link":"http:\/\/www.macerobotics.com\/?p=2284","title":{"rendered":"Imitation learning with MRPiZ robot"},"content":{"rendered":"<p>Imitation learning exemple with the MRPiZ robot :<\/p>\n<ul>\n<li>record the speed of the two motors<\/li>\n<li>repead the speed of the motors<\/li>\n<\/ul>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/w2Aima_2in8\" allowfullscreen=\"allowfullscreen\" width=\"560\" height=\"315\" frameborder=\"0\"><\/iframe><\/p>\n<p>&nbsp;<\/p>\n<p><em><strong>The python code :<\/strong><\/em><\/p>\n<pre><strong>from mrpiZ_lib import *<\/strong>\r\n<strong>import time<\/strong>\r\n\r\n\r\n<span style=\"color: #008000;\"><strong># acquisition frequency<\/strong><\/span>\r\n<strong>TIME_ACQ = 0.1<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong># acquisition time<\/strong><\/span>\r\n<strong>TEMPS_ACQ = 200<\/strong>\r\n\r\n<strong>liste_mr = []<\/strong>\r\n<strong>liste_ml = []<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong># main program<\/strong><\/span>\r\n\r\n<span style=\"color: #008000;\"><strong># record loop<\/strong><\/span>\r\n<strong>c = 0<\/strong>\r\n\r\n<strong>motorsDisable()<\/strong>\r\n\r\n<strong>time.sleep(1)<\/strong>\r\n\r\n<strong>while c &lt; TEMPS_ACQ:<\/strong>\r\n<strong>  ml = motorLeftSpeed() <span style=\"color: #008000;\"># read left motor speed<\/span><\/strong>\r\n<strong>  mr = motorRightSpeed() <span style=\"color: #008000;\"># read right motor speed<\/span><\/strong>\r\n<strong>  liste_mr.append(mr)<\/strong>\r\n<strong>  liste_ml.append(ml)<\/strong>\r\n<strong>  time.sleep(TIME_ACQ)<\/strong>\r\n<strong>  print ml, mr, c<\/strong>\r\n<strong>  c = c + 1<\/strong>\r\n\r\n\r\n<strong>print \"END RECORD -----------\"<\/strong>\r\n<strong>time.sleep(2)<\/strong>\r\n\r\n<strong>c=0<\/strong>\r\n<strong>cmd_right=0<\/strong>\r\n<strong>cmd_left=0<\/strong>\r\n<strong>dir_right = 0<\/strong>\r\n<strong>dir_left = 0<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong># H-bridge enable<\/strong><\/span>\r\n<strong>motorsEnable()<\/strong>\r\n\r\n<span style=\"color: #008000;\"><strong>##########################################################<\/strong><\/span>\r\n\r\n<strong><span style=\"color: #008000;\"># imitation<\/span><\/strong>\r\n<strong>while c &lt; TEMPS_ACQ:<\/strong>\r\n<strong>  if liste_mr[c] &gt;= 0:<\/strong>\r\n<strong>    cmd_right = 2.8*liste_mr[c]<\/strong>\r\n<strong>    dir_right = 0<\/strong>\r\n<strong>  elif liste_mr[c] &lt; 0:<\/strong>\r\n<strong>    cmd_right = 2.8*liste_mr[c]<\/strong>\r\n<strong>    dir_right = 1<\/strong>\r\n<strong>  else:<\/strong>\r\n<strong>    dir_right = 0<\/strong>\r\n<strong>    cmd_right = 0<\/strong>\r\n\r\n<strong>  if liste_ml[c] &gt;= 0:<\/strong>\r\n<strong>    cmd_left = 2.8*liste_ml[c]<\/strong>\r\n<strong>    dir_left = 0<\/strong>\r\n<strong>  elif liste_ml[c] &lt; 0:<\/strong>\r\n<strong>    cmd_left = 2.8*liste_ml[c]<\/strong>\r\n<strong>    dir_left = 1<\/strong>\r\n<strong>  else:<\/strong>\r\n<strong>    cmd_left = 0<\/strong>\r\n<strong>    dir_left = 0<\/strong>\r\n<strong>  print cmd_left, cmd_right, c<\/strong>\r\n<strong>  c= c + 1<\/strong>\r\n<span style=\"color: #008000;\"><strong>  # motors commands<\/strong><\/span>\r\n<strong>  motorRight(dir_right,abs(cmd_right))<\/strong>\r\n<strong>  motorLeft(dir_left,abs(cmd_left))<\/strong>\r\n<strong>  time.sleep(TIME_ACQ)<\/strong>\r\n\r\n<strong>stop()<\/strong>\r\n<span style=\"color: #008000;\"><strong># end<\/strong><\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Imitation learning exemple with the MRPiZ robot : record the speed of the two motors repead the speed of the motors &nbsp; The python code : from mrpiZ_lib import * import time # acquisition frequency TIME_ACQ = 0.1 # acquisition time TEMPS_ACQ = 200 liste_mr = [] liste_ml = [] # main program # record &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-2284","post","type-post","status-publish","format-standard","hentry","category-mrpiz","category-raspberry-pi","category-robot"],"_links":{"self":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2284"}],"version-history":[{"count":4,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2284\/revisions"}],"predecessor-version":[{"id":2288,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2284\/revisions\/2288"}],"wp:attachment":[{"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2284"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}