Counter Class Not Counting

UPDATE: Turns out the problem was that our electronics “lead” put a 10k resistor on instead of a 1k.

We’ve been trying to use the counter class for a Lidar Lite V3. We are following the code used here. However, the counter does not seem to be going up, regardless of whether it says it is stopped or not, since Get() is always returning 0.
Our code is here:>

#include “LidarSensor.h”


LIDARSensor::LIDARSensor(int channel):







// counter.SetDownSource(channel);





double LIDARSensor::getDistance()


/*if (counter.Get() < 1)


    return 0.0;


std::cout << std::endl << "GET: " << counter.Get() <<  std::endl;

std::cout << std::endl << "STOPPED: " << counter.GetStopped() << std::endl;

std::cout << std::endl << "PERIOD: " << counter.GetPeriod() << std::endl;

return (counter.GetPeriod() * factor + offset); // Use lin reg to obtain values



#pragma once

#include “frc/DigitalInput.h”

#include “frc/Counter.h”

#include “frc/DigitalSource.h”

class LIDARSensor// : public frc::DigitalInput



frc::Counter counter;

static constexpr double offset = 0.0;

static constexpr double factor = 100000;

/* Based on your sensor, you will have different data.

 * Use multiple data points and a linear regression program

 * to obtain personal factor and offset values.

 * for cm: 100000, for in: 39400 (from our testing)



LIDARSensor(int channel);

void LIDARSensorInit();

double getDistance();


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.