Hello there,
I have been trying to use the IR sensor to have the robot follow it. I have tried to use the example code in the KISS IDE, but it doesn't work either. Is there something I'm doing wrong?
Thanks,
Alex
Please post the code you're using, exactly what you expect it to do, and exactly what it's doing wrong.
-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
What do you mean by "doesn't do anything"? The robot doesn't move? I would expect this code to move the robot forward.
//drives robot straight until the tophat in port 0 sees black
while(analog10(0)){//900 was experimentally determined as the midpoint between white and black
//while the sensor sees white
mav(0,300);//move straight
mav(3,300);
}
This is suspicious. It is unlikely that analog10(0) will ever be equal to 0 (analog sensors have some random jitter), so I would expect this while loop to never terminate. Did you intend to compare the analog10 result to an int value?
Also, please use the < c > element for C code on the forum, not < code >. It works much better.
-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
Thanks for telling the the < c > tag works here too.
Anyway, what I was doing originally was playing with the example lesson. I tried to test it and it didn't work. Then I tried to use the example code and it also did not move. I ran it through the simulator also and that also doesn't move. It does print the values however.
Hmm, I don't see anything in the code you posted that would prevent the robot from moving at all. If it's printing values, then it should have also evaluated the if/else statement, meaning it should execute mav. Does anyone else see anything I'm overlooking?
(The usual things such as trying a different CBC, trying different motor ports, etc., are candidates... but if it's not working in the simulator either, those probably aren't the problem....)
-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
Change the while(analog10(3)) to while(analog10(3) < 900). That will work in the simulator. Leaving out the comparison simply does not work.
Since analog10() is defined as an int it is very possible for it to return a negative value, which would cause the bodies of while blocks in the program to not be executed.
The expression in the while() (in the absence of a comparison) evaluates to "true" when greater than zero and "false" when zero and below. (That statement in questions is not good programming style.)
In light this, the analog10() function should be defined as "unsigned int" by kipr.
Also make sure that the motor and sensor port numbers are correct. The reflective sensor on the simulator defaults to port 7, so the "3" in the analog10() calls would have to change to "7" throughout the program.
analog10 is defined to return a 10-bit value corresponding to the voltage of the input. signed ints have 31 bits of positive values. So analog10 will not return a negative value.
I'm also fairly sure that casting a negative number into a boolean value will result in true (it's not doing a signed comparison).
-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
I changed the codes how you said to
It moves to the line, and stops while printing the values on the screen
Should I put more code under the IR sensor code?
My guess is that it's detecting white and terminating the while loop. This happens fairly often when following lines. A common solution is to enter a "search mode" when white is detected (e.g. rotating in place until black is found), rather than terminating the loop.
You can verify whether this is the problem by looking at the debug output from your program; is it detecting white right before the loop terminates?
-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
So, just to clarify, you're trying to follow the SENSOR (perhaps from another robot or something?)
-amehta (Andrew Mehta)
Please post the code you're using, exactly what you expect it to do, and exactly what it's doing wrong.
-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
@amehta: No, It needs to follow black lines that are on a white sheet.
@Jeremy Rand: Here's the code
The robot doesn't do anything. Am I missing something?
By the way, this was the example code that KISS gives you.
[Edited by Jeremy to fix code display issue... use the < c > element for C code instead of < code >]
What do you mean by "doesn't do anything"? The robot doesn't move? I would expect this code to move the robot forward.
This is suspicious. It is unlikely that analog10(0) will ever be equal to 0 (analog sensors have some random jitter), so I would expect this while loop to never terminate. Did you intend to compare the analog10 result to an int value?
Also, please use the < c > element for C code on the forum, not < code >. It works much better.
-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
Thanks for telling the the < c > tag works here too.
Anyway, what I was doing originally was playing with the example lesson. I tried to test it and it didn't work. Then I tried to use the example code and it also did not move. I ran it through the simulator also and that also doesn't move. It does print the values however.
Hmm, I don't see anything in the code you posted that would prevent the robot from moving at all. If it's printing values, then it should have also evaluated the if/else statement, meaning it should execute mav. Does anyone else see anything I'm overlooking?
(The usual things such as trying a different CBC, trying different motor ports, etc., are candidates... but if it's not working in the simulator either, those probably aren't the problem....)
-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
Change the while(analog10(3)) to while(analog10(3) < 900). That will work in the simulator. Leaving out the comparison simply does not work.
Since analog10() is defined as an int it is very possible for it to return a negative value, which would cause the bodies of while blocks in the program to not be executed.
The expression in the while() (in the absence of a comparison) evaluates to "true" when greater than zero and "false" when zero and below. (That statement in questions is not good programming style.)
In light this, the analog10() function should be defined as "unsigned int" by kipr.
Also make sure that the motor and sensor port numbers are correct. The reflective sensor on the simulator defaults to port 7, so the "3" in the analog10() calls would have to change to "7" throughout the program.
Eugene Myers
Cedarhouse Robotics
analog10 is defined to return a 10-bit value corresponding to the voltage of the input. signed ints have 31 bits of positive values. So analog10 will not return a negative value.
I'm also fairly sure that casting a negative number into a boolean value will result in true (it's not doing a signed comparison).
-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
I changed the codes how you said to
It moves to the line, and stops while printing the values on the screen
Should I put more code under the IR sensor code?
My guess is that it's detecting white and terminating the while loop. This happens fairly often when following lines. A common solution is to enter a "search mode" when white is detected (e.g. rotating in place until black is found), rather than terminating the loop.
You can verify whether this is the problem by looking at the debug output from your program; is it detecting white right before the loop terminates?
-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