Please Help!

I am building a robot for my senior project. I have one of those Ping sensors that i want to connect to the robot but I cant figure out how to make the motors run in conjunction with the ping. i broke the scanning into thirds so that it would be easier to work with here is what i mean:

calibrate sensor

  • setmotors to forward
    -set head to left (00)
    scan from left to right 1/3(1800)=600
    hit something?
    (turn right)
    -otherwise keep going
  • scan from left to right 2/3(1800)=1200
    hit something?
    (Turn left)
    etc.

if anyone has any idea of how to put this into code please let me know or if you have a better way please shar it with me. i am using the tamiya double gearbox with 2 DC motors in it.

hey am not good at code but can hopefully point you in some right directions, i have a ping into an arduino and is working fine here is some code that outputs values from 0 127 to the serial port, I think all you need to do is send the ultrasound value back out of the arduino into what ever pin you have your thing connected to so for instance 0 would be - 180 and 127 would be +180 so would go round in a circle maybe, hope this helps

/* New Variables */
int delay_time = 20; // delay for this amount each write cycle. 
byte printing_byte = 0;




/* Ultrasound Sensor
 *------------------
 *
 * Reads values (00014-01199) from an ultrasound sensor (3m sensor)
 * and writes the values to the serialport.
 *
 * http://www.xlab.se | http://www.0j0.org
 * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
 *
 */
 
 // CODE EDITED BY SEBASTIAN TOMCZAK 23 APRIL 2008

int ultraSoundSignal = 7; // Ultrasound signal pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int ledPin = 13; // LED connected to digital pin 13

void setup() {
  beginSerial(9600);                  // Sets the baud rate to 9600
  pinMode(ledPin, OUTPUT);            // Sets the digital pin as output
}

void loop() {
  timecount = 0;
  val = 0;
  pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output

  /* Send low-high-low pulse to activate the trigger pulse of the sensor
   * -------------------------------------------------------------------
   */

  digitalWrite(ultraSoundSignal, LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignal, LOW); // Holdoff

  /* Listening for echo pulse
   * -------------------------------------------------------------------
   */

  pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
  val = digitalRead(ultraSoundSignal); // Append signal value to val
  while(val == LOW) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
  }

  while(val == HIGH) { // Loop until pin reads a high value
    val = digitalRead(ultraSoundSignal);
    timecount = timecount +1;            // Count echo pulse time
  }

  /* Writing out values to the serial port
   * -------------------------------------------------------------------
   */

  ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue

  /* BEGIN EDITED CODE */

  ultrasoundValue = ultrasoundValue - 14; 
  ultrasoundValue = ultrasoundValue / 5;

  if(ultrasoundValue > 127) {
  }
  
  else {
  
  printing_byte = ultrasoundValue;
  Serial.print(printing_byte);
  }
  /* END EDITED CODE */



  /* Lite up LED if any value is passed by the echo pulse
   * -------------------------------------------------------------------
   */

  if(timecount > 0){
    digitalWrite(ledPin, HIGH);
  }

  /* Delay of program
   * -------------------------------------------------------------------
   */

  delay(40);
}

yes that helps a lot but do you know how I can interface it with the motors that I have? I am not very familliar with programming yet and honestly, I have no idea as to what I am doing =(

A good idea in situations like this is to think in "blocks of functionality".

Split your problem up in managable subproblems and try to create generalised functions for them, and then call the functions from your main loop.

For instance you might (this is only an example it's maybe not practical in your case) create a function that takes an angle as a parameter and then in that function move the ping sensor to that angle and do a "scan" and return a value indicating an obstacle.

I don't really know anything about the Ping sensor and building bots so i can't be more specific.

I have no ideas about this stuff either and it is literally the blind leading the blind, but the learning and reference pages have helped me a lot and when you don't understand something then come on here i'll have a look for you if you tell me the specific motors, i'll help you as much as i can or help you ask the right questions!

I belive that I have the Tamiya 980112M Mabuchi FA-130 Motors that were included with the double gearbox.

A good idea in situations like this is to think in "blocks of functionality".

Split your problem up in managable subproblems and try to create generalised functions for them, and then call the functions from your main loop.

For instance you might (this is only an example it's maybe not practical in your case) create a function that takes an angle as a parameter and then in that function move the ping sensor to that angle and do a "scan" and return a value indicating an obstacle.

thats what I was trying to do when I broke it up into thirds I knew that it would be a lot simpler to handle that way

i've had a look online and can't find an already made bit of code so i can't analyse how the motor works witht he duino, if you have a bit stick it up here and i'll give it a try. My assumptions based on what you have said is you want the motor to control where the sensor is pointed - you could make a routine that tells the motor to turn round 360 degrees every 5 seconds, the ping would turn round with it telling you whether an object is in the way, but this is still quite impractical. what i am trying to do at the moment with the help from the genii on here is sett up 3 pings so in essence you could if you then applied a triangulation algorithm get the exact placement of the object in space then you can use the data to tell the robot what to do over time using if functions! hope this elps

"thats what I was trying to do when I broke it up into thirds I knew that it would be a lot simpler to handle that way"

I don't think that is what he is trying to say -
give us an explanation of the little jobs you want to do; then try and fit them into a greater scheme of things so to say!
say for instance:
read a sensor
move a motor
read a different sensor
move a different motor

What I am looking for my robot to do is very simple for right now. All I want it to do is move around on it's own and aviod things with the sensor. I only have one sensor. So in essence I want it to read the sensor and move the motors accordingly. I can provide pictures of what my robot looks like right now (it's all build it just needs to programmed) if that will help you figure it out.

no that doesn't really help me sorry. if you had any code that could help me it would be perfect otherwise i'd just be making it for you from scratch, and i haven't got the same equipment or set up so wouldn't know if it even worked. I come from a music perspective and am lost with robot stuff but have read about servo stuff and think that's what people in this community use to do things, like move a motor - what specifically do you want your robot to do is it remote controlled or do you want it to move untill i cant then change direction - just wonder round aimlessly!

Sry I don't Really have any code that I could give you. I really wanted it to wander around aimlessly. I wasn't going to use a remote control or anything. if it just went in a straight line, detected something, avoided it, and continued in a straight line, that would be great and thats all i need. even if your code doesn't work, that would be fine it would give me something to work off of and I would be able to toy around with it until I got it to work. Thanks so much for all of your help!

Go to the parallax site and look at some of the code in the boebot book and see the logic they use. I built a boebot with a ping and my strategy was to look forward, move forward and check forward until something is 12 inches away then stop, look left and right and move off in the direction most open and repeat. Once you get this done you then have to work on what to do if you get stuck in a corner and other imbelishments.