Wednesday, March 16, 2016

SciBorg Part 2 (Drive Straight, Follow the Line, Follow Another SciBorg)

Drive Straight

Our next task was to implement bang-bang control to make the SciBorg drive straighter. We wrote a program that only gave the SciBorg three options: drive with both motors at the same fixed speed, make a gentle left turn, or make a gentle right turn. We decided to use the motor encoder for this task to determine which direction the SciBorg was straying. If the position of motor 2 (the left motor) is greater than that of motor 1, that means motor 2 is travelling faster, so the SciBorg is turning right. This must be corrected with a gentle left turn. We defined a gentle left turn as motor 1 speed 5 faster than motor 2 speed. If the position of motor 1 (the right motor) is greater than that of motor 2, that means motor 1 is travelling faster, so the SciBorg is turning left. This must be corrected with a gentle right turn. We defined a gentle left turn as motor 2 speed 5 faster than motor 1 speed. If both motors are at the same position, the SciBorg is driving straight, so nothing should be done (that is, both motors should continue at the same speed).  Here is a picture of our code and videos of the SciBorg travelling on different surfaces. 


On the Lab Floor


The SciBorg goes straighter, but it's obviously not perfect. Towards the end, you can see that it's veering to the left. 

On the Carpet 


There's more friction on the carpet, so you can see the SciBorg shaking a bit. It also appears to veer right in the beginning and left towards the end. 

Going Up the Ramp


As you can see, the SciBorg veers to the right and falls off the ramp pretty quickly.

Going Down the Ramp


The SciBorg veers to the left and falls off the same side of the ramp as when it was going up. This made us think that the ramp was crooked or provided different friction forces to the two wheels. The SciBorg appeared to make it farther down the ramp before falling off than it did up the ramp.

Conclusion

It's very difficult to get the SciBorg to drive straight. Its path depends greatly on the surface it's driving on, but it seemed to do best on the lab floor. The various surfaces certainly all provide different frictional forces, which probably affects its path. I wonder what the coefficients of friction are for each of the surfaces and what the optimal coefficient is. I also wonder what the coefficient of friction between rubber car tires and asphalt is. It also may not be entirely the surface's fault that we could never get our car to drive straight. Perhaps we had a fault in our logic. I'm not sure if the assumption that equal motor positions means the car is going straight is true. The differences in speed between the two motors can be inconsistent, and the way we defined our gentle turns was pretty arbitrary. I'm thinking that perhaps if the SciBorg veers to the left (with a natural speed difference between the motors that is greater than or less than 5)  and we try to correct it with a gentle right turn (with a programmed speed difference of 5), maybe when the motor positions become equal again, it won't necessarily be pointing straight. I don't think using the motor encoder with this strategy was the best way to make the SciBorg drive straight. We had a couple other ideas: First, put a straight line of white tape down and, using the light sensor, program the SciBorg to follow the line. Second, put a narrow delrin board 2 feet behind wherever you want the SciBorg to stop (as documented in my last blog post). Put another delrin to the left and 1 foot behind the first delrin board. Put a third delrin board to the right and 2 ft behind the first board. This way, the three boards are staggered, and the ultrasonic sensor would have different readings depending on which one it was pointing at. Then, you could program the SciBorg to make a gentle right turn if the ultrasonic sensor reading was consistent with facing the left delrin board, or make a gentle left turn if it was facing the right board. However, both of these methods are pretty complicated and involve augmenting the lab floor course, which I'm not sure if we were allowed to do. I feel like there must be a better way that we haven't thought of yet. 

Bang-Bang Line Following

Our next challenge was to use our brightness sensor to make our Sciborg follow a zigzagging line. We tried for a very long time with no success to get this to work. Finally, we came to the realization that using while loops to make the SciBorg follow the edge of the white line would be our best bet. We found that the edge of the white line had a brightness reading in the 80s (depending on how much white vs. brown was under the sensor), so we decided to use a value of 80. We coded the SciBorg so that while it saw a brightness of less than 80 (meaning it's over wood), it should make a hard left. Once it sees a brightness of greater than 80 (meaning it's over the white tape), it should make a hard right, and then repeat the loop. (Note: In the code below, we accidentally named the right turn left and the left turn right!) The trickiest part was fine-tuning the speeds of each motor in the turn definitions. The turns had to be hard enough that the SciBorg could handle the sharp turns on the course. Here is a picture of our code and a video of our SciBorg following the line. 






Follow Things

Our final challenge was to make our SciBorgs follow each other in a line. We wrote a program using the ultrasonic sensor that told the SciBorg to drive if the object in front of it was more than 2 feet away, and stop otherwise. We used an ultrasonic reading value of 37 to correspond to an object 2 feet away (details in my last blog post). Here is a picture of our code and videos of our SciBorg following me and another SciBorg. 


Following Me




Following Another SciBorg



This was pretty neat! It was easier to make the SciBorg follow me because I could sense when it was veering and adjust my position so that it would continue following me. Even though the SciBorgs didn't drive completely straight, they still stayed in line for quite some time.

1 comment: