No announcement yet.

IMU/Enocders Android Studio

  • Filter
  • Time
  • Show
Clear All
new posts

  • IMU/Enocders Android Studio

    Our programmers are having issues when they combine functions they created when using IMU and Encoders in Andriod Studio. When they run the IMU function on it's own it works perfectly but when they run their Encoder function first then the IMU function it will not run the IMU and it get stuck in a stop loop and crashes. Attached is a sample of their code. Any help on this issue would be greatly appreciated.
    Attached Files

  • #2
    The drive_2() function ends with the RunMode "Stop and Reset Encoder". This prevents any further driving. RunModes are mutually exclusive; only one can be in effect at a time.

    Try removing that; not needed if all drive/encoder functions begin with that anyway. The RunMode "Run To Position" will continue to operate, until some other RunMode is called.

    In its place, or at the beginning of the rotateCCW() function, use the RunMode "Run Using Encoder". This will replace the "Run To Position" that's still in effect from the drive_2() function.


    Side note 1: your IMU calibration file should end with .json, not .josn. Even better, consider updating to SDK 8.1.1 and use the new IMU interface. More info is here:

    Side note 2: both of your while loops need an additional boolean condition: && whileOpModeIsActive
    This allows you to stop the OpMode safely (and not crashing) by touching STOP.

    Side note 3: consider the use of "Zero Power Behavior"
    Last edited by Westside; 02-17-2023, 03:19 PM.