Autonomous TranslationΒΆ
Translation is quite simple. Here is an example.
Just use setTarget
to set the target position.
controller->setTarget({XPOSE_in, YPOSE_in, ZPOSE_deg});
Since the controller is asynchronous, you can use waitUntilSettled
to block other actions
until the target is reached.
controller->setTarget({XPOSE_in, YPOSE_in, ZPOSE_deg});
controller->waitUntilSettled();
The code snippet above is equivalent to the following:
controller->setTarget({XPOSE_in, YPOSE_in, ZPOSE_deg}, true);
If you want to move while doing something else (ex. raising a lift to a certain height), you can use the do something like this:
controller->setTarget({XPOSE_in, YPOSE_in, ZPOSE_deg});
while(true) {
LIFT_MOVEMENT();
pros::delay(10);
}
controller->waitUntilSettled();
Here is a complete example:
1/** Create Okapi OdomChassisController - used as a base for HolonomicLib's chassis controller */
2std::shared_ptr<OdomChassisController> chassis = ChassisControllerBuilder()
3 .withMotors(
4 1, // Top left
5 -2, // Top right (reversed)
6 -3, // Bottom right (reversed)
7 4 // Bottom left
8 )
9 .withSensors(
10 ADIEncoder{'A', 'B'}, // left encoder in ADI ports A & B
11 ADIEncoder{'C', 'D', true}, // right encoder in ADI ports C & D (reversed)
12 ADIEncoder{'E', 'F'} // middle encoder in ADI ports E & F
13 )
14 // specify the tracking wheels diameter (2.75 in), track (7 in), and TPR (360)
15 // specify the middle encoder distance (1 in) and diameter (2.75 in)
16 .withOdometry({{2.75_in, 7_in, 1_in, 2.75_in}, quadEncoderTPR})
17 .buildOdometry();
18
19/** Create HolonomicLib AsyncHolonomicChassisController - controls chassis movement */
20std::shared_ptr<AsyncHolonomicChassisController> controller =
21 AsyncHolonomicChassisControllerBuilder(chassis)
22 // PID gains (must be tuned for your robot)
23 .withDistGains(
24 {0.05, 0.0, 0.00065, 0.0} // Translation gains
25 )
26 .withTurnGains(
27 {0.05, 0.0, 0.00065, 0.0} // Turn gains
28 )
29 .build();
30
31/** Opcontrol: moves chassis to a target position */
32void opcontrol() {
33 controller->setTarget({XPOSE_in, YPOSE_in, ZPOSE_deg}, true);
34}
More information regarding the HolonomicLib API can be found here