programming question

Hey, im extremely new to vex. I learned some simple programming through the 2005 inventors guide. One challenge is to make a robot hit a wall three times and then stop. THe guide indicates the solution code is on this site somewhere, but i can not find it anywhere. Does anyone know where to find it or can they share the solution with me?

Aaron Mosher

First off let me ask which programming language are you trying to use? EasyC? ROBOTC?

The concept is very simple:

int Bumps = 0; //Create a variable for the number of times the robot hits the wall. (also set it to 0, as the robot has not hit the wall yet)

while(Bumps < 3) //Repeat the following code until the robot has hit the wall 3 times.
{
if(SensorValue[Touch] = 1) //If the touch sensor has been pressed, i.e. if the robot has hit the wall.
{
Bumps = Bumps + 1; //Record that bump by adding 1 to the variable Bumps.
//Also run the drive motors in reverse away from the wall.
}

else //Otherwise assume that the touch sensor has not been pressed, i.e. assume that the robot is not touching the wall yet.
{
//Run the drive motors forward towards the wall.
}
}

//After Bumps has reached 3, turn off the drive motors.

Hopefully I explained that well enough.

~Jordan

Thanks for the response, i will try to program this. I am using Easy C programming.

You’ll need to add at least a 100ms time delay after setting robot to backup from the wall, otherwise the bump counter will keep counting before the robot can even stop.

The typical while(1) {} event loop in EasyC takes 1-5ms per loop.
The motor PWM signal only updates once per 20ms.
The robot takes even longer than that to react as well.
So without a time delay, this program will count 3 bumps before the motors can even reverse from the first bump.

Whoops – I knew I was missing something. I completely forgot to write that the backup should be for an amount of time. Here:

int Bumps = 0; //Create a variable for the number of times the robot hits the wall. (also set it to 0, as the robot has not hit the wall yet)

while(Bumps < 3) //Repeat the following code until the robot has hit the wall 3 times.
{
if(SensorValue[Touch] = 1) //If the touch sensor has been pressed, i.e. if the robot has hit the wall.
{
Bumps = Bumps + 1; //Record that bump by adding 1 to the variable Bumps.
//Also run the drive motors in reverse away from the wall for 3 seconds. (or a different amount of time -- your decision)
}

else //Otherwise assume that the touch sensor has not been pressed, i.e. assume that the robot is not touching the wall yet.
{
//Start running the drive motors forward towards the wall.
}
}

//After Bumps has reached 3, turn off the drive motors.

~Jordan

Thanks everyone for your replies, i was able to successfully get the robot to work.