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 10 years 22 weeks 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: 1168
User offline. Last seen 7 years 19 weeks 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-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 10 years 22 weeks 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: 1168
User offline. Last seen 7 years 19 weeks 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-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 10 years 22 weeks 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: 154
User offline. Last seen 5 years 3 weeks 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