Friday, 11 March 2016

SciBorg Part 2

If you remember from Part 1, we had named our SciBorg Daniel. Unfortunately, he had a hard time driving on rough surfaces like the lab floor and only liked the top of our lab tables. It galloped like a horse rather than driving on the floor.

Long story short, the following will be about Daniela, the better-behaving SciBorg!

The goal of this second part was to use different sensors (light, ultrasonic, switch, and motor encoder), get readings on an Arduino serial monitor, and later utilize these sensors to control the SciBorg's behavior. Specifically, we programmed Daniella to travel 5 ft and stop by sensing a change in the environment or motor condition (we tested one sensor at a time).

The SciBorg has two motors that rotate at slightly different speeds, and it tends to bend over the course of its journey. We shortened the distance to 5 ft so the SciBorg doesn't have enough time to stray away too much. Regardless of the distance traveled, the SciBorg shows noticeable reaction to what its sensors detect. 

Measurements by different detectors and their use to stop the SciBorg

1) Motor Encoder
      a) Measurement of position of each motor
Sketch:
Serial Monitor Readings: 
Notice the highlighted value is that which coincides with 8 seconds, the time it takes the SciBorg to travel 5 ft.
As you can see, the numbers read by the encoder change over time, since the motors are not perfect. But we noticed a trend and graphed it for fun:
Based on this increase, we know the encoder wouldn't read the same or lower values as time goes by. So we gave the SciBorg a command to stop once the encoder passed the value at 8 seconds.

We repeated this with the batteries connected to the SciBorg and got higher values that better match the speed of the motors during the drive. (Value at 8 seconds with connected batteries not shown here but used in the following sketch.)
      b) Stopping after 5 ft
Sketch: 


Video:

  Daniela stopped 1.5 in short of the finish line. We attribute this to the lack of friction as we read the values next to the computer and its presence on the 5 ft course.

2) Touch Switch
      a) Measurement 
Sketch: We used the one from the course page
Button Readout with Narration:

      b) Stopping after 5 ft
Sketch: 


Video:

The switch worked well in stopping the SciBorg without moving too far or too short. We put a solid in front of the car to touch switch. In retrospect, I think this object was also strong enough to stop the low-torque car without the switch control. With more time, I would investigate how hard one has to press the switch for the SciBorg to stop. On the other hand, this method eliminates chances that the SciBorg stops too short because the switch is only pressed at the finish line. 

3) Light Sensor
      a) Measurement
Sketch:
Videos of Readout:
        First we tried the readings with the LED on. To do so, we got rid of the comment signs before the last three lines before delay(). This allowed us to see where the LED, therefore, the sensor is pointing. We also used it to identify what height gives a sharper area. However, the differences between different colors were not apparent because LED light reflected off of surfaces more than the light in the room.

Then, we read the values without LED (commenting out the lines commanding the use of LED). This gave a better reading with distinct values for different colors. We placed the table surface (light brown), a black paper, and a white paper under at different points to obtain the following readout. 


      b) Stopping after 5 ft
Sketch:



Video:

The light sensor worked very well; the SciBorg stopped with an uncertainty of less than half an inch from the finish line. We placed a white paper at the finish line  and ordered the SciBorg's motors to stop the moment the value read by the light sensor exceeded 90, which is true for the white paper. Since light travels at the maximum speed of any known being, the reaction time was almost solely due to the processing time. Also, since the white paper only started from the finish line, there was no chance of the SciBorg stopping before the finish line.

4) Ultrasonic Sensor
      a) Measurement 
Sketch from course page: 

Video of Readout:


      b) Stopping after 5 ft
Sketch:

Video

We put a delrin sheet 20 inches from the finish line (because the ultrasonic reads distances greater than 20 inches better) and programmed the SciBorg to stop at a value we measured from the readings to correspond to what is physically 20 inches away. It worked pretty well with an uncertainty of less than an inch. Although we should note that the readings from Arduino aren't unique to a length, so the approximation we make can affect the functionality significantly. 

Bang-Bang Control to Drive Straight (Using Encoder) 

 We tried to move our SciBorg in a straight line on the lab floor with some success, and on the ramp outside with little success. Below, I present the lab floor trial. With more time, I will investigate how the SciBorg acts on a ramp and a carpet.

Sketch:

Video showing Daniela following a relatively more straight line:


On the lab floor










On the carpet outside: We placed the car on the white line to have a reference.











On a the ramp:
On the ramp, our SciBorg tilted to the same side of the ramp both when going upwards and downwards. This may indicate a tilt in the ramp itself rather than a significant problem because if it had been due to an uneven speed in the motors, the car would have consistently fallen off either to the right or left of itself and not to the same side of the ramp.



We picked the encoder for this task because it needs no external signals. In contrast, a light sensor would need some line to follow, an ultrasonic detector needs some obstacles in front of it, and a switch needs to be pressed by an external body. We designed this for the case when the SciBorg goes straight based on the rotation of its wheels (motors) rather than its interactions with external objects designed for the specific purpose. 

We learned that the Encoder, while relatively independent of external guidance, is very imprecise due to the inconsistency in the friction the wheels feel, battery power over time, etc.


Bang-Bang Control to Follow a Marked Path (Using Light Sensor)

Sketch:
We tried several sketches like the one displayed below with loops including if/else clauses that make the SciBorg turn to the left or to the right depending on the light sensor reading. However, there was no way of telling if the sensor is reading a low value because it has strayed to the left or to the right. Plus, going straight ahead often made the SciBorg overshoot the line and stray off forever. This made the motion of the SciBorg unpredictable and we had to change it to a while loop and adjust the physical placement (relative to the line to follow) of the sensor itself. 
Failed attempt at using if/else commands to make the SciBorg follow the white line 
In our final iteration, we adjusted the sensor to sit right above (or a little to the right) of the right-hand-side edge of the white line to follow. Watch the video below for a visual. We used the "While" loop as shown in the sketch below to tell the SciBorg to either turn right (where a brown background lies) when it detects white (value > 80) or turn left (where a white tape lies) when it detects brown (value < 80). We avoided the "StraightAhead" function completely because the difference in the motors doesn't allow the SciBorg to go perfectly straight ahead, anyway. 







Daniela at Work

Reflections: This exercise required an outside-the-box thinking where a straight path (which in theory works well) is actually counterproductive. While the car looked "confused" turning left and right very quickly, it followed the path best when it was set to turn right or left depending on the value read by the sensor. The problems with the SciBorg made it a more realistic problem to deal with. 

The height at which we attached the light sensor to the SciBorg originally was too high and read very similar values for the brown and white surfaces. We adjusted the sensor to sit slightly lower such that the difference in values was unambiguously distinguishable.


Following an Object or other SciBorgs

On Friday, March 11th, we challenged Daniela to socialize a bit and follow other SciBorg using her ultrasonic sensor.

An ultrasonic sensor reads the distance of an object in front of it by sending a wave (of known speed) and timing how long it takes to return (distance = velocity*time).

We know our sensor reads values beyond 20 inches better. And we know the approximate reading on the Arduino program that corresponds with an object placed 20 inches away. So, we programmed our SciBorg's motor to run at approximately equal speeds correcting for its natural bend when it detects objects beyond 20 inches and to stop when it detects anything closer.

Sketch:


Video 1: Daniela Following another SciBorg


Video 2: Daniela Following Thessaly's feet


This worked pretty well as Daniela followed a Delrin sheet, another SciBorg (a new friend!), and our feet. We didn't measure how far off from the 20 inch distance the SciBorg stopped or how much later than the object in front of it. However, it did the task of stooping when the object ahead stopped and moving when the object ahead moved further. I can imagine this being useful in traffic where the distance between cars needs to be maintained at some minimum limit.


5 comments:

  1. Great to see Daniella working hard! Nice reflection!

    ReplyDelete
  2. Great idea analyzing the motor encoder using a graph! And I love the name of your SciBorg!

    ReplyDelete
  3. I like that you used a graph to compare the time in seconds and the readings provided by the motor encoder. It would have been interesting to include the distance in feet that the sciborg traveled in the graph as well to see the relationship between all three variables.

    ReplyDelete
  4. Good point, Nanaki. Hmmm... If we maybe had photo-gates to measure instantaneous speeds at different times from the start, we might have been able to check how the car accelerates over time.

    ReplyDelete
  5. very clever getting the Sciborg to follow feet!

    ReplyDelete