|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Encoders for testing
When implementing tests for an off season evaluation I've run into a lack of documentation on how to mock out encoders. Obviously, for booleans and analogs it is possible to do stuff like:
Code:
hal_data['analog_in'][2]['voltage'] = self.position Was curious if anyone had tried to do this and found a good way to do it? (65% test coverage is bothering me) |
|
#2
|
|||
|
|||
|
Re: Encoders for testing
In case someone else comes along curious about the same thing, because it wasn't intuitive to me, you can access the encoder count value by using:
Code:
hal_data['encoder'][index]['count'] |
|
#3
|
||||
|
||||
|
Re: Encoders for testing
The encoders are driven by the way that they're initialized underneath the hood, and it's a bit odd. Perhaps the HAL implementation will get updated this fall and it'll get better. Sorry about the lack of documentation. Feel free to improve it and submit a PR.
![]() You'll note of course that the place where the implementation tends to be strong is in stuff that we used, and as you mentioned I like to attach encoders to the CAN devices directly instead of using them standalone. ![]() |
|
#4
|
||||
|
||||
|
Re: Encoders for testing
I suspect a good utility function to add to the test HAL would be 'get_encoder(pinA, pinB)' that would scan the list of encoders and find a matching encoder, and return that dictionary. (Bug report now at https://github.com/robotpy/robotpy-wpilib/issues/152)
Last edited by virtuald : 29-06-2015 at 20:41. |
|
#5
|
|||
|
|||
|
Re: Encoders for testing
Quote:
And don't worry, I'll take a whack at a PR (or one of my students will) once we have something to contribute back. And we haven't (yet) made the leap to CAN though I suspect that might be coming in the near future. But possibly one major change in the software is enough for the time being. |
|
#6
|
||||
|
||||
|
Re: Encoders for testing
When I said 'driven', I should have said 'the design for the encoders was driven'
|
|
#7
|
|||
|
|||
|
Re: Encoders for testing
Ah ok. I'll double check that this approach will work and I'll see what I can write up. If nothing else, this thread should show up in searches for anyone else who is lost.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|