-
Notifications
You must be signed in to change notification settings - Fork 38
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
✨Feature/redundant imu #256
base: main
Are you sure you want to change the base?
Conversation
…od imu collection and bad one, allowing for imus to swithc between the two. Also added deconstructor. Needs testing from jess for memory leaks, and for threshold tuning (constant defined in util). Big change so matters a lot with teams.
…code looks fine on glance.
…(forgot and Imu is not sortable/comparable). now it compiles.
Merge pull request #262 from EZ-Robotics/bug/make-right-swings-work
Merge pull request #267 from EZ-Robotics/dev
Ran clangd Fixed typos Removed multiple imu support from deprecated constructors Added "get" to multiple scalers
Ran some example autos with 1 IMU and code still works as expected |
Unplugging port 20 while looking at the current pose on the blank page does successfully switch angle over to the second IMU in port 21. There is a slight lag where the IMU doesn't update anything for a second, then the orange "Inertial Sensor Disconnected" vexos warning comes up, and once that is dismissed angle updates as expected. But after it switches, x and y are |
I tested unplugging port 20 and plugging it in very quickly, I did it within a timeframe that the orange warning screen did not appear. Once it was plugged in the IMU was drifting considerably. I went into the devices menu with this program still running and confirmed port 20 is drifting and port 21 is stable, but the code is using port 20 as the "good" IMU. Disconnects aren't being found quick enough right now |
I ran this code to figure out what can be done to detect disconnects. pros::Imu testimu1(20);
pros::Imu testimu2(21);
std::vector<pros::Imu> testimu = {testimu1, testimu2};
/**
* Runs the operator control code. This function will be started in its own task
* with the default priority and stack size whenever the robot is enabled via
* the Field Management System or the VEX Competition Switch in the operator
* control mode.
*
* If no competition control is connected, this function will run immediately
* following initialize().
*
* If the robot is disabled or communications is lost, the
* operator control task will be stopped. Re-enabling the robot will restart the
* task, not resume it from where it left off.
*/
void opcontrol() {
// This is preference to what you like to drive on
chassis.drive_brake_set(MOTOR_BRAKE_COAST);
while (true) {
// Gives you some extras to make EZ-Template ezier
ez_template_extras();
printf("Status: {");
for (int i = 0; i < testimu.size(); i++) {
if (i != 0) printf(" - ");
printf("%i", testimu[i].get_status());
}
printf("} ");
printf("Value: {");
for (int i = 0; i < testimu.size(); i++) {
if (i != 0) printf(" - ");
printf("%.2f", testimu[i].get_rotation());
}
printf("}\n");
chassis.opcontrol_tank(); // Tank control
// chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
// chassis.opcontrol_arcade_standard(ez::SINGLE); // Standard single arcade
// chassis.opcontrol_arcade_flipped(ez::SPLIT); // Flipped split arcade
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade
// . . .
// Put more user control code here!
// . . .
pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME
}
} With this code I did a few tests. This test has me unplugging the IMU in and never plugging it back in. You can see it disconnects where the value is In this test, I unplugged the IMU and plugged it back in maybe half a second later. The length of time it was unplugged for was not long enough for the disconnected screen to appear. In both tests, the IMU comes back and gives data again but it drifts a considerable amount after reconnecting, and it sets its state to calibrate. I think something in the data above should be used to determine if the IMU is disconnected or not. With how IMUs can silently come back and pretend like nothing is wrong, I think every IMU needs to be checked every iteration, intsead of just the current IMU like it is now. |
…disconnects. (As long as the two values are not equal to each other, won't disconnect). Needs to be tested. Removed the bad imu implementation, waiting on meeting, to be able to add encoders to the redundancy feature.
…lement get_encoder_angle, and odom one too. Also need to figure out how to set priority. After meeting with Jess, will fine tune and review design choices.
…on, and needs to be tested too. Checked all the imu and removed faulty ones. Need to be tested with prev_imu_values made. Need to see if all implementation of get_imu_angle was swapped with drive_get_angle.
I had false positives happen with 10 and 20ms, but I could not replicate it with 30ms. To be safe this is 50ms. The calibrate IMU function can remove good IMUs if one started unplugged.
…od imu collection and bad one, allowing for imus to switch between the two. Also added deconstructor. Needs testing from jess for memory leaks, and for threshold tuning (constant defined in util). Big change so matters a lot with teams.
Summary and Motivation:
These changes needed to be to allow for redundant imu support, switching the focused imu to good imus while bad imus disconnect or become invalid. I did clean up the ptr to the bad imus once proven always bad. Also switching from good the bad was handled with time and pros::millis(), which should be precise enough. Later on a change to unique and shared ptrs, would probably be needed but this is a quick, but sound fix for now. Also added inputting for scaling.
References (optional):
Test Plan:
Test for memory leaks on deconstructor and bad imus or fully disconnected imus, and see if the switch works. Tests the scaling make sure that works, and the mapping does too. I made map private, but it might be better to make public. Not sure. Test the scaling, memory leeks, switching back and forth multiple times, and maybe even log the switching.
Download the template for this pull request:
Note
This is auto generated from
Add Template to Pull Request