Latest version offers newer settings that auto calibrate the "at rest" state of BB8 when powering up.
These new settings allow less tweaking to my code when adapting it to your build.
https://github.com/jlvandusen/SHADOWBB8
Code changes below to getPOT and getMPU
void getMPU()
{
if (isMPUENABLED)
{
float timeStep = 0.01;
if (!isMPUCheck)
{
Vector norm = mpu.readNormalizeGyro(); // Read normalized values
pitch = pitch + norm.YAxis * timeStep; // Calculate Pitch
roll = roll + norm.XAxis * timeStep; // Calculate Roll
startpitch = pitch + norm.YAxis * timeStep; // Store Initial pitch
startroll = roll + norm.XAxis * timeStep; // Store Initial roll
#ifdef SHADOW_DEBUG_MPU
output += "\tPitch: ";
output += pitch;
output += "\tStartPitch: ";
output += startpitch;
output += "\tRoll: ";
output += roll;
output += "\tStartRoll: ";
output += startroll;
#endif
isMPUCheck = true;
}
else
{
// if (PS3Nav->PS3Connected || PS3Nav->PS3NavigationConnected)
// {
unsigned long currentmpuMillis = millis(); // grab current time
if ((unsigned long)(currentmpuMillis - previousmpuMillis) >= mpuinterval) // check if "interval" time has passed (1000 milliseconds)
{
// float timeStep = 0.01; // commented and move to beginning
Vector norm = mpu.readNormalizeGyro(); // Read normalized values
pitch = pitch + norm.YAxis * timeStep; // Calculate Pitch
roll = roll + norm.XAxis * timeStep; // Calculate Roll
yaw = yaw + norm.ZAxis * timeStep; // Calculate yaw
// Output raw
#ifdef SHADOW_DEBUG_MPU
output += "\tPitch: ";
output += pitch;
output += "\tStartPitch: ";
output += startpitch;
output += "\tRoll: ";
output += roll;
output += "\tStartRoll: ";
output += startroll;
#endif
previousmpuMillis = ((timeStep*1000) - (millis() - timer)); // Wait to full timeStep period
}
// }
// else return;
}
}
}
// =======================================================================================
// getPOT test data verify its working
// =======================================================================================
void getPOT()
{
if (!isPotCheck)
{
startpot = analogRead(A0); // read initial trousers pot and set as center point
if (startpot > 512)
{
potdeviation = startpot - 512;
}
else potdeviation = 512 - startpot;
#ifdef SHADOW_DEBUG_POT
output += "\tstartpot: ";
output += startpot;
output += "\tpotdeviation: ";
output += potdeviation;
#endif
isPotCheck = true;
}
else
{
// if (PS3Nav->PS3Connected || PS3Nav->PS3NavigationConnected)
// {
pot = analogRead(A0); // read trousers pot
if (startpot > 512)
{
pot = pot-potdeviation;
}
else
{ pot = pot+potdeviation;
}
#ifdef SHADOW_DEBUG_POT
output += "\tPOT: ";
output += pot;
output += "\tpotdeviation: ";
output += potdeviation;
#endif
// }
// else return;
}
}
https://github.com/jlvandusen/SHADOWBB8
No comments:
Post a Comment