Hat Sensor moving for a begineer

1 reply [Last post]
vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 10 years 22 weeks ago.

Hello Guys I'm a new programmer but a fast pace learner (good).

Today I was at the Botball competition saw some really good ideas using the sensors. It is my first time and i did not try hard enough.
So now I am home and I was reading how to use the hard sensor but i still don't know why my robot stops.

It has only one motor for two back wheels and a servo for a front wheel.
This is the passage which I read.

"int main()
{
while(1){ //loop forever
fd(0); //drive motor
while(analog10(0)>512){ //if sensor detects an object
ao();} //stop motor
}
}"

When it starts the wheels move for like 0.1 second and then it does nothing I don't understand what the while does and I'm trying to make it go forward until it finds an object like a wall and then reverse from then I can start playing around making it go in different directions.

So if you guys need more feedback I will be glad to give them.

Doing science.

AdamF
Title: MiniBot+
Joined: 03/17/2010
Posts:
BotPoints: 62
User offline. Last seen 9 years 19 weeks ago.

Your code is telling the robot to turn off motors (ao();) while the sensor value is greater than 512.
I think you want something like this:

int main()
{
while(1){
fd(0);

// Notice the brackets in this next line: tells bot to keep doing nothing while statement is true
while(analog10(0) > 512){} // keep looping while the sensor value is above a threshold

ao();}
}

Adam Farabaugh
Hampton High School