go_away

### Author Topic: to cartesian scans  (Read 5526 times)

0 Members and 1 Guest are viewing this topic.

#### benji

• Supreme Robot
• Posts: 832
##### to cartesian scans
« on: January 21, 2008, 06:22:57 AM »
i actually have to build a matrix (cartesian coordinates)from my ranges data with angles
im havin the problem of estimation,,the error,, its just about transforming the polar data into cartesian data, but there is always that error
,whats the best way to do this with minimum error?
im using matlab which is goin to recieve the data as a matrix that has 2 raws (one for range and the other for angle) and 180 columns(the number of readings)
i need to end up with a matrix with lets say 200 raws and 200 columns cartesian coordinates
,,i need the algo for minimum error
good ol' BeNNy

#### hazzer123

• Supreme Robot
• Posts: 460
##### Re: to cartesian scans
« Reply #1 on: January 21, 2008, 10:59:22 AM »
I don't really understand this problem totally either. Why would you need an 200 by 200 array to store the outputted values?

Surely the size of the input will be the same as the size of the output in this case. (theta and range --> x and y)

Anyway, to convert precisely between polar co-ordinates and cartesian these are the equations -

input angle = theta
input 'range' = h

output x = h*cos(theta)
output y = h*sin(theta)

Imperial College Robotics Society
www.icrobotics.co.uk

#### paulstreats

• Supreme Robot
• Posts: 1,381
##### Re: to cartesian scans
« Reply #2 on: January 21, 2008, 11:05:46 AM »
The way to create your matrix is easy with arrays like:

unsigned char matrix[200][200]

then use this to store your data although you will need 40kb ram just for this matrix

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #3 on: January 21, 2008, 05:17:57 PM »
i know, thats gum ,but that wasnt my question.. again..
well, the cartesian matrix isnt x and y for each reading only, i mean i want to make a matrix that represents the area that has been scanned with cartesian data ,like an image.....

lets suppose the bot is facing a straight wall,so my wanted matrix should look like this( considering 6 * 10 instead of 200*200)

0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0

that means the wall is a bit close

thats my wanted matrix from my polar data

so the problem that arises is when you do simple math to have the x and y for the polars you somtimes get a floating point numbers (eg 5.4)
assigning this to my wanted matrix would presents an error,, is 5.4  5 or 6 ?)

good ol' BeNNy

#### hazzer123

• Supreme Robot
• Posts: 460
##### Re: to cartesian scans
« Reply #4 on: January 21, 2008, 05:37:22 PM »
Ahh ok.
If it is decimal, i would set both the nearby cells to 1, since the wall will be in both (i think )

For example i have the cartesian coordinate (x  , y).

Code: [Select]
`array(floor(y),floor(x)) = 1;     if (x-floor(x)) > 0    //Is the x value a decimal?     array(floor(y),floor(x) + 1) = 1;   // Set the other cell to 1endifif (y-floor(y)) > 0    //Is the y value a decimal?     array(floor(y)+1,floor(x)) = 1;   // Set the other cell to 1endifif ((x-floor(x)) > 0) && ((y-floor(y)) > 0)  //Are both x and y values decimals?     array(floor(y)+1,floor(x) + 1) = 1;   // Set the other cell to 1endif`
This is all assuming that a decimal coordinate occupies 2 cells. If not, the code could be easily changed and applied to other situations. The key thing is the checking for a decimal and round-down function (floor).
Imperial College Robotics Society
www.icrobotics.co.uk

#### paulstreats

• Supreme Robot
• Posts: 1,381
##### Re: to cartesian scans
« Reply #5 on: January 21, 2008, 06:36:47 PM »
This problem will occur even with 16 floating point numbers, since many of them will will require more than 16 floating points to be accurate.

Just something that you have to accept and put up with

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #6 on: January 21, 2008, 06:42:09 PM »
well maybe that lets say x with its floating point will settle inside a specific square(element) in the matrix
maybe its better to assign all the elements surrounding it by 1 also,, i think i should go with the error
good ol' BeNNy

• Supreme Robot
• Posts: 11,673
##### Re: to cartesian scans
« Reply #7 on: February 03, 2008, 06:20:21 PM »
When you digitize anything (such as putting your readings into an X-Y grid), you are putting error into it. Its not avoidable. Make a grid with twice the resolution, your error goes down by half.

But then you have to deal with higher computation time, memory usage, etc.

And then you need to ask yourself, is the error rate good enough? I mean, if your encoders are slipping at a 10% rate, who cares if your matrix has a 1% error

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #8 on: February 04, 2008, 10:57:28 AM »
yea very true admin, and i guess my hexapod will slip 1 cm or more each 1 meter walk
good ol' BeNNy

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #9 on: February 15, 2008, 04:15:36 PM »
hey guys, as im generating my grif from the polar data im facing another problem, its about that there would be squares unmapped
because of obstacles ,the problem is that during a scan,how do i identify mapped squares from unmapped ones?
good ol' BeNNy

• Supreme Robot
• Posts: 11,673
##### Re: to cartesian scans
« Reply #10 on: February 15, 2008, 05:47:10 PM »
In each square you place a label.

For example:
1 = object
2 = no object
3 = robot
4 = unmapped area

etc . . .

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #11 on: February 16, 2008, 03:26:22 AM »
Quote
In each square you place a label.

For example:
1 = object
2 = no object
3 = robot
4 = unmapped area
yea i know that but how would you be able to identify each square based on one scan?
, obstacles are easy to identify (transforming plar to cartesian)
but when an obstacle is identified the squares just behinde it would not be mapped
,im talking about those,how would you identify em,,?

its like in this pic, green(unmapped) , red(robot) , black(mapped obstacle) , white(mapped  &  clean)

so due to some obstacles there would be unmapped squares in the matrix,, how do i solve this?(identify mapped from unmapped)
good ol' BeNNy

• Supreme Robot
• Posts: 11,673
##### Re: to cartesian scans
« Reply #12 on: February 16, 2008, 04:38:35 PM »
Start the entire map as empty, with no objects.

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #13 on: February 16, 2008, 04:54:24 PM »
do you mean considering green areas are mapped and empty?

if yes then the bot may include em in its path so itll bump if there was an obstacle(considering a very strange set of obstacles)
good ol' BeNNy

• Supreme Robot
• Posts: 11,673
##### Re: to cartesian scans
« Reply #14 on: February 16, 2008, 05:33:58 PM »
Yeap, you assume the green is empty (has no object) when plotting a path. But define it as 'unknown' instead of empty.

Your robot will never bump into green, because your robot will/should always scan an unexplored area before moving into it.

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #15 on: February 17, 2008, 08:05:50 AM »
yea admin i totally agree with you,but you seem to not understand my question...
my question is that

i will send from the micro to the pc serially a matrix like this one

255 - 80 - 80  - 90 - 120 - 90 - 80- -------------- - 255
0    -  2   - 4   -  6 -   8 -   10  - 12 - ------------ - 180

the first row contains distance values(nearest obstacle, 255 = no obstacle)
the second contains the coresponding angles

now in pc i will convert these polar data into cartesian (easy) BUT this way iwill be able to identify squares that are obstacles
,, what about whats behind the obstacle?? sure unmapped(unknown) but how do i know which ones would be unknown??

considering the data with angle 45 is 127 so this way i know that the obstacle is in a specific square AND the other squares wich lies behind it with angle 45 are unknown, this is easy because at angle 45 its easy to know which squares would be unmapped
but at angles like 78 you can plot the obstacle but how would you know what squares behinde the obstacle to mark as unknown?

i did plot the green ones by hand(guess) but assume that its the same pic without green squares
,can you fing the algorithm to mark them as green?
good ol' BeNNy

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #16 on: February 17, 2008, 08:13:51 AM »
this is to make it more clear , its a one angle with obstacle distance,  i need to know how do i mark the green ones( here marked by a guess)
good ol' BeNNy

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #17 on: February 17, 2008, 08:17:24 AM »
i forgot to tell you about someway to do it but i would want to mention it cuz its long n looks dumb

its for example you have a 200 at angle 60
you mark this one as obstacle then you incremet it(the distance,200 here) by 3(or any small number) n you mark the coresponding square
as unknown and you still do this until you reach 255

,, it works but i think there could be another solution?
good ol' BeNNy

• Supreme Robot
• Posts: 11,673
##### Re: to cartesian scans
« Reply #18 on: February 17, 2008, 09:20:12 AM »
I don't think you understood what I meant . . .

When solving for your robot path, mark the green as empty - meaning, assume no obstacles are there.

If your robot is trying to explore unexplored area, mark the green as a goal location.

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #19 on: February 17, 2008, 11:57:05 AM »
yea true ,but i was asking about how to know mapped from unmapped areas depending on polar data
good ol' BeNNy

• Supreme Robot
• Posts: 11,673
##### Re: to cartesian scans
« Reply #20 on: February 17, 2008, 12:03:43 PM »
When your robot gets turned on, set the entire map to be labeled as unexplored.

Then when you use your scanner, only change the areas that you explore to a new label - otherwise it remains unexplored. Hence, areas behind objects will remain labeled unexplored on your map.

#### benji

• Supreme Robot
• Posts: 832
##### Re: to cartesian scans
« Reply #21 on: February 17, 2008, 12:12:11 PM »
Quote
its for example you have a 200 at angle 60
you mark this one as obstacle then you incremet it(the distance,200 here) by 3(or any small number) n you mark the coresponding square
as unknown and you still do this until you reach 255
so its  like this but instead of marking unknown ones i mark known ones
good ol' BeNNy