{"id":561,"date":"2013-05-27T14:13:28","date_gmt":"2013-05-27T04:13:28","guid":{"rendered":"http:\/\/legoeng.local\/?p=561"},"modified":"2022-08-01T10:04:15","modified_gmt":"2022-08-01T00:04:15","slug":"measuring-area-with-a-robot-part-one-follow-the-path","status":"publish","type":"post","link":"http:\/\/legoeng.local\/measuring-area-with-a-robot-part-one-follow-the-path\/","title":{"rendered":"Area Measurement: Follow the Path"},"content":{"rendered":"
I’ve often wanted to see greater educational use of LEGO robots more in alignment with how robots get used in the real world – taking on that dull, dirty, dangerous, or distant task.<\/p>\n
One approach could be to measure an area, map the features, and then conduct missions based on the calculated map. The idea sounds a bit challenging for a LEGO robot, but not if we take it in bite-sized pieces. Let’s start with measuring area while following a line.<\/p>\n
If we can provide a frame of reference for the robot, then we can calculate how far we’ve gone in any direction with a little odometry and trigonometry.<\/p>\n
The easiest frame of reference I found is to use a magnetic compass and set magnetic North to be the Y-axis on a cartesian coordinate system. I also assume the robot begins its travel from the origin: (0,0).<\/p>\n
When the robot moves, the distance it travels becomes the hypotenuse of a right triangle whose legs are the North (y-axis) and East (x-axis) components. The new robot position can then be calculated by adding the North components (old y position + additional travel in the y direction) and the East components (old x position + additional travel in the x direction).<\/p>\n
When written as equations, this becomes:<\/p>\n
X new<\/sub> = X old <\/sub>+ <\/b>\u0394X<\/b><\/p>\n Y new<\/sub> = Y old <\/sub>+ <\/b>\u0394Y<\/b><\/p>\n Where do the \u0394X and \u0394Y come from? They come from multiplying the distance traveled and the sine or cosine of the robot’s heading. In equations:<\/p>\n \u0394X = Dist *Sine (Hdg) <\/b><\/p>\n \u0394Y = Dist *Cosine (Hdg)<\/b><\/p>\n Programmers get to choose how far between each coordinate pair they want to let the robot travel before calculating the new (x,y) coordinate pair. In LEGO robots, that value usually comes from odometry based on wheel rotations.<\/p>\n Here’s a graphic summarizing the creation of new (x,y) coordinates for one leg of travel:<\/p>\n Here’s a graphic summarizing the creation of (x,y) coordinate pairs for five legs of robot travel along the line:<\/p>\n When doing this the first few times, it will probably be easier to write the (x,y) coordinate pairs to a file and then calculate the area off line, which I’ll explore next.<\/p>\n Calculating exact area from continuous curves perfectly usually requires double integrals. But our robot is converting the smooth boundary it’s following into a series of (x,y) coordinate pairs connected by straight lines. There’s a method to measure area within any polygon bounded by straight lines. Here it is:<\/p>\n Here’s a graphic showing the approach:<\/p>\n I’ve implemented the approach using a line following robot by writing the calculated (x,y) pairs to a data file and then bringing them into a spreadsheet for plotting and calculating.<\/p>\n Here’s a graphic showing the results:<\/p>\n They’re not perfect, but should be good enough for most classroom applications. The red arrows indicate the difference between the origin \/ robot starting position and its endpoint. Both points at the tips of the red arrows are actually coincident and result (most likely) from odometry errors in the robot’s distance calculations.<\/p>\n But what about South and West<\/b>? Think of South as negative North<\/i> and West as negative East.<\/i><\/p>\n Odometry errors<\/b>. For most applications with LEGO robots, using the values LEGO provides on the side of the tire is probably sufficient. Similarly, a measured wheelbase from tire center to opposite tire’s center is usually sufficient. But, when we start into more precise measurements, those approximations become apparent as they introduce error. There are a couple of ways to reduce this error.<\/p>\n Distance Choice<\/b>. We need to choose a small enough distance between each set of new (x,y) calculations to make sure we don’t miss any significant features… but we also need to be mindful of our robot’s ability to store data and accurately calculate distance. Also, if our shape for measurement has long straight sides, it’s probably sufficient to calculate each new (x,y) pair less often than if we are working with a more complex shape. In the data plots above I used one inch of distance and the LEGO motorcycle wheels (design circumference = 10.09 inches) with no corrections.<\/p>\n If you’re up to the programming challenge, this can calculated during the robot’s travel so it arrives at the end point with the answer shown on screen. I hope to share an example in the relatively near future.<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" I’ve often wanted to see greater educational use of LEGO robots more in alignment with how robots get used in the real world – taking on that dull, dirty, dangerous, or distant task. One approach could be to measure an area, map the features, and then conduct missions based on the calculated map. The idea […]<\/p>\n","protected":false},"author":6,"featured_media":565,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[83,80,82,158,81],"_links":{"self":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/561"}],"collection":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/comments?post=561"}],"version-history":[{"count":1,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":14389,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/posts\/561\/revisions\/14389"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media\/565"}],"wp:attachment":[{"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/media?parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/categories?post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legoeng.local\/wp-json\/wp\/v2\/tags?post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<\/a>
<\/a>
\n
<\/a>
<\/a>
Pitfalls<\/h2>\n
\n
Further reading <\/b><\/h2>\n
\n