Thursday, April 2, 2015

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.




1 comment:

  1. Nice job making a clear and concise blog post! My partners and I also had trouble getting our sciborg to travel in a straight line. At first we went straight to trying to correct it through coding, but just as you did, we realized that the problem could be greatly reduced (although not eliminated) by making sure to tighten and realign the wheels of the sciborg. We are finding now that we have to correct it often, and that sometimes correcting it physically means that the code no longer makes it go straight. The struggle is very real!

    ReplyDelete