Thursday, April 9, 2015

MATLAB Introduction

Today, we started our section on MATLAB. This program can be used for a variety of calculations and functions. Using Arduino and having a bit of programming experience made starting the MATLAB programming an easier transition. 

We started by introducing ourselves to MATLAB by reading Physical Modeling in MATLAB by Allen B. Downey. In chapters one through four, he writes about basic functions of the program, such as writing loops, and functions, and vectors.

As we read the chapters, we also did some of the exercises.

Fibonaci Sequence

The first exercise was to write a script to compute the nth term of the Fibonaci sequence, which can be calculated using the following equation. 

We translated the equation into something that MATLAB could read. Each portion of the equation was set as a separate variable, and then put together in one line of code at the end. We also set n as 10, so that the program computed the 10th term of the sequence. 

We ran the program and got the 10th term as 55, which was what we expected.

Car Update

The next exercise was to create a script that updates the number of cars at two rental car companies, one in Albany and one in Boston. 5% of the Albany cars get dropped off in Boston  and 3% from Boston to Albany each week. Each location started off with 150 cars, so we set the initial a and b as 150 in the command window. Then we set A and B as the number of cars in each location after one week. Then, we set a as A and b as B so that the new initial number of cars would be changed. That way, if we run the function once, it displays the number of cars in each location after one week; if we run it 10 times, it shows the cars for after 10 week, and so on.
The round function is to round the number displayed to a whole number, as one cannot have half a car.



Car Loop

Next, we were to create a loop for the previous script so that the function automatically runs a specified number of times. In this case, we set the loop to run 52 times to simulate the number of cars in each location in one year. The initial conditions for a and b were set as 150.


When we ran the loop, we found that after a while, the values of A and B stopped changing. A stopped at 118 cars while B stopped at 182 cars.

Car Loop Plot

Next, we created a script that would also plot the values of the car loop script from above. Again, the initial values were 150. The hold on ensure that the graph doesn't automatically clear the points each time. The cars in Albany were plotted by red circles, while the Boston cars were plotted in blue diamonds.


As you can see from the above graph, the values eventually stop changing. 

We also tried using initial values of 10,000 cars. The result was that the graph resembled a better parabola shape. 



Fibonaci 2

The next exercise was to write a script to compute the elements of the Fibonaci sequence using a loop. The Fibonaci sequence is calculated using the equation 

Fi = F(i-1) + F(i-2)

In order to display the first 10 terms of the sequence, F1 and F2 are set as 1. Then, inside the loop, the nth term of the sequence is the sum of the previous two terms. Then, the previous two terms are updated to the newer two terms.

Then, we generalized the loop so that any number of terms could be calculated. The value of n just needs to be specified before the script is run.

Fibonaci Ratios

The last exercise was to write a script to first calculate the vector of the nth number of terms in the Fibonaci sequence, and then calculate the vector of the ratios of F(i+1)/F(i) -- that is the ratio of two consecutive terms. Then the ratios were plotted on a graph to see if the values do indeed converge. 

The ratios were plotted versus X, which was the value of n of that specific ratio.






Friday, April 3, 2015

Arduino Day 5

We continued to work with the sciborg and were introduced to some sensors that can be used with the sciborg. We also worked on bang-bang control and proportional control.


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.




Then, we have the proportional control conga. We put the ultrasonic reading into the loop as the integer value, and set the maximum speed of the sciborg equal to (value - 11)*-10

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.








Thursday, April 2, 2015

Final project ideas

Before spring break, we visited some children and observed them playing in their classrooms and interacting with each other and the teachers. 

Our final project is to design a project that will enhance the children and teachers' experience in the classroom. 

I saw a few things that may be potential for my final project. 

One, the bathroom sinks: one of the teachers said that the children sometimes forget to wash their hands after using the bathroom. I think that a possible project would be to design some kind of feedback and control so that if a child doesn't wash his/her hands after using the bathroom, there will be some kind of flashing of lights or other reminder for him/her to wash hands. 

Two, the children seem to have trouble remaining seated on their carpet squares. Perhaps if the child starts to get up off the carpet square, or is sitting on the edge of it, the carpet square could vibrate or make a sound to remind the child to sit down. Some kind of pressure sensor would have to be built into the mats. 

And three, the children easily spill water or sand from out of the tubs. There needs to be some kind of reminder for them to clean up the water or sand when there is a large spill. Maybe there could be a sensor on the legs of the table that detect spills. And, if there is a spill, a short song could be played that reminds the children to clean up the mess.

All of these ideas involve some kind of visual or auditory simulation to remind the children to do or to not do something. It is also important to keep in mind that whatever the simulation is, it cannot over simulate the children. We don't want to encourage them do things on purpose to make the lights go off or make the song play. 







Arduino Day 4


The next segment of our work with Arduino involves using a sciborg -- basically a robot. To start, we first learned how to make functions.

Making Functions

The purpose of making functions is to avoid retyping code multiple times. Our functions programmed an LED light to blink in the pattern on morse code: dot-dot-dot-dash-dash-dash-dot-dot-dot. The program is shown below.
The use of the dot and dash functions effectively shortened the loop function.

Setting up the sciborg

The first step in setting up the sciborg was to solder the battery pack so that we could attach it to the board of the sciborg. We then screwed down the battery pack to the sciborg, taped over the screws, and installed the batteries. Next, we screwed down the Arduino board to the sciborg board, and set the bricktronics shield on top of the Arduino board. 

Using the sciborg

Motors and speed

There are two main wheels on the sciborg, each of which are powered by a motor. The first step in using the sciborg was to run the example sketch "single motor". 



Next, we ran both motors at the same speed by including both motors in the sketch.

When the motors are run at a speed of 0 or 1, nothing happens. This is because there is a minimum speed that the sciborg needs in order to overcome static friction.

We tested various motor speeds and found the that the approximate minimum speed that the sciborg needs is 40.

Turning

The next step was to create a sketch to make the sciborg make a "hard turn" -- that is, have one motor on at full speed and the other at reverse full speed. 

We also created a sketch for the sciborg to make gentler turns. We did this by having one motor at full speed and the other motor at a reduced speed.

Driving straight and 10 feet

Then, we created a sketch to make the sciborg travel 10 feet and automatically stop. We timed how long it took for the sciborg to reach the 10 ft mark, 14.5 seconds, and used that time for the delay. After the delay, we used another function, dot, to stop the two motors. 


The most difficult aspect of this part was getting the sciborg to travel in a straight line. We realized that the two motors spun at slightly different speeds. Therefore, the left motor needed to have a slightly higher speed than the right motor so that the sciborg would not travel in curves. 

We also took a close look at the two wheels and saw that one wheel was closer to the center of the sciborg than the other, so we adjusted the position of the wheels to be equal.

Also, the small front wheel of the sciborg contributes to the difficulty of traveling in a straight path. Sometimes the wheel gets stuck in a certain direction and the sciborg thus can only travel in that direction.

Touch sensor and hitting the wall

Next, we incorporated a touch sensor into the sciborg and Arduino program so that the sciborg would go forward until it hits a wall (or the touch sensor is pressed), back up a bit, turn around and continue to go forward. 

First, we ran the example sketch "motor button", where when the button (of the touch sensor) is pressed, the sciborg reverses direction. 

Then, we modified the code so that it would behave as mentioned above. 


At the beginning of the loop, the motors momentarily stop when the touch sensor button is pressed. There is then a short delay to "debounce the button", or in other words, give it time to react to the pressing of the button. Then, the button is released, and there is another delay for the debounce. The press and release of the button mimic the sciborg hitting a wall or other obstacle. 

The speed of the sciborg is reversed for 5 seconds, using another delay function, so that the sciborg can back up away from the wall or obstacle. The speed is reversed again at the end of those 5 seconds. After the second reverse speed, motor 2 travels at half the speed of motor 1 for 5 seconds so that the sciborg can turn around. 



There was no great location to attach the sensor on the sciborg. We tried to attach the sensor to the front of the sciborg, but when the sciborg hit a wall, the sensor would not get pressed enough to activate the reverse speed. I would build some kind of structure on the front of the sciborg to securely hold the sensor in order to improve the sciborg's mobility.




Arduino Day 3

Photocell

One of our assignments was to program a photocell, which senses the amount of light it is exposed to and displays whether it is "Dark", "Dim", "Light", "Bright" or "Very Bright". The original program is shown below. 



Our job was to take this original program and modify it so that a servos motor moves and an LED light blinks in accordance to the reading of the photocell. 

Using the setup for the servos motor and LED from previous Arduino programs, we incorporated the two into the program and connected them to the arduino board.


We then incorporated a series of else if statements into the loop so that the motor would spin more quickly as the photocell senses more light. This was done by increasing the size of the steps that the servos takes. The LED was also programmed to blink more quickly as the photocell sense more light using the different delays.


















Sunday, March 15, 2015

Lecture Alternate Assignment

Summary and critique of the article by Professor Wood and his colleagues
Seitz, Benedikt F., et al,  “Bio-inspired mechanisms for inclined locomotion in a legged insect-scale robot.” Harvard Microrobotics Laboratory. 14 December, 2014.

The development of insect-scale robots has made a lot of progress in flat surface movements. However, locomotion of the insect-scale robots on slanted surfaces has not been as successful. This paper explores the use of different adhesion and alignment mechanisms on the Harvard Ambulatory Microrobot (HAMR), the model insect-scale robot for this experiment. The legs of the robot must exert enough peak and normal forces on the surface to prevent slipping. Therefore, the different adhesion methods must be tested for a degree of stability.

The components to of the HAMR were carefully analyzed and tested to ensure the best performance of the robot. The design of the actuator of the HAMR was selected after testing different thicknesses of the various actuators. The 2-ply actuator was determined to have the best mechanical advantage. Also the transmission performance of the legs of the HAMR was tested. The locomotion of the legs was then analyzed; it was found that the motion of the legs as they took steps was not ideal for climbing inclined planes, as the robot rocked back and forth on the legs that were in contact with the ground as the other legs were moving. In order to compensate for this unwanted motion, a passive tail was added to the HAMR so that its motion would be more stable.

There were three types of adhesion methods that were tested: electroadhesion, micro-spine adhesion, and gecko-like dry adhesion. The HAMR’s performance using these adhesion methods was recorded.

In testing the three methods, the HAMR was programmed to simulate walking on a flat surface. The peak shear force (x-direction) and peak normal force (z-direction) were recorded for each adhesion method. The directional gecko adhesive resulted in the highest average shear force, while the electro-adhesive material resulted in the highest average normal force.

Then, the adhesion methods were tested in a climbing test. Each adhesive was tested for the maximum incline and decline angle for which slipping would not occur. The gecko dry adhesive, h = 100um, resulted in the greatest angle for incline and decline – 22 and 45 degrees, respectively.          

The paper presents an exploration of ways to design locomotion on inclined planes for insect-scale robots. By comparing the performances of the three adhesion methods, the experiment clearly showed why one was more effective than the other. The data and conclusions agree with each other – the gecko dry adhesive had the largest maximum angle without slipping. The data and conclusions address the limitations of certain aspects of the experiment, as well. The micro-spine feet have a limited trajectory, and thus the trajectory must be adjusted to create an adhesive force. This acknowledgement is thorough and provides room for improvement in future experiments. Also, the analysis of the original HAMR and corrections to its mechanics, such as adding the tail, was very important to the overall experiment.


Possible future experiments include using a combination of different adhesives to achieve maximum attachment to inclined surfaces. I would also suggest that future experiments include the same peak/normal force test and climbing test, but with slightly different specifics – for example, alter the h value for the gecko dry adhesive. I found it very interesting and helpful to see an example of hybrid adhesion systems in nature – the Oecophylla smaragdina ant’s foot. This shows that the idea of the insect-scale robot’s hybrid adhesion systems is modeled after something found in the natural world.

Sunday, March 8, 2015

Ardunio Day 2

On our second day of programming with the Arduino Uno, we started off by attaching a Servos motor to the Arduino board. The example program used to control the motor was called Sweep. The circular plate on the motor rotates from 0 to 180 degrees at different speeds, depending on the program. 

The program starts off by indicating that the servo is being used, and that it is named "my servo". Its initial position is at 0 degrees, and it is connected to pin 9. 

Then, a loop is created so that the motor rotates from 0 to 180 degrees, and then back. The speed of the rotation can be controlled by specifying by how large of a step should be taken during the rotation. For example, with the code pos +=2, it will rotate at twice the speed with pos +=1.

The delay(15) is needed to give the motor enough time to reach the desired position.




Next, we attached a potentiometer and an LED light to the Arduino board. The LED was defined as ledPin as an output at pin 7, with an initial setting of LOW -- or off. The potentiometer was attached at A0. 

The goal was to have the blink rate of the LED to depend on the position of the potentiometer. In the loop, the integer val was defined as the analog reading of the potentiometer, whose values go from 0 to 1023. The range of values was scales to 0 to 180. 

The light was turned on and off by digitalWrite. We set the delay of the LED to be val, so that as the potentiometer was turned from 0 to 180, the light would blink more quickly. 


In the Knob program, the servos did not do anything -- we only kept it there because it had been used in the previous program.

The next project involves using Arduino with a photocell. Look forward to posting about that!