Pages

Saturday, April 4, 2015

Arduinos: Day 4

Today Sarah Barden and I continued to work with Arduinos and Sciborgs as Part of our "Feedback and Control" unit. Our aim for this section was to troubleshoot the use of various sensors to control the movement of the Sciborg using bang-bang or proportional control. 


Encoders


An encoder is a type of sensor that  captures position information and relays that data to other devices. The position information can be read in several ways including optically and magnetically. The encoder sensor we used reads the number of times the shaft of the wheel on the Sciborg has rotated to judge position.

For this exercise, we were given the sample code below. This code start the sensor reading value at 0 and then precedes to serial print the position of the Sciborg as it moves (as read by the encoder).


Fixed Distance: Bang-Bang Control

We then modified the above code so that the Sciborg is able to travel exactly 10 ft through the use of an encoder to judge whether or not the device had reached the desired position. The code below utilizes bang-bang control to direct the movement speeds if the device.




Fixed Distance: Proportional Control

The following code uses proportional, rather than bang-bang control to ensure that the Sciborg travels exactly 10 ft, as measured by the encoder. In using proportional control, we are able to prevent possible overshoots of the desired distance due to the momentum of the wheels at full speed by gradually slowing down the Sciborg as it nears its destination.






Ultrasonic Sensor


An ultrasonic sensor can detect objects within a certain area through the use of high frequency sound waves. This sensor measures the time of flight for sound that has been transmitted to nearby objects and uses that to output a range reading. 

To start with we were given the sample code below that allows us to track what values the sensor is reading.




Sciborg: Stop at Obstacle

Once we understood how the sensor worked, and the range of values it recorded, we then set out to create a code which would stop the Sciborg whenever it got too close to an object (the sensor read a value <30).





Feedback & Control: Bang-Bang Conga Line

Now that we new how to program actions based on sensor values, we wanted to make a code that would allow the Sciborg to follow another device/object in front of it. This would be achieved using the ultrasonic sensor to first find an object to follow, then to make adjustements in position (i.e. move) to keep in line with said object. The code below uses bang bang control to achieve this. 



Feedback & Control: Proportional Conga Line

The above code resulted in jerky movements, so we adjusted it to use proportional control instead. This new code allows the Sciborg to adjust its speed based on how far away it is from other objects, and even come to a stop if it gets too close to one.






Light Sensor: Line Following


Our last assignment for working the Sciborgs involved the use of light sensors. After calibrating the light sensor and getting a sense of the range of values it was able to measure, Sarah and I set out to design a code that would allow the Sciborg to follow a white line on a dark background. 


Feedback & Control: Bang-Bang Line Following

The first method we sought to utilize was bang-bang control. The main challenge for this task was coding for both left and right turns based on sensor values. In order to ensure that the Sciborg could return to the line regardless of which direction if strayed in, we ended up creating three different "ranges" of values. The first range was when the sciborg was fully on the line; in this case the Sciborg would go straight. The second case was when the light sensor was only partially on the white line; in this case the Sciborg would turn left. The final range was when the light sensor was fully off the line; in this case the sciborg would turn right.






Feedback & Control: Proportional Line Following

Using the bang-bang code, we also created a code that used proportional control. This allowed the speed of the Sciborg's turns to be proportional to how far away from the line the sensor was. 



Reflection

Before starting this project I was not aware of how many sensors were available and their many uses. After troubleshooting the above codes/actions, however, I feel that I have a better understanding of how they work and the ways I can use them in the future. I feel the most challenging thing about these sensors, particularly the ultrasonic and light sensors, is that the readings they take can vary slightly depending on how they are calibrated. The most difficult ask was by far the line following codes. While overall the codes we created worked, the fine tuning needed to select the right turn speeds and sensor ranges was time consuming. 


1 comment:

  1. I agree that there are a lot of interesting sensors that you can use with Arduino! Unfortunately their readings do fluctuate sometimes.

    ReplyDelete