Show Posts
Pages: [1] 2 3 ... 5
1  Topics / Robotics / Re: need some help with code on: September 01, 2013, 06:12:24 pm
oh my i feel like an idiot went back through my wiring and found a loose ground it works now
2  Topics / Robotics / Re: need some help with code on: August 30, 2013, 09:27:58 pm
uh oh i think something broke i went to test it out again to show some buddies and for some reason my right servo does not stop when the danger thresh hold is met the rest of the parts do what they are supposed to

Code:
#include<Servo.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // lcd screen pins
const int pingPin = 4; //declares the ping pin
const int irPin = 0;  //Sharp infrared sensor pin
const int RForward = 0; //full speed forward
const int RBackward = 180; //full speed reverse
const int LForward = RBackward; //this decides the motor control
const int LBackward = RForward; //this decides the motor control
const int RNeutral = 90; //nuetral for motors
const int LNeutral = 90; //constants for motor speed
const int dangerThresh = 5; //threshold for obstacles (in cm)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;  //this is the "neck" of the robot
Servo leftMotor; //declare left servo motor
Servo rightMotor; //declare right servo motor
long duration; //time it takes to recieve PING))) signal

void setup()
{
  Serial.begin(9600); //allows for serial monitoring
  lcd.begin(16, 2); //turn on the lcd screen
  lcd.print("Hello Jason");
  delay(250);
  lcd.clear();
  lcd.print("Activating KITT");
  delay(250);
  lcd.clear();
  rightMotor.attach(5); //attach left servo motor to proper pin
  leftMotor.attach(6); //attach right servo motor to proper pin
  panMotor.attach(3); //attach pan servo motor to proper pin
  panMotor.write(90); //center the "neck" of the robot
  delay(50);
  lcd.print("KITT Online");
  delay(250);
  lcd.clear();
 
}


void loop()
{
   
  int distanceFwd = ping(); //tells the robot distance forward
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward);
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);
    rightMotor.write(RNeutral); //stop forward motion
    panMotor.write(0);
    delay(100);
    rightDistance = ping(); //scan to the right
    delay(100);
    panMotor.write(180);
    delay(100);
    leftDistance = ping(); //scan to the left
    delay(100);
    panMotor.write(90); //return to center
    delay(100);
    compareDistance();
  }
}
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward);
    rightMotor.write(RForward); //turn left
    delay(100);
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn right
    delay(100);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn 180 degrees
    delay(100);
  }
}
long ping()
{
  long duration, inches;
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  inches = microsecondsToInches(duration);
  lcd.print(inches);
  lcd.print("in to obstacle");
  delay(100);
  lcd.clear(); 
  delay(100);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.println(); // this is for serial monitoring of the ping signal
  return inches;
}
long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

3  Topics / Robotics / Re: About Sharp distance Sensor on: August 30, 2013, 03:47:33 pm
http://www.adafruit.com/products/164 found the first one you posted at adafruit
4  Topics / Robotics / Re: Wheel Placement on Robot on: August 30, 2013, 01:35:35 pm
weight wise best placement of the load is in the center
5  Topics / Robotics / Re: need some help with code on: August 29, 2013, 07:46:10 pm
from what ive read both beaglebone and raspberry pi will integrate with an arduino
6  Topics / Robotics / Re: need some help with code on: August 29, 2013, 12:33:13 pm
well if the yun has better processing than the beaglebone black ill think about it
7  Topics / Robotics / Re: Fast and cheap robot vision sensor on: August 28, 2013, 08:50:35 pm
that would rock to
8  Topics / Robotics / Re: Wheel Placement on Robot on: August 28, 2013, 08:29:11 pm
than possibly not sure if you have the access to scrap wood or not but you might want to make a couple of wood platforms with those dimensions and test different mounting positions for the wheels that way when you found a place that works with the radius you want you will have the measurements and everything (yes i learn a lot by trial and error)
9  Topics / Robotics / Re: Wheel Placement on Robot on: August 28, 2013, 08:06:58 pm
but in that case you might just need a motor for each side of the robot
10  Topics / Robotics / Re: Wheel Placement on Robot on: August 28, 2013, 08:05:36 pm
in my opinion i would say have the wheels near the corners with the transmission in the dead center of the robot if you want to keep the turning radius in the center
11  Topics / Robotics / Re: Wheel Placement on Robot on: August 28, 2013, 07:31:59 pm
are you using a servo or motor on each wheel?
12  Topics / Robotics / Re: need some help with code on: August 28, 2013, 06:59:03 pm
so far my robot is working well next step is to build a chassis and then eventually add more sensors possibly even that new pixy cam that i saw on kickstarter and a beaglebone or raspberry pi for wireless transmission of video and data
13  Topics / Robotics / Re: Sensors on: August 28, 2013, 01:24:09 pm
i think the board hes asking about is the ardupilot but thats a custom made arduino clone just for quadcopter drones
14  Topics / Robotics / Re: need some help with code on: August 28, 2013, 12:39:31 pm
i will think about that but it all depends on whether or not the sensors and stuff i want to add will work with it
15  Topics / Robotics / Re: need some help with code on: August 27, 2013, 02:36:24 pm
ok so at some point in the future i want to add more sensors to my robot but i am out of pins how would i break this code down so i could use two arduinos via I2C with one running the sensors and the other running just the servos

Code:
#include<Servo.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // lcd screen pins
const int pingPin = 4; //declares the ping pin
const int irPin = 0;  //Sharp infrared sensor pin
const int RForward = 0; //full speed forward
const int RBackward = 180; //full speed reverse
const int LForward = RBackward; //this decides the motor control
const int LBackward = RForward; //this decides the motor control
const int RNeutral = 90; //nuetral for motors
const int LNeutral = 90; //constants for motor speed
const int dangerThresh = 5; //threshold for obstacles (in cm)
int leftDistance, rightDistance; //distances on either side
Servo panMotor;  //this is the "neck" of the robot
Servo leftMotor; //declare left servo motor
Servo rightMotor; //declare right servo motor
long duration; //time it takes to recieve PING))) signal

void setup()
{
  Serial.begin(9600); //allows for serial monitoring
  lcd.begin(16, 2); //turn on the lcd screen
  lcd.print("Hello Jason");
  delay(250);
  lcd.clear();
  lcd.print("Activating KITT");
  delay(250);
  lcd.clear();
  rightMotor.attach(5); //attach left servo motor to proper pin
  leftMotor.attach(6); //attach right servo motor to proper pin
  panMotor.attach(3); //attach pan servo motor to proper pin
  panMotor.write(90); //center the "neck" of the robot
  delay(50);
  lcd.print("KITT Online");
  delay(250);
  lcd.clear();
 
}


void loop()
{
   
  int distanceFwd = ping(); //tells the robot distance forward
  if (distanceFwd>dangerThresh) //if path is clear
  {
    leftMotor.write(LForward);
    rightMotor.write(RForward); //move forward
  }
  else //if path is blocked
  {
    leftMotor.write(LNeutral);
    rightMotor.write(RNeutral); //stop forward motion
    panMotor.write(0);
    delay(100);
    rightDistance = ping(); //scan to the right
    delay(100);
    panMotor.write(180);
    delay(100);
    leftDistance = ping(); //scan to the left
    delay(100);
    panMotor.write(90); //return to center
    delay(100);
    compareDistance();
  }
}
void compareDistance()
{
  if (leftDistance>rightDistance) //if left is less obstructed
  {
    leftMotor.write(LBackward);
    rightMotor.write(RForward); //turn left
    delay(100);
  }
  else if (rightDistance>leftDistance) //if right is less obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn right
    delay(100);
  }
   else //if they are equally obstructed
  {
    leftMotor.write(LForward);
    rightMotor.write(RBackward); //turn 180 degrees
    delay(100);
  }
}
long ping()
{
  long duration, inches;
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  inches = microsecondsToInches(duration);
  lcd.print(inches);
  lcd.print("in to obstacle");
  delay(100);
  lcd.clear(); 
  delay(100);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.println(); // this is for serial monitoring of the ping signal
  return inches;
}
long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

Pages: [1] 2 3 ... 5