Monday, March 3, 2014

SciBorg Day 2

The second SciBorg assignment required a lot of patience and time.

Fixed Distance
In order to make our SciBorg go exactly ten feet, we used count a. First we allowed the SciBorg to go forward for 3000 counts and measured the distance to be 117.5 in. Since there are (3000/117.5)=25.5 counts per inch, we calculated that there would be 3,063 count a's in 10 ft.
 The code for this was pretty simple. The Sciborg was told to go forward (F) until count a reached 3063 and stop (Br). This method is great if we want the SciBorg to travel a certain distance, but there are no feedback invovlved (it's an open loop control).

We had some trouble making the car go straight no matter how many times we adjusted the motor powers and it remained a consistent problem throughout the assignment. Through trial and error, we found out that the car seemed to veer right when two motor powers are equal, so setting the power of the left motor to a lower value seemed to help a little.

Next, we used the touch switch sensor to make the car stop when it runs into an obstacle. 

 The sensor reading was zero when the switch was pressed. So we made a code that allowed the car to drive forward until the sensor reading zero and stop afterwards.
This feedback mechanism is very simple and easy to code for because the touch sensor reads 0 every single time it hits an obstacle. However, it might not be so practical for certain devices especially if it is going at very high speeds or runs into an obstacle that has a significantly greater mass than the device, because it would cause a lot of damage to the device.


Using the ultrasonic sensor that detects the presence of obstacles by emitting waves, we made a code that stops the car when it gets to a fixed distance from the wall.

 Prior to making the code, we tested out the ultrasonic sensor. The sensor read 10~15 when an object was about 2,3 inches away. The code allowed the car to move forward until the sensor reads a value under 10, and stops afterwards. 
The car followed the code accurately, and stopped just before it ran into a wall. This mechanism seems more practical than the touch sensor control, because it there is less probability of the device getting damaged from running into an obstacle. 

Lastly, we used the NXT brightness sensor to allow the car to stop at the white line on the floor. 

The NXT brightness sensor read ~700 when it was on a white tape, so we made a code similar to the previous ones where the car was told to go forward until the sensor reads a value less than 700 and stop when it does. 
This method is great if there is a pattern on the floor that the car wants to follow, but it would be hard to use in a very dark setting.

Using a combination of sensors, we can make the SciBorg go a certain fixed distance (counting), but stop when it senses an obstacle (using either the touch and ultrasonic sensors).


Drive Straight
Making the car go in a straight path was a more difficult task than it seemed. Setting the motor b power to 62 and motor a power to 60 seemed to work best because the car tends to go right when the powers are equal. 
Implementing the bang-bang control, we allowed the car to bear left when count a was greater and bear right when count b was greater. 

 
 As seen in the picture, we set the power of b to a lower value because the car tends to go right.

On the lab floor, the car moved pretty straight if we positioned the front wheel correctly. On the carpet, it was going less straight due to the friction on the wheels but we could make it go straighter by changing the motor powers accordingly. 
The ramp posed a greater problem for us because the car would go in different directions even with the same code. On the first attempt, the car went perfectly straight up the ramp. Unfortunately, that was pretty much our only successful attempt (and we couldn't get in on video!!). We think that this mostly due to the front wheel moving in all directions. We even tried making it go backwards so it would be a 'front-wheel drive' but that did not seem to help very much.
Going down the ramp gave pretty similar results as going up the ramp.

Here's a video of a semi-successful attempt in going up the ramp:
 
To sum it up, the car went the straightest path when there was less friction on both wheels. If there was friction on one wheel preventing that wheel from spinning as much, the car went in a particular direction. Our results are not very reproducible because the car wanted to go in random directions even with the same code.


Bang-bang Line Following
This part of the assignment gave us the most trouble. Our first idea was to make the car bear left until it goes off the tape and bear right until it goes back on the tape. The NXT sensor read ~634 for the tape, ~720 for the melamine, so we tried to make the car bear left until the sensor reads a value that is greater than ~640 (we changed around this value multiple times to make it work better) and bear right until it reads a value less than 640. We tried using both the 'wait until' and 'if-then' statements, but the car would either go off in one direction without stopping, or go through the loop once. We were told that changing a direction of the car suddenly can cause problems, so we added a wait between each bear lefts and bear rights but later found out that it was the reason why it was causing problems for us. Another big reoccurring problem was that our car refused to go straight.
After many many attempts, we even tried attaching the sensor at different points on the SciBorg and made the SciBorg go backwards, but that wasn't making much of a difference.
We tried making the car go straight until it went off the tape and rotate in one direction until it found the tape again, but given our problem with the car not going straight it was difficult to make it work
We also found another strategy, where the car would follow the right edge of the tape (sensor reading of ~651) and when it senses that it is on the tape, it would bear right and when it senses that it is on the melamine, it would bear left. It was a great idea in theory, but executing it was a lot harder. Our coding made perfect sense but when we tested it out on the melamine it would give bad results. Sometimes, the car would simply refuse to move and most other times it would just choose a direction and go off forever. 
Finally, with the help of Juliette, we were able to figure out a way that worked. It was very aggravating to know that after all of the unsuccessful attempts, the one that actually works was the method that we had started out with. Basically, we made the car go right if it's on the tape and left if it's off the tape without any breaks in between. The car was able to zigzag through the course using this method.

The whole process was quite the struggle because we invested many hours to get it to work. The bang-bang control seemed very inefficient because it did not have any subtle controls and the car would jerk left and right throughout the course.       



(Ignore the block 'wait until' and everything after it)



    


 


 






 





     
 

No comments:

Post a Comment