Remove square root from magnitude calculation on accel_gyro.c
Motors start now at 990 instead of 1000 to prevent glitches
This commit is contained in:
parent
8bd9dc986d
commit
3eeb4d3741
@ -245,6 +245,8 @@ bool mpu6000_init(gyro_t* gyro, accel_t* accel)
|
|||||||
|
|
||||||
HAL_Delay(60);
|
HAL_Delay(60);
|
||||||
|
|
||||||
|
accel->pitchAngle = 0;
|
||||||
|
accel->rollAngle = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -558,14 +560,15 @@ void mpu6000_read_angle(accel_t* accel, gyro_t* gyro)
|
|||||||
accel->accelZconv = smooth[2] * smooth[2] * sign[2];
|
accel->accelZconv = smooth[2] * smooth[2] * sign[2];
|
||||||
|
|
||||||
/* The total magnitude of the acceleration */
|
/* The total magnitude of the acceleration */
|
||||||
float magnitude = sqrtf( \
|
float magnitude = ( \
|
||||||
ABS_FLOAT(accel->accelXconv) * ABS_FLOAT(accel->accelXconv) + \
|
ABS_FLOAT(accel->accelXconv) * ABS_FLOAT(accel->accelXconv) + \
|
||||||
ABS_FLOAT(accel->accelYconv) * ABS_FLOAT(accel->accelYconv) + \
|
ABS_FLOAT(accel->accelYconv) * ABS_FLOAT(accel->accelYconv) + \
|
||||||
ABS_FLOAT(accel->accelZconv) * ABS_FLOAT(accel->accelZconv) \
|
ABS_FLOAT(accel->accelZconv) * ABS_FLOAT(accel->accelZconv) \
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Everything is normal. No outer forces */
|
/* Everything is normal. No outer forces */
|
||||||
if (0.85 < magnitude && magnitude < 1.15)
|
if (0.81 < magnitude && magnitude < 1.21)
|
||||||
|
//if (false)
|
||||||
{
|
{
|
||||||
// Roll
|
// Roll
|
||||||
accel->rollAngle = -atan2(accel->accelXconv, sqrt(accel->accelYconv*accel->accelYconv + accel->accelZconv*accel->accelZconv))*180/M_PI;
|
accel->rollAngle = -atan2(accel->accelXconv, sqrt(accel->accelYconv*accel->accelYconv + accel->accelZconv*accel->accelZconv))*180/M_PI;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "drivers/motors.h"
|
#include "drivers/motors.h"
|
||||||
#include "drivers/failsafe_toggles.h"
|
#include "drivers/failsafe_toggles.h"
|
||||||
#include "config/eeprom.h"
|
#include "config/eeprom.h"
|
||||||
|
#include "drivers/motormix.h"
|
||||||
|
|
||||||
const int MotorPWMPeriode = 2000; //Micro seconds
|
const int MotorPWMPeriode = 2000; //Micro seconds
|
||||||
const int MotorPWMInitPulse = 1000;
|
const int MotorPWMInitPulse = 1000;
|
||||||
@ -162,7 +163,11 @@ void pwmEnableMotor(uint8_t motor, motorOutput motorOutput)
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
void pwmEnableAllMotors(motorOutput motorOutput)
|
void pwmEnableAllMotors(motorOutput motorOutput)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 1; i < 11; i++ ) pwmEnableMotor(i, motorOutput);
|
for (uint8_t i = 1; i < 11; i++ )
|
||||||
|
{
|
||||||
|
pwmEnableMotor(i, motorOutput);
|
||||||
|
pwmAdjustSpeedOfMotor(i,mixerConfig.minCommand);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
Reference in New Issue
Block a user