Question: #include #include const int MPU _ addr = 0 x 6 8 ; / / I 2 C address of the MPU - 6 0
#include
#include
const int MPUaddrx; IC address of the MPU
intt AcX,AcY,AcZ,TmpGyXGyYGyZ;
float deltat ;
float pitchAcc,rollAcc, pitch, roll, pitched;
float PCompCoeff;
Servo myservo myservo;
void setup
Wire.begin;
Wire.beginTransmissionMPUaddr;
Wire.writexB; PWRMGMT register
Wire.write; set to zero wakes up the MPU
Wire.endTransmissiontrue;
Serial.begin;
myservoattach;
myservoattach;
Serial.begin;
void loop
Wire.beginTransmissionMPUaddr;
Wire.writexB; starting with register xB ACCELXOUTH
Wire.endTransmissionfalse;
Wire.requestFromMPUaddr,true; request a total of registers
AcXWire.readWireread; xB ACCELXOUTH & xCACCELXOUTL
AcYWire.readWireread; xD ACCELYOUTH & xEACCELYOUTL
AcZWire.readWireread; xF ACCELZOUTH & xACCELZOUTL
TmpWire.readWireread; xTEMPOUTH & xTEMPOUTL
GyXWire.readWireread; xGYROXOUTH & xGYROXOUTL
GyYWire.readWireread; xGYROYOUTH & xGYROYOUTL
GyZWire.readWireread; xGYROZOUTH & xGYROZOUTL
Serial.printAcX;
Serial.printt;
Serial.printAcY;
Serial.printt;
Serial.printAcZ;
Serial.printt;
Serial.printGyX;
Serial.printt;
Serial.printGyY;
Serial.printt;
Serial.printlnGyZ;
Complementary filter
long squaresumPlongGyYGyYlongAcYAcY;
long squaresumRlongGyXGyXlongAcXAcX;
pitchAcYfdeltat;
rollAcXfdeltat;
pitchAcc atanAcYsqrtsquaresumPRADTODEG;
rollAcc atanAcXsqrtsquaresumRRADTODEG;
pitch PCompCoeffpitch fPCompCoeffpitchAcc;pitch
PCompCoeffpitch fPCompCoeffpitchAcc;
roll PCompCoeffroll fPCompCoeffrollAcc;
ifstatements to make the roll command go to where it is meant to go
ie clockwisecounterclockwise rotation
if pitch
pitched abspitch ;
pitched pitched ;
else if pitch
pitched abs pitch;
pitched pitched;
locked movement for upward direction of pitch
if pitched
pitched ;
Servo commands, rollpitch nr where nr is compensation for mountingto start horizontally
myservowriteroll ;
myservowritepitched ;
Serial.printroll;
Serial.print;
Serial.printlnpitched;
i have this code for selfstabalizing spoon, but the problem is that our servo which is related to pitching is not responding, also the gyroscope values is constant at but it must changes the angle as the object is shaking so i need anyone to provide a correct code with same connection
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
