To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 375
374  |  376
Subject: 
Solved?? rotation sensor problem.
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Fri, 10 Sep 1999 03:44:39 GMT
Viewed: 
1021 times
  
I tried solutions posted on this newsgroup to fix the rotation sensor
problem.But It didn't work stable enough.
I tracked the sensor input and realized the sensor sometimes picked up
transient signal between two states.

To solve this problem, I modified 'ds_rotation_handler()' to process sensor
values in two separete IRQ cycles.
1st cycle: Detect state change.
2nd cycle: Determine the new state.

The macro 'CURRENT_STATE'  in my sample is based on
http://graphics.stanford.edu/~kekoa/rcx/index.html#Rom

--------------
I found a problem in a sample code 'demo/rotation-sensor.c'
It determines the initial state before a sensor actually becomes active.

  ds_active(&SENSOR_3);
  msleep(10);                   << I put short delay here.
  ds_rotation_set(&SENSOR_3,0);
  ds_rotation_on(&SENSOR_3);


------------- direct-sensor.c ---------------
-------- new variable

static char StateChanged[3];     // State changing flag (1999.9.3 by Abuku)


-------- macros

/***  1999.9.3 by Abuku
//! A/D values for the rotation sensor states

#define RANGE_SIZE    (ds_unscale(  40U))
#define STATE_0_VALUE (ds_unscale(1023U))
#define STATE_1_VALUE (ds_unscale( 833U))
#define STATE_2_VALUE (ds_unscale( 405U))
#define STATE_3_VALUE (ds_unscale( 623U))


//! rotation sensor range matching function
//
#define IN_RANGE( val ) (raw > (val - RANGE_SIZE) && \
                         raw < (val + RANGE_SIZE) )
*/

//  Determine current state  1999.9.2 by Abuku.
#define CURRENT_STATE
(raw<0x6fc0?STATE_0:(raw<0xafc0?STATE_1:(raw<0xefc0?STATE_2:STATE_3)))
//  Delay for final determination. (number of IRQ cycles)  1999.9.3 by Abuku
#define SAMPLING_WAIT  1

--------  in void ds_rotation_set()

  if(sensor>=&AD_A && sensor<=&AD_C) {    // catch range violations

/****  1999.9.3 by abuku
    if (raw <= STATE_2_VALUE )      // determine current state
      state=STATE_2;
    else if ( raw <= STATE_3_VALUE )
      state=STATE_3;
    else if ( raw <= STATE_1_VALUE )
      state=STATE_1;
    else
      state=STATE_0;
*/

    state = CURRENT_STATE;        //    Determine the initial state. 1999.9.2
by Abuku
    StateChanged[channel] = 0;    //    1999.9.3 by Abuku

-------- in void ds_rotation_handler()

/*****  1999.9.3 by Abuku
  switch(state) {
    case STATE_0:
     if ( IN_RANGE ( STATE_3_VALUE ) ) {
       state=STATE_3;
       cooked--;
:
:
:
       cooked++;
     } else if( IN_RANGE ( STATE_2_VALUE ) ) {
       state=STATE_2;
       cooked--;
     }
     break;
   }
*/


  //***     1999.9.3 by Abuku.
  RotationState current_state = CURRENT_STATE;

  if(StateChanged[channel] == 0) {              // Not triggered ?
    if(state != current_state)                  // State has changed ?
      StateChanged[channel]++;
    return;
  }
  else {                                        // Already triggered
    if(StateChanged[channel]++ < SAMPLING_WAIT) // Update the flag
      return;                                   // Keep waiting
    StateChanged[channel] = 0;                  // Clear the flag
  }

  switch(state) {                               // Update state and angle value
                                                //   0 <- +> 1 <- +> 3 <- +> 2
<- +> 0
    case STATE_0:
     if ( current_state == STATE_2 ) {
       state=STATE_2;
       cooked--;
     } else if ( current_state == STATE_1 ) {
       state=STATE_1;
       cooked++;
     }
     break;

    case STATE_1:
     if ( current_state == STATE_0 ) {
       state=STATE_0;
       cooked--;
     } else if( current_state == STATE_3 ) {
       state=STATE_3;
       cooked++;
     }
     break;

    case STATE_2:
     if ( current_state == STATE_0 ) {
       state=STATE_0;
       cooked++;
     } else if ( current_state == STATE_3 ) {
       state=STATE_3;
       cooked--;
     }
     break;

    case STATE_3:
     if ( current_state == STATE_2 ) {
       state=STATE_2;
       cooked++;
     } else if( current_state == STATE_1 ) {
       state=STATE_1;
       cooked--;
     }
     break;
   }
   //   END modification. 1999.9.3 by Abuku



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR