{"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