Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Gripper with push button on: February 23, 2011, 02:11:46 am
Excellent my friend!!! It worked like a charm. One more question. Knowing that it stop quickly, how could I write it so that it squeezes a bit but than stop. I would like it to have a good grip on the object, some sort of the delay after its pressed.
2  Using Arduino / Programming Questions / Re: Gripper with push button on: February 23, 2011, 01:40:33 am
Thank you for the response. I did a ruff sketch to understand it a bit better. I don't know how I would stop the servo if the button is pressed. Can you see if my coding is correct and what would I add to my else statement.
Code:
#include <Servo.h>;
Servo G;    //Gripper
int button;  //Normally opened push button
int grab;

void setup (){
  pinMode(button, 1);
  digitalWrite(button, HIGH);
}

void loop(){
int state_button;
G.attach(5); //Gripper
    
    state_button = digitalRead(button);

    if (state_button == 1)
      {  
        for(grab = 0; grab < 180; grab += 1){           // Open gripper                            
        G.write(grab);
        delay(15);        
        }
      }
     else { }  //how would I write it to stop the servo?      
}
3  Using Arduino / Programming Questions / Gripper with push button on: February 23, 2011, 01:18:23 am
Hello,

I've built an arm with a gripper and I've add a push button on one of the side of the gripper. When the gripper is closing, the push button is press down by the object. How would add this to my code to stop the gripper from crushing my object? Here is my current code for my gripper, it's simple.
Code:
void Armextend()
{
 
  S1.attach(5);
  S1.write(90);
  S2.attach(6);
  S2.write(0);
  E1.attach(9);
  E1.write(0);
  E2.attach(10);
  E2.write(180);
  W.attach(4);
  W.write(50);
  G.attach(3);
 
    for(grab = 0; grab < 180; grab += 1){           // Open gripper                           
        G.write(grab);
        delay(15);       
      }
      delay(1000);  // more code follows after this line
4  Using Arduino / Programming Questions / Re: Continuous Servo, moving slowly on: February 20, 2011, 06:22:17 pm
Would you be able to show me an example using my code
Code:
int RW     =  7;    // right wheel
int LW     =  8;            // left wheel

int minPulse     =  1170;  // maximum servo speed clockwise
int maxPulse     =  1770; // maximum servo speed anticlockwise
int turnRate     =  75;  // servo turn rate increment (larger value, faster rate)
int refreshTime  =  20;   // time (ms) between pulses (50Hz)

/** The Arduino will calculate these values for you **/
int centerServo;         // center servo position
int pulseWidth;          // servo pulse width
int moveServo;           // raw user input
long lastPulse   = 0;    // recorded time (ms) of the last pulse


void setup() {
  pinMode(RW, OUTPUT);  // Set servo pin as an output pin
  pinMode(LW, OUTPUT);
  centerServo = maxPulse - ((maxPulse - minPulse)/2);
  pulseWidth = centerServo;   // Give the servo a stop command

  Serial.begin(115200);
  Serial.println("Arduino Serial Continuous Rotation Servo Control");
  Serial.println("          by Orfeus for GRobot.gr");
  Serial.println("   Press < or > to move, spacebar to center");
  Serial.println();
}

void loop() {
  // wait for serial input
  if (Serial.available() > 0) {
    // read the incoming byte:
    moveServo = Serial.read();

    // ASCII '<' is 44, ASCII '>' is 46 (comma and period, really)
    if (moveServo == 44) {
          pulseWidth = pulseWidth + turnRate;   
        }
       
    if (moveServo == 46) {
          pulseWidth = pulseWidth - turnRate;     
        }
       
    if (moveServo == 32) {
          pulseWidth = centerServo;     
        }

    // stop servo pulse at min and max
   if (pulseWidth > maxPulse) { pulseWidth = maxPulse; }
    if (pulseWidth < minPulse) { pulseWidth = minPulse; }
   


     //print pulseWidth back to the Serial Monitor (comment to undebug)
     Serial.print("Pulse Width: ");
     Serial.print(pulseWidth);
     Serial.println("us");
  }

  // pulse the servo every 20 ms (refreshTime) with current pulseWidth
  // this will hold the servo's rotation and speed till we told it to do something else.
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(RW, HIGH);   // start the pulse
    digitalWrite(LW, HIGH);   // start the pulse
    delayMicroseconds(pulseWidth);  // pulse width
    digitalWrite(RW, LOW);    // stop the pulse   
    digitalWrite(LW, LOW);    // stop the pulse
   
   
    lastPulse = millis();           // save the time of the last pulse
  }
}
5  Using Arduino / Programming Questions / Re: Continuous Servo, moving slowly on: February 20, 2011, 06:15:15 pm
I would like to use the code I have because it works better with my design but I need both servos to rotate together, one clockwise and the other counter clockwise.
6  Using Arduino / Programming Questions / Continuous Servo, moving slowly on: February 20, 2011, 05:21:04 pm
I have two Parallax servo motors as wheels to move a robot. I was researching about the motors and how to slow them down. I understand you cant really control the speed of the servo but I did manage to find a sketch. The sketch uses ONE continuous servo to move slowly, counterclockwise or clockwise. I was very intrigued by this because it just might work for my design. However, I am using two continuous servos. I've tried to manipulate the sketch to work for two servos. Although I managed to make it work, I don't know how manipulate the code so that one servo goes clockwise and the other counterclockwise. Which is why I am seeking help. It will be very helpful if someone can review the code and help me change it so that one servo goes clockwise and the other goes counterclockwise, slowly and at the same time.
Code:
int RW     =  7;    // right wheel
int LW     =  8;            // left wheel

int minPulse     =  1170;  // maximum servo speed clockwise
int maxPulse     =  1770; // maximum servo speed anticlockwise
int turnRate     =  75;  // servo turn rate increment (larger value, faster rate)
int refreshTime  =  20;   // time (ms) between pulses (50Hz)

/** The Arduino will calculate these values for you **/
int centerServo;         // center servo position
int pulseWidth;          // servo pulse width
int moveServo;           // raw user input
long lastPulse   = 0;    // recorded time (ms) of the last pulse


void setup() {
  pinMode(RW, OUTPUT);  // Set servo pin as an output pin
  pinMode(LW, OUTPUT);
  centerServo = maxPulse - ((maxPulse - minPulse)/2);
  pulseWidth = centerServo;   // Give the servo a stop command

  Serial.begin(115200);
  Serial.println("Arduino Serial Continuous Rotation Servo Control");
  Serial.println("          by Orfeus for GRobot.gr");
  Serial.println("   Press < or > to move, spacebar to center");
  Serial.println();
}

void loop() {
  // wait for serial input
  if (Serial.available() > 0) {
    // read the incoming byte:
    moveServo = Serial.read();

    // ASCII '<' is 44, ASCII '>' is 46 (comma and period, really)
    if (moveServo == 44) {
          pulseWidth = pulseWidth + turnRate;    
        }
        
    if (moveServo == 46) {
          pulseWidth = pulseWidth - turnRate;    
        }
        
    if (moveServo == 32) {
          pulseWidth = centerServo;    
        }

    // stop servo pulse at min and max
   if (pulseWidth > maxPulse) { pulseWidth = maxPulse; }
    if (pulseWidth < minPulse) { pulseWidth = minPulse; }
    


     //print pulseWidth back to the Serial Monitor (comment to undebug)
     Serial.print("Pulse Width: ");
     Serial.print(pulseWidth);
     Serial.println("us");
  }

  // pulse the servo every 20 ms (refreshTime) with current pulseWidth
  // this will hold the servo's rotation and speed till we told it to do something else.
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(RW, HIGH);   // start the pulse
    digitalWrite(LW, HIGH);   // start the pulse
    delayMicroseconds(pulseWidth);  // pulse width
    digitalWrite(RW, LOW);    // stop the pulse  
    digitalWrite(LW, LOW);    // stop the pulse
    
    
    lastPulse = millis();           // save the time of the last pulse
  }
}
7  Using Arduino / Programming Questions / when x and d == some value....do this one time. on: February 18, 2011, 07:20:07 pm
When my robot is centered(variable x) to the object, and when my distance is equaled to some amount(variable d). I would like it to drop my arm() function, do it once but redo if variables change. I can add my code but it's a bit long. If anyone wants to look at it, I willing to post it.
8  Using Arduino / Programming Questions / Re: My functions do not operate in order, why? on: February 18, 2011, 07:15:19 pm
I tried your method but it still runs both functions, now it moves forward and tries to pan at the same time.
9  Using Arduino / Programming Questions / Re: My functions do not operate in order, why? on: February 18, 2011, 06:52:51 pm
If I do remove the "move();" and the delay. The robot will pan correctly.
10  Using Arduino / Programming Questions / Re: My functions do not operate in order, why? on: February 18, 2011, 06:46:47 pm
I've also tried to delay but the robot functions very slow. Any delay I add only slows down the robot, plus anything in my function.
11  Using Arduino / Programming Questions / My functions do not operate in order, why? on: February 18, 2011, 06:32:30 pm
Hello, I am having an issue with my code. I have a mobile robot and a webcam to search for an object, the robot centers itself to the object and moves forward to some amount. However, what the codes does is run the functions pan() and move(), at the same time. I would like it to run the pan() for some amount than move() for some other amount. I am not sure where to begin, I've read a few on the millis() and tried it out but it still didn't help. Any help would be appreciated. I posted my loop to show where I would like this to happen.

Code:
void loop()
{
   readNextByte();
    
//============================================================================
// Servo/Motor Control Algorithms
//============================================================================
// Print back parsed data

    if(count == 3)
    {    
       for (int i = 0; i < 3; i++)
       {
          Serial.print(command[i]);Serial.print(var[i]);Serial.print(' ');
       }
              
// Pan servo algorithm
    
       pan();
       move();
   }

}
12  Using Arduino / Programming Questions / Re: Executing a function on: February 17, 2011, 09:09:20 pm
Wow Paul! I don't know what to say, other than Thank You for simplifying my code. It's much better than what I have, but it comes with my amateur title lol.
13  Using Arduino / Programming Questions / Re: Do this...when all this happens...or repeat on: February 17, 2011, 02:56:55 am
Edison,
Thank you for all your references. I will sure to look into that. Thank you for the structure of the code, it's exactly what I was looking for.
14  Using Arduino / Programming Questions / Do this...when all this happens...or repeat on: February 17, 2011, 02:28:57 am
Hello,

I'm going to keep it very short and straight to the point. I'm having trouble on how to write a line of code. This is what I want done when a set of commands are completed and than execute a line of code unless re checking the commands. In other words "do this.... when all this happens....or repeat"
15  Using Arduino / Programming Questions / Executing a function on: February 17, 2011, 01:55:18 am
Hello,

I'm an amateur when it comes down to writing code but currently I'm working on a project and need some advice. I've built a robot with wheels, a webcam for my image processing software(RoboRealm), and I also built an arm for it. The goal is for the robot to find the object, center itself to the object, move a certain distance away (serialread from roborealm), and than execute my function arm to grab the object. Everything works great till I have to execute the arm.

I'm reading the values from roborealm to turn left or right, where ever the object is. Than I have the robot move forward or backwards, I would like it to grab the object here after it completes centering. It should only execute onces unless it needs to re center. I am not sure how or where to write this on my code. I'm asking to understand how to write it and possibly a short example. Thank you, any help is useful.

Here is my line of the void loop where I would like my function called out.
Code:
void loop()
{
  if (Serial.available()){              // Do stuff if serial available
 
//============================================================================
// Data Parsing Algorithm
// RoboRealm serial send sequence:  P[COG_X];D[COG_BOX_SIZE];
//============================================================================

    char ch = Serial.read();
    if(ch >= '0' && ch <= '9'){         // Check if character is a number
        pos = pos * 10 + ch - '0'; // If yes, accumulate the value
        }
         
    else if(ch != ';'){                 // Check for delimiter
command[count] = ch;
pos = 0;
        }
   
    if( ch == ';' ){
        var[count] = pos;
  if(command[0] == 'P'){        //Pan variable
            x = var[0];
            }

          if(command[1] == 'D'){        //Distance(BoxSize) variable
            d = var[1];
            }
           
        count++;
        pos = 0;   
        }     
     
//============================================================================
// Servo/Motor Contol Algorithms
//============================================================================
// Print back parsed data

    if(count == 3){     
          for (int i = 0; i < 3; i++){
              Serial.print(command[i]);Serial.print(var[i]);Serial.print(' ');
              }
             
// Pan servo algorithm
          if(x < (imageX/2 - tolerance) && x != 0){        // If object x is to the left of the y-axis move right
              LW.writeMicroseconds(1600); 
              RW.writeMicroseconds(1600); 
              delay(100);
              LW.writeMicroseconds(1500); 
              RW.writeMicroseconds(1500);
              }
       
          else if(x > (imageX/2 + tolerance) && x != 0){   // If object x is to the right of the y-axis move left
              LW.writeMicroseconds(1400); 
              RW.writeMicroseconds(1400);
              delay(100);
              LW.writeMicroseconds(1500);
              RW.writeMicroseconds(1500);
              }
       
          else if(x == 0){                                 // If object x is not in sight, search by rotating clockwise continuously
              LW.writeMicroseconds(1600); 
              RW.writeMicroseconds(1600); 
              }
       
          else if (d > 90  && d > 110){                    // If distance of object x is greater than 12 inches, move backwards
              LW.writeMicroseconds(1600); 
              RW.writeMicroseconds(1400);
              }
       
          else if (d < 90  && d < 110 ) {                 // If distance of object x is less than 12 inches, move forward
              LW.writeMicroseconds(1400); 
              RW.writeMicroseconds(1600);
              }
             
          else if (d == 0 ) {                 
              LW.writeMicroseconds(1500); 
              RW.writeMicroseconds(1500);
              }                                     
          count = 0;                                       // Reset count to retrieve next data packet         
        }         
        }
}


Pages: [1] 2