Friday, March 11, 2016

Sciborgs Part 2

Day 13 (3/8/16)

Today we started to delve deeper to understand the functions and uses of different sensors and feedback and control systems, specifically related to our sciborg (which we recently named Creepy Crawly Jr.). Nanaki and I immediately got to work on our new tasks which are outlined below.


Task 1 - Motor Encoder:

Our first task was to learn about the motor encoder. First we downloaded the code from the class website and adjusted if for our needs. The original program looked like:



The original code depended on the time the program had been running. Since the loop was set up to adjust the "previousMillis" to the new time, the code wouldn't start back at time=0 so the position would be the total position the motor has moved. It wouldn't restart the position each time the loop ran, it would just add the positions each time. We changed the code to no longer depend on the time the program has been running and set the limits of the loop according to the motor position.

We ran tests of different versions of the code using different position limits on the motor to figure out what distance corresponds to the specific value for the motor position. We figured out that the sciborg will move 10 inches with the corresponding motor position of 1,000. We then did a calculation to determine what the motor encoder will read to correspond to 10 feet. This value ended up being about 12,000, so we set the motors to run at full power until the motor position read 12,000 and then stop. Here is what our code looked like:


After running this code several times, we determined that the sciborg was off by kind of a lot (almost a foot). This is likely due to the uncertainties in our measurements for the conversion from motor position to actual distance traveled. Also, every run with the sciborg is different and most don't go completely straight. Here is a video of our sciborg controlled by the motor encoder:



Task 2 - Touch Switch: 

Our next task was to control the sciborg using the touch switch at the front of the robot:


To do this, we downloaded the code given to us on the class website and then included the motors in to the code. It was set up so that if the switch was pushed in, the sciborg would stop and if it wasn't, the sciborg would move ahead at full speed. Here is what the code looked like:


We figured out that we could put a barrier 10 feet from the starting position and the sciborg would travel at full speed until it hit the barrier and would stop at 10ft.

Here's how the switch worked:


Task 3 - Light Sensor:

Our third task was to learn how to use the light sensor and figure out a way to make the sciborg move 10 feet using the sensor as the feedback in the feedback and control system.

First we once again downloaded the code and tested it out to see what it did. Before we included the motors in the code we did tests to determine how accurate the sensor is. The range of the scaled value of the sensor was from 0 to 98. We determined that the light sensor would be accurate enough that it could be of use to us for later tasks when it is a few centimeters from the ground.

One extra function that the light sensor had was a guide LED light. You could turn the LED on or off and this would change how the light sensor worked and measured its values. After testing the differences in values between the white tape and the brown board we determined that the light sensor was more accurate with the LED turned off. 

Here is what the code looked like for the light sensor:


To make our sciborg go the 10m and then stop using the light sensor, we determined that we could lay down a piece of tape 10m from where the sciborg started and set it up that the sciborg would run at full speed when the sensor was reading the values that correspond to the dark ground and once the sensor detected the smaller number of the white tape, the motors would stop.






Task 4 - Ultrasonic Sensor:

Our next task was to learn how the ultrasonic sensor. First we downloaded the code and set it up with the motors. We then ran tests to determine how accurate the sonar is and what distance the readings correspond to. We determined that with a sonic reading of 3, the sciborg will be about 10in from the barrier. Also we determined that the sensor was accurate with about an inch of error.

Here is our resulting code to control the motors:


We set up a barrier 10ft 10in from the starting point of the sciborg and set the motors to run until the sensor read a value of 3 and then turn the motors off. Here is how it worked:



Task 5 - Drive straight:

To accomplish this, Nanaki and I used the motor encoder code. What we did is when the position of the motor on the left was less than the position of the motor on the right, we would turn up the power of the left motor and turn down the right motor. This way, the sciborg would correct for the difference in motor position by turning. Here is what our code looked like:



And here is how the code worked:



Difficulties we faced:

Throughout this phase of the project, we faced many challenges. First off, the sensors are not completely accurate, so there will always be a margin of error when using sensors. Also, the sciborg doesn't travel the same during each run.

One of the biggest things we struggled with was the ball bearing catching on the ground and messing up the positioning and the timing of the sciborg. To fix this we removed the ball bearing and lubricated it to make it run smoother:


After all of these tasks, we came up with some good ideas to have the sciborg follow a path. I will discuss these ideas further in my next blog post.

1 comment:

  1. I like how you found out the encoder reading should be for the car to run 10 feet.

    ReplyDelete