# Math with XYZWPR variables in Karel?

• Hey guys, I am having some trouble doing math with XYZWPR variables.

I have two XYZWPR variables, say pos1 and pos2.

At first I tried to subtract them and get the result into a 3rd XYZWPR variable like so:

Code
VAR
pos1, pos2, pos3: XYZWPR

BEGIN
pos3 = pos2 - pos1
END

But I got an error saying:

Operator expected POSITION data type for left operand.

Any idea how to properly do math with that datatype?

• Code
VAR
pos1, pos2,pos3 : XYZWPR
pos4: POSITION

BEGIN
pos4 = pos2 : INV(pos1)
pos3 = pos4

END

The robot in most times does automatic conversions between XYZWPR and POSITION.

• Code
VAR
pos1, pos2,pos3 : XYZWPR
pos4: POSITION

BEGIN
pos4 = pos2 : INV(pos1)
pos3 = pos4

END

The robot in most times does automatic conversions between XYZWPR and POSITION.

Hi,

Is it possible to access fields of POSITION data just like XYZWPR?

I have initialized

uframe, utool : POSITION

and gett the following error.

What is the correct syntax to access fields of this position variable? This works for an XYZWPR

• POSITION.LOCATION.X

Hi,

Just to confirm,

Does the orient field contain the roll, pitch, and yaw values? and Location field just contains XYZ values?

• Hi,

Just to confirm,

Does the orient field contain the roll, pitch, and yaw values? and Location field just contains XYZ values?

No. This is a matrix representation of the point. The location vector just contains XYZ values, but if you're looking for WPR representation you'll need to convert your position into XYZWPREXT. I believe that karel automatically converts between the data types, so you should be able to declare a new variable as XYZWPREXT and then assign it your position value. Something like this:

uframe : position

uframe2 : XYZWPREXT

.

.

.

.

uframe2 = uframe

write(uframe2.x,cr)

I haven't tested this but from what I've read it should work.

• I believe that karel automatically converts between the data types,

Thanks, I did similar but i use INV() built-in.