Go Down

Topic: Interpreting sensor input for robot. (Read 2383 times) previous topic - next topic

Crock101

Mar 02, 2014, 05:23 am Last Edit: Mar 02, 2014, 05:29 am by Crock101 Reason: 1
Hello, I am currently trying to make a robot that will follow me by using a HiTechnic inferred LED beacon and a HiTechnic Ir seeker sensor. What I want it to do is if the beacon is in sectors 1 thru 4 the robot would turn left until it's in sector 5, and if the beacon in sectors 6 thru 9 the robot would turn right till it's in sector 2, and if it's in sector 2 it does nothing except detect if I am farther than 2 ft using a Parallax Ultrasonic distance sensor, and if I am it will move forward until I am no longer farther than 2 ft. I need help with making my Arduino Uno Board interpret these sensors recorded values so that i can use them in If-Then-Else statements that tell the motors what to do. Can anyone help me?

References/Research:

http://www.usfirst.org/sites/default/files/uploadedFiles/Robotics_Programs/FTC/FTC_Documents/Using_the_IR_Seeker.pdf

http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=HBK2100

http://learn.parallax.com/KickStart/28015

http://blog.birkb.eu/hitechnic-infrared-seeker-library-for-arduino/

retronet_RIMBA1ZO

are you sure this sensor can be connected to the Arduino and not just the NXT brick ?
how does the connector look like ?

Crock101

I would use the cable that comes with the sensor to connect it to the Arduino. The cable has 6 wires inside it, White, Black, Red, Green, Yellow, and Blue. White goes to a battery +9V (Vcc), Black goes to Arduino GND, Red goes to battery - (GND), Green goes to Arduino +3.3V (Vcc), Yellow goes to Arduino SCL, and Blue goes to Arduino SDA.

Click this link for more info:

http://blog.birkb.eu/hitechnic-infrared-seeker-library-for-arduino/


retronet_RIMBA1ZO

that means you are using the I2C connection to the Arduino; SDA = pin 4, SCL = pin 5 .

have you already tried connecting all these and just trying to read the raw data FROM the sensor and display it to the Serial Monitor in Arduino ?

Crock101

What i want to know is do I need any special code to interpret the data coming from this sensor, and if so what is it? What I want is  the directional data to output a number between 1 and 9 representing each of the sectors.

Click this for more info:

http://www.usfirst.org/sites/default/files/uploadedFiles/Robotics_Programs/FTC/FTC_Documents/Using_the_IR_Seeker.pdf

retronet_RIMBA1ZO


Click this for more info:

http://www.usfirst.org/sites/default/files/uploadedFiles/Robotics_Programs/FTC/FTC_Documents/Using_the_IR_Seeker.pdf

it is of no use to me.
just glancing at it, it seems like code specific to output on the NXT brick - don't expect to use that code on the Arduino.



What i want to know is do I need any special code to interpret the data coming from this sensor, and if so what is it? What I want is  the directional data to output a number between 1 and 9 representing each of the sectors.

i guess the answer is 'Yes' - you will need actual Arduino code.

have you tried writing any yet ?

what have you already done with the Arduino ?

AGAIN;
Quote
have you already tried connecting all these and just trying to read the raw data FROM the sensor and display it to the Serial Monitor in Arduino ?

Crock101

I've done a bit of programing with the arduino but nothing too advanced, if I could have the arduino tell me what values the sensor is outputting while it's happening, that would go a long way twords helping me complete this project. What I have so far is the commands telling the motors what to do, i just need the data from the sensors to active them. I'll try some test runs without the interpretation code and see what happens. In the mean time don't be afraid to post anything you might find helpful on this topic.

Crock101

Never mind I found this website that says the sensor already outputs a value from 0 to 9(for each sector). Now I just need to know if the arduino will be able to use this code to pick up on only the Ir beacon and not just any source of Ir light.

void initializeRobot()
{
HTIRS2setDSPMode(irSeeker, DSP_1200);// FTC beacons are 1200Hz emitters
return;
}

I'll test it myself, but if anyone knows how or if this needs to be adapted please post a reply.

Here is the website:
http://ftcforum.usfirst.org/archive/index.php/t-1337.html

retronet_RIMBA1ZO


I've done a bit of programing with the arduino but nothing too advanced,
nothing wrong with that

if I could have the arduino tell me what values the sensor is outputting while it's happening, that would go a long way twords helping me complete this project.

some people would give you the code served on a platter and you can be on your way in the project immediately, but i would prefer to give you the tools and show you how to do it yourself.

What I have so far is the commands telling the motors what to do, i just need the data from the sensors to active them.

okay, telling motors what to do is simple enough, what you need to learn about is Serial communication - ie. getting the data from a sensor connected to the Arduino. (in your case, the sensor is sending the data to the Arduino via I2C (which is an even more advanced version of Serial communication - so let's take it slowly and learn the basic Serial communication first)
have a look at this page; http://arduino.cc/en/Reference/Serial
if that seems a bit much to learn, try this tutorial from SparkFun;
https://learn.sparkfun.com/tutorials/serial-communication/serial-intro


I'll try some test runs without the interpretation code and see what happens. In the mean time don't be afraid to post anything you might find helpful on this topic.

i think it's you that shouldn't be afraid to try something.


Never mind I found this website that says the sensor already outputs a value from 0 to 9(for each sector).

"already outputs a value from 0 to 9" - but to where ? using which code ?
i am guessing that website is informative for using the NXT brick - you are using the Arduino now, those resources might not be particularly helpful.

Now I just need to know if the arduino will be able to use this code to pick up on only the Ir beacon and not just any source of Ir light.

void initializeRobot()
{
HTIRS2setDSPMode(irSeeker, DSP_1200);// FTC beacons are 1200Hz emitters
return;
}

chances are it won't - that's a code snippet - if you don't already have the definition of HTIRS2setDSPMode() there is NO WAY the Arduino is going to understand what to do.


I'll test it myself, but if anyone knows how or if this needs to be adapted please post a reply.

Here is the website:
http://ftcforum.usfirst.org/archive/index.php/t-1337.html

i don't think that website is of any use to you, it looks like it's for some totally different platform to the Arduino - i'm a newbie myself and i don't know what all this
Code: [Select]
#pragma stuff is about.

you need to learn to use the Arduino using the Arduino environment, or the "IDE" - the basic starting page is;
http://arduino.cc/en/Reference/HomePage

what other sensors do you have that you could start experimenting with ?
if you want to get a quick jump to see how Serial communication works, you can always use the Serial Monitor which is available in the Arduino IDE (icon in the top-right corner); use the code here; http://arduino.cc/en/Serial/Read

Crock101

Will the Library i found earlier help me with this?

retronet_RIMBA1ZO


Will the Library i found earlier help me with this?

Help you with 'what' ?
That library 'does it all' for you !
You're looking for help WITH the library - that is pretty advanced, even beyond my level.
You're choosing quite a complicated project to start with if you don't know the basics of Serial & I2C communications.

If you take the time to learn those, you should be able to interpret that sensor WITHOUT the complicated library.

Crock101

So based on the info you sent me the first thing i need to do is use this code:

int incomingByte = 0;   // for incoming serial data

void setup() {
        Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
}

void loop() {

        // send data only when you receive data:
        if (Serial.available() > 0) {
                // read the incoming byte:
                incomingByte = Serial.read();

                // say what you got:
                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
}
to find out what bytes of data are being sent to the arduino from the sensor. I can then assign values to those bytes of data, and then use those values in the commands for my motors to make the robot follow me around. Correct?

retronet_RIMBA1ZO

yes, correct - now we move forward !
don't forget to use the CODE tags (#) when you post code.

if you open your Serial Monitor - you can actually send those bytes manually via your keyboard, that way you can test your code to run the motors already - let's say type 'w' moves the robot forward, 's'= backwards, 'a' & 'd' = left & right respectively.

after you've got that code running smoothly and able to command your robot the way you want and it moves as you expect, then we insert code to ask the sensor to provide "those bytes" automatically.

in other words, in the above code - instead of just :
Code: [Select]
Serial.println(incomingByte, DEC);
you can add;
Code: [Select]
if (incomingByte == 'w')
{
   << insert your code to move the robot forwards here >>
}

you could leave the Serial.println() in there just to confirm what keys are being pressed.

Crock101

What do you think of my code so far?
Code: [Select]
int incomingByte = 0;
int LeftF= 1;
int RightF= 2;
int LeftB= 3;
int RightB= 4;
const int pingPin = 7;
void setup()
{
  pinMode(RightF,OUTPUT);
  pinMode(LeftF,OUTPUT);
  pinMode(LeftB,OUTPUT);
  pinMode(RightB,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
        if (Serial.available() > 0) {
                incomingByte = Serial.read();

                Serial.print("I received: ");
                Serial.println(incomingByte, DEC);
        }
{
  long duration, inches, cm;
  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);
  cm = microsecondsToCentimeters(duration);

  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();

  delay(100);
}

long microsecondsToInches(long microseconds);
{
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds);
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
{
If (incomingByte = 97) Then;
digitalWrite(RightF,HIGH);
digitalWrite(LeftB,HIGH);
EndiIf;

If (incomingByte = 100) Then;
digitalWrite(LeftF,HIGH);
digitalWrite(RightB,HIGH);
EndIf;

If (incomingByte = 119) Then;
digitalWrite(LeftF,HIGH);
digitalWrite(RightF,HIGH);
EndIf;

If (incomingByte = 0) Then;
digitalWrite(LeftB,HIGH);
digitalWrite(RightF,HIGH);
EndIf;

If (incomingByte = 115) Then;
digitalWrite(LeftB,HIGH);
digitalWrite(RightB,HIGH);
EndIf;
}
}


For some reason it dosn't like this line of code when i try to upload it.
Code: [Select]
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);


it says that microsecondsToInches was not declared in the scope and I don't know how it wants me to declare it.

I got the code from here:

http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor

retronet_RIMBA1ZO


What do you think of my code so far?
...
...

not too bad i guess, but take a look at your If...Then section, it shouldn't be down there, and the syntax isn't quite correct, have a look at http://arduino.cc/en/Reference/If for how Arduino uses the If...Then conditional statement


For some reason it dosn't like this line of code when i try to upload it.
Code: [Select]
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);


it says that microsecondsToInches was not declared in the scope and I don't know how it wants me to declare it.

i'm not sure about that one, i'll try it out and get back to you.


I got the code from here:

http://arduino.cc/en/Tutorial/Ping?from=Tutorial.UltrasoundSensor

yes, well, that's for an entirely different sensor altogether, if it's not connected to the Arduino and you're asking it to read a non-existent sensor - it makes no sense.

step back a bit and just control the robot with the keyboard via your Serial Monitor - at least you seem to be on the right track there, but DO CHANGE the ;
Code: [Select]
If (incomingByte = 100)
to
Code: [Select]
if (incomingByte == 100)
there is a big difference in meaning; the first is assigning values, the second is comparing values - read here for the details;
http://arduino.cc/en/Reference/Assignment
vs.
http://arduino.cc/en/Reference/If
if there's anything in there you don't understand - ASK !

Go Up