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 / 26955
26954  |  26956
Subject: 
Re: TachoSpeed.nqc
Newsgroups: 
lugnet.robotics
Date: 
Tue, 13 Mar 2007 14:41:41 GMT
Viewed: 
3900 times
  
I don't see 1) how I could make an if/else statement or 2) what the
benefit would be.

1) If I make an if/else statement isn't 'else' executed always if 'if'
is not true?

The question you need to answer for yourself is this:  Do I want my robot to to
potentially execute both if blocks in sequence or do I only want the second if
block to execute if the first condition is known to be false?  If you only want
the second one to execute when the first one is false then you want a construct
like this:

if (TachoSpeed(OUT_R) < threshold) {
}
else if (TachoSpeed(OUT_L) < threshold) {
}

You don't need to add another else without an if.  You would benefit a lot from
writing out your program in what is called "pseudo code".  Something like this:

Go forward
until I'm going faster than some threshold
while going forward
  if my right motor appears to have slowed down then
    beep twice
    back up for 1 second
    turn clockwise for 1 second
    Go forward
    until I'm going faster than some threshold
  otherwise
  if my left motor appears to have slowed down then
    beep once
    back up for 1 second
    turn counter-clockwise for 1 second
    Go forward
    until I'm going faster than some threshold
continue looping


This sort of "english" description will help you describe exactly what you want
your robot to do and it will make it much easier for you to then write NQC code
which makes your robot do exactly what you want it to do.

The pseudo code above would quite readily be written like this:

#define threshold 62          // change to make more/less sensitive
#define reverse(t) OnRev(OUT_L+OUT_R); Wait(t);
#define clockwise(t) OnRev(OUT_R); OnFwd(OUT_L); Wait(t);
#define c_clockwise(t) OnRev(OUT_L); OnFwd(OUT_R); Wait(t);

task main()
{
  OnFwd(OUT_L+OUT_R);
  until((TachoSpeed(OUT_L) > threshold) && (TachoSpeed(OUT_R) > threshold));
  while (true)
  {
    if (TachoSpeed(OUT_R) < threshold)
    {
      PlayTone(440, 50);
      PlayTone(440, 50);
      reverse(100);
      clockwise(100);
      OnFwd(OUT_L+OUT_R);
      until((TachoSpeed(OUT_L) > threshold) && (TachoSpeed(OUT_R) > threshold));
    }
    else if (TachoSpeed(OUT_L) < threshold)
    {
      PlayTone(440, 50);
      reverse(100);
      c_clockwise(100);
      OnFwd(OUT_L+OUT_R);
      until((TachoSpeed(OUT_L) > threshold) && (TachoSpeed(OUT_R) > threshold));
    }
  }
}


You need to experiment with the timings and you may not want to use an until
loop in case the robot runs into an obstacle before it gets back up to speed.

The main problem with your approach is that the motors do not stall when the
robot hits an obstacle so it will be hard for you to distinguish between the
motor speed slowing due to low battery levels, increased load (like going up an
incline), or pushing a moveable obstacle out of the way.  Why not just use a
touch sensor attached to a bumper mechanism?

John Hansen



Message has 2 Replies:
  Re: TachoSpeed.nqc
 
(...) I found again an old code I wrote for Cybermaster to do avoiding based on tacho slowdown. The trick is indeed to drive at a low power level, or the wheels simply sleep and there is not enough slowdown to be reliable. Philo ---...--- task main (...) (18 years ago, 13-Mar-07, to lugnet.robotics)
  Re: TachoSpeed.nqc
 
(...) That's exactly what I'm trying to achieve. I hadn't actually written out any pseudo code, but it is (almost)exactly the way I had thought it through in my head. My main problem is that I think up what I'd like to do and then have to scour the (...) (18 years ago, 13-Mar-07, to lugnet.robotics)

Message is in Reply To:
  Re: TachoSpeed.nqc
 
(...) Sorry. I meant to say 'the brick never executes the if statement'. (...) I don't see 1) how I could make an if/else statement or 2) what the benefit would be. 1) If I make an if/else statement isn't 'else' executed always if 'if' is not true? (...) (18 years ago, 12-Mar-07, to lugnet.robotics)

13 Messages in This Thread:



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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
6 hours ago
Custom Search

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