Skip to content

Added Kalman Filter + Minor Motion Control Changes #3420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

mkhlb
Copy link
Contributor

@mkhlb mkhlb commented Jan 11, 2025

Please fill out the following before requesting review on this PR

Description

Many changes were done.

Implemented a kalman filter for thunderloop that composes IMU data to track robot position more accurately.

Testing Done

Moved robot

Tested IMU variance, got about 0.0019 deg variance, expected about 0.0016 deg.

Resolved Issues

Length Justification and Key Files to Review

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

Comment on lines 20 to 23
map<uint32, Angle> robot_orientations = 5;

uint64 sequence_number = 4;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
map<uint32, Angle> robot_orientations = 5;
uint64 sequence_number = 4;
}
uint64 sequence_number = 4;
map<uint32, Angle> robot_orientations = 5;
}

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work cleaning this up, left a few more comments

{
if (!initialized_)
{
return std::nullopt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should have a LOG(INFO) here telling people that the IMU is uninitialized

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump @mkhlb

int ret = ioctl(file_descriptor_, I2C_SLAVE_FORCE, 0x6b);
if (ret < 0)
{
return std::nullopt;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also LOG(INFO) that this SPI operation failed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump @mkhlb

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes to this file seem accidental

Comment on lines +104 to 117
reserved 5;
oneof primitive
{
MovePrimitive move = 1;
StopPrimitive stop = 2;
DirectControlPrimitive direct_control = 3;
}
Angle orientation = 7;

// Sequence number for the primitive
uint64 sequence_number = 4;

reserved 5;

// Epoch timestamp when primitives were assigned
Timestamp time_sent = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you make these in order?

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, some minor nits and it looks like you have some failing tests in CI

Comment on lines +114 to +121
auto least_significant =
int16_t(i2c_smbus_read_byte_data(file_descriptor_, YAW_LEAST_SIG_REG));
auto most_significant =
int16_t(i2c_smbus_read_byte_data(file_descriptor_, YAW_MOST_SIG_REG));


auto foo = (int16_t)(most_significant << 8);
auto full_word = foo + least_significant;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use auto. Use the types directly. Especially when using bit shift operators, it becomes very difficult to predict how the number will get interpreted.

int16_t(i2c_smbus_read_byte_data(file_descriptor_, YAW_MOST_SIG_REG));


auto foo = (int16_t)(most_significant << 8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto foo = (int16_t)(most_significant << 8);
int16_t foo = static_cast<int16_t>(most_significant << 8);

@@ -238,6 +247,10 @@ void Thunderloop::runLoop()
// Save new primitive
primitive_ = new_primitive;

auto orientation_msg = primitive_.orientation();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid auto unless it's a really long type name. It makes the code harder to read for newer members (especially since we have multiple "angle"-ish types in the codebase)

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants