V5 inertial sensor collision callback parameters?

Hi, sorry if this is documented somewhere and I’m missing it. I’m trying to figure out the parameters to the inertial sensor collision callback. Seeing as its taking an axisType as the first argument, why are there three doubles following that?

The three doubles will receive the raw data used for detecting the collision, that’s the change in acceleration for each axis. collision detection is not particularly accurate, a collision in one axis may cause acceleration change in the others as well. I’m not sure anyone has ever used this functionality. Looking at the code shows the default threshold is 1.5G but there seems to be a protected class member function to change that (ie. you would need to subclass inertial to use it)

void setCollisionThreshold( double value );   

an example.

// define your global instances of motors and other devices here
vex::inertial    imu(PORT1);

void
collision_det( axisType axis, double raw_x, double raw_y, double raw_z ) {
    printf("collision detected\n");

    switch( axis ) {
      default:
        // Z axis detected
        break;
      case  axisType::xaxis:
        // X axis detected
        break;
      case  axisType::yaxis:
        // Y axis detected
        break;
    }
}


int main() {
    imu.collision( collision_det );

    while(1) {
        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}
2 Likes

Got it, thanks! Was trying to see if i can spot collisions with objects with this.