-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with simulated CANCoder #61
Comments
What you're seeing is not expected behavior. My process:
// Don't forget to import CANCoderSimCollection at the top
/* New code */
CANCoderSimCollection simCollection = _CANCoder.getSimCollection();
@Override
public void simulationPeriodic() {
simCollection.addPosition(1);
simCollection.setVelocity(20);
}
/* Existing code */
@Override
public void teleopInit() {
_CANCoder.setPosition(0); // New line
}
Could you provide a process similar to what I did that reproduces the issue? FYI, triple backtick will allow you to paste multiple lines of code, and you can specify language on the first line, like so:
|
So I did more testing and found two things:
The cancoder sim is working now. Perhaps the failed reset call was causing some corruption and why doing reset in constructor is a problem I sure don't know, but looking good now. I worked with you earlier on encoder (SRX) reset in sim and problems related to timing. I adjusted my timings and things seemed fine then, but testing today on the cancode issue revealed I am still seeing pretty strange issues on resetting an SRX, waiting longer than the frame speed, seeing zero returned and then not long later the old pre-reset counts reappear. I will file a new issue after I look at this a bit more. |
So I think the error on reset in constructor is the robot is not yet enabled and so signals to hardware are not transmitted by the Rio causing the cancoder library to return the error. Thoughts? |
I looked further into this, what you're seeing is close to what you think is happening. Phoenix need some sensor configuration information from CANCoder when it performs the setPosition operation. This is normally not an issue in hardware since CANCoder always sends out the CAN frames, so the RIO will receive frames during its boot process. However when you construct a CANCoder and use it immediately afterward while simulating, there hasn't been enough time for Phoenix to receive the CAN frames. |
So when I set the position to zero in the class constructor and ignored the error, the position did not reset to zero, getposition returned a nonsense value that did not change during the test run. If I waited, like you suggest, then set position to zero, that worked: getposition returned zero and incremented as expected after that. While what I observed and what you described don't seem to quite match up, I am good with calling this one solved. |
I have wrapper classes for SRX & FX encoders. Cloned the FX encoder class to create to wrapper for CANCoder. The code that drives the sim updates:
` public void setSimValues(double position, double velocity)
{
simCollection.setRawPosition(metersToTicks(position));
'
Reset is done with:
` public void reset()
{
ErrorCode errorCode;
`
Running under sim, the absolute position works fine but the encoder count returned by get() is way out of whack. Start sim do no driving, just call for reset of encoder, the next (and all subsequent) get() returns a huge negative number. Then driving some does not change that value returned by get(). Note that I get this error on the reset() call:
encoder reset failed (-3) CAN_MSG_NOT_FOUND
The text was updated successfully, but these errors were encountered: