Servos going crazy connected to MPU6050.

First thing first, sorry but I'm an extreme noob when it comes to C coding, this is my first Arduino project, so I would really appreciate if you guys could elaborate on solutions and suggestions.

Hi, I am building a robotic 5 servos hand as a college project, and having a bit of trouble. My
project counsler found an MPU6050 code ( trying to write one ourselves was a complete failure, and looking at the code he found, it is obvious why, I'll link it below ) that I have added a bit of setup to make the servos work and obey all the angles and axis. It worked ( most of the time ) like a charm as seen in this link, but then annoying stuff started to happen. My biggest problem was that instead of starting to move or await orders, one of the servos would spas, make a rotation to one of the ends, and try to move further, making grinding and buzzing sounds which are pretty alarming. It's weird because it would'nt always happen.

My project counsler suggested it could be a timing issue in the program, that me adding code to it is breaking the balance.

Another problem would be that the servo would spin to the "current angle" of the MPU, making the same buzzing sound and sometime ignoring the rest of the servos until I would move the MPU to an angle that the servo accepts, I guess? I would have to rotate the MPU on the table.

I have checked the servos and replaced one of them, but it didn't solve the problem.

My question are:

  1. Is there a way to make the current angle the MPU the starting angle ( 0 or 90 degrees )?
  2. Is there a way to prevent the servo from going to grind mode ( code just won't let it )?
  3. If it really is a timing issue in the MPU code, how can I fix it?

Thank you for your time.

I am attaching the code to the message, It goes over the charcter limit here.

ThreeAxis.ino (36.2 KB)

Just a guess, but, disable the servos until you wakeup and calibrate the MPU-6050. Also check the limits of your PID variables.

How are you powering everything?
Servos must be powered separately from the Arduino, by a power supply capable of one ampere per active servo.

123Splat:
Just a guess, but, disable the servos until you wakeup and calibrate the MPU-6050. Also check the limits of your PID variables.

I have no way of knowing if the MPU is calibrated or not, but I am powering the arduino and MPU through a battery that is only connected to the engines by the ground and communication pins, so the MPU is always powered before the servos.

I am powering the servos with a big power supplier - every one of them is getting at least 1 Amp. What is PID?

jremington:
How are you powering everything?
Servos must be powered separately from the Arduino, by a power supply capable of one ampere per active servo.

The Arduino and MPU are powered by a portable battery, and the servos are powered by a big power suppleir that supports each servo with at least 1 Amp, and is connected to the Arduino by a common ground.

A quick glance through the program suggests that it is blindly ordering the servos to move anywhere in the range of 0-180 degrees. Most servos can't do that. You have to know their limits and obey them. Also, what values of gyro_angle_z do you observe?

  int angle_xi= ((int) angle_x) + 90; // convert angle_x float -90 +90 to int 0 to 180
  int angle_yi= ((int) angle_y) + 90; // convert angle_y float -90 +90 to int 0 to 180
  int angle_zi = ((int) gyro_angle_z);  //Accelerometer doesn't give z-angle

  Serial.println(angle_zi);
  
  myservo1.write(angle_xi);
  myservo2.write(angle_yi);
  myservo3.write(angle_zi);

jremington:
A quick glance through the program suggests that it is blindly ordering the servos to move anywhere in the range of 0-180 degrees. Most servos can't do that. You have to know their limits and obey them. Also, what values of gyro_angle_z do you observe?

  int angle_xi= ((int) angle_x) + 90; // convert angle_x float -90 +90 to int 0 to 180

int angle_yi= ((int) angle_y) + 90; // convert angle_y float -90 +90 to int 0 to 180
  int angle_zi = ((int) gyro_angle_z);  //Accelerometer doesn't give z-angle

Serial.println(angle_zi);
 
  myservo1.write(angle_xi);
  myservo2.write(angle_yi);
  myservo3.write(angle_zi);

Tested the servos both by hand and mechanically, then can reach around 200 degrees around, so we absolutely tried to obey these rules. Z is the main pain, Z represents Azimuth ( Yaw I think? ). I think I recall seeing that Z was dependant on the position of the MPU at the time, so it could be from 0 to 359.

Is this piece of code edited or taken from the code? sorry for the silly question.

I think I recall seeing that Z was dependant on the position of the MPU at the time, so it could be from 0 to 359.

Do you think that is not a problem for the servo?

jremington:
Do you think that is not a problem for the servo?

I do, man, that's why I'm asking for help, because I'm not sure how to handle this.. no need to attack or doubt my mental capacity.

I am attaching the code to the message, It goes over the charcter limit here.

Then perhaps you should make smaller test code for a single servo to trouble shoot the issue. If the servos mechanically operate within the servo mechanical bounds when tested with simple 0-180 deg commands, then the problem is most likely malformed/out of bounds control pulses, inadequate power supply, or perhaps poor or inadequate grounding between the servo power supply and the arduino. You might try disconnecting all the servos except the one having problems, then try your setup. If the servo acts like it should, then the power supply might be the issue.

zoomkat:
Then perhaps you should make smaller test code for a single servo to trouble shoot the issue. If the servos mechanically operate within the servo mechanical bounds when tested with simple 0-180 deg commands, then the problem is most likely malformed/out of bounds control pulses, inadequate power supply, or perhaps poor or inadequate grounding between the servo power supply and the arduino. You might try disconnecting all the servos except the one having problems, then try your setup. If the servo acts like it should, then the power supply might be the issue.

Problem is the thing operating the servos is 10 lines out of that whole code. This whole code is suposed to be calibaration and such.

Bump?

Please, I assume the core of my problem is that when the MPU is activated, it probably signals its current position in the Z ( rotational ) axis and it might be the cause for the servo going nuts. I need a way to make sure that no matter the case, the servo won't try going beyond 180 degrees ( grinds and buzzes ). I need the MPU to start and 0 degrees no matter when I swich it on and no matter where it faces. Even if it seems like a really dumb question and has a simple solution, my college project depends on it. Thanks.

I think I recall seeing that Z was dependant on the position of the MPU at the time, so it could be from 0 to 359.

If this is still the case, you need to add code to make sure that the servo is never driven beyond its limits.

Did you bother to read the product description manual for the MPU?

Have you bothered to google PID?

The MPU doesn't tell the servos what to do, Your code does/should, after looking at some things (like what the MPU says....)

Hmmm, that might be a good place to implement PID, ya' think?

"I'm not sure how to handle this.. no need to attack or doubt my mental capacity." no indication that anybody doubts your mental capacity, just your willingness to do your own research.

123Splat:
Did you bother to read the product description manual for the MPU?

Have you bothered to google PID?

The MPU doesn't tell the servos what to do, Your code does/should, after looking at some things (like what the MPU says....)

There was no manual. I googled around and tried to figure out how to run this piece of tech in all sorts in situation. I've come here in my guides' advice. I know the MPU is hardware, but I still need the code for it to suit my needs. I don't know what PID is.

Look, I get it that you know more than me, you got your daily confidence boost from calling someone an idiot or lazy in a forum that is up to help people who need help with projects, some of them have little to NO knowlege or anything above a very, very basic level. So please let people who have the will to at least try and help instead of being a stuck up commenter.

jremington:
If this is still the case, you need to add code to make sure that the servo is never driven beyond its limits.

I am not sure how this works.

Either you do not know how to spell "Google", or "MPU-6050", or they do not have google or webcrawler on your planet, or ,,, you are "an idiot or lazy" (your choice, you said it, not me).
Google is spelled G O O G L E
once there, look up:

  1. PID
  2. MPU-6000/MPU-6050 Product Specification
  3. MPU-6000/MPU-6050 Register Map and Descriptions

In spite of the way you act, I do not think you are an idiot (yet). I do, however think that you are lazy, so get off your arse and do your own research and try to actually earn the credit for your project.

RM-MPU-6000A.pdf (827 KB)

With zero progress in 13 days between posts, I vote for "lazy".

J,

If I may be so informal,,

Give the boy a break. Let's not rule out idiot, until all the evidence is in.