Issue: attempting to reset an Okapilib rotation sensor works for a few milliseconds, but after that returns to its original value.
Relevant parts of code:
RotationSensor odomL(11);
RotationSensor odomR(12, true);
shared_ptr<OdomChassisController> chassis = ChassisControllerBuilder()
.withMotors(1, 2, 3, 4) //I don't use these anyways for now
.withDimensions(AbstractMotor::gearset::green, {{4_in, 10_in /*doesn't matter*/}, imev5GreenTPR})
.withSensors(odomL, odomR)
.withOdometry({{2.75_in, 2.25_in}, 360 /*?*/})
.buildOdometry();;
void initialize() {
odomL.reset();
odomR.reset();
}
void opcontrol() {
chassis->setState({0_in, 0_in, 0_deg});
while (1) {
auto state = chassis->getState();
cout << state.x.convert(inch) << " " << state.y.convert(inch) << " " << state.theta.convert(degree) << " | " << odomL.get() << " " << odomR.get() << "\n";
pros::delay(5);
}
}
The output:
0 0 0 | 0 -0
0 0 0 | 0 -0
0 0 0 | 0 -0
0 0 0 | 0 -0
0 0 0 | 0 -0
0 0 0 | 0 -0
0 0 0 | 0 -0
0 0 0 | 222.45 -212.34
0 0 0 | 222.45 -212.34
-0.0258316 0.0280807 265.222 | 222.45 -212.34
and from there on, all of the lines are -0.0258316 0.0280807 265.222 | 222.45 -212.34 (I’m not moving the sensors). This behavior isn’t consistent though, and sometimes it prints out 2.69346 2.64069 265.222 | 222.53 -212.34 (the slightly different left odom value probably comes from the fact that I bumped the robot, but doesn’t change anything). I believe these are the only two “options”. I used to think it alternated but that doesn’t actually seem to be the case.
Notes:
Moving odomL.reset(); odomR.reset(); to the start of opcontrol() (right before setting the state) doesn’t change anything.
Changing the initial state more or less works as you’d expect: for example, if we start with 5_in for the x-value instead, the states printed out will either have x-value 7.64... or 4.97.... Degrees work the same way.
Both the rotation sensor values and the odometer state seem to update accurately when I do move the robot.
Anyone know why this is occurring? (Also, while we’re here: is using 360 in the .withOdometry() correct? Edit: looks like 360 is correct?)