Looking for simple code to use for encoders during autonomous. preferably without pid because our pid isnt tuned.
We use Grayhill Encoders.
This isn’t nearly enough information here to provide any substantive help. What language do you use? What motor controllers? What kind of drive? Do you have a github where we can view your team’s code?
C++ probably
Minimum code for determining distance with an e4t encoder. I have not used the grayhill, but if they are quadrature I would expect them to be similar.
#include “wpilib.h”
class Robot: public IterativeRobot
{
private:
Encoder MyEncoder;
public:
Robot() :
MyEncoder(0, 1, true, CounterBase:: k4X) //DIO 0 and 1 channels
{
}
void RobotInit()
{
// DistancePerPulse = (wheeldiameter * 3.1415)/360
float DistancePerPulse = 0.05911;
MyEncoder.SetDistancePerPulse(DistancePerPulse);
}
void AutonomousInit() override
{
MyEncoder.Reset(); //zero the encoders
}
void AutonomousPeriodic()
{
double distance = MyEncoder.GetDistance();
}
void TeleopInit() { }
void TeleopPeriodic() { }
};
START_ROBOT_CLASS(Robot)