Skip to content

Commit 59f2c07

Browse files
committed
Merge branch 'odometry_cv' of https://github.com/ut-ras/robomaster into odometry_cv
2 parents 17a933b + 24f0259 commit 59f2c07

File tree

10 files changed

+102
-17
lines changed

10 files changed

+102
-17
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/discord.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/robomaster.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ut-robomaster/src/robots/standard/standard_control.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class StandardControl : CommonControlManual
1111
CommonControlManual::initialize();
1212

1313
agitator.initialize();
14+
odometry.initialize();
1415
drivers->commandScheduler.registerSubsystem(&agitator);
16+
drivers->commandScheduler.registerSubsystem(&odometry);
1517

1618
drivers->commandMapper.addMap(&leftMouseDown);
1719
drivers->commandMapper.addMap(&leftSwitchUp);
@@ -20,6 +22,7 @@ class StandardControl : CommonControlManual
2022
private:
2123
// Subsystems
2224
AgitatorSubsystem agitator{drivers, &flywheel, AGITATOR};
25+
OdometrySubsystem odometry{drivers, &chassis, &turret};
2326

2427
// Commands
2528
CommandAgitatorContinuous rotateAgitator_LeftMouse{drivers, &agitator, BarrelId::STANDARD1};
Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#include "subsystems/odometry/observer_displacement.hpp"
2+
#include "tap/architecture/clock.hpp"
3+
4+
/*
5+
* Notes:
6+
* https://gitlab.com/aruw/controls/aruw-mcb/-/tree/develop/aruw-mcb-project/src/aruwsrc/algorithms/odometry?ref_type=heads
7+
* */
28

39
namespace subsystems::odometry
410
{
@@ -20,7 +26,26 @@ bool ChassisDisplacementObserver::getVelocityChassisDisplacement(
2026
modm::Vector3f* const velocity,
2127
modm::Vector3f* const displacement) const
2228
{
23-
bmi088::Bmi088* imu = &drivers->bmi088;
29+
uint32_t currTime = tap::arch::clock::getTimeMicroseconds();
30+
if (prevTime != 0)
31+
{
32+
modm::Vector3f myv = chassis->measureVelocity();
33+
velocity->set(myv.x, myv.y, myv.z);
34+
35+
// velocity.set(chassisRelVel.x, chassisRelVel.y);
36+
// displacement->move(tickDisp);
37+
float deltaT = (static_cast<float>(currTime - prevTime)) / 1'000'000.0f;
38+
modm::Vector3f myDisp = lastDisp + *velocity * DT;
39+
lastDisp = myDisp;
40+
displacement->set(myDisp.x, myDisp.y, myDisp.z);
41+
42+
// myDisp = *displacement + *velocity * (static_cast<float>(currTime - prevTime) / 1'000'000.0f);
43+
// displacement->set(myDisp * (static_cast<float>(currTime - prevTime) / 1'000'000.0f));
44+
// displacement += velocity * (static_cast<float>(currTime - prevTime) / 1'000'000.0f);
45+
}
46+
47+
prevTime = currTime;
48+
// bmi088::Bmi088* imu = &drivers->bmi088;
2449

2550
// Attempt integration with Velocity Verlet
2651
// a(t) = last acceleration, a(t + dt) = current acceleration
@@ -29,25 +54,26 @@ bool ChassisDisplacementObserver::getVelocityChassisDisplacement(
2954

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

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

40-
// Update by copy
41-
lastTime = nowTime;
42-
lastAcc = nowAcc;
43-
lastVel = nowVel;
44-
lastDisp = nowDisp;
65+
// // Update by copy
66+
// lastTime = nowTime;
67+
// lastAcc = nowAcc;
68+
// lastVel = nowVel;
69+
// lastDisp = nowDisp;
4570

46-
// Return
47-
*velocity = nowVel;
48-
*displacement = nowDisp;
71+
// // Return
72+
// *velocity = nowVel;
73+
// *displacement = nowDisp;
4974

50-
return imu->getImuState() == ImuInterface::ImuState::IMU_CALIBRATED;
75+
// return imu->getImuState() == ImuInterface::ImuState::IMU_CALIBRATED;
76+
return true;
5177
}
5278

5379
} // namespace subsystems::odometry

ut-robomaster/src/subsystems/odometry/observer_displacement.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
#define SUBSYSTEMS_ODOMETRY_OBSERVER_DISPLACEMENT_HPP_
33

44
#include "tap/algorithms/odometry/chassis_displacement_observer_interface.hpp"
5-
65
#include "subsystems/chassis/chassis_subsystem.hpp"
76

87
#include "drivers.hpp"
98

9+
1010
namespace subsystems::odometry
1111
{
12+
1213
using modm::Vector3f;
1314
using tap::algorithms::odometry::ChassisDisplacementObserverInterface;
1415
using namespace tap::communication::sensors::imu;
@@ -28,6 +29,7 @@ class ChassisDisplacementObserver : public ChassisDisplacementObserverInterface
2829
mutable Vector3f lastVel; // m/s
2930
mutable Vector3f lastDisp; // m
3031
mutable uint32_t lastTime; // ms
32+
mutable uint32_t prevTime = 0;
3133
};
3234
} // namespace subsystems::odometry
3335

ut-robomaster/src/subsystems/odometry/odometry_subsystem.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@ void OdometrySubsystem::initialize() {};
2121

2222
void OdometrySubsystem::refresh()
2323
{
24+
Vector3f lastAcc; // m/s^2
25+
2426
setAmputated(!hardwareOk());
2527
if (!isAmputated())
2628
{
2729
chassisTracker.update();
2830
}
31+
32+
// Vector3f velocity = chassis->measureVelocity(); // m/s^2
33+
// chassisDisplacement.getVelocityChassisDisplacement(&velocity, &lastAcc);
34+
35+
if (refreshTimer.execute())
36+
{
37+
38+
drivers->rtt.plot(3, getPosition().getX()); //problematic function
39+
drivers->rtt.plot(2, getPosition().getY()); //problematic function
40+
drivers->rtt.plot(1, getLinearVelocity().getX());
41+
}
2942
}
3043

3144
bool OdometrySubsystem::hardwareOk() { return chassis->hardwareOk() && turret->hardwareOk(); }

ut-robomaster/src/subsystems/odometry/odometry_subsystem.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "tap/algorithms/odometry/odometry_2d_interface.hpp"
55
#include "tap/algorithms/odometry/odometry_2d_tracker.hpp"
66
#include "tap/control/subsystem.hpp"
7+
#include "tap/architecture/periodic_timer.hpp"
8+
79

810
#include "modm/math/geometry.hpp"
911
#include "modm/math/geometry/location_2d.hpp"
@@ -48,5 +50,6 @@ class OdometrySubsystem : public Subsystem
4850
ChassisDisplacementObserver chassisDisplacement;
4951
ChassisWorldYawObserver chassisYaw;
5052
Odometry2DTracker chassisTracker;
53+
tap::arch::PeriodicMilliTimer refreshTimer{100};
5154
};
5255
} // namespace subsystems::odometry

0 commit comments

Comments
 (0)