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:>
//source
#include “LidarSensor.h”#include
LIDARSensor::LIDARSensor(int channel):
//counter(frc::Counter::Mode::kSemiperiod)
counter(channel)
//DigitalInput(channel)
{
counter.SetMaxPeriod(25.0); //counter.SetUpSource(channel);
// counter.SetDownSource(channel);
//counter.SetUpdateWhenEmpty(false); counter.SetSemiPeriodMode(true); counter.Reset();
}
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
}
and
//header
#pragma once#include “frc/DigitalInput.h”
#include “frc/Counter.h”
#include “frc/DigitalSource.h”
class LIDARSensor// : public frc::DigitalInput
{
private:
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) */
public:
LIDARSensor(int channel);
void LIDARSensorInit(); double getDistance();
};
Thanks