Announcement

Collapse
No announcement yet.

NXT Sensors Import files?

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

  • NXT Sensors Import files?

    Hi we have the following set of imports found by a tutorial on youtube, but the tutorial was using Modern Robotics Hardware and hence why they gave us Modern Robotics Imports.

    unfortunately we do not have any Modern Robotics Sensors and will be using the Legacy Module with the NXT Sensors, this year our robot will have a Color, Sonar, Compass Sensor.

    we wanted to know if we had to specify any files to include in order for those devices to work with the code we are writing.

    The Following are Files/Imports from the Tutorial, which include Modern Robotics files, again to clarify we wanna know if we have to specify any NXT or Legacy Imports in order to use those sensors, Thank you!!

    package com.qualcomm.ftcrobotcontroller.opmodes;


    import com.qualcomm.hardware.ModernRoboticsI2cGyro;
    import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
    import com.qualcomm.robotcore.hardware.DcMotor;
    import com.qualcomm.robotcore.hardware.DcMotorController;
    import com.qualcomm.robotcore.hardware.GyroSensor;
    import com.qualcomm.robotcore.util.Range;

  • #2
    Generally, it is not necessary to manually specify imports. If you use a class in your program and autocomplete the name, Android Studio will take care of adding the import. In addition, you don't need to specify in your program whether you are using a HiTechnic Color Sensor, Compass Sensor, etc. vs. a MR one. The config file will take care of that, so when you get, for example, a CompassSensor from the hardwareMap, you can use its functionality without caring how it is actually implemented (which takes care of choosing between using a Legacy Module or a DIM). I think the only reason you would import the MR gyro class is that it has some extra functionality that can be used if you know you are using one.

    Comment


    • #3
      FYI, the Lego NXT Color Sensor is not supported by the FTC hardware/software platform, though the HiTechnic NXT Color Sensor is supported.

      Comment


      • #4
        Thanks for a quick Responces

        @GearTicks Thank you so much for clarifying that, so from what i understand if i go and do the following

        sensorGyro = hardwareMap.gyroSensor.get("gyro"); // Get the gyro sensor configured on phone named gyro
        mrGyro = (ModernRoboticsI2cGyro) sensorGyro; // How would i use the following, obviously i wouldn't need the Modern Robotics command since it is a NXT Sensor not a Modern Robotics one.
        //obviously the compass and the Sonar sensor would use similar commands correct?

        @Cheer4FTC that is great to hear we would have spent hours trying to figure that out, thanks for saving us allot of time and hassle

        Comment


        • #5
          Originally posted by FTC9260 View Post
          @GearTicks Thank you so much for clarifying that, so from what i understand if i go and do the following

          sensorGyro = hardwareMap.gyroSensor.get("gyro"); // Get the gyro sensor configured on phone named gyro
          mrGyro = (ModernRoboticsI2cGyro) sensorGyro; // How would i use the following, obviously i wouldn't need the Modern Robotics command since it is a NXT Sensor not a Modern Robotics one.
          //obviously the compass and the Sonar sensor would use similar commands correct?
          You can just call methods on sensorGyro directly, e.g. sensorGyro.getRotationFraction(). There is no need for mrGyro.

          Comment


          • #6
            @GearTicks anyway you can write us a sample code for each individual sensor? we are having major problems trying to figure it out on our own.

            or anyone else on the forum, sample code for Color Sensor, Gyro Sensor, Ultrasonic sensor!!

            Comment


            • #7
              With last year's FTC SDK, it didn't do any heading integration on the NXT gyro. Does it do that this year? If not, it means you have to write code to do your own heading integration. Our team library does support software integration on the NXT gyro if you want to look at it.
              https://github.com/trc492/Ftc2016Fir...chnicGyro.java
              Regarding the Ultrasonic sensor, you can just use the UltrasonicSensor class.

              Comment

              Working...
              X