1
Fork 0

Compare commits

..

No commits in common. "86549f30935d0ac31a6f30bb6dee73e1e10fb79f" and "9483d84ad5d32b281103aa82951925070b4ceae7" have entirely different histories.

5 changed files with 11 additions and 30 deletions

View file

@ -29,7 +29,7 @@ LSM6::LSM6(void)
bool LSM6::checkForNewData(void) bool LSM6::checkForNewData(void)
{ {
bool retVal = false; bool retVal = false;
if(getStatus() & 0x02) if(getStatus() & 0x01)
{ {
read(); read();
@ -228,7 +228,7 @@ void LSM6::enableDefault(void)
{ {
// Set the gyro full scale and data rate // Set the gyro full scale and data rate
setFullScaleGyro(GYRO_FS245); setFullScaleGyro(GYRO_FS245);
setGyroDataOutputRate(ODR104); setGyroDataOutputRate(ODR13);
// Set the accelerometer full scale and data rate // Set the accelerometer full scale and data rate
setFullScaleAcc(ACC_FS2); setFullScaleAcc(ACC_FS2);

View file

@ -141,12 +141,6 @@ public:
vector<float> updateGyroBias(void) vector<float> updateGyroBias(void)
{ {
if (initialMeasurement) {
gyroBias.z = g.z;
initialMeasurement = false;
}
float retain = (0.98);
gyroBias.z = g.z * (1- retain) + gyroBias.z * retain;
/** /**
* TODO: add a low-pass filter to update the bias * TODO: add a low-pass filter to update the bias
*/ */
@ -175,7 +169,6 @@ public:
// float estimatedPitchAngle = 0; // float estimatedPitchAngle = 0;
// vector<float> eulerAngles; // vector<float> eulerAngles;
vector<float> gyroBias; vector<float> gyroBias;
bool initialMeasurement = true;
/* We make Robot a friend to avoid all the setters and getters. */ /* We make Robot a friend to avoid all the setters and getters. */
friend class Robot; friend class Robot;

View file

@ -25,10 +25,10 @@ protected:
enum CTRL_MODE : uint8_t {CTRL_DIRECT, CTRL_SPEED}; enum CTRL_MODE : uint8_t {CTRL_DIRECT, CTRL_SPEED};
volatile CTRL_MODE ctrlMode = CTRL_DIRECT; volatile CTRL_MODE ctrlMode = CTRL_DIRECT;
float Kp = 6.00; // proportional to error float Kp = 2.50; // proportional to error
float Ki = 0.05; float Ki = 0.03;
float Kd = 0; float Kd = 0;
float Kf = 4.50; // proportional to setpoint float Kf = 3.00; // proportional to setpoint
int16_t C = 22; // constant added to effort int16_t C = 22; // constant added to effort
// Used to keep track of the target speed, in counts / interval. // Used to keep track of the target speed, in counts / interval.

View file

@ -76,16 +76,16 @@ void Robot::HandleKeyCode(int16_t keyCode)
switch(keyCode) switch(keyCode)
{ {
case UP_ARROW: case UP_ARROW:
chassis.SetTwist(15, 0); chassis.SetTwist(5, 0);
break; break;
case RIGHT_ARROW: case RIGHT_ARROW:
chassis.SetTwist(0, -1.25); chassis.SetTwist(0, -0.25);
break; break;
case DOWN_ARROW: case DOWN_ARROW:
chassis.SetTwist(-15, 0); chassis.SetTwist(-5, 0);
break; break;
case LEFT_ARROW: case LEFT_ARROW:
chassis.SetTwist(0, 1.25); chassis.SetTwist(0, 0.25);
break; break;
case ENTER_SAVE: case ENTER_SAVE:
chassis.SetTwist(0, 0); chassis.SetTwist(0, 0);

View file

@ -1,6 +1,5 @@
#include "robot.h" #include "robot.h"
#include <IRdecoder.h> #include <IRdecoder.h>
#include <limits.h>
void Robot::InitializeRobot(void) void Robot::InitializeRobot(void)
{ {
@ -80,22 +79,11 @@ void Robot::HandleOrientationUpdate(void)
else // update orientation else // update orientation
{ {
float z_rot = ((float)imu.g.z - imu.gyroBias.z) / (float) INT_MAX; // TODO: update the orientation
z_rot /= 104;
z_rot *= 245;
eulerAngles.z += z_rot;
} }
#ifdef __IMU_DEBUG__ #ifdef __IMU_DEBUG__
Serial.print(imu.gyroBias.z); Serial.println(eulerAngles.z);
Serial.print('\t');
Serial.print(eulerAngles.z);
Serial.print('\t');
//Serial.print(imu.g.x);
//Serial.print('\t');
//Serial.print(imu.g.y);
//Serial.print('\t');
Serial.println(imu.g.z);
#endif #endif
} }