How to detect cliffs?

5 replies [Last post]
vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 3 weeks 1 day ago.

How can I properly use the cliff detector commands and bumper commands together?
I want the Irobot to stop if it senses a cliff or to stop if it sees a bumper.
But how can I make both of the work at the same time?

Doing science.

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 841
User offline. Last seen 18 min 21 sec ago.

You can use the logical OR operator || to test whether the cliff or bumper is hit. E.g.:

if(cliff || bump) // Substitute the relevant functions for cliff and bump sensors
{
// Something got triggered
}

Hope this helps.

-Jeremy Rand
Senior Programmer, Team SNARC (2012), Norman Advanced Robotics (2010-2011), Norman High (2008-2009), Norman North (2005-2007), Whittier Middle School (2003-2004)
2012 VP of Comm, 2011 President, Botball Youth Advisory Council (2009-2012)

vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 3 weeks 1 day ago.

I did this but for some reason after the first inner while loop is done it goes up to the top. Do you know what can I do so it goes further ahead?

// Created on Mon Jul 18 2011

#include

int main()
{

create_connect();

while(1)
{

create_drive_straight(100);

while (get_create_lbump(1) || get_create_rbump(1) || get_create_lcliff(1) )
{

create_drive_straight(-300); sleep(2);
create_spin_CW(300); sleep(0.6);
create_drive_straight(300); sleep(3);
}

while (get_create_lcliff(1) )
{
create_stop();
create_drive_straight(-300); sleep(1.5);
create_drive_straight(500); sleep(1.5); create_drive_straight(500);
while(get_create_lbump(1))
{
create_drive_straight(-300); sleep(0.5);
create_spin_CW(500); sleep(3);
create_drive_straight(400); sleep(5);
}
while (get_create_rbump(1))
{
create_drive_straight(-300); sleep(0.5);
create_spin_CW(500); sleep(3);
create_drive_straight(400); sleep(5);
}
}

}

}

Doing science.

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 841
User offline. Last seen 18 min 21 sec ago.

I'm not certain what your code is trying to accomplish... you have three nested while loops; I suspect that that isn't what you want. Both of your while loops will not execute if the lcliff sensor is false. Exactly what behavior are you trying to achieve? (Feel free to post pseudocode.)

-Jeremy Rand
Senior Programmer, Team SNARC (2012), Norman Advanced Robotics (2010-2011), Norman High (2008-2009), Norman North (2005-2007), Whittier Middle School (2003-2004)
2012 VP of Comm, 2011 President, Botball Youth Advisory Council (2009-2012)

vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 3 weeks 1 day ago.

Well after the first inner loop drive directly until it hits something again, but turn in a different way. and I want to keep doing that infinitly ( not infinity just doing it until lets say i turn around a few places I want)

Doing science.

KIPR Matthew
KIPR Matthew's picture
Title: KIPR Staff
Joined: 06/04/2009
Posts:
BotPoints: 122
User offline. Last seen 1 week 7 hours ago.

Since both of your inner while loops do the same thing, I would changet hem to if statements and lump them together after a while loop that does nothing until bumped:

//rest of code above

while(get_create_rbump(1)==0&&get_create_lbump(1)==0){}
if (get_create_rbump(1)||get_create_lbump(1))
{
create_drive_straight(-300); sleep(0.5);
create_spin_CW(500); sleep(3);
create_drive_straight(400); sleep(5);
}
//continue to end below

Join the Botball folding at home team!
http://folding.stanford.edu/
Team 87314 "Botball"
Stats: http://folding.extremeoverclocking.com/team_summary.php?s=&t=87314