Go Down

Topic: [SOLVED]Six servos robot arm homing function going very slow (Read 573 times) previous topic - next topic

Redneck

Hi all, i am trying to make a 6DOF robot arm.
So far so good, I got all the servos to do what I want, but this function attached doesn't work as expected; The motors should returns to 90° when I press the button, and they do, but painfully slow...

I cutted the sketch to include just this function for the sake of readability; Please note that the other function (not attached) works the same by incrementing the angle of a servo by one degree every millisecond given the corresponding button is pressed.
While that one works good and with the right timing, this one moves like 2 degree every second.

Any help appreciated,
Thanks in advance!

Code: [Select]

Servo joints[7];
const byte homeAngles[7] = {0, 90, 90, 90, 90, 90, 90};
byte jointAngles[7] = {0, 90, 90, 90, 90, 90, 90};
byte resetAxis = 1;
void loop() {
   if(homeButtonStatus == HIGH) {
     resetPosition();
   }
}
void resetPosition() {
 if (jointAngles[resetAxis] != homeAngles[resetAxis]) {
   if (jointAngles[resetAxis] < homeAngles[resetAxis]) {
     joints[resetAxis].write(jointAngles[resetAxis]++);
     resetAxis++;
   } else {
     joints[resetAxis].write(jointAngles[resetAxis]--);
     resetAxis++;
   }
 } else {
   resetAxis++;
 }
 if (resetAxis == 7) {
   resetAxis = 1;
 }


Edit: It was slow because of too many lcd prints.

GrooveFlotilla

Your code doesn't compile, so it is hard to comment on how it should perform.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Redneck

Your code doesn't compile, so it is hard to comment on how it should perform.
You're right, i only included the troubled part...

Please, try the sketch i just attached!

PaulS

Code: [Select]
  for (int i = 1 ; i < 7 ; i++) {
    int minPulse;
    int maxPulse;
    switch (i) {
      case 1:
      minPulse = 740;
      maxPulse = 2350;
      break;
      case 2:
      minPulse = 690;
      maxPulse = 2320;
      break;
      case 3:
      minPulse = 710;
      maxPulse = 2310;
      break;
      case 4:
      minPulse = 620;
      maxPulse = 2230;
      break;
      case 5:
      minPulse = 525;
      maxPulse = 2450;
      break;
      case 6:
      minPulse = 625;
      maxPulse = 2655;
      break;
    }
    joints[i].attach(i+1, minPulse, maxPulse);

Why do you use a for loop when every iteration does something different?

Comment out all that writing to the LCD. Does your program speed up?
The art of getting good answers lies in asking good questions.

Redneck

Why do you use a for loop when every iteration does something different?
I used the for loop to assign the servos to their pins, then later added the switch to change the pulse length... Guess it could be just written straight, thanks for the input!

Comment out all that writing to the LCD. Does your program speed up?
Commenting that worked! But why does it clog the execution so bad? The other function does just the same... I wonder why.

Thanks a lot, i would have never figure it out!

Isaac96

You could try a I2C LCD backpack which would be much quicker. The LCD is only able to handle so much clock speed, and I2C is exponentially faster. The backpack is just another microcontroller which handles the actual writing to the LCD.
Do not PM me for help. I will delete immediately.
CONNECT THE GROUNDS!

After Tuesday, even the calendar goes W T F

GrooveFlotilla

Quote
You could try a I2C LCD backpack which would be much quicker. The LCD is only able to handle so much clock speed, and I2C is exponentially faster
Except when you use an I/O extender I2C LCD in four bit mode, which could be much slower than a parallel eight bit mode LCD.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Redneck

You could try a I2C LCD backpack which would be much quicker. The LCD is only able to handle so much clock speed, and I2C is exponentially faster. The backpack is just another microcontroller which handles the actual writing to the LCD.
I'm already using it, it's a life saver! Don't know if it's in 4bit though

Go Up