> For the complete documentation index, see [llms.txt](https://docs.andymark.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.andymark.com/frc-electronics/can-sensors/can-lidar-am-5684/examples.md).

# Examples

## Use case

This example reads the CAN Lidar’s distance, status, flags, peak signal, and ambient-light values and publishes them to SmartDashboard. Use it to verify CAN communication, confirm the configured device ID, evaluate mounting, and collect data for application-specific validation thresholds.

{% hint style="info" %}
The snippets use CAN bus 2 and device ID 0. Change both values to match the controller and sensor configuration.
{% endhint %}

## Mounting example

<figure><img src="https://2060440806-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcQgnvayQud3Xf5sZi0wz%2Fuploads%2FmLXu7MmcL0HsiC9FyRSC%2FPXL_20250829_123210530.jpg?alt=media&amp;token=8a70c0bd-27b1-4008-b6d3-de418dea4321" alt="CAN Lidar mounted to robot structure" width="188"><figcaption><p>Mount the sensor rigidly with an unobstructed view of the target.</p></figcaption></figure>

## Setup

Install the [AndyMark WPILib vendor library](/frc-electronics/wpilib-am-vendor-library-setup.md) before using these examples. See [Device API](/frc-electronics/can-sensors/can-lidar-am-5684/device-api.md) for all available methods.

{% tabs %}
{% tab title="Java" %}

```java
import com.andymark.jni.AM_CAN_Lidar;
import com.andymark.jni.AM_CAN_Lidar.AM_LidarData;
import com.andymark.jni.AM_CAN_Lidar.AM_LidarDebugData;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

// CAN bus 2, device ID 0
AM_CAN_Lidar myLidar = new AM_CAN_Lidar(2, 0);

// Restore the default 50 ms report period.
myLidar.resetReportPeriod();

AM_LidarData data = myLidar.getData();
AM_LidarDebugData debug = myLidar.getDebugData();

SmartDashboard.putNumber("Lidar/DistanceMm", data.distanceMm);
SmartDashboard.putNumber("Lidar/Status", data.status);
SmartDashboard.putNumber("Lidar/Flags", data.flags);
SmartDashboard.putNumber("Lidar/TimestampMs", data.millisStamp);
SmartDashboard.putNumber(
    "LidarDebug/PeakSignalCentiMcps",
    debug.peakSignalCentiMcps
);
SmartDashboard.putNumber(
    "LidarDebug/AmbientCentiMcps",
    debug.ambientCentiMcps
);
SmartDashboard.putNumber(
    "LidarDebug/TimestampMs",
    debug.millisStamp
);
```

{% endtab %}

{% tab title="C++" %}

```cpp
#include "AM_CAN_Lidar.h"
#include <frc/smartdashboard/SmartDashboard.h>

// CAN bus 2, device ID 0
AM_CANLidar myLidar{2, 0};

// Restore the default 50 ms report period.
myLidar.ResetReportPeriod();

AM_LidarData data = myLidar.GetData();
AM_LidarDebugData debug = myLidar.GetDebugData();

frc::SmartDashboard::PutNumber("Lidar/DistanceMm", data.distanceMm);
frc::SmartDashboard::PutNumber("Lidar/Status", data.status);
frc::SmartDashboard::PutNumber("Lidar/Flags", data.flags);
frc::SmartDashboard::PutNumber("Lidar/TimestampMs", data.millisStamp);
frc::SmartDashboard::PutNumber(
    "LidarDebug/PeakSignalCentiMcps",
    debug.peakSignalCentiMcps
);
frc::SmartDashboard::PutNumber(
    "LidarDebug/AmbientCentiMcps",
    debug.ambientCentiMcps
);
frc::SmartDashboard::PutNumber(
    "LidarDebug/TimestampMs",
    debug.millisStamp
);
```

{% endtab %}
{% endtabs %}

## Next steps

* Move the target through the full operating range.
* Compare status, peak signal, and ambient values under realistic lighting.
* Use the [Validation](/frc-electronics/can-sensors/can-lidar-am-5684/validation.md) page to establish acceptance criteria.
* Apply tuning only after recording baseline performance.
