> For the complete documentation index, see [llms.txt](https://guides.mccaskeyrobotics.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guides.mccaskeyrobotics.org/ftc/sensors/360-ir-locator.md). Agents can also search and read this documentation through its [MCP server](https://guides.mccaskeyrobotics.org/~gitbook/mcp).

# 360 IR Locator

360 IR Navigation

Part 1: The Sensor

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fgit-blob-39376bf202e12e9b5d71bb292307801d7b66dfe2%2Fimage6?alt=media)

\- Plug the sensor in like this:

Or with REV Stuff…

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fgit-blob-d7a4b02f220badfea9be860f85257e11f7b381eb%2Fimage8?alt=media)

\- Configure your sensor as an I2C Device and name it “irl”

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fgit-blob-a977b21a843c74c19184c0f806930e297e2c63c3%2Fimage7?alt=media)

Part 2: Testing the Sensor

\- You will need to build TWO programs to make this work… one is a class to handle setting up the sensor and the other is the actual OpMode. First, the class…

\- Add a new class and call it MRIIrLocator. Don’t use an example file. Once you have added the class, delete everything inside it and copy/paste the code below.

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fgit-blob-b29a0630614bc7e32291e17cf194512ee9b0ec48%2Fimage3?alt=media)

```
/* 
DO NOT EDIT THIS PROGRAM 
Modern Robotics IR Locator 360 Driver 
Created 7/27/2017 by Colton Mehlhoff of Modern Robotics using FTC SDK 3.10 Reuse permitted with credit where credit is due 
This class provides functions to use the IR Locator 360 http://modernroboticsinc.com/ir-locator-360 Support is available by emailing support@modernroboticsinc.com 
*/ 
package org.firstinspires.ftc.teamcode; 
import com.qualcomm.robotcore.hardware.HardwareMap; 
import com.qualcomm.robotcore.hardware.I2cAddr; 
import com.qualcomm.robotcore.hardware.I2cDevice; 
import com.qualcomm.robotcore.hardware.I2cDeviceSynch; 
import com.qualcomm.robotcore.hardware.I2cDeviceSynchImpl; 
public class MRIIrLocator { 
 private byte[] chache; 
 private I2cDevice sensor; 
 private I2cDeviceSynch reader; 
 HardwareMap hwMap = null;
 public MRIIrLocator() { 
 } 
 public void init(HardwareMap ahwMap, String cfgName) { 
 init(ahwMap, cfgName, 0x1C); //Default I2C address for color beacon is 0x4c  } 
 public void init(HardwareMap ahwMap, String cfgName, int i2cAddr8) {  hwMap = ahwMap; 
 sensor = hwMap.i2cDevice.get(cfgName); 
 reader = new I2cDeviceSynchImpl(sensor, I2cAddr.create8bit(i2cAddr8), false); 
 reader.engage(); 
 } 
 byte[] readAll(){ 
 chache = reader.read(0x00, 8); 
 return chache; 
 } 
 int heading1200hz(){ 
 return (reader.read8(0x04)&0xFF) * 5; 
 }
 int strength1200hz(){ 
 return reader.read8(0x05) & 0xFF; 
 } 
 int heading600hz(){ 
 return (reader.read8(0x06) & 0xFF) * 5; 
 } 
 int strength600hz(){ 
 return reader.read8(0x07) & 0xFF; 
 } 
} 
- The next program that will need to be added should be called Locator_Test. Following a similar procedure as above, copy and paste the code below into your new OpMode.  
/* 
Modern Robotics IR Locator 360 Example 
Created 7/27/2017 by Colton Mehlhoff of Modern Robotics using FTC SDK 3.10 Reuse permitted with credit where credit is due 
Configuration: 
I2CDevice "irl" (MRI IR Locator 360 with default I2C address 0x1C) 
MRIIrLocator class must be in the same folder as this program. Download from  http://modernroboticsinc.com/ir-locator-360 
To change I2C Addresses, go to http://modernroboticsedu.com/mod/lesson/view.php?id=96 Support is available by emailing support@modernroboticsinc.com 
*/ 
package org.firstinspires.ftc.teamcode; 
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; 
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@Autonomous (name = "IR Locator Test", group = "MRI") 
public class Locator_Test extends LinearOpMode { 
 MRIIrLocator locator = new MRIIrLocator(); 
 @Override 
 public void runOpMode() throws InterruptedException { 
 telemetry.addData("Status", "Initialized"); 
 telemetry.update(); 
 locator.init(hardwareMap, "irl"); //initializes the I2CDevice. Second parameter is the name  of the sensor in the configuration file. 
 waitForStart(); 
 while (opModeIsActive()) { 
 telemetry.addData("Dir 1200", locator.heading1200hz()); 
 telemetry.addData("Dir 600", locator.heading600hz()); 
 telemetry.addData("Str 1200", locator.strength1200hz()); 
 telemetry.addData("Str 600", locator.strength600hz()); 
 telemetry.update(); 
 } 
 } 
} 
```

Now build everything and run your Locator\_Test OpMode. Take some time to understand how your sensor responds to your beacon.

Part 3: Navigating to the Sensor

You should now begin to add your motors to the Locator\_Test file right inside your main class area…

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fgit-blob-58e1e28d051ba8ef9b300a4c6b3b1679c3b65f84%2Fimage5?alt=media)

Next, complete hardware mapping to tell your robot controller where to find your motors…(feel free to copy/paste this in from other files!)

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fgit-blob-422b26f4d92c60f628d7849bdaf9cdfae73e4bd4%2Fimage4?alt=media)

Your main loop should look like this:

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fgit-blob-bdafc770aa3414de965ebbf98039084304b286f7%2Fimage1?alt=media)

Now run the OpMode with a beacon placed on the floor somewhere in the room. Your robot should be able to find the beacon even if you start it facing the other direction.
