{"id":147,"date":"2010-02-13T11:24:47","date_gmt":"2010-02-13T16:24:47","guid":{"rendered":"http:\/\/ammonsengineering.com\/blog\/?p=147"},"modified":"2010-02-16T13:33:43","modified_gmt":"2010-02-16T18:33:43","slug":"measuring-position-and-speed","status":"publish","type":"post","link":"https:\/\/ammonsengineering.com\/blog\/2010\/02\/measuring-position-and-speed\/","title":{"rendered":"Measuring position and speed"},"content":{"rendered":"<p>I wired up the encoder to the 9505 module so I can measure position and speed of the cart.\u00a0 It is a standard quadrature encoder with 1000 pulses per rev.\u00a0 Looking at the transition edges, we get 4000 edges per rev.<\/p>\n<p>I started with a LabVIEW example to read the position of the encoder.\u00a0 This works fine and was very easy to set up.\u00a0 I also want to measure speed, though, and that gets a little more challenging.\u00a0 I decided to look at instantaneous speed by measuring the space between consecutive edges.\u00a0 I started with a routine that outputs the max of either the last space measured (space-1) or the current space being measured.\u00a0 Including the current measurement helps when the system is slowing down.\u00a0 I ran the motor at low speed and took a look at the space measurements.\u00a0 I found out that the pulse edges on the encoder I am using are not equally spaced.\u00a0 The graph below shows alternating long and short spaces.\u00a0 The long spaces were about twice the length of the short spaces.\u00a0 This would make the speed measurements very wild and inaccurate.<\/p>\n<div id=\"attachment_152\" style=\"width: 536px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-One-Pulse.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-152\" class=\"size-full wp-image-152\" title=\"Speed - One Pulse\" src=\"http:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-One-Pulse.png\" alt=\"Speed - One Pulse\" width=\"526\" height=\"299\" srcset=\"https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-One-Pulse.png 526w, https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-One-Pulse-150x85.png 150w, https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-One-Pulse-300x170.png 300w\" sizes=\"auto, (max-width: 526px) 100vw, 526px\" \/><\/a><p id=\"caption-attachment-152\" class=\"wp-caption-text\">Speed - One Pulse<\/p><\/div>\n<p>My second approach was to always average the last two\u00a0space measurements.\u00a0 I averaged space-1 and max (space-2, current) to get a smoothed measurement of the spacing.\u00a0 This worked pretty well and reduced the variation significantly.\u00a0 The graph below shows there is\u00a0still\u00a0a small variation that repeated every four spaces, though.\u00a0 I realized that the widths of the on and off portions of the A and B pulses were not perfectly spaced either.\u00a0 I am guessing the on portion is slightly longer or shorter than the off portion of each signal.<\/p>\n<div id=\"attachment_150\" style=\"width: 536px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Two-Pulses.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-150\" class=\"size-full wp-image-150\" title=\"Speed - Two Pulses\" src=\"http:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Two-Pulses.png\" alt=\"Speed - Two Pulses\" width=\"526\" height=\"297\" srcset=\"https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Two-Pulses.png 526w, https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Two-Pulses-150x84.png 150w, https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Two-Pulses-300x169.png 300w\" sizes=\"auto, (max-width: 526px) 100vw, 526px\" \/><\/a><p id=\"caption-attachment-150\" class=\"wp-caption-text\">Speed - Two Pulses<\/p><\/div>\n<p>My third approach was to average the last four space measurements.\u00a0 I averaged space-1, space-2, space-3, and max (space-4, current) to get a very nice, clean space measurement.\u00a0 This removed all the cyclical variation from the measurements and gave me a nice smooth curve, which you can see in the graph below.\u00a0 My only concern was that at low speeds with deceleration\u00a0the delay for measuring true speed could be significant.\u00a0 The measured speed is always a couple of counts behind when averaging four values.\u00a0 I decided that when the current space measurement\u00a0exceeds 40,000 (1\/1000 of a second), I will only use the last two spaces.\u00a0 This trades a little variation for quicker response.\u00a0 I may adjust this cutoff level later.<\/p>\n<div id=\"attachment_151\" style=\"width: 537px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Four-Pulses.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-151\" class=\"size-full wp-image-151\" title=\"Speed - Four Pulses\" src=\"http:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Four-Pulses.png\" alt=\"Speed - Four Pulses\" width=\"527\" height=\"298\" srcset=\"https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Four-Pulses.png 527w, https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Four-Pulses-150x84.png 150w, https:\/\/ammonsengineering.com\/blog\/wp-content\/uploads\/2010\/02\/Speed-Four-Pulses-300x169.png 300w\" sizes=\"auto, (max-width: 527px) 100vw, 527px\" \/><\/a><p id=\"caption-attachment-151\" class=\"wp-caption-text\">Speed - Four Pulses<\/p><\/div>\n<p>Now that I had a very accurate measurement of the spacing between the pulses, I had to convert it to speed.\u00a0 I ended up using the new high throughput division available in LabVIEW 2009.\u00a0 I was able to divide 40,000,000 (total counts per second) by the spacing to get pulses per second.\u00a0 One nice thing is that the high throughput math works inside a single cycle timed loop.\u00a0 There is a delay of 29 cycles between inputting the numbers and getting the\u00a0answer,\u00a0but that is a very short amount of time when each cycle is\u00a025 ns.\u00a0 Good enough for me!!!<\/p>\n<p>Now I feel I have very accurate measurements of current, position, and speed.\u00a0 The next step will be adding PID control of the current.<\/p>\n<p>On a side note, there is no noticeable noise in the encoder signals.\u00a0 Apparently the combination of\u00a0shielding and differential encoder inputs is enough to eliminate any noise issues.\u00a0 This means I can run all the cables in the same track when I get some cable carrier, which will save me a little money.\u00a0 If there was too much noise, I was considering using two cable carriers in opposite directions &#8211; one for the encoders and one for the motor cable.\u00a0 I need to order the carrier soon, because the cables would get very tangled if the cart moves around much, and I am very close to moving the cart.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wired up the encoder to the 9505 module so I can measure position and speed of the cart.\u00a0 It is a standard quadrature encoder with 1000 pulses per rev.\u00a0 Looking at the transition edges, we get 4000 edges per rev. I started with a LabVIEW example to read the position of the encoder.\u00a0 This [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-software"],"_links":{"self":[{"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/comments?post=147"}],"version-history":[{"count":6,"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/posts\/147\/revisions\/153"}],"wp:attachment":[{"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/media?parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/categories?post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ammonsengineering.com\/blog\/wp-json\/wp\/v2\/tags?post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}