Hi,
I am new here so I apologize in advance if I am posting in the wrong section.
I am working on a code for a tankbot with a light sensor and a touch sensor. It has to follow a black line, and make turns at t intersections. It will bump into a small object, back up and turn. It has to stop at a green pad at the end of a track. This is my code so far:
Can you post your code in a code block ([ followed by "code" followed by ] then your code followed by the [] with /code inside). That will keep it indented properly, which will make it easier to read.
I don't really think you need a separate turn task. You may need 2 light sensors, one to keep you on the path and another to check for which side the path turns toward. You know to turn whenever the light sensor on the path detects the red spot and the direction to turn is right if the light sensor on the right side of your robot detected black before you reached the red spot or left if the light sensor on the right side of your robot did not detect black before you reached the red spot. When you reach the red spot you may need to backup a bit, depending on the size of your robot and the position of the light sensor that sits above the path. You may need a rotation sensor to count how far back you backup.
If your light sensor is 4 inches ahead of the center of your robot and you can turn in place then you would not need to have a second light sensor at all and you would not need to backup at all. Just rotate clockwise 90 degrees to check for a line to the right and if not found rotate 180 degrees clockwise to check for a line to the left, ignoring the first line found.
Steve Hassenplug can probably give you a lot better advice than I can, though.
Steve,
I need the robot to follow the line until it bumps into the obstacle (touch sensor), then back up about 4 inches, and then pick up the line that it needs to follow without going back in the direction it came from. This code did exactly what you said, it bumped and then turned without picking up any lines.
Also,
I only have 1 touch sensor and 1 bump sensor. The robot is a tankbot with a bumper on the front for bumping into the obstacles. I used a timer in the code to tell it when to turn right or left. So when x == 0 and sensor 1 == 1, that is the first turn and so on. This is a very basic engineering class but this one project has been giving me troubles.
aleynov wrote:Steve,
I need the robot to follow the line until it bumps into the obstacle (touch sensor), then back up about 4 inches, and then pick up the line that it needs to follow without going back in the direction it came from.
That's a good start. Now, you need to expand on that a bit.
1) How does the robot follow the line?
2) What exactly should it do after bumping into an obstacle?
The more you can break down each of these steps, the easier it will be to write the program.
Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
hassenplug wrote:
That's a good start. Now, you need to expand on that a bit.
1) How does the robot follow the line?
2) What exactly should it do after bumping into an obstacle?
The more you can break down each of these steps, the easier it will be to write the program.
Steve
The robot is a tankbot with a front mounted light sensor facing down to follow the line, and a touch sensor with an attached bumper to bump into the red obstacles. When the robot bumps the red cube, it has to back up and make the correct turn according to the track. It has to repeat this process until it reaches the green pad where it has to stop.
Does having a light sensor pointing downward enable a robot to follow a line? Do you need to think about and maybe write down what you want the motors on your tank bot to do based on the sensor values that you read from the light sensor? Maybe something like
while the light sensor reading tells me that it sees a black line set both motors to turn forward at the same speed.
while the light sensor reading tells me that it sees a white surface then turn clockwise.
Document using words the algorithm that you want your robot to perform. I am not a line following algorithm expert so my example above is probably not a good plan. Once you have it described in a fair amount of detail in words then it will be lot easier for you to translate that plan into NQC or any other programming language.
Here's an example using 2 sensors over a white line on a black surface:
Here's the best I can think of with what I want the robot to do.
the threshold I am using is 39, which is what it reads when it is on the black line. I am using variable x to keep count of the bumps in order to tell it which way to rotate. So on the first bump,
x=x+1 will tell it to turn right so it picks up the correct line.
while the light sensor is at 39 or below, power motors A and C;
when it bumps the first obstacle and x == 0, rotate clockwise until light sensor is at 39 or below, back to powering motors A and C;
when it bumps the second obstacle and x == 1 (having already hit an obstacle making x == 1), rotate counter-clockwise until light sensor is at 39 or below, back to powering motors A and C;
when it bumps the third obstacle and x == 2 (hitting the last obstacle made x == 2), rotate counter-clockwise until light sensor is at 39 or below. back to powering motors A and C;
when it bumps the fourth obstacle and x == 3, rotate clockwise until light sensor is at 39 or below, and power motors A and C;
when it bumps the fifth obstacle and x == 4, rotate clockwise until light sensor is at 39 or below and power motors A and C;
when the light sensor reads the green pad, (i believe it read 36) terminate the program.