Subject:
|
Rotation sensor help (some progress)
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Fri, 16 Apr 1999 22:04:32 GMT
|
Viewed:
|
1365 times
|
| |
| |
Again about my problems with legOS and the rotation sensor. First of all I
checked the four values returned by both my two rotation sensor. They are
different from the ones inside direct-sensor.c but anyway inside the specified
range
legOS:
RANGE_SIZE (40U<<6)
STATE_0_VALUE (1023U<<6)
STATE_1_VALUE (833U<<6)
STATE_2_VALUE (405U<<6)
STATE_3_VALUE (623U<<6)
my values:
STATE_0_VALUE (1023U<<6)
STATE_1_VALUE (851U<<6)
STATE_2_VALUE (437U<<6)
STATE_3_VALUE (649U<<6)
So the problem is not in those values. I wrote a simple "finite state machine"
to use the rot sensor like any other active sensor and bypass
ds_rotation_handler. I used the originals legOS state values. It works very
well. Here is my code (well, I know I'm not a C programmer...):
// the rotation driver
//
int rotation_driver(void) {
int state,newstate,count;
unsigned curvalue;
ds_active(&SENSOR_3);
count=0;
curvalue=SENSOR_3;
if (curvalue>65470-2560)
state=0;
else if (curvalue>53312-2560 && curvalue<53312+2560)
state=1;
else if (curvalue>25920-2560 && curvalue<25920+2560)
state=2;
else
state=3;
while(1) {
curvalue=SENSOR_3;
if (curvalue>65470-2560)
newstate=0;
else if (curvalue>53312-2560 && curvalue<53312+2560)
newstate=1;
else if (curvalue>25920-2560 && curvalue<25920+2560)
newstate=2;
else
newstate=3;
switch (state) {
case 0:
if (newstate==1) count++;
if (newstate==3) count--;
break;
case 1:
if (newstate==2) count++;
if (newstate==0) count--;
break;
case 2:
if (newstate==3) count++;
if (newstate==1) count--;
break;
case 3:
if (newstate==0) count++;
if (newstate==2) count--;
break;
}
state=newstate;
lcd_int(count);
lcd_refresh();
}
}
So I deduced:
- my sensors are OK;
- the values defined by legOS for the rot sensor states are correct;
- the principle used by ds_rotation_handler works;
I double checked all the code about rotation sensor inside legOS but couldn't
find any bug (I must stress again that I'm back to C after many years and don't
feel perfectly at ease yet).
Am I the only one with this problem? Or the only one with both rotation
sensors and legOS? :)
Thanks for any help
Mario
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|