Show Posts
|
|
Pages: [1] 2
|
|
2
|
Forum 2005-2010 (read only) / Syntax & Programs / robot with sharp IR
|
on: June 29, 2010, 03:41:10 pm
|
|
hello everybody, I'm building a robot with an arduino, two servos (continuous rotation) for the two wheels, one servo 0-->180 for the head scanning, two leds for the eyes and a speaker to make weird noises ;-) For the moment, it goes forward and when it detects an obstacle, it turns until te way is clear... I'm already happy because I'm beginner, but I'd like to improve it: I'd like it to execute a sequence..like an animation, for example: when it detects an obstacle, I'd like it to stop for two seconds,than head scanning to the right and to the left and and then turn to the clearest way. I paste the code I use Thanx [tr]#include <Servo.h>
#define IR_pin 0
int ledPinR = 11; int ledPinL = 12; int IR_val = 0; Servo myservo_tete; Servo myservo_gauche; Servo myservo_droite;
int speakerPin = 9;
void setup()
{ Serial.begin(9600); pinMode(speakerPin, OUTPUT);
myservo_tete.attach(2); myservo_gauche.attach(3); myservo_droite.attach(4);
pinMode(ledPinR, OUTPUT); pinMode(ledPinL, OUTPUT); }
void loop() { IR_val = analogRead(IR_pin); Serial.println(IR_val); if (IR_val < 250){ myservo_droite.write(50); myservo_gauche.write(130); digitalWrite(ledPinR, HIGH); digitalWrite(ledPinL, HIGH); digitalWrite(speakerPin, LOW); } else { myservo_droite.write(100); myservo_gauche.write(80); digitalWrite(speakerPin, HIGH); digitalWrite(ledPinR, HIGH); digitalWrite(ledPinL, HIGH); delay(IR_val); digitalWrite(ledPinR, LOW); digitalWrite(ledPinL, LOW); delay(IR_val); digitalWrite(speakerPin, LOW);
} } [/tr]
|
|
|
|
|
3
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: servo speed problem
|
on: May 24, 2010, 09:12:33 pm
|
hi, ..so , it works well, but now, I'm wondering if I could have the servo to change its rotation sense immediately when I'm approaching the distance sensor, and not waiting it to reach the end of its movement and also, Awol, you said so here, the traverse takes about 3* 180 milliseconds. I don't understand this calculation, I thought the 180 in the code was about degrees, not about time...? thanx
|
|
|
|
|
5
|
Forum 2005-2010 (read only) / Syntax & Programs / servo speed problem
|
on: May 24, 2010, 03:43:14 pm
|
hello, I'm sure that my problem is really a beginner problem,...but I'm actually a beginner  .. so, I want to control a servo with a sharp IR, I want the servo to turn in a sense if I'm approaching the sensor, and in the other sense if I'm not approaching the sensor... I'm actually able to do it, but I can't control the speed with this code below , I think there is something to do with an increment operator, but I'm not able to do it thank you #include <Servo.h> #define IR_pin 0 Servo myservo1;
int pos = 0;
int IR_val = 0; void setup() { Serial.begin(9600); myservo1.attach(2); }
void loop() { IR_val = analogRead(IR_pin); Serial.println( IR_val); if (IR_val < 200) { myservo1.write(180); delay(30); } if (IR_val > 200) { myservo1.write(0); delay(30); } Serial.println( IR_val); }
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Interfacing / Re: pduino+arduino mega+20 servos
|
on: November 17, 2010, 09:57:18 am
|
|
...and do you know if it's possible to write something to make firmata aware of all the pins, or you think it's not possible to do it? and if it's not possible, do you know a way to control 24 servos with arduino and pure data? two boards synchronized?? :-/ thanx manu
|
|
|
|
|
9
|
Forum 2005-2010 (read only) / Interfacing / pduino+arduino mega+20 servos
|
on: November 16, 2010, 01:19:12 pm
|
hi everybody, Like I said in the subject, I use pure data(pduino) with an arduino mega and I'd like to control +/- 24 servos for a big project, I want to control several robot musicians,here is a video of the work in progress http://www.dailymotion.com/video/xepro5_robot-drummer-work-in-progress-3_creation but I'm just able to control 14 servos, which is not so bad, but unfortunately not enough for my project, the pins that are working are 2,3,4,5,6,7,8,9,10,11,12,13,14 ....but I'm really frustrated when I see the number of pins on the mega board(more than 50..!!) or should I use two duemilanove? if it's the case, is it possible to use pduino with two duemilanove boards?? thanx manu
|
|
|
|
|
10
|
Forum 2005-2010 (read only) / Interfacing / Re: PURE DATA to ARDUINO_2 servos
|
on: August 09, 2010, 08:09:00 am
|
hi, thank you for the response, but I found a simplest way to do what I want with the Simple Message System library. I use this arduino sketch: /* ---- SimpleMessageSystem Example 1 ---- Control Arduino board functions with the following messages: r a -> read analog pins r d -> read digital pins w d [pin] [value] -> write digital pin w a [pin] [value] -> write analog pin Base: Thomas Ouellet Fredericks Additions: Alexandre Quessy */
// Include de SimpleMessageSystem library // REMOVE THE FOLLOWING LINE IF USING WIRING #include <SimpleMessageSystem.h> #include <Servo.h> Servo myservo1; // create servo object to control a servo Servo myservo2; void setup()
{ // The following command initiates the serial port at 9600 baud. Please note this is VERY SLOW!!!!!! // I suggest you use higher speeds in your own code. You can go up to 115200 with the USB version, that's 12x faster Serial.begin(9600); //Baud set at 9600 for compatibility, CHANGE! myservo1.attach(4); myservo2.attach(5);
}
void loop() {
if (messageBuild() > 0) { // Checks to see if the message is complete and erases any previous messages switch (messageGetChar()) { // Gets the first word as a character case 'r': // Read pins (analog or digital) readpins(); // Call the readpins function break; // Break from the switch case 'w': // Write pin writepin(); // Call the writepin function }
}
}
void readpins(){ // Read pins (analog or digital)
switch (messageGetChar()) { // Gets the next word as a character
case 'd': // READ digital pins
messageSendChar('d'); // Echo what is being read for (char i=2;i<14;i++) { messageSendInt(digitalRead(i)); // Read pins 2 to 13 } messageEnd(); // Terminate the message being sent break; // Break from the switch
case 'a': // READ analog pins
messageSendChar('a'); // Echo what is being read for (char i=0;i<6;i++) { messageSendInt(analogRead(i)); // Read pins 0 to 5 } messageEnd(); // Terminate the message being sent
}
}
void writepin() { // Write pin
int pin; int state;
switch (messageGetChar()) { // Gets the next word as a character
case 'a' : // WRITE an analog pin
pin = messageGetInt(); // Gets the next word as an integer state = messageGetInt(); // Gets the next word as an integer pinMode(pin, OUTPUT); //Sets the state of the pin to an output analogWrite(pin, state); //Sets the PWM of the pin break; // Break from the switch
// WRITE a digital pin case 'd' :
pin = messageGetInt(); // Gets the next word as an integer state = messageGetInt(); // Gets the next word as an integer pinMode(pin,OUTPUT); //Sets the state of the pin to an output digitalWrite(pin,state); //Sets the state of the pin HIGH (1) or LOW (0)
}
}
so, with this code and a patch in pure data, I can control each pin separately, but it remains a problem... In pure data, I send for example te message "list w d 4 130", which indicates to my servo connected to the digital pin 4 to write 130°, I can connect a number box or a slider (0-->180) to move the servo, but when I move the slider in PD from 0 to 180, the servo moves from 0 to 180 but when I don't move the slider, the servo goes back to 0°. I hope that my description is clear... :-? I think there is something to add in the arduino sketch...I don't know what...Does somebody know?? thank you manu
|
|
|
|
|
11
|
Forum 2005-2010 (read only) / Interfacing / Re: PURE DATA to ARDUINO_2 servos
|
on: August 06, 2010, 10:13:09 am
|
|
okay,...I really searched the net, but I'm not able to find the solution..I know it's not a pure data forum, but this is the interfacing part of the forum so I retry here... I found something to control two servos on pins 9 and 10, but I'd like to control 4 servos and I'd like to use the command myservo2.write(120); I think I'm close to the solution...I understand I have to send a suite of integers from PD like 20 120 50 80 to control the 4 servos, but I don't know how to build the message in PD and how to decompose it in arduino to give each different value to each different servo. I hope there is a pure data arduino master who could tell me the solution or send me in the good way.. thanx and sorry again if it's not exactly the good place to ask this.. manu
|
|
|
|
|
13
|
Forum 2005-2010 (read only) / Interfacing / Re: PURE DATA to ARDUINO_2 servos
|
on: August 02, 2010, 09:28:15 am
|
thank you, but I knew it was the way to make it work but I don't know how and where to write this... :-/ is it a new object or a new message in PD? or do I have to add something in the object comport 4 9600 ... I told you I was a noob  thanx manu
|
|
|
|
|
14
|
Forum 2005-2010 (read only) / Interfacing / PURE DATA to ARDUINO_2 servos
|
on: August 02, 2010, 08:53:27 am
|
hello everybody, I'd like to control several servos with pure data. For the moment I'm able to control one servo with this simple arduino sketch: #include <Servo.h>
Servo myservo1; int incomingByte = 0; // for incoming serial data
void setup() { Serial.begin(9600); // opens serial port, sets data rate to 9600 bps myservo1.attach(3);
}
void loop() {
// send data only when you receive data: if (Serial.available() > 0) { // read the incoming byte: incomingByte = Serial.read(); myservo1.write(incomingByte); } }
in PD, the patch is a simple HSLIDER 0-->180 linked to the object comport 4 9600I read on the net that to control multiple servos I need to write a communication protocol, ... I'm a noob and don't know how to do this, does anybody know how to? thank you manu
|
|
|
|
|