{"id":294,"date":"2019-01-29T15:52:17","date_gmt":"2019-01-29T20:52:17","guid":{"rendered":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/?p=294"},"modified":"2019-01-29T15:55:12","modified_gmt":"2019-01-29T20:55:12","slug":"initial-pid-behavior-observation-matlab-code","status":"publish","type":"post","link":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/2019\/01\/initial-pid-behavior-observation-matlab-code\/","title":{"rendered":"Initial PID Behavior Observation MatLab Code"},"content":{"rendered":"<p>Matlab Code used for initial PID behavior observation. Several different constants and graphical outputs were observed with a step function to see how the controller outputs would change with time.\u00a0 Will be used if Matlab communication with teensy board is made available through Matlab features<\/p>\n<p>Useful information regarding MatLab to arduino transformation: https:\/\/www.mathworks.com\/help\/supportpkg\/arduinoio\/getting-started-with-matlab-support-package-for-arduino-hardware.html<\/p>\n<p>% PID Control Implementation<\/p>\n<p>% Step function input<\/p>\n<p>arr = zeros(1,20);<br \/>\ntime = 0:19;<br \/>\narr = [arr, 1];<br \/>\ntime = [time, 19.02];<br \/>\narr = [arr, ones(1,20)];<br \/>\ntime = [time, 20:39];<\/p>\n<p>arr = [arr,zeros(1,20)];<br \/>\ntime = [time, 40:59];<br \/>\narr = [arr, 1];<br \/>\ntime = [time, 59.02];<br \/>\narr = [arr, ones(1,20)];<br \/>\ntime = [time, 60:79];<br \/>\nsubplot(1,2,2)<br \/>\nplot(time, arr)<\/p>\n<p>%PID loop<br \/>\nmicro_out = 0;<br \/>\nerror =0;<br \/>\npreviousE=0;<br \/>\nto_plot = [];<br \/>\nthreshold = 0.5;<br \/>\nk=1;<br \/>\nk2=0;<br \/>\nk3=0;<br \/>\nfor i=1:length(arr)<\/p>\n<p>%function with feedback from previous output<br \/>\ninput_to_pid = arr(i) &#8211; micro_out;<\/p>\n<p>error = threshold &#8211; input_to_pid;<br \/>\npe = k * error;<\/p>\n<p>error_n = error + previousE;<br \/>\nie = k2 * i;<\/p>\n<p>d = error &#8211; previousE;<br \/>\nde = k3 * d;<\/p>\n<p>error = previousE;<\/p>\n<p>micro_out = input_to_pid + pe + ie + de<\/p>\n<p>to_plot = [to_plot, micro_out]<\/p>\n<p>end<br \/>\nsubplot(1,2,1)<br \/>\nplot(time, to_plot)<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Matlab Code used for initial PID behavior observation. Several different constants and graphical outputs were observed with a step function to see how the controller outputs would change with time.\u00a0 Will be used if Matlab communication with teensy board is made available through Matlab features Useful information regarding MatLab to arduino transformation: https:\/\/www.mathworks.com\/help\/supportpkg\/arduinoio\/getting-started-with-matlab-support-package-for-arduino-hardware.html % PID&#8230;<\/p>\n","protected":false},"author":7955,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-notebook"],"_links":{"self":[{"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/users\/7955"}],"replies":[{"embeddable":true,"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":2,"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/posts\/294\/revisions\/297"}],"wp:attachment":[{"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/my.dev.vanderbilt.edu\/forcebasedprosthesiscontroller\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}