Show Posts
|
|
Pages: 1 2 [3]
|
|
31
|
Topics / Robotics / Re: Robot control using top camera image analysis?
|
on: January 01, 2013, 08:30:04 am
|
|
What kind of track is it? Is it an open area or a sort of maze? Because you're idea is not that easy to realize. If it's a maze or something like that, then its easier to use a ultrasonic sensor or a line-follower.
I really have no skills in programming MATLAB, C++ and OpenCV so i cant help you with that. But i follow you're project because it's sounds interesting!
Good Luck!
|
|
|
|
|
33
|
Topics / Robotics / Re: The car not moving, but motor speed is set to max
|
on: October 17, 2012, 02:18:52 am
|
|
Just upload a sketch that only turn on/off the motor's. It seems like you have not enough power to let te motors spin. How do you feed the motor(shield)? I hope not via the 5v of the arduino because that pin doesn't have enough current.
|
|
|
|
|
35
|
Using Arduino / LEDs and Multiplexing / Re: 3x3x3 LedCube; shorten POV code
|
on: February 22, 2012, 05:33:36 am
|
Without a good explanation, it will be hard to help. It also depends on how you have you multiplexing set up.
The 9 columns are the anodes of the leds. The 3 levels have a common cathode and can be turn on/off with transistors so i can use HIGH an LOW to control them. Are you trying to light an outside square on one level then shift it up and down?
No, i try to explain: - Front down 3 leds, the 3 horizontal in the middle and the back-top 3 leds. - The middle 9 vertical leds. - Back down 3 leds, the 3 horizontal in the middle and the front-top 3 leds. - The middele 9 horizontal leds. Something like this: / ->|-> \ -> -- I didn't use shift-registers, but i think that i'm gonna use them next time. Because i can use binary numbers to set the colums/levels HIGH and LOW. This is so much more easy than the tons of digitalwrite-lines that i have to use now.
|
|
|
|
|
36
|
Using Arduino / LEDs and Multiplexing / 3x3x3 LedCube; shorten POV code
|
on: February 20, 2012, 03:38:15 pm
|
Hi all, I've build a 3x3x3 led cube with the multiplexing technique so i only have 13 pins to control it. So far so good. I use the next code to scroll the horizontal rows up and down (i don't know how to explain is clearly) // Scripted by Stealth0113 (stealthaerox@gmail.com)
//declare the pins for the 3x3x3 Ledcube int colpins[] = {29,30,31,32,33,34,35,36,37}; //ColumnPins int lvlpins[] = {11,12,13}; //LevelPins int count;
void setup() { for (count=0;count<9;count++) { pinMode(colpins[count], OUTPUT); // Set al the columns as output digitalWrite(colpins[count], LOW);} //ensure that they are low for (count=0;count<4;count++) { pinMode(lvlpins[count], OUTPUT); // Set al the levels as output digitalWrite(lvlpins[count], LOW);} //ensure that they are low }
void loop() { for (int i=0; i<10; i++){ digitalWrite(11, HIGH); digitalWrite(29, HIGH); digitalWrite(30, HIGH); digitalWrite(31, HIGH); delay(5); digitalWrite(11, LOW); digitalWrite(29, LOW); digitalWrite(30, LOW); digitalWrite(31, LOW); digitalWrite(13, HIGH); digitalWrite(35, HIGH); digitalWrite(36, HIGH); digitalWrite(37, HIGH); delay(5); digitalWrite(13, LOW); digitalWrite(35, LOW); digitalWrite(36, LOW); digitalWrite(37, LOW); delay(5); } for (int i=0; i<10; i++){ digitalWrite(11, HIGH); digitalWrite(13, HIGH); digitalWrite(32, HIGH); digitalWrite(33, HIGH); digitalWrite(34, HIGH); delay(5); digitalWrite(11, LOW); digitalWrite(13, LOW); digitalWrite(32, LOW); digitalWrite(33, LOW); digitalWrite(34, LOW); delay(5); } for (int i=0; i<10; i++){ digitalWrite(13, HIGH); digitalWrite(29, HIGH); digitalWrite(30, HIGH); digitalWrite(31, HIGH); delay(5); digitalWrite(13, LOW); digitalWrite(29, LOW); digitalWrite(30, LOW); digitalWrite(31, LOW); digitalWrite(11, HIGH); digitalWrite(35, HIGH); digitalWrite(36, HIGH); digitalWrite(37, HIGH); delay(5); digitalWrite(11, LOW); digitalWrite(35, LOW); digitalWrite(36, LOW); digitalWrite(37, LOW); delay(5); } for (int i=0; i<10; i++){ digitalWrite(12, HIGH); digitalWrite(29, HIGH); digitalWrite(30, HIGH); digitalWrite(31, HIGH); digitalWrite(35, HIGH); digitalWrite(36, HIGH); digitalWrite(37, HIGH); delay(5); digitalWrite(12, LOW); digitalWrite(29, LOW); digitalWrite(30, LOW); digitalWrite(31, LOW); digitalWrite(35, LOW); digitalWrite(36, LOW); digitalWrite(37, LOW); delay(5); } }
As you can see the code is not very short for such a simple thing. I've seen that some people use hex or binary code's to control leds on rotating led strips. I think this is the best way to manage the leds on my cube, but i don't know how to apply it on my cube.
|
|
|
|
|
38
|
Using Arduino / Programming Questions / Re: Compare diffrent measurements.
|
on: December 17, 2011, 04:22:11 am
|
|
@ryschwith: i don't fully understand your code. The "for" loop is clear to me, but the "if" string looks like gibberish to me...
Can you explain to me why furthest < 2 stands for 45 or 90 degrees??
And why did you use the light45 = false and light135 = false? I don't see it back anywhere in the code
|
|
|
|
|
40
|
Using Arduino / Programming Questions / Compare diffrent measurements.
|
on: December 16, 2011, 04:56:18 am
|
I've got an HC-SR04 Ultrasonic range detector mounted on a servo. It rotate, scan and store 3 values (45, 90 and 135 degrees) Now i want that it can compare the 3 values to choose the longest distance. I used an if..else loop to let is choose but is there any way that works better. Because now it compares 45 with 90 and 135 with 90 degrees. But if the first string (45>90) is true, it won't check (135>90). Here's my sketch: void loop() { myservo.write(45); delay(1000); int microsec45 = ultrasonic.timing(); Serial.print("MS45: "); Serial.print(microsec45); myservo.write(90); delay(1000); int microsec90 = ultrasonic.timing(); Serial.print("MS90: "); Serial.print(microsec90); myservo.write(135); delay(1000); int microsec135 = ultrasonic.timing(); Serial.print("MS135: "); Serial.print(microsec135); for(pos = 135; pos>=45; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } if (microsec45 > microsec90) { digitalWrite(ledpin43, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(ledpin43, LOW); // set the LED off } else if (microsec135 > microsec90) { digitalWrite(ledpin13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(ledpin13, LOW); // set the LED off } else { digitalWrite(ledpin13, HIGH); // set the LED on digitalWrite(ledpin43, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(ledpin13, LOW); // set the LED off digitalWrite(ledpin43, LOW); // set the LED off }
I used the 2 led pins on my Uno32 in stead of dc motors, to make it move visible what choices it makes.
|
|
|
|
|
42
|
Topics / Robotics / Re: How to avoid obstacle with 2x IR
|
on: November 13, 2011, 11:01:59 am
|
This is wat i've already got for now... #include <Servo.h>
Servo leftServo; Servo rightServo;
//define pins. #define irLedPinLeft 30 // IR Led on this pin #define irSensorPinLeft 29 // IR sensor on this pin #define irLedPinRight 4 // IR Led on this pin #define irSensorPinRight 3 // IR Sensor on this pin
void setup() { tone(5, 440, 1000); pinMode(irSensorPinLeft, INPUT); pinMode(irLedPinLeft, OUTPUT); pinMode(irSensorPinRight, INPUT); pinMode(irLedPinRight, OUTPUT); /*Serial.begin(9600); // prints title with ending line break Serial.println("Program Starting"); // wait for the long string to be sent delay(100);*/ }
void loop() { /* Serial.println(irReadLeft(irSensorPinLeft, irLedPinLeft)); //display the results Serial.println(irReadRight(irSensorPinRight, irLedPinRight)); //display the results delay(10); //wait for the string to be sent*/ int pulseleft; int pulseright; int (irReadLeft(irSensorPinLeft, irLedPinLeft)); int (irReadRight(irSensorPinRight, irLedPinRight)); if (irReadLeft == 0 and irReadRight == 0) { //Backup pulseleft = 1400; pulseright = 1600; } else if (irReadLeft == 0) { //turn right pulseleft = 1400; pulseright = 1400; } else if (irReadRight == 0) { //turn left pulseleft = 1600; pulseright = 1600; } else { pulseleft = 1600; pulseleft = 1400; } { leftServo.attach(9); leftServo.writeMicroseconds(pulseleft); rightServo.attach(8); rightServo.writeMicroseconds(pulseright); } }
int irReadLeft(int readPinLeft, int triggerPinLeft) { int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond int i; for (i=0; i <=cycles; i++) { digitalWrite(triggerPinLeft, HIGH); delayMicroseconds(halfPeriod); digitalWrite(triggerPinLeft, LOW); delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead } return digitalRead(readPinLeft); }
int irReadRight(int readPinRight, int triggerPinRight) { int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond int i; for (i=0; i <=cycles; i++) { digitalWrite(triggerPinRight, HIGH); delayMicroseconds(halfPeriod); digitalWrite(triggerPinRight, LOW); delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead } return digitalRead(readPinRight); } But de if...else string doesn't get any data. The serial.printin shows the data on the serial monitor and the ir sensors seem to respond well. But it wont reach the if...else string. My robot turns only left for some reason... Any help?
|
|
|
|
|
43
|
Topics / Robotics / Re: How to avoid obstacle with 2x IR
|
on: November 13, 2011, 03:36:05 am
|
I've changed the code so i get "irReadLeft" and "irReadRight". But my sketch is very long to do only this job. Is there any way to shorten this?? //define pins. I used pins 4 and 5 #define irLedPinLeft 30 // IR Led on this pin #define irSensorPinLeft 29 // IR sensor on this pin #define irLedPinRight 4 // IR Led on this pin #define irSensorPinRight 3 // IR Sensor on this pin
//int irRead(int readPin, int triggerPin); //function prototype
void setup() { pinMode(irSensorPinLeft, INPUT); pinMode(irLedPinLeft, OUTPUT); pinMode(irSensorPinRight, INPUT); pinMode(irLedPinRight, OUTPUT); Serial.begin(9600); // prints title with ending line break Serial.println("Program Starting"); // wait for the long string to be sent delay(100); }
void loop() { Serial.println(irReadLeft(irSensorPinLeft, irLedPinLeft)); //display the results Serial.println(irReadRight(irSensorPinRight, irLedPinRight)); //display the results delay(10); //wait for the string to be sent }
/****************************************************************************** * This function can be used with a panasonic pna4602m ir sensor * it returns a zero if something is detected by the sensor, and a 1 otherwise * The function bit bangs a 38.5khZ waveform to an IR led connected to the * triggerPin for 1 millisecond, and then reads the IR sensor pin to see if * the reflected IR has been detected ******************************************************************************/ int irReadLeft(int readPinLeft, int triggerPinLeft) { int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond int i; for (i=0; i <=cycles; i++) { digitalWrite(triggerPinLeft, HIGH); delayMicroseconds(halfPeriod); digitalWrite(triggerPinLeft, LOW); delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead } return digitalRead(readPinLeft); }
int irReadRight(int readPinRight, int triggerPinRight) { int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond int i; for (i=0; i <=cycles; i++) { digitalWrite(triggerPinRight, HIGH); delayMicroseconds(halfPeriod); digitalWrite(triggerPinRight, LOW); delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead } return digitalRead(readPinRight); }
|
|
|
|
|
44
|
Using Arduino / Sensors / Re: hscr 04 not working with mega?
|
on: November 09, 2011, 03:34:50 pm
|
i've got the same ultrasonic sensor, and got it working on an Chipkit Uno32 with this code. /* Ping))) Sensor This sketch reads a PING))) ultrasonic rangefinder and returns the distance to the closest object in range. To do this, it sends a pulse to the sensor to initiate a reading, then listens for a pulse to return. The length of the returning pulse is proportional to the distance of the object from the sensor. The circuit: * +V connection of the PING))) attached to +5V * GND connection of the PING))) attached to ground * SIG connection of the PING))) attached to digital pin 6 * Echo connection of the PING))) attached to digital pin 7
http://www.arduino.cc/en/Tutorial/Ping created 3 Nov 2008 by David A. Mellis modified 30 Jun 2009 by Tom Igoe This example code is in the public domain.
*/
// this constant won't change. It's the pin number // of the sensor's output: const int pingPinIn = 7; const int pingPinOut = 6;
void setup() { // initialize serial communication: Serial.begin(9600); }
void loop() { // establish variables for duration of the ping, // and the distance result in inches and centimeters: long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPinIn, OUTPUT); digitalWrite(pingPinIn, LOW); delayMicroseconds(2); digitalWrite(pingPinIn, HIGH); delayMicroseconds(5); digitalWrite(pingPinIn, LOW);
// The same pin is used to read the signal from the PING))): a HIGH // pulse whose duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(pingPinOut, INPUT); duration = pulseIn(pingPinOut, HIGH);
// convert the time into a distance inches = microsecondsToInches(duration); cm = microsecondsToCentimeters(duration); Serial.print(duration); Serial.print("time, "); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); }
long microsecondsToInches(long microseconds) { // According to Parallax's datasheet for the PING))), there are // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per // second). This gives the distance travelled by the ping, outbound // and return, so we divide by 2 to get the distance of the obstacle. // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf 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; }
i'll hope this will work for you. You can find the wiring i used on the top of the code.
|
|
|
|
|
45
|
Topics / Robotics / How to avoid obstacle with 2x IR
|
on: November 09, 2011, 03:19:14 pm
|
I've got a Arduino Uno with a Ping sensor and 2 InfraRed sensors on the left and right front of my robot. I want it to drive autonomous and avoiding objects with Ping (works already), but i want IR as backup system. i've already the code for detecting objects with IR but i can't get them work together, so i can't detect left and right. This is what i already got. //define pins. #define irLedPinLeft 30 // IR Led on this pin #define irSensorPinLeft 29 // IR sensor on this pin #define irLedPinRight 4 // IR Led on this pin #define irSensorPinRight 3 // IR Sensor on this pin
int irRead(int readPin, int triggerPin); //function prototype
void setup() { pinMode(irSensorPinLeft, INPUT); pinMode(irLedPinLeft, OUTPUT); pinMode(irSensorPinRight, INPUT); pinMode(irLedPinRight, OUTPUT); Serial.begin(9600); // prints title with ending line break Serial.println("Program Starting"); // wait for the long string to be sent delay(100); }
void loop() { Serial.println(irRead(irSensorPinLeft, irLedPinLeft)); //display the results Serial.println(irRead(irSensorPinRight, irLedPinRight)); //display the results delay(10); //wait for the string to be sent }
/****************************************************************************** * This function can be used with a panasonic pna4602m ir sensor * it returns a zero if something is detected by the sensor, and a 1 otherwise * The function bit bangs a 38.5khZ waveform to an IR led connected to the * triggerPin for 1 millisecond, and then reads the IR sensor pin to see if * the reflected IR has been detected ******************************************************************************/ int irRead(int readPin, int triggerPin) { int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond int i; for (i=0; i <=cycles; i++) { digitalWrite(triggerPin, HIGH); delayMicroseconds(halfPeriod); digitalWrite(triggerPin, LOW); delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead } return digitalRead(readPin); }
What i want is a "irDetectLeft" and a "irDetectRight" so i can use a if..else loop to turn left on a irDetectRight, and turn right on a irDetectLeft.
|
|
|
|
|