Thursday, January 14, 2016

Final Project

The Challenge

For our final project we were allowed to pick between two options for the final. One of these options was to build an autonomous robot that could roam around the room without crashing into anything. The other option was to create a countdown clock using two 7-segment led displays to countdown from 99 to zero. This was the project that my group decided to work on. To our favor the project was a success and the counter successfully counts down from 99 to 00. The catch for this project was that an Arduino does not have enough pins to power two led displays. There are many solutions to this and many other groups just used two arduinos and tried to sync them up manually as best as they could. Our group didn't choose this option because we wanted the counter to be timed perfectly. Unfortunately the other option is to use 2 shift registers which are probably to most confusing thing that you can find in robotics. However we worked through all the problems of figuring out how these shift registers work and finally have a working design.

The Code

https://docs.google.com/document/d/140Ip2d9b16KwwrtQMW2rLL7gNifYij56FjnmomPC-o4/edit?usp=sharing

Code Snippets

int numberone = 72;
int numbertwo = 61;
int numberthree = 109;
int numberfour = 75;
int numberfive = 103;
int numbersix = 119;
int numberseven = 76;
int numbereight = 127;
int numbernine = 79;

int numberzero = 126;

This part of the code shows the decimal values for each number that can be displayed on the 7-segment led displays. This was a challenge because first we had to figure out the binary value for each configuration. Then we had to convert the binary value to a decimal value by hand. This conversion involves a lot of math and a lot of time.

int writenumber(int first,int second){
  digitalWrite(LATCH,LOW);
  shiftOut(DATA,CLOCK,MSBFIRST,first);
  shiftOut(DATA,CLOCK,MSBFIRST,second);

  digitalWrite(LATCH,HIGH);

This piece of code shows the writenumber function that we built specifically for outputting numbers to the 7-segment led display. This function takes our two numbers that we want outputted and converts them to decimal values then binary values and outputs them to the shift register. Finally it will trigger the shift register to output the individual binary values to the led displays.

Future

Unfortunately this is the last project that I will be working on as a part of the robotics class. However that will not stop my future dabbling in the wonderful world of logic and science that is robotics.

Photos


The Clock

https://gfycat.com/DefiniteCloudyHoverfly
Gif of counter functioning (note this is the counter counting up, normally it would count down)

Sunday, December 6, 2015

November Blog post pt. 2

Robot Update and More

This November has been a great month for robotics. The class has worked on a wide variety of things such as addition of a distance sensor and also a motion sensor to the robot. This month we have also worked on projects other than the robot such as fixing a drone and experimenting with motors. The distance sensor we added to the robot was very cool and definitely could be a major part of the robot. However because we wanted the robot to be able to be remote controlled we didn't allow the distance sensor to modify the way that the robot was moving. Other groups did let the robot modify its behavior by making it stop and turn whenever it got too close to an obstacle or something similar to that. The only thing that we let the distance sensor do however was to give us the distance that it was from an object in millimeters. This was a good way to utilize the distance sensor without having to compromise our goal of total control by remote. The motion sensor would also have been cool but it was much too sensitive and didn't really have a plausible use on a robot. Our group also had the time to take a drone that my partner had broken and fix it. One of the motors on the drone was broken and we had to unsolder that motor and solder on a new one for it to be able to work. Fixing something in a mechanical way is always satisfying and it was a good experience putting robotics skill to use in the real world. This month was a very productive month of playing around with electronics to get a feel for what the limits and abilities are in the field of robotics.

Code Snippets

//distance sensor function
int distanceFunction(){
  int distance = 0;
  
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  
  distance = pulseIn(echoPin,HIGH);
  
  Serial.println(distance);
  
  return(distance);

}

Future
In the future what we have done in this month will give me and my group a better understanding of robotics. Much of this course is tinkering until you figure stuff out, or make something cool. As this is an essential part of learning how everything works, it is very important not to forget to relax and mess around with some parts to advance your knowledge. Robotics is a great thing to know and messing around with it helps a lot to be great and times when you can't just mess around.

Thursday, November 19, 2015

November Blog Post

Robot Update

The robot has ben updated again and this time it is has been greatly approved.
The bot now has wide turns. This was a hard challenge to overcome because the common answer to wide turns as opposed to spinning is just to make one wheel spin faster than the other and the robot will gradually turn instead of spinning all at once. The problem with this solution is that the servos that we are working with only spin at one speed. This means that both wheels can only be in 3 modes: forwards, stopped, and backwards. The way we overcame this challenge was to spin on wheel at full speed and to alternate the other wheel between forwards and off. This makes it so that the robot will jerkily move forward and turn at the same time making a circle that is about 1 foot in diameter. But we didn't stop there. Like with the normal turns, where we made it able to turn a certain amount of degrees, we made a precision wide turn function. This function makes you input a degree for the turn and it will make a wide turn that many degrees. If I put in 180 then it would turn all the way around, but it wouldn't spin, it would slowly turn in a wide circle.

Wide turns were the main thing that we added but thats not where we ended. We also rebuilt the bot using cleaner wires so that it doesn't look like so much of a jumbled mess anymore. We also added support for a distance sensor on the front of the robot. What this does is when you ask it will return how far the robot is from whatever is directly in front of it. In the future we will be able to easily make a code where the robot will turn around once it gets too close to something or create an AI that can guide it around objects. Like I said we have already implemented most of the code for the distance sensor but haven't really "turned it on" yet.

Code Snippets

The function that returns a distance
//returns a distance
int distanceFunction(){
  int distance = 0;
  
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  
  distance = pulseIn(echoPin,HIGH);
  
  Serial.println(distance);
  
  return(distance);
}

The part of the wide turn function that alternates the servo mode
if(counter<counterFinal){
      if(evenCounter == 1){
        left.write(180);
        right.write(90);
      }
      else{
        left.write(180);
        right.write(0);
      }
    }


Future
In the future this robot will hopefully be a lot smarter and be able to navigate around objects or avoid certain things. We continue to use more and more different types of robotic parts that will broaden our knowledge about the subject. Implementing a distance sensor will teach me and the entire class more about how different parts work and is sure to help us in our futures of electronics.







Friday, November 6, 2015

October Blog

We've been working on the robots and making them able to have precision steering and lots of other stuff.

Today we worked on the robot a little more and added precision steering and precision distance traveling. With these features you can make the robot turn anywhere between 0 and 360 degrees and with the distance you can put in a distance in feet and the robot will move forward that many feet. This is accomplished with the map function that takes your input of an angle or distance and turns that into milliseconds to make the robot understand how to do things precisely.

The map function translating degrees into milliseconds:

int angleTime = map(angle,0,360,0,3070);

The map function converting distance in feet to milliseconds:

counterFinal = map(distanceForward,0,1,0,2286);

The entire code is available here

Picture:

Projects like this reinforce how robotics can de very precise things in the real world and can solve a ton of problems. Things that I used to make this robot are things that I can use in the future of this class and in life to make cool and effective things using the Arduino.

Friday, October 30, 2015

Robot part 1

For this project we are making a robot that has to satisfy these requirements:

  1. Go forward for 3 seconds
  2. Roam randomly
  3. Precision Steering
  4. Wide turn & Spin
  5. Turn signals

So far we have only completed the first two steps so our Robot can go forward and then stop after three seconds and then can also roam completely randomly.

For the code we have made three functions:
  1. Go forward
  2. Turn right
  3. Turn left

The go forward function:

//go forward function
int goForward(){
  int counter = 0;
  int counterFinal = 3000;
  boolean breakFunction = false;
  
  while(true){
    if(counter<counterFinal){
      left.write(180);
      right.write(0);
    }
    
    if(counter>(counterFinal-1)){
      left.write(90);
      right.write(90);
      break;
      
    }
    counter += 1;
    delay(1);
    
  }
}


The turn right function:
//turn right function
int turnRight(){
  int counter = 0;
  int counterFinal = 3000;
  boolean breakFunction = false;
  
  while(true){
    if(counter<counterFinal){
      left.write(180);
      right.write(90);
    }
    
    if(counter>(counterFinal-1)){
      left.write(90);
      right.write(90);
      break;
      
    }
    counter += 1;
    delay(1);
    
  }
}


The turn left function:
//turn left function
int turnLeft(){
  int counter = 0;
  int counterFinal = 3000;
  boolean breakFunction = false;
  
  while(true){
    if(counter<counterFinal){
      left.write(90);
      right.write(0);
    }
    
    if(counter>(counterFinal-1)){
      left.write(90);
      right.write(90);
      break;
      
    }
    counter += 1;
    delay(1);
    
  }
}


The main loop:
void loop(){
  
  int randomNumber = random(3);
  
  if(randomNumber == 0){
    turnRight();
  }
  if(randomNumber == 1){
    turnLeft();
  }
  if(randomNumber == 2){
    goForward();
  }
  claw.write(0);
  delay(1);
  
}


The main loop chooses one of three numbers: 0, 1, or 2. Depending on which number it picks the robot will do one of three things: turn right, turn left, or go forward. After completing the function it will repeat this endlessly and become a random roaming robot.

Pictures:



Making a robot like this one is a great way to put together all the things that we have learned in robotics and will help me in the future because it is good practice on how to put all these parts together to make something bigger.

Changing pitch with a Potentiometer

For this project we used a Potentiometer to change the pitch that our Piezo was putting out.

We used this code plus the pitches.h code to make the sound:

int playTone = 0;

int tonePin = 8;

int inputPin = A0;

void setup(){
  pinMode(inputPin,INPUT);
  pinMode(tonePin,OUTPUT);
  Serial.begin(9600);
}

void loop(){
  playTone = map(analogRead(inputPin),0,600,60,1500);
  Serial.println(analogRead(inputPin));
  
  
  tone(tonePin,playTone,10);
}

In this code we have an analog input from the potentiometer that gives a value between 0 and 1024. We cut down this number because we were only getting values between 0 and 600. This will make the sound more precise. We then mapped this number between the values 60 and 1500 which is any sound between a very very low rumble to a super high pitched "fly-buzzing" like sound. Then we outputted this to the Piezo and the sound would change whenever we turned the potentiometer.

Pictures:
The Piezo


The Potentiometer

In the future, knowing how to use a Piezo is only really important if you are going to be working with sound or sound processors or the like. Knowing how to use a potentiometer is a very important skill for robotics because it is one of the core parts of robotics.

Learning how to drive a Servo

This Code makes the Servo switch between 2 points in the 180 degree range repeatedly.

#include <Servo.h>

boolean buttonCheck = false;

int buttonTimer = 0;

int servoAmount = 1700;

int valid = LOW;

int pin = 8;

int MAX = 5000;

int MIN = 600;

Servo servo1;

void setup(){
  servo1.attach(2);
  pinMode(pin,INPUT);
}

void loop(){
  
  valid = digitalRead(pin);
  
  if (buttonCheck == false) {
    if (valid == HIGH) {
      
      //turn on the fact that the button is being pushed
      buttonCheck = true;
      
      //switches the variable controlling the position of servo
      if (servoAmount == MAX) {
        servoAmount = MIN;
      }
      else {
        servoAmount = MAX;
      }
    }
  }
  
  //timer for the button check
  if (buttonCheck == true) {
    // should add 1 microsecond to the timer
    buttonTimer = buttonTimer + 1;
    
    //stops the timer once it gets to half a second
    if (buttonTimer == 500) {
      buttonTimer = 0;
      buttonCheck = false;
    }
  }
    
  
  //controls where the servo should be
  //servo should run 1700 to 1200
  servo1.writeMicroseconds(servoAmount);
  
  //delays 1 microsecond
  delay(1);

}

A picture of the Servo that we used:


In the future we can use the code that we used to drive the Servo's to drive speed controllers for motors and also continuous servos. Learning how to drive a Servo is an important skill in robotics.