Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/robomaster.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 40 additions & 16 deletions ut-robomaster/src/subsystems/odometry/observer_displacement.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "subsystems/odometry/observer_displacement.hpp"

#include "tap/architecture/clock.hpp"

/*
* Notes:
* https://gitlab.com/aruw/controls/aruw-mcb/-/tree/develop/aruw-mcb-project/src/aruwsrc/algorithms/odometry?ref_type=heads
* */

namespace subsystems::odometry
{

Expand All @@ -20,7 +27,23 @@ bool ChassisDisplacementObserver::getVelocityChassisDisplacement(
modm::Vector3f* const velocity,
modm::Vector3f* const displacement) const
{
bmi088::Bmi088* imu = &drivers->bmi088;
uint32_t currTime = tap::arch::clock::getTimeMicroseconds();
if (prevTime != 0)
{
modm::Vector3f myv = chassis->measureVelocity();
velocity->set(myv.x, myv.y, myv.z);

// velocity.set(chassisRelVel.x, chassisRelVel.y);

// displacement->move(tickDisp);
float deltaT = (static_cast<float>(currTime - prevTime)) / 1'000'000.0f;
modm::Vector3f myDisp = myv * deltaT;
displacement->set(myDisp.x, myDisp.y, myDisp.z);
// displacement += velocity * (static_cast<float>(currTime - prevTime) / 1'000'000.0f);
}

prevTime = currTime;
// bmi088::Bmi088* imu = &drivers->bmi088;

// Attempt integration with Velocity Verlet
// a(t) = last acceleration, a(t + dt) = current acceleration
Expand All @@ -29,25 +52,26 @@ bool ChassisDisplacementObserver::getVelocityChassisDisplacement(

// TODO: Depending on when this subsystem gets initialized,
// the first time this function runs, deltaT might be large
auto nowTime = imu->getPrevIMUDataReceivedTime(); // Units of us
auto dt = (nowTime - lastTime) / 1e6f; // Want units of s
// auto nowTime = imu->getPrevIMUDataReceivedTime(); // Units of us
// auto dt = (nowTime - lastTime) / 1e6f; // Want units of s

// z is 0 since we're moving on the x-y plane and gravity affects z
Vector3f nowAcc{imu->getAx(), imu->getAy(), 0.0f};
Vector3f nowDisp = lastDisp + lastVel * dt + lastAcc * dt * dt / 2.0f;
Vector3f nowVel = lastVel + (lastAcc + nowAcc) * dt / 2.0f;
// // z is 0 since we're moving on the x-y plane and gravity affects z
// Vector3f nowAcc{imu->getAx(), imu->getAy(), 0.0f};
// Vector3f nowDisp = lastDisp + lastVel * dt + lastAcc * dt * dt / 2.0f;
// Vector3f nowVel = lastVel + (lastAcc + nowAcc) * dt / 2.0f;

// Update by copy
lastTime = nowTime;
lastAcc = nowAcc;
lastVel = nowVel;
lastDisp = nowDisp;
// // Update by copy
// lastTime = nowTime;
// lastAcc = nowAcc;
// lastVel = nowVel;
// lastDisp = nowDisp;

// Return
*velocity = nowVel;
*displacement = nowDisp;
// // Return
// *velocity = nowVel;
// *displacement = nowDisp;

return imu->getImuState() == ImuInterface::ImuState::IMU_CALIBRATED;
// return imu->getImuState() == ImuInterface::ImuState::IMU_CALIBRATED;
return true;
}

} // namespace subsystems::odometry
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ChassisDisplacementObserver : public ChassisDisplacementObserverInterface
mutable Vector3f lastVel; // m/s
mutable Vector3f lastDisp; // m
mutable uint32_t lastTime; // ms
mutable uint32_t prevTime = 0;
};
} // namespace subsystems::odometry

Expand Down