Hi all, need some help with gear ratios in OkapiLib:
So I set my gear ratio to .withDimensions({AbstractMotor::gearset::green, (48.0/72.0)}, {{4_in, 12.0_in}, imev5GreenTPR})
And move distance, drive to point, and turn to angle works accurately (drives 100cm, turns 90 degrees).
However, when calling get state, after moving 1m, the brain screen says it moved x=0.67m (0.6772/48) (ie multiply it by external gear ratio and it is correct)
Same for turning - it says turned 60 degrees - 6072/48=90
- shouldn’t OkapiLib odom take into account gear ratio, or did I do something wrong?
When trying the 2d motion profiling, the movements are completely off (under turns, under drives, etc) - is this something to do with this gear configuration? Many thanks for everyone’s help.
Code:
init
okapichassis = okapi::ChassisControllerBuilder()
.withMotors(
{3, 4}, // Left motors are 3 & 4
{1, 2} // Right motors are 1 & 2
)
// Green gearset, external ratio of (48.0 / 72.0), 4 inch wheel diameter, 13 inch wheel track
.withDimensions({AbstractMotor::gearset::green, (48.0/72.0)}, {{4_in, 12.0_in}, imev5GreenTPR})
.withMaxVelocity(100)
.withOdometry()
/*.withGains(
{0.003, 0, 0.0002}, // Distance controller gains
{0.004, 0, 0.0002} // Turn controller gains
) */
//.build();
.buildOdometry();
profileController = AsyncMotionProfileControllerBuilder()
.withLimits({
1.0, // Maximum linear velocity of the Chassis in m/s
2.0, // Maximum linear acceleration of the Chassis in m/s/s
10.0 // Maximum linear jerk of the Chassis in m/s/s/s
})
.withOutput(okapichassis)
.buildMotionProfileController();
print remote controller screen task:
okapi::OdomState current_state = okapichassis->getState();
std::string tmp1, tmp2, tmp3,tmp4; //max 2 values for each row - temp strings for combining strings
tmp1 = current_state.str();
tmp2 = tmp1.substr(12,4)+", "+tmp1.substr(22,4)+", "+tmp1.substr(36,4);
controller_master.print(1,0,tmp2.c_str());
pros::delay(70);
auton:
okapichassis->setState({0_m, 0_m, 0_deg});
okapichassis-> moveDistance(1_m);
okapichassis-> turnAngle(90_deg);
profileController->generatePath({
{0_m, 0_m, 0_deg}, // Profile starting position, this will normally be (0, 0, 0)
{1_m, 0_m, 90_deg},
{0_m, 0_m, 90_deg}}, // The next point in the profile, 3 feet forward
"A" // Profile name
);
profileController->setTarget("A");
profileController->waitUntilSettled();