I am trying to use an RCX rotation sensor with the NXT (NXC). It all functions as it should, but I am using it in a clock application, so a signed 16 bit variable doesn't last very long (in this case, about 11 minutes). Is there any way to get a 32 bit value (signed or unsigned long) from the FW? According to my calculations, a signed long would allow for over a year of constant use (500+ days).
I think this may be a FW issue, but I am not sure.
RCX rotation sensor with NXC
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
RCX rotation sensor with NXC
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: RCX rotation sensor with NXC
If there isn't, an alternative solution would be to check if it's abs(rotationcount)>32000; if so, increase `unsigned long base_rotationcount` by 32768*sign(rotationcount). Then, you detect the arithmetic overflow (when it happens... unless every time it overflows, it's reset to 0 or some other value... I don't know what that would be), and get the adjusted rotation counts. It's crude, but unless your motor's moving at 30k degrees/ms, it should work. (Unless there is no arithmetic overflow, or reset to 0/etc... then it won't work.)
The exact implementation for this will take a bit of research.
The exact implementation for this will take a bit of research.
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: RCX rotation sensor with NXC
Not sure exactly what you mean, but I found a solution. Although I would like 32 bit support for the sensor, this works fine in this situation.I have a way to deal with the "overflow". I also know it could be == 32767, but there is a limiting factor elsewhere in the program.
Code: Select all
if(SENSOR_1>=32760){ClearSensor(S1);}
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: RCX rotation sensor with NXC
I'd recommend lowering that down to 16384 (or even eliminating it, and relying on 10 seconds only):
This way, there's no chance of error (unless the NXT "freezes" for a few seconds, but the motors keep working, and this is terribly unlikely).
Code: Select all
// #define ELIMINATE
long base_value[4] = {0, 0, 0, 0};
task forever()
{
while(1)
{
#ifndef ELIMINATE
if(abs(SENSOR_1) >= 16384)
{
#endif
base_value[S1] += SENSOR_1;
ClearSensor(S1);
#ifndef ELIMINATE
}
#endif
Wait(10000); // You can change this value, if you want; although, 10 second polling won't really affect your program speed, even by 1/100000 of a second, on average
// The wait value is based on the time it can potentially take to rotate the motor by 16383 degrees in the worst case scenario... And 10 seconds for moving the motor *that* would require 1638 degrees/second
}
}
long ReadSensor(const byte port)
{
return(Sensor(port) + base_value[port]);
}
Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE
Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Re: RCX rotation sensor with NXC
The firmware does not support more than 2 bytes for sensor values.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: RCX rotation sensor with NXC
I may lower it a little, but for now it works great. Thanks for the code idea, but I think I found a good solution for my needs.muntoo wrote:I'd recommend lowering that down to 16384 (or even eliminating it, and relying on 10 seconds only):
This way, there's no chance of error (unless the NXT "freezes" for a few seconds, but the motors keep working, and this is terribly unlikely).
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: RCX rotation sensor with NXC
Okay, that's what I figured. Thanks for confirming.afanofosc wrote:The firmware does not support more than 2 bytes for sensor values.
John Hansen
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: Semrush [Bot] and 1 guest