REVrobotics / SPARK-MAX-Examples

Example code for SPARK MAX
BSD 3-Clause "New" or "Revised" License
106 stars 107 forks source link

Alternate Encoder Example moves to half the number of revolutions set. #15

Open vatbrain opened 4 years ago

vatbrain commented 4 years ago

When running the Alternate Encoder example using the Rev Through Bore Encoder, the shaft with the Through Bore Encoder moves half the number of revolutions specified by the setpoint. This appears to be because m_alternateEncoder.GetPosition() returns twice the number of revolutions that the encoder rotates. Strangely enough, changing kCPR from 8192 counts per revolution to 4096 counts per revolution does not seem to have any effect on this.

willtoth commented 4 years ago

Thanks for running with the example, can you provide a summary of how you have the sensor wired?

vatbrain commented 4 years ago

One of the cables that was included with the encoder is plugged into the encoder on one end and an Alternate Encoder Adapter on the other end. The Alternate Encoder Adapter is plugged into the Spark Max such that the zip tie slots on the adapter and the Spark Max line up. I am running the code on a VMX-pi, not a Roborio, but I would not expect that to make a difference.

vatbrain commented 4 years ago

Here is the latest code I was running to watch the behavior of the alternate encoder: `/----------------------------------------------------------------------------/ / Copyright (c) 2017-2018 FIRST. All Rights Reserved. / / Open Source Software - may be modified and shared by FRC teams. The code / / must be accompanied by the FIRST BSD license file in the root directory of / / the project. / /----------------------------------------------------------------------------/

include <frc/TimedRobot.h>

include <frc/smartdashboard/smartdashboard.h>

include "rev/CANSparkMax.h"

class Robot : public frc::TimedRobot { /**

ifndef RUNNING_FRC_TESTS

int main() { return frc::StartRobot(); }

endif`

Note that the above code sets the position conversion factor of the alternate encoder to 0.5, which gives me one revolution reported per one actual revolution. When I do not make that call, I get two revolutions reported per one actual revolution.

vatbrain commented 4 years ago

@willtoth Has anyone at Rev had a chance to look at this? I am really interested in whether this can be confirmed or denied on another set of hardware using a robo-rio (I am using a VMX-pi in place of a robo-rio).