To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 27293
27292  |  27294
Subject: 
Re: Need help combining steering with odometry in NXC
Newsgroups: 
lugnet.robotics
Date: 
Wed, 5 Dec 2007 13:41:59 GMT
Viewed: 
5671 times
  
In lugnet.robotics, Joe Strout wrote:
In lugnet.robotics, Joe Strout wrote:

This is true even when I instead use

  OnFwdSyncEx( OUT_AC, 75, turnRatio, RESET_NONE );

which I thought explicitly told it not to reset the tacho counts.

Update: upon a couple more hours' testing, I found that the above command
actually prevents the bot from turning at all.  It will only turn if I pass at
least RESET_BLOCK_COUNT for the last parameter (of course other combinations
that include resetting the block count, e.g. RESET_ALL, also work).

Whew, that was a couple of hours wasted!  Lesson learned, but I still don't seem
to be getting good tacho counts, and I'm still curious whether there is a
standard NXC loop for following a line while measuring distance travelled.


Here is a line follower from my book, NXT Power Programming:

#define SLOW_SPEED 25
#define FAST_SPEED 75
#define EYE_PORT   S1
#define EYE_VALUE  SENSOR_1

int BlackThreshold;
int WhiteThreshold;

inline int min(int v1, int v2) {
  return (v1 < v2) ? v1 : v2;
}

inline int max(int v1, int v2) {
  return (v1 > v2) ? v1 : v2;
}

task main() {
  // set sensor type and mode
  SetSensorType(EYE_PORT, SENSOR_TYPE_LIGHT_ACTIVE);
  SetSensorMode(EYE_PORT, SENSOR_MODE_RAW);
  ResetSensor(EYE_PORT);

  int lowest, highest, SV;
  lowest  = 10000;
  highest = -10000;
  while (!ButtonPressed(BTNLEFT, false)) {
    SV = EYE_VALUE;
    lowest  = min(lowest, SV);
    highest = max(highest, SV);
    NumOut(0, LCD_LINE1, SV);
  }
  BlackThreshold = lowest+200;
  WhiteThreshold = highest-200;
  NumOut(0, LCD_LINE1, BlackThreshold, true);
  NumOut(0, LCD_LINE2, WhiteThreshold);
  until(ButtonPressed(BTNCENTER, false));
  while (true) {
    SV = EYE_VALUE;
    if (SV < WhiteThreshold)
      OnFwd(OUT_A, FAST_SPEED);
    else
      OnFwd(OUT_A, SLOW_SPEED);
    if (SV > BlackThreshold)
      OnFwd(OUT_C, FAST_SPEED);
    else
      OnFwd(OUT_C, SLOW_SPEED);
  }
}


All you need to do to read OUT_A's rotation count is insert a call to
MotorRotationCount(OUT_A) within the while loop at the end.  You could reset the
rotation count just prior to the final while loop and break out of the loop when
the OUT_A rotation count exceeds your limit.

John Hansen



Message is in Reply To:
  Re: Need help combining steering with odometry in NXC
 
(...) Update: upon a couple more hours' testing, I found that the above command actually prevents the bot from turning at all. It will only turn if I pass at least RESET_BLOCK_COUNT for the last parameter (of course other combinations that include (...) (17 years ago, 4-Dec-07, to lugnet.robotics)

4 Messages 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