Encoders
The first sensor that we used is called an encoder. This sensor reads the number of times the shaft of the wheel has rotated and displays the reading on the serial monitor.The starting value is and should be zero because the wheel has not rotated yet. The ending value is not zero because the wheel has rotated a number of times, both forward and backward, and cannot get back to exactly zero.
Touch Switch
The next sensor we worked with is called the touch switch. At the front of the sciborg is a switch that you can press by lifting the big arm up and down. We wired the touch switch to the Arduino board pin 9 using the breadboard and also connected an LED light to pin 3. We ran the sample sketch of the touch switch.The LED stays on forever when the button is pressed because the sketch does not include that when the button is released, the light will turn off. To make the light go on only when the button is pressed, we created an if else statement in the loop.
Ultrasonic Sensor
Another cool sensor we worked with is the ultrasonic sensor. This sensor detects objects in the vicinity. The sample code allows the sensor to display the distance of the nearest object using the serial monitor. The smallest reading on the serial monitor is associated with an object being extremely close to the sensor. By playing with the sensor, we observed the smallest reading to be about 11 when I put my hand directly in front of the sensor.
Feedback & Control
Fixed distance, bang-bang control
Bang-bang control means that the system is either completely on, at full speed, or completely off. In the following sketches, the sciborg uses bang-bang control.Last time, we were able to get the sciborg very close to the ten foot mark after several trials with the delay time. We started off with 12.5 seconds, but because the sciborg didn't go in a straight line, the 12.5s was not enough time to make it to the line. We then tested 13.5 and 14.5 seconds. The 14.5 seconds brought us the closest to the 10-foot mark -- the sciborg stopped with the center of its body on the white line!
Using the previous sketch with the 14500ms delay and the encoder sample code, we measured the rotation of the wheel shafts using the encoder sensor. The encoder reading was 14336 after traveling forward for 14.5 seconds.
We then used the touch sensor and the ultrasonic sensor to stop the sciborg at the 10 feet, instead of using the time delay.
With the touch sensor, we created the sketch so that the sciborg would stop when we pressed and released the button. We pressed the button when the sciborg reached the ten-foot mark.
With the ultrasonic sensor, we programmed the sciborg to move when there is an object within a reading of 30 on the ultrasonic sensor reading. That way, the sciborg could follow a hand or wooden board until it reaches the ten-foot mark. When that object is taken away and there are no objects close to sciborg, it stops moving.
Fixed distance, proportional control
The next assignment was to use proportional control instead of bang-bang control. Proportional control means that the sciborg adjusts its speed according to how far away it is from its target.Proportional control involves the following equation:
Output = error x gain factor
= (target - current position) x gain factor
The output is the power supply, or in the case of the sciborg, the speed. The target is the desired distance travelled, in our case, ten feet, and the current position is the distance from the ten-foot mark.
Using the ten-foot encoder reading from last time, we set the encoder reading of 14366 as the desired target, and the current position as the current encoder reading. We wanted the maximum output, or speed, to be -150. So using the equation, we calculated the gain factor to be -0.010441.
The encoder reading was put into the loop so that it would be constantly updated. The speed was set as shown below so that as the sciborg approached the target, it would slow down.
We also created a nudge function using the ultrasonic sensor. We found that when using only proportional sketch, the sciborg would not reach the target because in the end, there would not be enough power for it to continue moving. So the nudge function makes the sciborg travel in short intervals at a low speed until it reaches the desired distance.
We incorporated the ultrasonic sensor into the final nudge function so that we could control when the sciborg stops performing the nudge function. We used an if else statement, so that if the nearest object is greater than a reading of 15, the sciborg performs the nudge function, and if the reading is under 15, the sciborg stops.
Conga Line
The last part of the feedback and control section was to use the ultrasonic sensor to have the sciborg follow another object. This was similar to what we did for the fixed distance, bang-bang control with the ultrasonic. However, this time, we also programmed the sciborg to slow down if it got too close to the object in front of it -- that is, if the ultrasonic reading became too small.
First, is the bang-bang control conga. The sciborg is programmed to follow an object within an ultrasonic reading of 30 at full speed.
The 11 is the minimum ultrasonic reading, so when something is extremely close to the sciborg, the speed will be zero.
We wanted the maximum speed to be between -100 and -200, so we determined the gain factor to be -10.
This way, as the object that the sciborg is following gets further away, the sciborg speeds up. If the object gets closer, the sciborg slows down, or stops.
I really liked how you explained what each sensor does before you talked about your code and defined all the relevant terms. Great post!
ReplyDelete