Hi Michael,
We've performed some testing w/the ftc_app 3.1 SDK and the navX-Micro libraries from 2/10/2017.
So far we haven't found any problems testing the samples that are provided w/the navX-Micro distribution. You should be able to test these to verify proper operation of the libraries (for example, the SensorNavXProcessedOp opmode, and the ConceptNavXDriveStraightPIDLoopOp.
Since the samples work for us, it makes sense next to start looking more closely at the opmode code you have provided.
I see one thing that might be an issue: a stale reference to the navxDevice might be being accessed.
In our op-mode examples, ~each and every time~ the opmode starts this is invoked:
// get a reference to NavX-micro device
navxDevice = AHRS.getInstance(hwMap.deviceInterfaceModule.get("dim2"),
NAVX_DIM_I2C_PORT,
AHRS.DeviceDataType.kProcessedData,
NAVX_DEVICE_UPDATE_RATE_HZ);
This library is designed so that there will only ever be a single instance. However, if close() is ever invoked, that instance will be shutdown and destroyed. And a new instance will not be created until AHRS.getInstance() is invoked again.
Therefore, if close() is invoked somewhere in the code, and if some code has cached a reference to the navxDevice, after close() occurs that will be a reference to a deleted object. I think that's likely what's happening here.
I note that in HardwareShooterBotNavXMicroTest.java in the init(HardwareMap) method, AHRS.getInstance() is invoked and the returned object reference is assigned to the navXDevice variable. Then, in MMAutonomousRedTeamNavXTest.java, this variable is retrieved when the opmode starts, like this:
// get a reference to the Navx device and one of its PID controllers
navxDevice = robot.navxDevice;
So I believe what is happening is that somewhere in code, the close() method is being invoked on the navXDevice. At that point robot.navxDevice refers to a deleted object. And when the opmode runs a second time, it attempts to use that reference to a deleted object.
If that's correct, there are two ways to resolve it:
(a) remove all code that calls navxDevice.close(). This should cause no harm, except that the navXDevice will be continuing to gather data from the navX-Micro device even though it's not being used.
(b) instead of accessing the reference to the navXDevice that was retrieved via AHRS.getInstance() at the beginning of the robot program, at the beginning of each opmode re-retrieve a current reference by re-invoking AHRS.getInstance() at that time.
I realize that you had previously attempted removing the call to close(), and I can't explain why you still saw the problem after that.
However what you are describing sounds very much like during the second run of the opmode, a stale reference to the navxDevice is being accessed.
So please look into that and let us know what you find.
Cheers,
- scott