Announcement

Collapse
No announcement yet.

Using on-board sensors from opmodes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2009FTC3491
    replied
    You can use hardwareMap.appContext as follows:
    mSensorManager = (SensorManager) hardwareMap.appContext.getSystemService(Context.SE NSOR_SERVICE);
    accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELE ROMETER);
    magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNET IC_FIELD);

    Code for a simple opMode to display robot controller orientation as telemetry is at: https://github.com/acharraggi/my_ftc.../OrientOp.java

    Leave a comment:


  • hexafraction
    replied
    Originally posted by mikets View Post
    I don't think there is a hardwareMap.getContext() method. I can't find it in Javadoc but you can cast the hardwareMap.appContext public variable into an activity.
    Sorry, I think I mentally switched something around accidentally. It is in fact a field as you describe.

    Leave a comment:


  • mikets
    replied
    Originally posted by hexafraction View Post
    You can do this as if you were in an activity, since you actually are in an activity. To get an instance of an Android Context use hardwareMap.getContext(). To the best of my knowledge in this version the context *is* an activity so you can cast it if necessary.
    I don't think there is a hardwareMap.getContext() method. I can't find it in Javadoc but you can cast the hardwareMap.appContext public variable into an activity.

    Leave a comment:


  • mikets
    replied
    Our sample project contains some sample code for built-in phone sensors. You may find those useful.
    https://github.com/trc492/FtcSamples...idSensors.java

    Leave a comment:


  • hexafraction
    replied
    Originally posted by MechaTech10617 View Post
    Is there a way to use the on-board gyroscope and magnetometer (compass) on the Moto G 2nd Gen from an OpMode in Android Studio? I know that you can use those sensors from a standard activity, but it would be a big help if we could use the onboard sensors instead of buying a MR Gyro.
    You can do this as if you were in an activity, since you actually are in an activity. To get an instance of an Android Context use hardwareMap.getContext(). To the best of my knowledge in this version the context *is* an activity so you can cast it if necessary.

    Leave a comment:


  • MechaTech10617
    started a topic Using on-board sensors from opmodes

    Using on-board sensors from opmodes

    Is there a way to use the on-board gyroscope and magnetometer (compass) on the Moto G 2nd Gen from an OpMode in Android Studio? I know that you can use those sensors from a standard activity, but it would be a big help if we could use the onboard sensors instead of buying a MR Gyro.
Working...
X