View unanswered posts | View active topics It is currently Fri Jul 25, 2014 2:45 am






Reply to topic  [ 12 posts ] 
API documentation errors with nMotorEncoder, what is right? 
Author Message
Rookie

Joined: Wed Jan 09, 2013 7:25 pm
Posts: 20
Post API documentation errors with nMotorEncoder, what is right?
I am trying to help our FTC team work through an issue that has resulted in me getting a bit confused by the API guide itself.

According to: http://www.robotc.net/wiki/TETRIX_Motor ... torEncoder
the value of nMotorEncoder is a long with a range of -32768 to 32767.

According to: http://www.robotc.net/wiki/Data_Types a long is: A whole number ranging from -2,147,483,648 to 2,147,483,647.

So, between these two descriptions there is a conflict. Either the nMotorEncoder value is actually an int. Or there is something wrong in the way the encoder value is being returned and the long is being truncated to an int someplace.

This came up because we have an arm that travels vertically, by chain. If arm begins at the bottom and we zero the encoder value; A full travel from bottom to top and back to bottom again results in not returning back to '0' but instead the value is approximately 5000 above that. A second travel up and down again results in being about +5000 off.

So I got the idea from the nMotorEncoder description that the motor might be advancing past the 90 rotations and causing the value to wrap. Then it occurred to me that a long should be able to accommodate this and not wrap so quickly. Thus I discovered the inconsistency.

Any input into any of these issues?
Thanks!


Sun Jan 20, 2013 5:42 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: API documentation errors with nMotorEncoder, what is rig
I think the API guide is wrong. A "long" is a 32-bit signed number. It can hold approx. +/- 2G. Having said that, even if the nMotorEncoder is a 16-bit signed value which holds +/- 32K, it will take over 90 revolutions to overflow it. Did your arm motor really travel more than 90 revolutions one way? Assuming the travel range of the arm is about 180 degrees and the encoder is mounted on the motor shaft. For the encoder to overflow, you must have a gear ratio of greater than 180 to 1 (i.e. 90 revolutions on the motor resulting in 180 degrees displacement of the arm). It would be quite difficult to achieve that kind of gear ratio with the textrix sprockets. I have a feeling that 32-bit versus 16-bit is not the problem.

EDIT: Actually, if you have a US digital quadrature encoder with 360-line optical disc, it will generate 1440 counts per revolution (4 times of 360). Even with that, your gear ratio would have been 180/4 = 45 to 1. Still too high in reality, so still unlikely in my opinion.


Last edited by MHTS on Mon Jan 21, 2013 4:56 am, edited 1 time in total.



Mon Jan 21, 2013 12:33 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Re: API documentation errors with nMotorEncoder, what is rig
I am sure the API is wrong:
Code:
intrinsic long property(nMotorEncoderTarget,            propertyMotorTargetEncoder, kNumbOfTotalMotors, tMotor);

This is from one of the main ROBOTC includes.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 2:30 am
Profile WWW
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 556
Post Re: API documentation errors with nMotorEncoder, what is rig
I have just confirmed that the API is incorrect and the revolution count range for a Mindstorms encoder is -2,147,483,648 to 2,147,483,647. I apologize for the confusion on this and thank you for bringing it to our attention, I will make sure this gets updated properly.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Mon Jan 21, 2013 10:19 am
Profile
Rookie

Joined: Wed Jan 09, 2013 7:25 pm
Posts: 20
Post Re: API documentation errors with nMotorEncoder, what is rig
Thanks everyone.

I believe that the chain travel is about 4 feet. And it is geared at 2:1. Could it be making 90 revolutions? Yes, I actually believe so. But we have to focus a bit more on that.
Could there be a truncation issue from casting the long to an int all over the place? more likely.

Someone else pointed out to me that the Tetrix encoders are 32bit. And the NXT motor encoders are 16bit. So, this can easily lead to confusion taking examples intended for one and applying them to the other.

Again, Thanks all!


Mon Jan 21, 2013 11:53 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Re: API documentation errors with nMotorEncoder, what is rig
No, the NXT encoders are also held in 4 byte signed longs.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 12:40 pm
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: API documentation errors with nMotorEncoder, what is rig
mightor wrote:
No, the NXT encoders are also held in 4 byte signed longs.

Hmm, that's an interesting thought. Do you know how the NXT reads the NXT motor encoder? I would imagine on Textrix, the counting is done in the Textrix motor controller and reported to the NXT via I2C messages. But the NXT motors are dumb devices, so I would expect two of the motor port pins must be channel A and B of the encoder and the counting is done by the NXT. Furthermore, I assume nMotorEncoder[] is an array of LONGs and the NXT firmware periodically updates this array by reading all the NXT and Textrix encoders. So it all boils down to what is NXT encoder's "counter width"? This is probably a question for the RobotC folks.


Mon Jan 21, 2013 2:33 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Re: API documentation errors with nMotorEncoder, what is rig
The motor encoder is read by the ARM7 through a series of components that determine the direction and create interrupts. If you look at the schematics and follow the lines, you'll see this:
Attachment:
2013-01-21_20-27-03.png
2013-01-21_20-27-03.png [ 7.32 KiB | Viewed 2907 times ]

Attachment:
2013-01-21_20-27-23.png
2013-01-21_20-27-23.png [ 43.81 KiB | Viewed 2907 times ]

Attachment:
2013-01-21_20-28-29.png
2013-01-21_20-28-29.png [ 127.42 KiB | Viewed 2907 times ]

Since the function prototype returns a long, it's a pretty good assumption that the internal counters are also 32 bit.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 3:30 pm
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: API documentation errors with nMotorEncoder, what is rig
Is this info available on-line? I would like to read more about it.
Thanks.


Mon Jan 21, 2013 3:36 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Re: API documentation errors with nMotorEncoder, what is rig
Sure, just download the HDK from LEGO's Mindstorms website. If you're having trouble finding it, drop me a mail.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 3:39 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Re: API documentation errors with nMotorEncoder, what is rig
Here's another clue as to the width of the tacho field. This is from the official byte code documentation, which ROBOTC also uses, for the most part.
Attachment:
2013-01-21_20-43-39.png
2013-01-21_20-43-39.png [ 72.12 KiB | Viewed 2905 times ]


= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 3:44 pm
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: API documentation errors with nMotorEncoder, what is rig
mightor wrote:
Sure, just download the HDK from LEGO's Mindstorms website. If you're having trouble finding it, drop me a mail.

= Xander

Found it. Thanks.


Mon Jan 21, 2013 4:18 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.