Tuesday, 29 March 2016

Sci Borg Part 3

In the word of an engineer friend, proportional control is like working with a spring. For fellow physics enthusiast, F = -kx is a familiar expression that relates the force acting on an object attached to a spring (without damping) due to a displacement. The magnitude of the force increases (linearly) as the distance x increases. And k is the constant of proportionality that relates them.

Very similarly, we can use proportional control to change the behavior of our SciBorg (analogous to force) based on a change or error (analogous to displacement) recorded by a sensor. 

In the third part of our SciBorg project, we related the speeds of the motors to a linear expression containing k*error to:

              I) Drive Straighter
              II) Travel 10 ft and stop
              III) Follow an object using an ultrasonoic sensor
              IV) Follow a line using a light sensor 

I) Driving Straighter Using Proportional Control
We set a base speed of 150 to both motors and changed the speed of Motor 1 based on the relation v1 = 150 + error * k, where error = encoder reading for motor 2 - encoder reading for motor 1, and k is an arbitrarily set constant of proportionality that we changed based on observations.

Below are the sketch used, the different k values tried and their serial port readings, as well as videos showing how the SciBorg performed on the lab floor, a carpet, when the wheels traveled on surfaces of different friction constants, and going up/down a ramp (we have yet to try because the ramp is not set up now).

The results over several trials were fairly constant. The car looked less shaky than it did in the bang-bang control partly because proportional control results in gradual changes rather than abrupt turns.

 Sketch:




K=0.1

K=0.3
K=0.5

On the lab floor:

On a carpet:



With wheels on different surfaces:






Notice that the wheel on the smoother surface always moves faster and the car turns to the side away from this smooth surface. This is because we calibrated our k and our motor speeds for a surface where both wheels face the same amount of friction.

II) Go 10 feet
We used a similar logic of making the speed linearly dependent on some changing variable. But this time, we made the speed dependent on the number of encoder readings the car needs to go before it reaches its destination. This number of counts left decreases as the car approaches its destination, so it slows down before it finally stops. 

First, we attempted to find the encoder reading after the car has traveled 10 ft by timing the car travel the 10 ft and then timing the encoder reading as it is attached to the serial monitor. Later, we figured where we recorded encoder values and where we ran the car are different environments in which friction and power supplied to motors varies (the computer actually provides additional energy to the motors). 

Instead, we decided to calculate the number of encoder counts per rotation, which should be a constant value because the encoder readings come from physical structures within the motor.
We conducted the following mini experiment, where we took the ratio of the wheels' circumference to 10 ft and the encoder readings per turn to find the encoder readings per rotation.


(I will provide a more organized version of this picture with more time.)

Below are the sketch used and the video of Daniela (our SciBorg) stopping after traveling ~10 ft on the lab floor. 





Notice the tail not the front of the car was on the start line and it stops very close to 10 ft from where it starts (less than 3 in of uncertainty). However, we also attempted to use the nudge function.

Sketches and video below:





Ideally, we would have used a relation that looks like speed = k * counts left. However, when the speed is really small, the car starts wobbling and changing direction. It also stops before speed is actually equal to zero. So the function of our proportional control ended up being mostly slowing the car down before we tell the motors to stop. 


III) Using ultrasonic sensor follow objects
In this section we made the speed of the motors dependent on the distance of an object from the ultrasonic sensor. Given the relation, speed = 170 + k*error, the speed increases with a positive error and decreases with a negative error.

Again, because lower speeds result in an unstable SciBorg, we used the proportional control as a means of slowing the car down before it stops.




This worked well as the Daniela followed my feet and then other SciBorgs. I would say this worked as well as the bang-bang control method, especially because the stopping distance not precise as long as the SciBorg followed others and stopped before crashing into the object.




In this last video, Daniela was the one at the back.


IV) Proportional line following 
We faced the most challenge in this one because, while the logic made sense, the result was completely unpredictable.
Our setup:
We placed the sensor to the left of the line and told the code to set speed of motor 1 to 150 + k*error, where error = value of brightness - 80. We took 80 because it was the reading right between the brown and the white surfaces.

With error > 0 speed of motor 1 should increase, therefore car turns towards motor 2; error < 0 speed of motor 1 should decrease, therefore car turns towards motor 1.

In practice, this didn't happen.

Here are some of the several loop commands we attempted:

And when this didn't work:


In some of these cases the car just went straight ahead, while in others it just turned to the right.

Expect to hear back from me on this one.

Thursday, 17 March 2016

Real World Feedback and Control

Feedback and control systems are more familiar than their fancy name makes them sound. A large range of objects, from automatic doors and faucets to drones and spaceships rely on feedback and control systems. 



These systems have sensors, computers, and actuators that change the behavior of the machine based on observed light, movement, sound, heat, interference, etc. The control system, for example, can use if/else statements to make the machine behave one way when its sensor observes a specific property in its surrounding and to act differently otherwise. 


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheMb_mVma98k0o96czYIpZS96uHQl-Rsx21b7we0UfBMvw6M4AI9EL3pJMTeJAFWK5ES5nCu6nQE_jAnNuEZvRRPjYo_ffQCkTeyJ9ysv8VK4a5wIdtASH9ZCjWvyiCWmjGWdtiqWoAiMc/s640/loop+picture+for+real+life+feedback+and+control+systems+blog.png











The diagram above shows the general mechanism by which feedback and control systems work.

In class, we have seen two types of feedback and control systems -- open and closed loop. We have also used light sensors, ultrasonic sesnsors, encoders, and switches in combination with Arduino sketches to change and control the behavior of SciBorgs. 

Below, I present four common feedback and control systems I encounter daily: automatic doors, automatic water dispensers and faucets, automatic phone operators and smoke detector alarms. 

1) Automatic doors 


Such doors use light sensors, touch switches, or other sensors to open doors for a given amount of time in response to an observed change in the surrounding. 

https://www.elprocus.com/wp-content/uploads/2013/05/PIR-Sensor.jpg
PIR Sensor
https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQ5n3mABEouXKvo2gQ5c0069q8gpVeroXZ7xxOL7ifm2-I4p2rmhttps://blogger.googleusercontent.com/img/proxy/AVvXsEgZ6jtsScFXsjL5Stk9B3rUjOk-_5OL8-TSBXs_FtdAoQ-l7arj4u9vHFO4k1ucTXIhbkuaXWlS68S1mG6sT4vl_WK7YkF7v0VwegxY_mmo6nZMZ_BUCJkesRKld6AylEmyRZSx-M0NmQDyU61AloVXEJU14AyolixEiQxfnWY9tu8=


Some automatic doors use PIR (Passive Infrared Sensor) to detect the presence of humans. The near-black-body irradiation from our body due to our temperature is mostly in the form of infrared waves (~9500 nm). And the intensity (or the number of photons reaching the sensor) increases with shorter distance between the source and the detector. So the intensity of IR photons detected by the sensor on an automatic door increases when a human is near the sensor. The PIR has a crystal whose temperature increases upon irradiation (by the IR waves reaching it). This temperature creates an electric signal/charge that communicates with the micro-controller. The micro-controller orders the motors and other actuators in the system to move such that the door opens when there is a high IR signal (or change thereof) and close after a certain delay, and remain closed when the IR signal is low in terms of intensity: the person is far; or in terms of temperature: the radiation reaching the sensor is only that of the surrounding inanimate materials. 
Note: This sensor is called "passive" because unlike ultrasonic sensors, for example, it doesn't send out waves and measure the time delay before they return to observe something about the surrounding. It simply detects input from the environment. 


This has the following uses: 
  •  If a person cannot open the door due to a disability, because their hands are full, or they are too weak to do so (for example, a child), it is convenient to have an automatic door that doesn't need force to open.
  • Since the amount of time the door stays open is controlled, it avoids the risk of leaving the door open for too long and wasting either heater or AC energy.
Some drawbacks:
  • Since the specific sensor I discussed only detects IR reaching it an not the identity of the emitter, it can let either animals or children in our out the of the building without adult supervision. 
  • It adds to the load of power use by the building. We would spend more energy on doors than we would if we manually opened them. But often this drawback is overcome by the many advantages of such systems. 


2) Automatic faucets



https://blogger.googleusercontent.com/img/proxy/AVvXsEjMTVuv1v9Qav0SIULwdj2_yVYKy4OeJOwR96t6m7k4nj4l3AjyODFHukUxArS53CGYgbAraBmFLoySgeXEKIsvmdFlQM12-DvcNpc-s2UdiyfBuFBC5ZJ5uIg7NlK91c7-eEQ5btqi9pTVOlLbINnajjrh2EuWefkIYlXvEQ=
Automatic faucets can also use PIR but since one might want to wash items with temperatures lower than that of humans, such faucets also use ultrasonic sensors or infrared light next to a an IR detector to "measure the presence" of an item within a predefined distance. The object interrupts a light beam from the ultrasonic or the IR source and which reflect back to the sensors. If the reflection time is in the range of the calibrated value for a hand under the faucet (AKA not the sink or other items in the surrounding), an electric signal is sent to a solenoid valve (an electromagnet) to turn on the faucet. Otherwise, the solenoid valve isn't activated and the faucet remains closed. 
Advantages: 
    • It prevents water waste because if a person forgets to close the faucet, the IR or ultrasonic interruption is no longer present and the faucet turns off instantaneously
    • It is also sanitary especially in public bathrooms where manually opening faucets may introduce us to several germs. 
Drawbacks: 
    • The specific systems described above don't allow the user to choose the water temperature. 
    • While we save a lot of water, we have to sacrifice some electrical power. 


3) Ionization Smoke Detectors/Alarms


Smoke detectors contain a very tiny amount (on the order or 10^-6 g) of Americium which decays radioactively and emits alpha particles. These alpha particles collide with the nitrogen and oxygen molecules in the air and trigger a current flow in the opposite direction to an original current that would activate an alarm. This means the net current flow when there is ample N2 and O2 in the air is zero; the alarm can't go off. However, when smoke blocks off the clean air from occupying the space near the detector, not enough charges are created to counter the current that triggers the alarm. And depending on the occasion, either a life is saved or the user rushes to wave a towel under the detector (that is how my roommate and I handle completely random alarms). The following video from YouTube offers a good explanation for how this feedback and control system works: 



Advantages:
    • The detector is very sensitive and gives a very early warning to the start of fire before too much damage happens. Also because smoke detectors sit on top of the room, hot air from the fire reaches them quickly through convection. 
    • Needless to say, they save lives.
    • While the radioactive material sounds dangerous it poses little threat due to its small amount and proper packaging.
Drawbacks:
  • Disposal of smoke detectors containing radioactive material can be a health and environmental hazard if not done properly. 
  • There is a chance the alarm would go off even though there is no risk of fire. It is so sensitive, steam or dust can set it off sometimes. This is because it detects the absence of ions rather than the specific material that is present in their stead. 


4) Fume Hoods


Fume hoods are "cupboards" that enclose a working area to isolate and remove harmful gases from the room in which a chemist (mostly) works. They have feedback and control systems that monitor air flow and window height (opening), as well as allow the user to turn exhaust fan on and off. 

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpXcnggBKAgwa_AVSzg3UhTpFoFhNpGWsonkgWi6llo6SHN_j5VeH0twmezsSRZHda_qrRET5mHw1MzI2_HCA6_ihM98FUju6DeH9M8Ox_0-7nK07V7Wu3foXvjlNOObGVugo-4trOETZU/s640/fume+hood+diagram.png
Fume hoods have an air flow monitor that detects the face velocity (velocity of air at the fan opening). When the detected air flow is too low either due to excess exhaust, the sash being opened too high, or fan malfunction, an alarm goes off.


Advantages: 
  • Not only does it do the primary job of pumping out unwanted gas and replacing it with fresh air, it assesses the product: how high the air flow is. 
  • It prevents health and environmental hazards while allowing us to work with a variety of chemicals
Disadvantages: 
  • It runs for several hours and pumps out air from the room that has been thermally conditioned. So it ends up consuming too much energy. 

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.