Adafruit_BNO055 Vector<3> Vector Elements

35 Views Asked by At

I am new to using Vector datatype. My understanding is that it is similar to an Array. The Github repo for Arduino Vector seems to confirm it "This library is very similar to Array, however Array stores data internally in the container and this library stores data externally". Can someone explain what means data stored externally and internally? Where on the stack vectors and arrays go?

The example code on Adafruit shows Vector elements can be accessed using dot operation (ex myVector.x(), myVecotr.y()). Example from Adafruit Serial.print(euler.x()); Vector.h defines this operations on lines 168-170

double x() const { return p_vec[0]; }

double y() const { return p_vec[1]; }

double z() const { return p_vec[2]; }

I can also access the same data by indexing vector elements just as if it was an array e.g myVector[0], myVector[1']. What I find interesting and confusing is that in my Vector<3>, which I assume has 3 elements, I can access more than 3 elements if I index it as an array.

Code sample:

imu::Vector<3> grav = bno.getVector(Adafruit_BNO055::VECTOR_GRAVITY);
Serial.print(grav.x());
Serial.print(", ");
Serial.print(grav.y());
Serial.print(", ");
Serial.print(grav.z());
Serial.print("; Vector size> ");
Serial.println(grav.n());
Serial.print("Vector elements? >>> ");
for (int nn=0; nn<11; nn++){
  Serial.print(grav[nn]);
  Serial.print(", ");
}
Serial.println();

The output is following:

Gravity vector x,y,z>>> -0.32, 0.34, 9.79; Vector size> 3
Vector elements? >>> -0.32, 0.34, 9.79, -8.88, -3.38, -18.00, 1.00, 0.02, 0.02, -0.08, 0.00,

The first three elements are the same as the ones accessed with .x(), .y(), .z(), but what are the the other elements, after the first three in this vector/array? I can see data change when I rotate IMU in the first 10 vector/array elements.

0

There are 0 best solutions below